Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Provide a generic interface to serialize and deserialize presenters. #50

Closed
wants to merge 4 commits into from
Closed

Provide a generic interface to serialize and deserialize presenters. #50

wants to merge 4 commits into from

Conversation

vRallev
Copy link
Contributor

@vRallev vRallev commented Dec 19, 2016

This is useful to recreate presenters after a process has died.

…This is useful to recreate presenters after a process has died.
@vRallev
Copy link
Contributor Author

vRallev commented Dec 19, 2016

I know that you haven't decided what to do with #39, yet. But this would be a good compromise in my opinion. If we want to use your library in our app, then we need a solution for this issue. And I'd hate to fork it.

@vRallev vRallev mentioned this pull request Dec 19, 2016
@@ -52,7 +52,7 @@ public TiPresenter recover(final String id) {
}

public String safe(@NonNull final TiPresenter presenter) {
final String id = generateId(presenter);
final String id = presenter.getId();
TiLog.v(TAG, "safe presenter with id " + id + " " + presenter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it better to have the presenter generate the id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's the presenter's ID. Otherwise it would be an ID for a presenter used by the PresenterSavior. I'm using the ID at other places.

* a rare use case the default value is {@code null} and presenters aren't restored.
* @param serializer An implementation which can serialize and deserialize any presenter.
*/
public Builder setPresenterSerializer(TiPresenterSerializer serializer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the serializer as part of the configuration is interesting, I'll have to think about it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the ideal place for me. It's pretty handy with the global config and optional for tests.

…resenter

# Conflicts:
#	thirtyinch/src/main/java/net/grandcentrix/thirtyinch/TiConfiguration.java
#	thirtyinch/src/main/java/net/grandcentrix/thirtyinch/internal/PresenterSavior.java
#	thirtyinch/src/main/java/net/grandcentrix/thirtyinch/internal/TiActivityDelegate.java
#	thirtyinch/src/main/java/net/grandcentrix/thirtyinch/internal/TiFragmentDelegate.java
…resenter

# Conflicts:
#	thirtyinch/src/main/java/net/grandcentrix/thirtyinch/internal/PresenterSavior.java
#	thirtyinch/src/main/java/net/grandcentrix/thirtyinch/internal/TiActivityDelegate.java
#	thirtyinch/src/main/java/net/grandcentrix/thirtyinch/internal/TiFragmentDelegate.java
* a {@link TiPresenter} should be restored, after a process has died, but the UI component is
* being recreated.
*/
public interface TiPresenterSerializer {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@passsy After reviewing all the changes in the 0.8.0 version I think this interface can be removed and the new TiPresenterSavior could be used instead. After that it would be possible for me to release the module in #51 separately and I could finally stop working on the fork.

The only changes that would be necessary to make this work is to add the TiPresenterSavior as argument in the TiConfiguration. This way I get a chance to replace the default savior.

The 2nd change that's necessary is to modify the recover method in the savior interface TiPresenter recover(String presenterId, @NonNull Object host);. Here a third parameter would be necessary that you've already implemented: TiPresenterProvider. In most cases that would be the TiFragment or TiActivity. That would give me the option to construct a new presenter in case it can be recovered after the process died.

Would that be possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both changes are safe, because nothing of that was exposed to the public API, yet. Do you want me to create a different PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dang, I just realized that it's not necessary to make any changes in the config class, because in order to access the config, you need to create a presenter first.

There's no way to replace the savior in the delegate from TiFragment or TiActivity at the moment. I think it's better to add a new provider interface for the savior and the default implementation delegate to the PresenterSavior. Although a global config would be nicer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into presenter serialisation for the next release and we'll find a way to provide you an API.
The PresenterSavior is the new heart of this library. I don't think the savior will be replaceable with a third party impl because small mistakes could lead to major leaks. Instead I'm thinking about APIs for the savior to control the presenter store. Haven't thought this through completely but you get the direction.

@passsy
Copy link
Contributor

passsy commented May 7, 2017

I still don't get why a new API is required. I implemented saving presenter state with android-state in a few @minutes. (Can be tested with Developer options -> Apps -> Background process limit -> set to "No background processes")

see master...feature/save_state

This implementation could be moved into a BasePresenter/BaseActivity in your project when you want to use the @State annotation everywhere. A fork is not required.

What is missing?

@vRallev
Copy link
Contributor Author

vRallev commented May 7, 2017

This would be tied to the activity lifecycle again. That's not what you want in case a longer operation is going on. Then there wouldn't be a good hook to restore the presenter.

@vRallev vRallev closed this Jun 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants