From 4cadc099bac698ab94389a2c4b53db838661b83f Mon Sep 17 00:00:00 2001 From: Roman Tsisyk Date: Thu, 5 Oct 2023 09:52:03 +0300 Subject: [PATCH] [android] Switch to use BundleCompat Signed-off-by: Roman Tsisyk --- android/app/build.gradle | 1 + .../BookmarkCategorySettingsFragment.java | 8 ++++---- .../bookmarks/BookmarksListFragment.java | 12 +++++------- .../editor/FeatureCategoryFragment.java | 8 ++++++-- .../editor/HoursMinutesPickerFragment.java | 5 +++-- .../main/java/app/organicmaps/util/Utils.java | 18 ------------------ .../widget/placepage/DirectionFragment.java | 3 ++- .../ElevationProfileViewRenderer.java | 2 +- 8 files changed, 22 insertions(+), 35 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index c21d29278e..a32ae82c8a 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -109,6 +109,7 @@ dependencies { // > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable // We don't use Kotlin, but some dependencies are actively using it. // See https://stackoverflow.com/a/75719642 + implementation 'androidx.core:core:1.12.0' implementation(platform('org.jetbrains.kotlin:kotlin-bom:1.9.10')) implementation 'androidx.annotation:annotation:1.7.0' implementation 'androidx.appcompat:appcompat:1.6.1' diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkCategorySettingsFragment.java b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkCategorySettingsFragment.java index d5eb063903..d4c1654344 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkCategorySettingsFragment.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkCategorySettingsFragment.java @@ -13,6 +13,7 @@ import android.widget.EditText; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.os.BundleCompat; import app.organicmaps.R; import app.organicmaps.base.BaseMwmToolbarFragment; @@ -43,10 +44,9 @@ public class BookmarkCategorySettingsFragment extends BaseMwmToolbarFragment public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - final Bundle args = getArguments(); - if (args == null) - throw new IllegalArgumentException("Args must not be null"); - mCategory = Objects.requireNonNull(Utils.getParcelable(args, BookmarkCategorySettingsActivity.EXTRA_BOOKMARK_CATEGORY, BookmarkCategory.class)); + final Bundle args = requireArguments(); + mCategory = Objects.requireNonNull(BundleCompat.getParcelable(args, + BookmarkCategorySettingsActivity.EXTRA_BOOKMARK_CATEGORY, BookmarkCategory.class)); } @Nullable diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksListFragment.java b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksListFragment.java index bdffeb9db8..a332e2b3ca 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksListFragment.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksListFragment.java @@ -16,6 +16,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.os.BundleCompat; import androidx.recyclerview.widget.ConcatAdapter; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.SimpleItemAnimator; @@ -46,6 +47,7 @@ import app.organicmaps.util.bottomsheet.MenuBottomSheetItem; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class BookmarksListFragment extends BaseMwmRecyclerFragment implements BookmarkManager.BookmarksSharingListener, @@ -107,13 +109,9 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment T getParcelableOld(Bundle args, String key) - { - return (T) args.getParcelable(key); - } - - - @Nullable - public static T getParcelable(@NonNull Bundle args, String key, Class clazz) - { - args.setClassLoader(clazz.getClassLoader()); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) - return getParcelableOld(args, key); - return args.getParcelable(key, clazz); - } - @SuppressWarnings({"deprecation", "unchecked"}) @Nullable private static T getSerializableOld(Bundle args, String key) @@ -862,7 +845,6 @@ public class Utils return args.getSerializable(key, clazz); } - @SuppressWarnings("deprecation") private static Spanned fromHtmlOld(@NonNull String htmlDescription) { diff --git a/android/app/src/main/java/app/organicmaps/widget/placepage/DirectionFragment.java b/android/app/src/main/java/app/organicmaps/widget/placepage/DirectionFragment.java index 7d5ced7219..4be4b09fa6 100644 --- a/android/app/src/main/java/app/organicmaps/widget/placepage/DirectionFragment.java +++ b/android/app/src/main/java/app/organicmaps/widget/placepage/DirectionFragment.java @@ -10,6 +10,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.os.BundleCompat; import app.organicmaps.Framework; import app.organicmaps.R; @@ -52,7 +53,7 @@ public class DirectionFragment extends BaseMwmDialogFragment }); initViews(root); if (savedInstanceState != null) - setMapObject(Utils.getParcelable(savedInstanceState, EXTRA_MAP_OBJECT, MapObject.class)); + setMapObject(BundleCompat.getParcelable(savedInstanceState, EXTRA_MAP_OBJECT, MapObject.class)); return root; } diff --git a/android/app/src/main/java/app/organicmaps/widget/placepage/ElevationProfileViewRenderer.java b/android/app/src/main/java/app/organicmaps/widget/placepage/ElevationProfileViewRenderer.java index a8a630768a..616bbfed84 100644 --- a/android/app/src/main/java/app/organicmaps/widget/placepage/ElevationProfileViewRenderer.java +++ b/android/app/src/main/java/app/organicmaps/widget/placepage/ElevationProfileViewRenderer.java @@ -133,7 +133,7 @@ public class ElevationProfileViewRenderer implements PlacePageStateListener public void onRestore(@NonNull Bundle inState) { -// mElevationInfo = Utils.getParcelable(inState, PlacePageUtils.EXTRA_PLACE_PAGE_DATA, ElevationInfo.class); +// mElevationInfo = BundleCompat.getParcelable(inState, PlacePageUtils.EXTRA_PLACE_PAGE_DATA, ElevationInfo.class); // if (mElevationInfo != null) // render(mElevationInfo); }