forked from organicmaps/organicmaps
[android] Added bookmark categories cache
This commit is contained in:
parent
ed55712572
commit
e19d0b89d6
17 changed files with 290 additions and 89 deletions
42
android/src/com/mapswithme/maps/BookmarkCategoriesCache.java
Normal file
42
android/src/com/mapswithme/maps/BookmarkCategoriesCache.java
Normal file
|
@ -0,0 +1,42 @@
|
|||
package com.mapswithme.maps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Observable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BookmarkCategoriesCache extends Observable<RecyclerView.AdapterDataObserver>
|
||||
{
|
||||
@NonNull
|
||||
private List<BookmarkCategory> mCachedItems = new ArrayList<>();
|
||||
|
||||
public void updateItems(@NonNull List<BookmarkCategory> cachedItems)
|
||||
{
|
||||
mCachedItems = Collections.unmodifiableList(cachedItems);
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<BookmarkCategory> getItems()
|
||||
{
|
||||
return mCachedItems;
|
||||
}
|
||||
|
||||
private void notifyChanged() {
|
||||
for (int i = mObservers.size() - 1; i >= 0; i--) {
|
||||
mObservers.get(i).onChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static BookmarkCategoriesCache from(@NonNull Context context)
|
||||
{
|
||||
return MwmApplication.from(context).getBookmarkCategoriesCache();
|
||||
}
|
||||
}
|
|
@ -40,6 +40,7 @@ import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
|||
import com.mapswithme.maps.base.OnBackPressListener;
|
||||
import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
|
||||
import com.mapswithme.maps.bookmarks.BookmarksCatalogActivity;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategoriesDataProvider;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.CatalogCustomProperty;
|
||||
|
@ -2387,7 +2388,12 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
public void onBookmarksLoadingFinished()
|
||||
{
|
||||
// Do nothing
|
||||
BookmarkCategoriesDataProvider.CoreBookmarkCategoriesDataProvider coreDataProvider =
|
||||
new BookmarkCategoriesDataProvider.CoreBookmarkCategoriesDataProvider();
|
||||
BookmarkCategoriesDataProvider.CacheBookmarkCategoriesDataProvider cacheDataProvider =
|
||||
new BookmarkCategoriesDataProvider.CacheBookmarkCategoriesDataProvider(getApplicationContext(), coreDataProvider);
|
||||
BookmarkCategoriesCache.from(getApplicationContext()).updateItems(coreDataProvider.getCategories());
|
||||
BookmarkManager.INSTANCE.setDataProvider(cacheDataProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.mapswithme.maps.background.NotificationChannelFactory;
|
|||
import com.mapswithme.maps.background.NotificationChannelProvider;
|
||||
import com.mapswithme.maps.background.Notifier;
|
||||
import com.mapswithme.maps.base.MediaPlayerWrapper;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategoriesDataProvider;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.downloader.CountryItem;
|
||||
import com.mapswithme.maps.downloader.MapManager;
|
||||
|
@ -88,6 +89,10 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
|
|||
private GeofenceRegistry mGeofenceRegistry;
|
||||
private boolean mFirstLaunch;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private BookmarkCategoriesCache mBookmarkCategoriesCache;
|
||||
|
||||
@NonNull
|
||||
public SubwayManager getSubwayManager()
|
||||
{
|
||||
|
@ -185,6 +190,7 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
|
|||
mPurchaseOperationObservable = new PurchaseOperationObservable();
|
||||
mPlayer = new MediaPlayerWrapper(this);
|
||||
mGeofenceRegistry = new GeofenceRegistryImpl(this);
|
||||
mBookmarkCategoriesCache = new BookmarkCategoriesCache();
|
||||
}
|
||||
|
||||
private void initNotificationChannels()
|
||||
|
@ -405,6 +411,12 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
|
|||
nativeOnTransit(foreground);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public BookmarkCategoriesCache getBookmarkCategoriesCache()
|
||||
{
|
||||
return mBookmarkCategoriesCache;
|
||||
}
|
||||
|
||||
private static class VisibleAppLaunchListener implements AppBackgroundTracker.OnVisibleAppLaunchListener
|
||||
{
|
||||
@Override
|
||||
|
|
|
@ -14,12 +14,16 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
|
||||
import com.cocosw.bottomsheet.BottomSheet;
|
||||
import com.mapswithme.maps.BookmarkCategoriesCache;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.adapter.OnItemClickListener;
|
||||
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
|
||||
import com.mapswithme.maps.base.Detachable;
|
||||
import com.mapswithme.maps.bookmarks.data.AbstractCategoriesSnapshot;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkSharingResult;
|
||||
import com.mapswithme.maps.bookmarks.data.FilterStrategy;
|
||||
import com.mapswithme.maps.dialog.EditTextDialogFragment;
|
||||
import com.mapswithme.maps.ugc.routes.UgcRouteEditSettingsActivity;
|
||||
import com.mapswithme.maps.ugc.routes.UgcRouteSharingOptionsActivity;
|
||||
|
@ -31,6 +35,8 @@ import com.mapswithme.util.sharing.SharingHelper;
|
|||
import com.mapswithme.util.statistics.Analytics;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFragment<BookmarkCategoriesAdapter>
|
||||
implements EditTextDialogFragment.EditTextDialogInterface,
|
||||
MenuItem.OnMenuItemClickListener,
|
||||
|
@ -59,6 +65,10 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
|
|||
@NonNull
|
||||
private BookmarkManager.BookmarksCatalogListener mCatalogListener;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private CategoriesAdapterObserver mCategoriesAdapterObserver;
|
||||
|
||||
@Override
|
||||
@LayoutRes
|
||||
protected int getLayoutRes()
|
||||
|
@ -70,7 +80,10 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
|
|||
@Override
|
||||
protected BookmarkCategoriesAdapter createAdapter()
|
||||
{
|
||||
return new BookmarkCategoriesAdapter(getActivity());
|
||||
FilterStrategy strategy = getType().getFilterStrategy();
|
||||
List<BookmarkCategory> items = BookmarkManager.INSTANCE.getCategoriesSnapshot(strategy)
|
||||
.getItems();
|
||||
return new BookmarkCategoriesAdapter(requireContext(), getType(), items);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
|
@ -92,6 +105,8 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
|
|||
.createVerticalDefaultDecorator(getContext());
|
||||
rw.addItemDecoration(decor);
|
||||
mCatalogListener = new CatalogListenerDecorator(createCatalogListener(), this);
|
||||
mCategoriesAdapterObserver = new CategoriesAdapterObserver();
|
||||
BookmarkCategoriesCache.from(requireContext()).registerObserver(mCategoriesAdapterObserver);
|
||||
}
|
||||
|
||||
protected void onPrepareControllers(@NonNull View view)
|
||||
|
@ -148,6 +163,13 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
|
|||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView()
|
||||
{
|
||||
super.onDestroyView();
|
||||
BookmarkCategoriesCache.from(requireContext()).unregisterObserver(mCategoriesAdapterObserver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item)
|
||||
{
|
||||
|
@ -161,7 +183,6 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected final void showBottomMenu(@NonNull BookmarkCategory item)
|
||||
{
|
||||
mSelectedCategory = item;
|
||||
|
@ -267,6 +288,9 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
|
|||
return new CategoryValidator();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected abstract BookmarkCategory.Type getType();
|
||||
|
||||
@Override
|
||||
public void onItemClick(@NonNull View v, @NonNull BookmarkCategory category)
|
||||
{
|
||||
|
@ -278,7 +302,7 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
|
|||
private Intent makeBookmarksListIntent(@NonNull BookmarkCategory category)
|
||||
{
|
||||
return new Intent(getActivity(), BookmarkListActivity.class)
|
||||
.putExtra(BookmarksListFragment.EXTRA_CATEGORY, category);
|
||||
.putExtra(BookmarksListFragment.EXTRA_CATEGORY, category);
|
||||
}
|
||||
|
||||
protected void onShareActionSelected(@NonNull BookmarkCategory category)
|
||||
|
@ -376,9 +400,12 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
|
|||
{
|
||||
SET_SHARE(R.id.share, shareAction(), new Analytics(Statistics.ParamValue.SEND_AS_FILE)),
|
||||
SET_EDIT(R.id.edit, editAction(), new Analytics(Statistics.ParamValue.EDIT)),
|
||||
SHOW_ON_MAP(R.id.show_on_map, showAction(), new Analytics(Statistics.ParamValue.MAKE_INVISIBLE_ON_MAP)),
|
||||
SHARING_OPTIONS(R.id.sharing_options, showSharingOptions(), new Analytics(Statistics.ParamValue.SHARING_OPTIONS)),
|
||||
LIST_SETTINGS(R.id.settings, showListSettings(), new Analytics(Statistics.ParamValue.LIST_SETTINGS)),
|
||||
SHOW_ON_MAP(R.id.show_on_map, showAction(),
|
||||
new Analytics(Statistics.ParamValue.MAKE_INVISIBLE_ON_MAP)),
|
||||
SHARING_OPTIONS(R.id.sharing_options, showSharingOptions(),
|
||||
new Analytics(Statistics.ParamValue.SHARING_OPTIONS)),
|
||||
LIST_SETTINGS(R.id.settings, showListSettings(),
|
||||
new Analytics(Statistics.ParamValue.LIST_SETTINGS)),
|
||||
DELETE_LIST(R.id.delete, deleteAction(), new Analytics(Statistics.ParamValue.DELETE_GROUP));
|
||||
|
||||
@NonNull
|
||||
|
@ -527,4 +554,35 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class CategoriesAdapterObserver extends RecyclerView.AdapterDataObserver implements Detachable<BaseBookmarkCategoriesFragment>
|
||||
{
|
||||
@Nullable
|
||||
private BaseBookmarkCategoriesFragment mFragment;
|
||||
|
||||
@Override
|
||||
public void attach(@NonNull BaseBookmarkCategoriesFragment object)
|
||||
{
|
||||
mFragment = object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach()
|
||||
{
|
||||
mFragment = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged()
|
||||
{
|
||||
super.onChanged();
|
||||
if (mFragment == null)
|
||||
return;
|
||||
|
||||
FilterStrategy strategy = mFragment.getType().getFilterStrategy();
|
||||
AbstractCategoriesSnapshot.Default snapshot =
|
||||
BookmarkManager.INSTANCE.getCategoriesSnapshot(strategy);
|
||||
mFragment.getAdapter().setItems(snapshot.getItems());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,18 @@ public abstract class BaseBookmarkCategoryAdapter<V extends RecyclerView.ViewHol
|
|||
{
|
||||
@NonNull
|
||||
private final Context mContext;
|
||||
@NonNull
|
||||
private List<BookmarkCategory> mItems;
|
||||
|
||||
BaseBookmarkCategoryAdapter(@NonNull Context context)
|
||||
BaseBookmarkCategoryAdapter(@NonNull Context context, @NonNull List<BookmarkCategory> items)
|
||||
{
|
||||
mContext = context;
|
||||
mItems = items;
|
||||
}
|
||||
|
||||
public void setItems(@NonNull List<BookmarkCategory> items)
|
||||
{
|
||||
mItems = items;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -29,7 +37,7 @@ public abstract class BaseBookmarkCategoryAdapter<V extends RecyclerView.ViewHol
|
|||
@NonNull
|
||||
public List<BookmarkCategory> getBookmarkCategories()
|
||||
{
|
||||
return BookmarkManager.INSTANCE.getOwnedCategoriesSnapshot().getItems();
|
||||
return mItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,6 +14,8 @@ import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
|||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.mapswithme.maps.bookmarks.Holders.CategoryViewHolder;
|
||||
import static com.mapswithme.maps.bookmarks.Holders.HeaderViewHolder;
|
||||
import static com.mapswithme.util.UiUtils.PHRASE_SEPARATOR;
|
||||
|
@ -37,18 +39,14 @@ public class BookmarkCategoriesAdapter extends BaseBookmarkCategoryAdapter<Recyc
|
|||
@NonNull
|
||||
private final BookmarkCategory.Type mType;
|
||||
|
||||
BookmarkCategoriesAdapter(@NonNull Context context, @NonNull BookmarkCategory.Type type)
|
||||
BookmarkCategoriesAdapter(@NonNull Context context, @NonNull BookmarkCategory.Type type,
|
||||
@NonNull List<BookmarkCategory> categories)
|
||||
{
|
||||
super(context.getApplicationContext());
|
||||
super(context.getApplicationContext(), categories);
|
||||
mType = type;
|
||||
mResProvider = type.getFactory().getResProvider();
|
||||
}
|
||||
|
||||
BookmarkCategoriesAdapter(@NonNull Context context)
|
||||
{
|
||||
this(context, BookmarkCategory.Type.PRIVATE);
|
||||
}
|
||||
|
||||
public void setOnClickListener(@Nullable OnItemClickListener<BookmarkCategory> listener)
|
||||
{
|
||||
mClickListener = listener;
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.cocosw.bottomsheet.BottomSheet;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.auth.Authorizer;
|
||||
import com.mapswithme.maps.auth.TargetFragmentCallback;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.widget.BookmarkBackupView;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
@ -78,6 +79,13 @@ public class BookmarkCategoriesFragment extends BaseBookmarkCategoriesFragment
|
|||
getSelectedCategory().isSharingOptionsAllowed());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected BookmarkCategory.Type getType()
|
||||
{
|
||||
return BookmarkCategory.Type.PRIVATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthCompleted()
|
||||
{
|
||||
|
|
|
@ -19,7 +19,6 @@ import com.mapswithme.maps.bookmarks.data.CatalogTagsGroup;
|
|||
import com.mapswithme.util.SharedPropertiesUtils;
|
||||
import com.mapswithme.util.UTM;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.sharing.TargetUtils;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -77,9 +76,9 @@ public class CachedBookmarkCategoriesFragment extends BaseBookmarkCategoriesFrag
|
|||
|
||||
@NonNull
|
||||
@Override
|
||||
protected CatalogBookmarkCategoriesAdapter createAdapter()
|
||||
protected BookmarkCategory.Type getType()
|
||||
{
|
||||
return new CatalogBookmarkCategoriesAdapter(requireContext());
|
||||
return BookmarkCategory.Type.DOWNLOADED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CatalogBookmarkCategoriesAdapter extends BookmarkCategoriesAdapter
|
||||
{
|
||||
CatalogBookmarkCategoriesAdapter(@NonNull Context context)
|
||||
{
|
||||
super(context, BookmarkCategory.Type.DOWNLOADED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public List<BookmarkCategory> getBookmarkCategories()
|
||||
{
|
||||
return BookmarkManager.INSTANCE.getDownloadedCategoriesSnapshot().getItems();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -11,6 +12,8 @@ import android.widget.TextView;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ChooseBookmarkCategoryAdapter extends BaseBookmarkCategoryAdapter<ChooseBookmarkCategoryAdapter.SingleChoiceHolder>
|
||||
{
|
||||
public static final int VIEW_TYPE_CATEGORY = 0;
|
||||
|
@ -27,9 +30,10 @@ public class ChooseBookmarkCategoryAdapter extends BaseBookmarkCategoryAdapter<C
|
|||
|
||||
private CategoryListener mListener;
|
||||
|
||||
public ChooseBookmarkCategoryAdapter(Context context, int pos)
|
||||
public ChooseBookmarkCategoryAdapter(Context context, int pos,
|
||||
@NonNull List<BookmarkCategory> categories)
|
||||
{
|
||||
super(context);
|
||||
super(context, categories);
|
||||
mCheckedPosition = pos;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,8 @@ public class ChooseBookmarkCategoryFragment extends BaseMwmDialogFragment
|
|||
|
||||
final Bundle args = getArguments();
|
||||
final int catPosition = args.getInt(CATEGORY_POSITION, 0);
|
||||
mAdapter = new ChooseBookmarkCategoryAdapter(getActivity(), catPosition);
|
||||
List<BookmarkCategory> items = BookmarkManager.INSTANCE.getOwnedCategoriesSnapshot().getItems();
|
||||
mAdapter = new ChooseBookmarkCategoryAdapter(getActivity(), catPosition, items);
|
||||
mAdapter.setListener(this);
|
||||
mRecycler.setAdapter(mAdapter);
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ public abstract class AbstractCategoriesSnapshot
|
|||
@NonNull
|
||||
private final List<BookmarkCategory> mSnapshot;
|
||||
|
||||
AbstractCategoriesSnapshot(@NonNull BookmarkCategory[] items)
|
||||
AbstractCategoriesSnapshot(@NonNull List<BookmarkCategory> items)
|
||||
{
|
||||
mSnapshot = Collections.unmodifiableList(Arrays.asList(items));
|
||||
mSnapshot = Collections.unmodifiableList(items);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -27,7 +27,7 @@ public abstract class AbstractCategoriesSnapshot
|
|||
@NonNull
|
||||
private final FilterStrategy mStrategy;
|
||||
|
||||
protected Default(@NonNull BookmarkCategory[] items, @NonNull FilterStrategy strategy)
|
||||
protected Default(@NonNull List<BookmarkCategory> items, @NonNull FilterStrategy strategy)
|
||||
{
|
||||
super(items);
|
||||
mStrategy = strategy;
|
||||
|
|
|
@ -116,7 +116,7 @@ public class Bookmark extends MapObject
|
|||
|
||||
public String getCategoryName()
|
||||
{
|
||||
return BookmarkManager.INSTANCE.getCategoryName(mCategoryId);
|
||||
return BookmarkManager.INSTANCE.getCategoryById(mCategoryId).getName();
|
||||
}
|
||||
|
||||
public void setCategoryId(@IntRange(from = 0) long catId)
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
package com.mapswithme.maps.bookmarks.data;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.maps.BookmarkCategoriesCache;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public interface BookmarkCategoriesDataProvider
|
||||
{
|
||||
@NonNull
|
||||
List<BookmarkCategory> getCategories();
|
||||
|
||||
@NonNull
|
||||
BookmarkCategory getCategoryById(long categoryId);
|
||||
|
||||
public abstract class AbstractDataProvider implements BookmarkCategoriesDataProvider
|
||||
{
|
||||
|
||||
@NonNull
|
||||
public AbstractCategoriesSnapshot.Default getAllCategoriesSnapshot()
|
||||
{
|
||||
List<BookmarkCategory> items = getCategories();
|
||||
return new AbstractCategoriesSnapshot.Default(items, new FilterStrategy.All());
|
||||
}
|
||||
}
|
||||
|
||||
public static class CoreBookmarkCategoriesDataProvider extends AbstractDataProvider
|
||||
{
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<BookmarkCategory> getCategories()
|
||||
{
|
||||
BookmarkCategory[] categories = BookmarkManager.INSTANCE.nativeGetBookmarkCategories();
|
||||
return Arrays.asList(categories);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public BookmarkCategory getCategoryById(long categoryId)
|
||||
{
|
||||
BookmarkCategory[] categories =
|
||||
BookmarkManager.INSTANCE.nativeGetBookmarkCategories();
|
||||
|
||||
for (BookmarkCategory each : categories)
|
||||
{
|
||||
if (each.getId() == categoryId)
|
||||
return each;
|
||||
|
||||
}
|
||||
throw new IllegalArgumentException("There is no category for id : " + categoryId);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CacheBookmarkCategoriesDataProvider extends AbstractDataProvider
|
||||
{
|
||||
@NonNull
|
||||
private final Context mContext;
|
||||
@NonNull
|
||||
private final BookmarkCategoriesDataProvider mCoreDataProvider;
|
||||
|
||||
public CacheBookmarkCategoriesDataProvider(@NonNull Context context,
|
||||
@NonNull BookmarkCategoriesDataProvider dataProvider)
|
||||
{
|
||||
mContext = context;
|
||||
mCoreDataProvider = dataProvider;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<BookmarkCategory> getCategories()
|
||||
{
|
||||
return BookmarkCategoriesCache.from(mContext).getItems();
|
||||
}
|
||||
|
||||
private void updateCache()
|
||||
{
|
||||
BookmarkCategoriesCache cache = BookmarkCategoriesCache.from(mContext);
|
||||
cache.updateItems(mCoreDataProvider.getCategories());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public BookmarkCategory getCategoryById(long catId)
|
||||
{
|
||||
List<BookmarkCategory> items = getAllCategoriesSnapshot().getItems();
|
||||
for (BookmarkCategory each : items)
|
||||
{
|
||||
if (catId == each.getId())
|
||||
return each;
|
||||
}
|
||||
throw new IllegalArgumentException(new StringBuilder().append("Category with id = ")
|
||||
.append(catId)
|
||||
.append(" missed")
|
||||
.toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -329,9 +329,9 @@ public class BookmarkCategory implements Parcelable
|
|||
DOWNLOADED(BookmarksPageFactory.DOWNLOADED, FilterStrategy.PredicativeStrategy.makeDownloadedInstance());
|
||||
|
||||
@NonNull
|
||||
private BookmarksPageFactory mFactory;
|
||||
private final BookmarksPageFactory mFactory;
|
||||
@NonNull
|
||||
private FilterStrategy mFilterStrategy;
|
||||
private final FilterStrategy mFilterStrategy;
|
||||
|
||||
Type(@NonNull BookmarksPageFactory pageFactory, @NonNull FilterStrategy filterStrategy)
|
||||
{
|
||||
|
|
|
@ -7,7 +7,6 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapswithme.maps.PrivateVariables;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.metrics.UserActionsLogger;
|
||||
import com.mapswithme.util.UTM;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
@ -62,6 +61,9 @@ public enum BookmarkManager
|
|||
|
||||
public static final List<Icon> ICONS = new ArrayList<>();
|
||||
|
||||
@NonNull
|
||||
private BookmarkCategoriesDataProvider mDataProvider = new BookmarkCategoriesDataProvider.CoreBookmarkCategoriesDataProvider();
|
||||
|
||||
@NonNull
|
||||
private final List<BookmarksLoadingListener> mListeners = new ArrayList<>();
|
||||
|
||||
|
@ -104,6 +106,11 @@ public enum BookmarkManager
|
|||
setVisibility(catId, !isVisible);
|
||||
}
|
||||
|
||||
public void setDataProvider(@NonNull BookmarkCategoriesDataProvider dataProvider)
|
||||
{
|
||||
mDataProvider = dataProvider;
|
||||
}
|
||||
|
||||
public Bookmark addNewBookmark(double lat, double lon)
|
||||
{
|
||||
final Bookmark bookmark = nativeAddBookmarkToLastEditedCategory(lat, lon);
|
||||
|
@ -336,7 +343,6 @@ public enum BookmarkManager
|
|||
public void onTagsReceived(boolean successful, @NonNull CatalogTagsGroup[] tagsGroups,
|
||||
int maxTagsCount)
|
||||
{
|
||||
//TODO(@yoksnod): Implement maxTagsCount usage.
|
||||
List<CatalogTagsGroup> unmodifiableData = Collections.unmodifiableList(Arrays.asList(tagsGroups));
|
||||
for (BookmarksCatalogListener listener : mCatalogListeners)
|
||||
{
|
||||
|
@ -405,12 +411,6 @@ public enum BookmarkManager
|
|||
nativeSetVisibility(catId, visible);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getCategoryName(long catId)
|
||||
{
|
||||
return nativeGetCategoryName(catId);
|
||||
}
|
||||
|
||||
public void setCategoryName(long catId, @NonNull String name)
|
||||
{
|
||||
nativeSetCategoryName(catId, name);
|
||||
|
@ -450,10 +450,10 @@ public enum BookmarkManager
|
|||
nativeUploadToCatalog(rules.ordinal(), category.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
/* *//**
|
||||
* @return total count - tracks + bookmarks
|
||||
* @param category
|
||||
*/
|
||||
*//*
|
||||
@Deprecated
|
||||
public int getCategorySize(@NonNull BookmarkCategory category)
|
||||
{
|
||||
|
@ -475,23 +475,15 @@ public enum BookmarkManager
|
|||
.append(catId)
|
||||
.append(" missed")
|
||||
.toString());
|
||||
}
|
||||
}*/
|
||||
|
||||
/*
|
||||
@Deprecated
|
||||
public long getCategoryIdByPosition(int position)
|
||||
{
|
||||
return nativeGetCategoryIdByPosition(position);
|
||||
}
|
||||
|
||||
public int getBookmarksCount(long catId)
|
||||
{
|
||||
return nativeGetBookmarksCount(catId);
|
||||
}
|
||||
|
||||
public int getTracksCount(long catId)
|
||||
{
|
||||
return nativeGetTracksCount(catId);
|
||||
}
|
||||
*/
|
||||
|
||||
@NonNull
|
||||
public Bookmark updateBookmarkPlacePage(long bmkId)
|
||||
|
@ -568,28 +560,35 @@ public enum BookmarkManager
|
|||
@NonNull
|
||||
public AbstractCategoriesSnapshot.Default getDownloadedCategoriesSnapshot()
|
||||
{
|
||||
BookmarkCategory[] items = nativeGetBookmarkCategories();
|
||||
List<BookmarkCategory> items = mDataProvider.getCategories();
|
||||
return new AbstractCategoriesSnapshot.Default(items, new FilterStrategy.Downloaded());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public AbstractCategoriesSnapshot.Default getOwnedCategoriesSnapshot()
|
||||
{
|
||||
BookmarkCategory[] items = nativeGetBookmarkCategories();
|
||||
List<BookmarkCategory> items = mDataProvider.getCategories();
|
||||
return new AbstractCategoriesSnapshot.Default(items, new FilterStrategy.Private());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public AbstractCategoriesSnapshot.Default getAllCategoriesSnapshot()
|
||||
{
|
||||
BookmarkCategory[] items = nativeGetBookmarkCategories();
|
||||
List<BookmarkCategory> items = mDataProvider.getCategories();
|
||||
return new AbstractCategoriesSnapshot.Default(items, new FilterStrategy.All());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public AbstractCategoriesSnapshot.Default getCategoriesSnapshot(FilterStrategy strategy)
|
||||
{
|
||||
return new AbstractCategoriesSnapshot.Default(nativeGetBookmarkCategories(), strategy);
|
||||
List<BookmarkCategory> items = mDataProvider.getCategories();
|
||||
return new AbstractCategoriesSnapshot.Default(items, strategy);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public BookmarkCategory getCategoryById(long categoryId)
|
||||
{
|
||||
return mDataProvider.getCategoryById(categoryId);
|
||||
}
|
||||
|
||||
public boolean isUsedCategoryName(@NonNull String name)
|
||||
|
@ -607,16 +606,6 @@ public enum BookmarkManager
|
|||
|
||||
public void prepareForSearch(long catId) { nativePrepareForSearch(catId); }
|
||||
|
||||
public boolean areAllCatalogCategoriesVisible()
|
||||
{
|
||||
return areAllCategoriesVisible(BookmarkCategory.Type.DOWNLOADED);
|
||||
}
|
||||
|
||||
public boolean areAllOwnedCategoriesVisible()
|
||||
{
|
||||
return areAllCategoriesVisible(BookmarkCategory.Type.PRIVATE);
|
||||
}
|
||||
|
||||
public boolean areAllCategoriesVisible(BookmarkCategory.Type type)
|
||||
{
|
||||
return nativeAreAllCategoriesVisible(type.ordinal());
|
||||
|
@ -936,7 +925,7 @@ public enum BookmarkManager
|
|||
|
||||
private native int nativeGetTracksCount(long catId);
|
||||
|
||||
private native BookmarkCategory[] nativeGetBookmarkCategories();
|
||||
public native BookmarkCategory[] nativeGetBookmarkCategories();
|
||||
|
||||
@NonNull
|
||||
private native Bookmark nativeUpdateBookmarkPlacePage(long bmkId);
|
||||
|
|
|
@ -225,7 +225,7 @@ public enum SharingHelper
|
|||
case BookmarkSharingResult.FILE_ERROR:
|
||||
DialogUtils.showAlertDialog(context, R.string.dialog_routing_system_error,
|
||||
R.string.bookmarks_error_message_share_general);
|
||||
String catName = BookmarkManager.INSTANCE.getCategoryName(result.getCategoryId());
|
||||
String catName = BookmarkManager.INSTANCE.getCategoryById(result.getCategoryId()).getName();
|
||||
LOGGER.e(TAG, "Failed to share bookmark category '" + catName + "', error code: "
|
||||
+ result.getCode());
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue