ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Make UI components DataBinding friendly

Open zishanj opened this issue 6 years ago • 35 comments

I am trying to use custom player controls and for this purpose I wish to use databinding with my viewmodel. Is it possible to set controller_layout_id of PlayerControlView programmatically so I can attach it with my viewmodel?

zishanj avatar Jan 21 '19 13:01 zishanj

I don't think this is possible. I'm somewhat unclear exactly how this works though. Is it not possible for you to set it in layout XML?

ojw28 avatar Jan 21 '19 17:01 ojw28

with databinding we can use something like this:

MyPlayerBinding myPlayerBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.my_player, myActivityBinding.myPlayerControl, false);
myActivityBinding.myPlayerControl.setControllerLayoutId(myPlayerBinding.getRoot());

We only need public access to layout property controller_layout_id so we can set it programmatically. Then we can access viewmodel methods, properties in our layout view. In above example MyPlayerBinding is automatically generated by DataBinding based on our my_player layout filename. myPlayerControl is id for ExoPlayer2.ui.PlayerControlView.

zishanj avatar Jan 21 '19 18:01 zishanj

I guess what I don't understand, is why do you need to be setting the controller layout programmatically? Why isn't the thing you inflate just the whole player view, which I think would avoid you having this problem? It's also unclear how the need to do this is directly related to databinding. It seems almost orthogonal?

ojw28 avatar Jan 21 '19 19:01 ojw28

Without databinding I have to manually use id of views in activity to enable, disable or set listeners etc. or may be have to use another third party lib like ButterKnife. With databinding its very easy to manage the layout from viewmodel based on your specific logic especially when you use MVVM design pattern.

zishanj avatar Jan 21 '19 19:01 zishanj

Yes, but why can't you inflate a whole player view using DataBindingUtil? That's what I don't understand.

ojw28 avatar Jan 21 '19 19:01 ojw28

Entire PlayerControlView still does not give you access to its child layout which is set using controller_layout_id in xml. Using databinding I can only access the parent PlayerControlView not its child controller layout. For this purpose I have to set databinding separately for its child controller.

zishanj avatar Jan 21 '19 19:01 zishanj

Oh right, the problem is that the controller layout is inflated internally in PlayerControlView, and so isn't inflated by DataBindingUtil.inflate. Is that correct?

ojw28 avatar Jan 21 '19 19:01 ojw28

yes... we can't use viewmodel inside child layout and have to inflate it separately.

zishanj avatar Jan 21 '19 19:01 zishanj

Got it. I don't think that's possible currently, I'm afraid. I'll mark this as an enhancement, but it will be considered low priority since we haven't seen anyone else asking for it.

ojw28 avatar Jan 21 '19 19:01 ojw28

I think this good question and make high priority since google has move forward to use data binding. Currently, adroid studio also already upgrade which are use data binding as well.

hafiz013 avatar Jan 22 '19 07:01 hafiz013

It would be very helpful to set it programmatically and show different controls depending on some conditions.

janbolat avatar Jan 29 '19 09:01 janbolat

I would also vote for High Priority as it is really basic feature that should be included.

musooff avatar Feb 18 '19 08:02 musooff

Voting for High Priority, as it is required for use cases where we need to programmatically create PlayerView based on some conditions, and need to attach different controllers on them.

arpanbag001 avatar Dec 15 '19 08:12 arpanbag001

@ojw28 Any update on this issue? its 2020 now. :)

zishanj avatar Feb 10 '20 18:02 zishanj

I also would like to see this. Most Android apps are going to MVVM and if we want to use data binding along with custom UI controls, this is almost required.

BlaineOmega avatar May 18 '20 19:05 BlaineOmega

any leads guys?

thealteria avatar Jun 16 '20 20:06 thealteria

Must have in 2020. We need this ASAP!

HE-LU avatar Jun 25 '20 10:06 HE-LU

So now that Kotlin Synthetics are getting deprecated (:c) and will no longer be in use past September 2021, we really need this ASAP!

sc941737 avatar Nov 27 '20 10:11 sc941737

Any update on this issues??

yeyintkoko1788 avatar Dec 15 '20 13:12 yeyintkoko1788

Still no way to use databinding with exoplayer controls??

AlexDundar avatar Feb 11 '21 14:02 AlexDundar

we should have an option to set the custom controller programmatically by now. Its 2021 already

ashirmehmood1996 avatar Feb 12 '21 06:02 ashirmehmood1996

it looks like Google has forgotten about us :(

schnaps1981 avatar Mar 30 '21 10:03 schnaps1981

Here is how I'm using with viewBinding.

  1. Add an ID to the root tag of custom controls
<androidx.constraintlayout.widget.ConstraintLayout 
    android:id="@+id/dragon_exo_control_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    >

    <TextView
        android:id="@+id/hello"
        ... 
        />

</androidx.constraintlayout.widget.ConstraintLayout>

Next In your activity onCreate()

YourBindingControlClass exoControlBinding = YourBindingControlClass.bind(findViewByID(R.id.dragon_exo_control_layout));

// Then use it like
exoControlBinding.setText("Hello, World !");

electrodragon avatar Apr 22 '21 16:04 electrodragon

any news?

schnaps1981 avatar Sep 28 '21 10:09 schnaps1981

Please fix this. It should be high priority

mikewalkerjr avatar Oct 01 '21 22:10 mikewalkerjr

Come on, guys, please fix this :(

victorraft avatar Oct 14 '21 16:10 victorraft

It's been 2022 and by the end of the year, the synthetic binding will vanish from an android ecosystem. Please fix this asap.

SurajBahadur avatar Jun 28 '22 05:06 SurajBahadur

View binding please. Another five months gone.

theBlbDan avatar Nov 02 '22 00:11 theBlbDan

Any update on data binding for custom UI?

in kotlin 1.8 synthetics will be deleted

schnaps1981 avatar Nov 30 '22 10:11 schnaps1981