diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkCollectionAdapter.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkCollectionAdapter.java index bce1b1127b..0025d72d76 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkCollectionAdapter.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkCollectionAdapter.java @@ -61,7 +61,6 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter categories = getCategories(); - - for (BookmarkCategory each : categories) - { - if (each.getId() == categoryId) - return each; - - } - throw new IllegalArgumentException("There is no category for id : " + categoryId); - } -} diff --git a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategoriesDataProvider.java b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategoriesDataProvider.java index bebccfd3e4..b8259910b1 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategoriesDataProvider.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategoriesDataProvider.java @@ -8,7 +8,10 @@ public interface BookmarkCategoriesDataProvider { @NonNull List getCategories(); - + @NonNull + List getChildrenCategories(long parentId); + @NonNull + List getChildrenCollections(long parentId); @NonNull BookmarkCategory getCategoryById(long categoryId); } diff --git a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategory.java b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategory.java index f1dd7f94af..b109d0a24c 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategory.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategory.java @@ -194,11 +194,6 @@ public class BookmarkCategory implements Parcelable return isLocal && size() > 0; } - public void invertVisibility() - { - mIsVisible = !mIsVisible; - } - public static class CountAndPlurals { private final int mCount; @PluralsRes diff --git a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java index f98a724a33..3832f53737 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java @@ -18,7 +18,6 @@ import com.mapswithme.util.statistics.Statistics; import java.io.File; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -82,9 +81,7 @@ public enum BookmarkManager @NonNull private BookmarkCategoriesDataProvider mCurrentDataProvider = mCategoriesCoreDataProvider; - @NonNull - private final BookmarkCategoriesCache mBookmarkCategoriesCache - = new BookmarkManager.BookmarkCategoriesCache(); + private final BookmarkCategoriesCache mBookmarkCategoriesCache = new BookmarkCategoriesCache(); @NonNull private final List mListeners = new ArrayList<>(); @@ -666,7 +663,7 @@ public enum BookmarkManager @NonNull public BookmarkCategory getCategoryById(long categoryId) { - return nativeGetBookmarkCategory(categoryId); + return mCurrentDataProvider.getCategoryById(categoryId); } public boolean isUsedCategoryName(@NonNull String name) @@ -901,13 +898,13 @@ public enum BookmarkManager @NonNull public List getChildrenCategories(long catId) { - return Arrays.asList(nativeGetChildrenCategories(catId)); + return mCurrentDataProvider.getChildrenCategories(catId); } @NonNull public List getChildrenCollections(long catId) { - return Arrays.asList(nativeGetChildrenCollections(catId)); + return mCurrentDataProvider.getChildrenCollections(catId); } public boolean isCompilation(long catId) diff --git a/android/src/com/mapswithme/maps/bookmarks/data/CacheBookmarkCategoriesDataProvider.java b/android/src/com/mapswithme/maps/bookmarks/data/CacheBookmarkCategoriesDataProvider.java index d034a42b97..ba3881e187 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/CacheBookmarkCategoriesDataProvider.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/CacheBookmarkCategoriesDataProvider.java @@ -2,14 +2,46 @@ package com.mapswithme.maps.bookmarks.data; import androidx.annotation.NonNull; +import java.util.Arrays; import java.util.List; -class CacheBookmarkCategoriesDataProvider extends AbstractBookmarkCategoriesDataProvider +class CacheBookmarkCategoriesDataProvider implements BookmarkCategoriesDataProvider { + @NonNull + @Override + public BookmarkCategory getCategoryById(long categoryId) + { + BookmarkManager.BookmarkCategoriesCache cache + = BookmarkManager.INSTANCE.getBookmarkCategoriesCache(); + + List categories = cache.getCategories(); + for (BookmarkCategory category: categories) + if (category.getId() == categoryId) + return category; + + return BookmarkManager.INSTANCE.nativeGetBookmarkCategory(categoryId); + } + @NonNull @Override public List getCategories() { return BookmarkManager.INSTANCE.getBookmarkCategoriesCache().getCategories(); } + + @NonNull + @Override + public List getChildrenCategories(long parentId) + { + BookmarkCategory[] categories = BookmarkManager.INSTANCE.nativeGetChildrenCategories(parentId); + return Arrays.asList(categories); + } + + @NonNull + @Override + public List getChildrenCollections(long parentId) + { + BookmarkCategory[] collections = BookmarkManager.INSTANCE.nativeGetChildrenCollections(parentId); + return Arrays.asList(collections); + } } diff --git a/android/src/com/mapswithme/maps/bookmarks/data/CoreBookmarkCategoriesDataProvider.java b/android/src/com/mapswithme/maps/bookmarks/data/CoreBookmarkCategoriesDataProvider.java index 2f349cbe6e..24c74964a7 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/CoreBookmarkCategoriesDataProvider.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/CoreBookmarkCategoriesDataProvider.java @@ -5,8 +5,15 @@ import androidx.annotation.NonNull; import java.util.Arrays; import java.util.List; -class CoreBookmarkCategoriesDataProvider extends AbstractBookmarkCategoriesDataProvider +class CoreBookmarkCategoriesDataProvider implements BookmarkCategoriesDataProvider { + @NonNull + @Override + public BookmarkCategory getCategoryById(long categoryId) + { + return BookmarkManager.INSTANCE.nativeGetBookmarkCategory(categoryId); + } + @NonNull @Override public List getCategories() @@ -14,4 +21,20 @@ class CoreBookmarkCategoriesDataProvider extends AbstractBookmarkCategoriesDataP BookmarkCategory[] categories = BookmarkManager.INSTANCE.nativeGetBookmarkCategories(); return Arrays.asList(categories); } + + @NonNull + @Override + public List getChildrenCategories(long parentId) + { + BookmarkCategory[] categories = BookmarkManager.INSTANCE.nativeGetChildrenCategories(parentId); + return Arrays.asList(categories); + } + + @NonNull + @Override + public List getChildrenCollections(long parentId) + { + BookmarkCategory[] collections = BookmarkManager.INSTANCE.nativeGetChildrenCollections(parentId); + return Arrays.asList(collections); + } }