Closed RiccardoM closed 4 years ago
@RiccardoM Sounds good, but
EasyMVP calls loaderManager.initLoader(id,..)
in each Activity, Fragment , View or Conductor Controller.
By default for each view, the id
is a hard coded generated integer (LOADER_ID.incrementAndGet()
), For example loaderManager.initLoader(500,..)
, so loader manager can distinguish assigned loader to this view from others.
In some situation that we need multiple instances of a same view class in an Activity or Fragment, we need to assign unique id to each instance. for example an activity has two MyCustomView
as its children, So we should assign for example id = 100
to first view and id = 200
to second one. But important thing is when the activity is recreated we need to assign id = 100
to first view again and id = 200
to second one too, So loader can preserve Presenter.
So who can we find proper ids in configuration changes when we use multiple instances of a class?
Easiest solution is using @PresenterId
, So we can change our initLoader
method to loaderManager.initLoader(view.presenterId,..)
So as you see UUID will not work. Maybe this solution will work:
if(alreadyHasIdInBundle()) {
loaderManager.initLoader(IdFromBundle(),..)
} else {
id = generateAUniqueId()
putIdIntoBundle(id)
loaderManager.initLoader(id,..)
}
From the last comment on #28:
What about using UUIDs as the presenteres' id?
Instead of passing the presenter id to its constructor and then associating it to the
@PresenterId
annotated object, a solution I came up with would be to have the same annotation (i.e.@Presenter
) with a new boolean parameter (let's saykeepInstance
) that will act as follows:keepInstance
is set totrue
, no action will be taken, and everything will be the same;keepInstance
is set tofalse
, the presenter id will be generated each time that a new instance of the view is created, usingUUID.randomUUID().toString().replace("-", "");
I think that the resulting code inside the generator class would be something along the lines of this:
This method shouldn't have problem with custom views or stuff like that, as the UUID is indipendent from the object that creates it.
What are your thoughts on this solution @SaeedMasoumi?