From 9240602fa583d4c1d363e1e51ba17ef211469893 Mon Sep 17 00:00:00 2001 From: savsch <119003089+savsch@users.noreply.github.com> Date: Sat, 15 Feb 2025 18:33:06 +0530 Subject: [PATCH] [android] Retain bookmark color/category edits across screen rotations Resolves #2419 Signed-off-by: savsch <119003089+savsch@users.noreply.github.com> --- .../placepage/EditBookmarkFragment.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/app/organicmaps/widget/placepage/EditBookmarkFragment.java b/android/app/src/main/java/app/organicmaps/widget/placepage/EditBookmarkFragment.java index 6dad3f6361..dd31a18ac1 100644 --- a/android/app/src/main/java/app/organicmaps/widget/placepage/EditBookmarkFragment.java +++ b/android/app/src/main/java/app/organicmaps/widget/placepage/EditBookmarkFragment.java @@ -43,6 +43,9 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. public static final String EXTRA_CATEGORY_ID = "CategoryId"; public static final String EXTRA_ID = "BookmarkTrackId"; public static final String EXTRA_BOOKMARK_TYPE = "BookmarkType"; + public static final String STATE_ICON = "icon"; + public static final String STATE_BOOKMARK_CATEGORY = "bookmark_category"; + public static final String STATE_COLOR = "color"; public static final int TYPE_BOOKMARK = 1; public static final int TYPE_TRACK = 2; @@ -142,8 +145,13 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. mIvColor.setOnClickListener(this); //For tracks an bookmarks same category is used so this portion is common for both - long categoryId = args.getLong(EXTRA_CATEGORY_ID); - mBookmarkCategory = BookmarkManager.INSTANCE.getCategoryById(categoryId); + if (savedInstanceState != null && savedInstanceState.getParcelable(STATE_BOOKMARK_CATEGORY) != null) + mBookmarkCategory = savedInstanceState.getParcelable(STATE_BOOKMARK_CATEGORY); + else + { + long categoryId = args.getLong(EXTRA_CATEGORY_ID); + mBookmarkCategory = BookmarkManager.INSTANCE.getCategoryById(categoryId); + } long id = args.getLong(EXTRA_ID); switch (mType) @@ -151,7 +159,9 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. case TYPE_BOOKMARK -> { mBookmark = BookmarkManager.INSTANCE.getBookmarkInfo(id); - if (mBookmark != null) + if (savedInstanceState != null && savedInstanceState.getParcelable(STATE_ICON) != null) + mIcon = savedInstanceState.getParcelable(STATE_ICON); + else if (mBookmark != null) mIcon = mBookmark.getIcon(); refreshBookmark(); } @@ -159,6 +169,8 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. { mTrack = BookmarkManager.INSTANCE.getTrack(id); mColor = mTrack.getColor(); + if (savedInstanceState != null) + mColor = savedInstanceState.getInt(STATE_COLOR, mColor); refreshTrack(); } } @@ -240,6 +252,15 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. dismiss(); } + @Override + public void onSaveInstanceState(@NonNull Bundle outState) + { + super.onSaveInstanceState(outState); + outState.putParcelable(STATE_ICON, mIcon); + outState.putParcelable(STATE_BOOKMARK_CATEGORY, mBookmarkCategory); + outState.putInt(STATE_COLOR, mColor); + } + @Override public void onClick(View v) {