[android]: fix for crash on bookmarksCategory unmarshalling during app restoration

This commit is contained in:
Alexey Osminin 2020-11-18 15:33:35 +03:00 committed by Alexander Boriskov
parent 8b7bbe7bb9
commit b388aa6a9b
3 changed files with 29 additions and 14 deletions

View file

@ -294,14 +294,7 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
public void onItemClick(@NonNull View v, @NonNull BookmarkCategory category)
{
mSelectedCategory = category;
startActivityForResult(makeBookmarksListIntent(category), REQ_CODE_DELETE_CATEGORY);
}
@NonNull
private Intent makeBookmarksListIntent(@NonNull BookmarkCategory category)
{
return new Intent(getActivity(), BookmarkListActivity.class)
.putExtra(BookmarksListFragment.EXTRA_CATEGORY, category);
BookmarkListActivity.startForResult(requireActivity(), category);
}
protected void onShareActionSelected(@NonNull BookmarkCategory category)

View file

@ -1,7 +1,9 @@
package com.mapswithme.maps.bookmarks;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
@ -13,6 +15,8 @@ import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.util.ThemeUtils;
import static com.mapswithme.maps.bookmarks.BookmarksListFragment.EXTRA_BUNDLE;
public class BookmarkListActivity extends BaseToolbarActivity
{
@CallSuper
@ -58,8 +62,25 @@ public class BookmarkListActivity extends BaseToolbarActivity
static void startForResult(@NonNull Activity activity, @NonNull BookmarkCategory category)
{
Intent intent = new Intent(activity, BookmarkListActivity.class);
intent.putExtra(BookmarksListFragment.EXTRA_CATEGORY, category);
activity.startActivityForResult(intent, BaseBookmarkCategoriesFragment.REQ_CODE_DELETE_CATEGORY);
activity.startActivityForResult(getStartIntent(activity, category),
BaseBookmarkCategoriesFragment.REQ_CODE_DELETE_CATEGORY);
}
@NonNull
static Intent getStartIntent(@NonNull Context context,
@NonNull BookmarkCategory bookmarkCategory)
{
Intent intent = new Intent(context, BookmarkListActivity.class);
return wrapDataToBundle(intent, bookmarkCategory);
}
@NonNull
private static Intent wrapDataToBundle(@NonNull Intent intent,
@NonNull BookmarkCategory bookmarkCategory)
{
Bundle bundle = new Bundle();
bundle.putParcelable(BookmarksListFragment.EXTRA_CATEGORY, bookmarkCategory);
intent.putExtra(EXTRA_BUNDLE, bundle);
return intent;
}
}

View file

@ -65,6 +65,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
{
public static final String TAG = BookmarksListFragment.class.getSimpleName();
public static final String EXTRA_CATEGORY = "bookmark_category";
public static final String EXTRA_BUNDLE = "bookmark_bundle";
@SuppressWarnings("NullableProblems")
@NonNull
@ -131,7 +132,8 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
{
Bundle args = getArguments();
BookmarkCategory category;
if (args == null || ((category = args.getParcelable(EXTRA_CATEGORY))) == null)
if (args == null || (args.getBundle(EXTRA_BUNDLE) == null) ||
((category = args.getBundle(EXTRA_BUNDLE).getParcelable(EXTRA_CATEGORY))) == null)
throw new IllegalArgumentException("Category not exist in bundle");
return category;
@ -152,8 +154,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
mBookmarkCollectionAdapter = new BookmarkCollectionAdapter(getCategoryOrThrow(),
mCategoryItems, mCollectionItems);
mBookmarkCollectionAdapter.setOnClickListener((v, item) -> {
Intent intent = new Intent(getActivity(), BookmarkListActivity.class)
.putExtra(BookmarksListFragment.EXTRA_CATEGORY, item);
Intent intent = BookmarkListActivity.getStartIntent(requireContext(), item);
final boolean isCategory = BookmarkManager.INSTANCE.getCompilationType(item.getId()) ==
BookmarkManager.CATEGORY;