Add saving and restoring state in SceneView

This commit is contained in:
seven332 committed 2017-05-13 20:28:35 +08:00
1 parent 2c2a2c2598
commit 24da35d8b4
2 files changed
+40

No files matched your search

@@ -20,6 +20,7 @@ package com.hippo.ehviewer.scene;
* Created by Hippo on 5/11/2017.
*/
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
@@ -133,4 +134,16 @@ public abstract class MvpScene<P extends ScenePresenter, V extends SceneView>
presenter.destroy();
presenter = null;
}
@Override
protected void onSaveViewState(@NonNull View view, @NonNull Bundle outState) {
super.onSaveViewState(view, outState);
this.view.saveState(outState);
}
@Override
protected void onRestoreViewState(@NonNull View view, @NonNull Bundle savedViewState) {
super.onRestoreViewState(view, savedViewState);
this.view.restoreState(savedViewState);
}
}
@@ -23,6 +23,7 @@ package com.hippo.ehviewer.view;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -143,6 +144,20 @@ public abstract class SceneView<P extends PresenterInterface> implements ViewInt
view = null;
}
/**
* Saves state for this view.
*/
public final void saveState(@NonNull Bundle outState) {
onSaveState(outState);
}
/**
* Restores state for this view.
*/
public final void restoreState(@NonNull Bundle savedViewState) {
onRestoreState(savedViewState);
}
/**
* Creates this actual {@code View}.
*/
@@ -190,4 +205,16 @@ public abstract class SceneView<P extends PresenterInterface> implements ViewInt
*/
@CallSuper
protected void onDestroy() {}
/**
* Called when saving state of the view.
*/
@CallSuper
protected void onSaveState(@NonNull Bundle outState) {}
/**
* Called when restoring state of the view.
*/
@CallSuper
protected void onRestoreState(@NonNull Bundle savedViewState) {}
}