diff --git a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailContainerFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailContainerFragment.java index dcf919807487..f51a98efabfa 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailContainerFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailContainerFragment.java @@ -30,6 +30,7 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat; import org.wordpress.android.databinding.HistoryDetailContainerFragmentBinding; import org.wordpress.android.editor.EditorMediaUtils; +import org.wordpress.android.editor.savedinstance.SavedInstanceDatabase; import org.wordpress.android.fluxc.model.revisions.RevisionModel; import org.wordpress.android.fluxc.store.PostStore; import org.wordpress.android.ui.history.HistoryListItem.Revision; @@ -245,7 +246,10 @@ public void onPrepareOptionsMenu(@NonNull Menu menu) { public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.history_load) { Intent intent = new Intent(); - intent.putExtra(KEY_REVISION, mRevision); + SavedInstanceDatabase db = SavedInstanceDatabase.Companion.getDatabase(WordPress.getContext()); + if (db != null) { + db.addParcel(KEY_REVISION, mRevision); + } requireActivity().setResult(Activity.RESULT_OK, intent); requireActivity().finish(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailFragment.kt index 64c8a4072b0c..f3e5a61a9471 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailFragment.kt @@ -5,9 +5,11 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import kotlinx.parcelize.parcelableCreator import org.wordpress.android.R +import org.wordpress.android.WordPress +import org.wordpress.android.editor.savedinstance.SavedInstanceDatabase.Companion.getDatabase import org.wordpress.android.ui.history.HistoryListItem.Revision -import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.widgets.DiffView class HistoryDetailFragment : Fragment() { @@ -16,10 +18,10 @@ class HistoryDetailFragment : Fragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - mRevision = if (savedInstanceState != null) { - savedInstanceState.getParcelableCompat(KEY_REVISION) + mRevision = if (getDatabase(WordPress.getContext())?.hasParcel(KEY_REVISION) == true) { + getDatabase(WordPress.getContext())?.getParcel(KEY_REVISION, parcelableCreator()) } else { - arguments?.getParcelableCompat(EXTRA_REVISION) + getDatabase(WordPress.getContext())?.getParcel(EXTRA_REVISION, parcelableCreator()) } } @@ -32,7 +34,7 @@ class HistoryDetailFragment : Fragment() { override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - outState.putParcelable(KEY_REVISION, mRevision) + getDatabase(WordPress.getContext())?.addParcel(KEY_REVISION, mRevision) } companion object { @@ -40,11 +42,8 @@ class HistoryDetailFragment : Fragment() { const val KEY_REVISION = "KEY_REVISION" fun newInstance(revision: Revision): HistoryDetailFragment { - val fragment = HistoryDetailFragment() - val bundle = Bundle() - bundle.putParcelable(EXTRA_REVISION, revision) - fragment.arguments = bundle - return fragment + getDatabase(WordPress.getContext())?.addParcel(EXTRA_REVISION, revision) + return HistoryDetailFragment() } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java index 0ac9235b2b32..2680c271fed2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java @@ -712,9 +712,8 @@ public void handleOnBackPressed() { updatePostLoadingAndDialogState(PostLoadingState.fromInt( savedInstanceState.getInt(STATE_KEY_POST_LOADING_STATE, 0))); - SavedInstanceDatabase db = SavedInstanceDatabase.Companion.getDatabase(WordPress.getContext()); - if (db != null) { - mRevision = db.getParcel(STATE_KEY_REVISION, Revision.CREATOR); + if (getDB() != null) { + mRevision = getDB().getParcel(STATE_KEY_REVISION, Revision.CREATOR); } mPostEditorAnalyticsSession = PostEditorAnalyticsSession @@ -1158,6 +1157,8 @@ private void removePostOpenInEditorStickyEvent() { @Override protected void onSaveInstanceState(Bundle outState) { + outState.remove("android:viewHierarchyState"); + outState.remove("androidx.lifecycle.BundlableSavedStateRegistry.key"); super.onSaveInstanceState(outState); // Saves both post objects so we can restore them in onCreate() updateAndSavePostAsync(); @@ -1173,9 +1174,8 @@ protected void onSaveInstanceState(Bundle outState) { outState.putBoolean(STATE_KEY_REDO, mMenuHasRedo); outState.putSerializable(WordPress.SITE, mSite); - SavedInstanceDatabase db = SavedInstanceDatabase.Companion.getDatabase(WordPress.getContext()); - if (db != null) { - db.addParcel(STATE_KEY_REVISION, mRevision); + if (getDB() != null) { + getDB().addParcel(STATE_KEY_REVISION, mRevision); } outState.putSerializable(STATE_KEY_EDITOR_SESSION_DATA, mPostEditorAnalyticsSession); @@ -2886,10 +2886,10 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } break; case RequestCodes.HISTORY_DETAIL: - if (data.hasExtra(KEY_REVISION)) { + if (getDB() != null && getDB().hasParcel(KEY_REVISION)) { mViewPager.setCurrentItem(PAGE_CONTENT); - mRevision = data.getParcelableExtra(KEY_REVISION); + mRevision = getDB().getParcel(KEY_REVISION, Revision.CREATOR); new Handler().postDelayed(this::loadRevision, getResources().getInteger(R.integer.full_screen_dialog_animation_duration)); } @@ -3958,4 +3958,8 @@ public void showJetpackSettings() { public LiveData getSavingInProgressDialogVisibility() { return mViewModel.getSavingInProgressDialogVisibility(); } + + @Nullable private SavedInstanceDatabase getDB() { + return SavedInstanceDatabase.Companion.getDatabase(WordPress.getContext()); + } }