forked from organicmaps/organicmaps-tmp
[bookmarks][android] Delete category from bookmarks list fragment.
This commit is contained in:
parent
df7ba7fbee
commit
5255859892
4 changed files with 37 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.CallSuper;
|
||||
|
@ -41,6 +42,9 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
|
|||
OnItemLongClickListener<BookmarkCategory>
|
||||
|
||||
{
|
||||
static final int REQ_CODE_CATALOG = 101;
|
||||
private static final int REQ_CODE_DELETE_CATEGORY = 102;
|
||||
|
||||
private static final int MAX_CATEGORY_NAME_LENGTH = 60;
|
||||
|
||||
@NonNull
|
||||
|
@ -266,7 +270,8 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
|
|||
@Override
|
||||
public void onItemClick(@NonNull View v, @NonNull BookmarkCategory category)
|
||||
{
|
||||
startActivity(makeBookmarksListIntent(category));
|
||||
mSelectedCategory = category;
|
||||
startActivityForResult(makeBookmarksListIntent(category), REQ_CODE_DELETE_CATEGORY);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -281,11 +286,33 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
|
|||
SharingHelper.INSTANCE.prepareBookmarkCategoryForSharing(getActivity(), category.getId());
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
protected void onDeleteActionSelected(@NonNull BookmarkCategory category)
|
||||
private void onDeleteActionSelected(@NonNull BookmarkCategory category)
|
||||
{
|
||||
BookmarkManager.INSTANCE.deleteCategory(category.getId());
|
||||
getAdapter().notifyDataSetChanged();
|
||||
onDeleteActionSelected();
|
||||
}
|
||||
|
||||
protected void onDeleteActionSelected()
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
protected void onActivityResultInternal(int requestCode, int resultCode, @NonNull Intent data)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == Activity.RESULT_OK && requestCode == REQ_CODE_DELETE_CATEGORY)
|
||||
{
|
||||
onDeleteActionSelected(mSelectedCategory);
|
||||
return;
|
||||
}
|
||||
onActivityResultInternal(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,7 +11,6 @@ import com.mapswithme.maps.base.BaseToolbarActivity;
|
|||
|
||||
public class BookmarksCatalogActivity extends BaseToolbarActivity
|
||||
{
|
||||
public static final int REQ_CODE_CATALOG = 101;
|
||||
public static final String EXTRA_DOWNLOADED_CATEGORY = "extra_downloaded_category";
|
||||
|
||||
public static void startForResult(@NonNull Fragment fragment, int requestCode,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
|
@ -618,6 +619,8 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
return false;
|
||||
|
||||
case R.id.delete_category:
|
||||
requireActivity().setResult(Activity.RESULT_OK);
|
||||
requireActivity().finish();
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -100,9 +100,8 @@ public class CachedBookmarkCategoriesFragment extends BaseBookmarkCategoriesFrag
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onDeleteActionSelected(@NonNull BookmarkCategory category)
|
||||
protected void onDeleteActionSelected()
|
||||
{
|
||||
super.onDeleteActionSelected(category);
|
||||
updateLoadingPlaceholder();
|
||||
}
|
||||
|
||||
|
@ -136,15 +135,15 @@ public class CachedBookmarkCategoriesFragment extends BaseBookmarkCategoriesFrag
|
|||
{
|
||||
String catalogUrl = BookmarkManager.INSTANCE.getCatalogFrontendUrl(
|
||||
UTM.UTM_BOOKMARKS_PAGE_CATALOG_BUTTON);
|
||||
BookmarksCatalogActivity.startForResult(this, BookmarksCatalogActivity.REQ_CODE_CATALOG,
|
||||
BookmarksCatalogActivity.startForResult(this, BaseBookmarkCategoriesFragment.REQ_CODE_CATALOG,
|
||||
catalogUrl);
|
||||
Statistics.INSTANCE.trackOpenCatalogScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
public void onActivityResultInternal(int requestCode, int resultCode, @NonNull Intent data)
|
||||
{
|
||||
if (requestCode == BookmarksCatalogActivity.REQ_CODE_CATALOG && resultCode == Activity.RESULT_OK)
|
||||
if (requestCode == BaseBookmarkCategoriesFragment.REQ_CODE_CATALOG && resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
requireActivity().setResult(Activity.RESULT_OK, data);
|
||||
requireActivity().finish();
|
||||
|
|
Loading…
Add table
Reference in a new issue