[android] Expanded bookmark categories provider interface to make it usable for childrent collections and categories

This commit is contained in:
alexzatsepin 2020-10-27 16:54:29 +03:00 committed by Alexander Boriskov
parent dfa689eee9
commit 95a709f205
7 changed files with 65 additions and 39 deletions

View file

@ -61,7 +61,6 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
{
BookmarkCategory category = mHolder.getEntity();
BookmarkManager.INSTANCE.toggleCategoryVisibility(category);
category.invertVisibility();
int type = BookmarkManager.INSTANCE.getCompilationType(category.getId());
String compilationTypeString = type == BookmarkManager.CATEGORY ?

View file

@ -1,23 +0,0 @@
package com.mapswithme.maps.bookmarks.data;
import androidx.annotation.NonNull;
import java.util.List;
abstract class AbstractBookmarkCategoriesDataProvider implements BookmarkCategoriesDataProvider
{
@NonNull
@Override
public BookmarkCategory getCategoryById(long categoryId)
{
List<BookmarkCategory> categories = getCategories();
for (BookmarkCategory each : categories)
{
if (each.getId() == categoryId)
return each;
}
throw new IllegalArgumentException("There is no category for id : " + categoryId);
}
}

View file

@ -8,7 +8,10 @@ public interface BookmarkCategoriesDataProvider
{
@NonNull
List<BookmarkCategory> getCategories();
@NonNull
List<BookmarkCategory> getChildrenCategories(long parentId);
@NonNull
List<BookmarkCategory> getChildrenCollections(long parentId);
@NonNull
BookmarkCategory getCategoryById(long categoryId);
}

View file

@ -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

View file

@ -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<BookmarksLoadingListener> 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<BookmarkCategory> getChildrenCategories(long catId)
{
return Arrays.asList(nativeGetChildrenCategories(catId));
return mCurrentDataProvider.getChildrenCategories(catId);
}
@NonNull
public List<BookmarkCategory> getChildrenCollections(long catId)
{
return Arrays.asList(nativeGetChildrenCollections(catId));
return mCurrentDataProvider.getChildrenCollections(catId);
}
public boolean isCompilation(long catId)

View file

@ -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<BookmarkCategory> categories = cache.getCategories();
for (BookmarkCategory category: categories)
if (category.getId() == categoryId)
return category;
return BookmarkManager.INSTANCE.nativeGetBookmarkCategory(categoryId);
}
@NonNull
@Override
public List<BookmarkCategory> getCategories()
{
return BookmarkManager.INSTANCE.getBookmarkCategoriesCache().getCategories();
}
@NonNull
@Override
public List<BookmarkCategory> getChildrenCategories(long parentId)
{
BookmarkCategory[] categories = BookmarkManager.INSTANCE.nativeGetChildrenCategories(parentId);
return Arrays.asList(categories);
}
@NonNull
@Override
public List<BookmarkCategory> getChildrenCollections(long parentId)
{
BookmarkCategory[] collections = BookmarkManager.INSTANCE.nativeGetChildrenCollections(parentId);
return Arrays.asList(collections);
}
}

View file

@ -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<BookmarkCategory> getCategories()
@ -14,4 +21,20 @@ class CoreBookmarkCategoriesDataProvider extends AbstractBookmarkCategoriesDataP
BookmarkCategory[] categories = BookmarkManager.INSTANCE.nativeGetBookmarkCategories();
return Arrays.asList(categories);
}
@NonNull
@Override
public List<BookmarkCategory> getChildrenCategories(long parentId)
{
BookmarkCategory[] categories = BookmarkManager.INSTANCE.nativeGetChildrenCategories(parentId);
return Arrays.asList(categories);
}
@NonNull
@Override
public List<BookmarkCategory> getChildrenCollections(long parentId)
{
BookmarkCategory[] collections = BookmarkManager.INSTANCE.nativeGetChildrenCollections(parentId);
return Arrays.asList(collections);
}
}