Open MFlisar opened 7 years ago
I think the way you're doing it makes lots of sense. Having a few views that implement an IsReady
interface of some kind, then creating ControllerChangeHandler
s that handle those should work very well.
If you're looking to separate business logic from your views and want to keep the isDataReady
-type calls out of the views, you can always do this from your controllers. There's an onChangeStarted
callback that passes in the ControllerChangeHandler
being used. Perhaps you could use this method to pass a listener to your change handler.
That's an interesting idea, instead of passing the Controller
to the ChangeHandler
the controller could pass data to it via the onChangeStarted
. I did not think about that yet...
But still, I don't see anything that speaks against passing the controller to the ChangeHandler
as well... or to keep the interface untouched, extend the ChangeHandler
base class to have a function like setController(controller)
which sets and unsets the controller appropriately, so that I can access the controller from within the ChangeHandler
.
This could be used to have direct access to a DataBinding
object that is in the controller as well (as I was suggesting something about that in another issue).
I don't like to split my code between Controller
and ChangeHandler
too much, having access to the controller would make this easier...
I've implemented following workflow to start animations as soon as my view is ready:
I've sub classed an
RecyclerView
adapter for the simple reason of adding the ability to add a custom listener like following:RecyclerView
when the controller is created, so that an adapter is always attached to theRecyclerView
onPreDraw
oronGlobalLayout
or similar... I manually notify the listener somewhere else when I know all items that are needed for the animation are ready. I need this, because my animation can only start as soon as some views of theRecyclerView
have finished inflating AND have finished loading their images.This works, but it looks ugly. It forces me to use a custom view (because the
ChangeHandler
only get's the from and the toView
and I must use something offered by thoseViews
).Is there any more beautiful way to do that? Or is this really the default way and wanted so by design? I think something like following would look nicer:
ChangeHandler
and register my listeners in the controller (currently I can't access the controller from within theChangeHandler
, can I?)I think it would really make sense to pass on the controllers to
ChangeHandler.performChange
so that the controllers can be used inside theChangeHandler
. Does anything speak against this?