From 24da35d8b4e153bbea429623ae5205e59b3ec99d Mon Sep 17 00:00:00 2001 From: seven332 Date: Sat, 13 May 2017 20:28:35 +0800 Subject: [PATCH] Add saving and restoring state in SceneView --- .../com/hippo/ehviewer/scene/MvpScene.java | 13 +++++++++ .../com/hippo/ehviewer/view/SceneView.java | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/app/src/main/java/com/hippo/ehviewer/scene/MvpScene.java b/app/src/main/java/com/hippo/ehviewer/scene/MvpScene.java index 09f031c1..c51a2659 100644 --- a/app/src/main/java/com/hippo/ehviewer/scene/MvpScene.java +++ b/app/src/main/java/com/hippo/ehviewer/scene/MvpScene.java @@ -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

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); + } } diff --git a/app/src/main/java/com/hippo/ehviewer/view/SceneView.java b/app/src/main/java/com/hippo/ehviewer/view/SceneView.java index 554c0ca7..0f636513 100644 --- a/app/src/main/java/com/hippo/ehviewer/view/SceneView.java +++ b/app/src/main/java/com/hippo/ehviewer/view/SceneView.java @@ -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

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

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) {} }