forked from organicmaps/organicmaps
[android] Displaying Categories and Collections on Guides' page.
This commit is contained in:
parent
17d2e1e0ce
commit
23ed2f6a18
3 changed files with 69 additions and 32 deletions
|
@ -20,6 +20,7 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
private final static int TYPE_COLLECTION_ITEM = 1;
|
||||
private final static int TYPE_CATEGORY_ITEM = 2;
|
||||
|
||||
// TODO (@velichkomarija): Delete this if do not need.
|
||||
@NonNull
|
||||
private final Context mContext;
|
||||
@NonNull
|
||||
|
@ -84,7 +85,7 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
public String getTitle(int sectionIndex, @NonNull Resources rs)
|
||||
{
|
||||
if (sectionIndex == mCollectionSectionIndex)
|
||||
// TODO (@velichkomarija): Replace categories
|
||||
// TODO (@velichkomarija): Replace categories for collections.
|
||||
return rs.getString(R.string.categories);
|
||||
return rs.getString(R.string.categories);
|
||||
}
|
||||
|
@ -111,23 +112,20 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
private List<BookmarkCategory> getItemsListByType(int type)
|
||||
{
|
||||
if (type == TYPE_COLLECTION_ITEM)
|
||||
{
|
||||
return mItemsCollection;
|
||||
}
|
||||
else
|
||||
{
|
||||
return mItemsCategory;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public BookmarkCategory getCategoryByPosition(int position, int type)
|
||||
public BookmarkCategory getCategoryByPosition(SectionPosition sp, int type)
|
||||
{
|
||||
List<BookmarkCategory> categories = getItemsListByType(type);
|
||||
|
||||
if (position < 0 || position > categories.size() - /* header */ 1)
|
||||
throw new ArrayIndexOutOfBoundsException(position);
|
||||
return categories.get(position);
|
||||
int itemIndex = sp.mItemIndex;
|
||||
if (sp.mItemIndex > categories.size() - 1)
|
||||
throw new ArrayIndexOutOfBoundsException(itemIndex);
|
||||
return categories.get(itemIndex);
|
||||
}
|
||||
|
||||
BookmarkCollectionAdapter(@NonNull Context context,
|
||||
|
@ -189,17 +187,27 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position)
|
||||
{
|
||||
int type = getItemViewType(position);
|
||||
|
||||
if (type == TYPE_HEADER_ITEM)
|
||||
bindHeaderHolder(holder);
|
||||
SectionPosition sectionPosition = getSectionPosition(position);
|
||||
if (sectionPosition.isTitlePosition())
|
||||
bindHeaderHolder(holder, sectionPosition.getSectionIndex() + 1);
|
||||
else
|
||||
bindCollectionHolder(holder, position, type);
|
||||
bindCollectionHolder(holder, sectionPosition, getItemsType(sectionPosition.mSectionIndex));
|
||||
}
|
||||
|
||||
private void bindCollectionHolder(RecyclerView.ViewHolder holder, int position, int type)
|
||||
@Override
|
||||
public int getItemViewType(int position)
|
||||
{
|
||||
final BookmarkCategory category = getCategoryByPosition(position, type);
|
||||
SectionPosition sectionPosition = getSectionPosition(position);
|
||||
if (sectionPosition.isTitlePosition())
|
||||
return TYPE_HEADER_ITEM;
|
||||
if (sectionPosition.isItemPosition())
|
||||
return getItemsType(sectionPosition.getSectionIndex());
|
||||
throw new AssertionError("Position not found: " + position);
|
||||
}
|
||||
|
||||
private void bindCollectionHolder(RecyclerView.ViewHolder holder, SectionPosition position, int type)
|
||||
{
|
||||
final BookmarkCategory category = getCategoryByPosition(position, type);
|
||||
Holders.CollectionViewHolder collectionViewHolder = (Holders.CollectionViewHolder) holder;
|
||||
collectionViewHolder.setCategory(category);
|
||||
collectionViewHolder.setName(category.getName());
|
||||
|
@ -215,26 +223,34 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
holder.setSize(template.getPlurals(), template.getCount());
|
||||
}
|
||||
|
||||
private void bindHeaderHolder(@NonNull RecyclerView.ViewHolder holder)
|
||||
private void bindHeaderHolder(@NonNull RecyclerView.ViewHolder holder, int nextSectionPosition)
|
||||
{
|
||||
Holders.HeaderViewHolder headerViewHolder = (Holders.HeaderViewHolder) holder;
|
||||
headerViewHolder.getText()
|
||||
.setText(getTitle(nextSectionPosition, holder.itemView.getResources()));
|
||||
// TODO: (@velichkomarija) : Hide and All button.
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position)
|
||||
public long getItemId(int position)
|
||||
{
|
||||
SectionPosition sectionPosition = getSectionPosition(position);
|
||||
if (sectionPosition.isTitlePosition())
|
||||
return TYPE_HEADER_ITEM;
|
||||
if (sectionPosition.isItemPosition())
|
||||
return getItemsType(sectionPosition.getSectionIndex());
|
||||
throw new AssertionError("Position not found: " + position);
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount()
|
||||
{
|
||||
return mItemsCategory.size() + mItemsCollection.size();
|
||||
int itemCount = 0;
|
||||
|
||||
for (int i = 0; i < mSectionCount; ++i)
|
||||
{
|
||||
|
||||
int sectionItemsCount = getItemsCount(i);
|
||||
if (sectionItemsCount == 0)
|
||||
continue;
|
||||
itemCount += sectionItemsCount + /* header */ 1;
|
||||
}
|
||||
return itemCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ import com.mapswithme.maps.MwmActivity;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.AbstractCategoriesSnapshot;
|
||||
import com.mapswithme.maps.bookmarks.data.Bookmark;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkInfo;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
@ -51,7 +50,6 @@ import com.mapswithme.util.sharing.ShareOption;
|
|||
import com.mapswithme.util.sharing.SharingHelper;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListAdapter>
|
||||
|
@ -122,6 +120,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
if (args == null || ((category = args.getParcelable(EXTRA_CATEGORY))) == null)
|
||||
throw new IllegalArgumentException("Category not exist in bundle");
|
||||
|
||||
initAdditionalCollectionAdapter(category.getId());
|
||||
return category;
|
||||
}
|
||||
|
||||
|
@ -133,11 +132,12 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
}
|
||||
|
||||
@NonNull
|
||||
private BookmarkCollectionAdapter createAdditionalCollectionAdapter(){
|
||||
// TODO (@velichkomarija): Get items from BookmarkMagager.
|
||||
List<BookmarkCategory> mCollectionItems = new ArrayList<>();
|
||||
List<BookmarkCategory> mCategoryItems = new ArrayList<>();
|
||||
return new BookmarkCollectionAdapter(requireContext(),mCategoryItems, mCollectionItems);
|
||||
private void initAdditionalCollectionAdapter(long categoryId)
|
||||
{
|
||||
List<BookmarkCategory> mCategoryItems = BookmarkManager.INSTANCE.getChildrenCategories(categoryId);
|
||||
List<BookmarkCategory> mCollectionItems = BookmarkManager.INSTANCE.getChildrenCollections(categoryId);
|
||||
|
||||
mBookmarkCollectionAdapter = new BookmarkCollectionAdapter(requireContext(),mCategoryItems, mCollectionItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -153,6 +153,9 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, "onViewCreated");
|
||||
configureAdapter();
|
||||
|
||||
configureCollectionRecycler(view);
|
||||
|
||||
configureFab(view);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
@ -232,6 +235,14 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
});
|
||||
}
|
||||
|
||||
private void configureCollectionRecycler(@NonNull View view){
|
||||
RecyclerView recyclerViewForCollection = view.findViewById(R.id.collections_recycler);
|
||||
LinearLayoutManager manager = new LinearLayoutManager(view.getContext());
|
||||
manager.setSmoothScrollbarEnabled(true);
|
||||
recyclerViewForCollection.setLayoutManager(manager);
|
||||
recyclerViewForCollection.setAdapter(mBookmarkCollectionAdapter);
|
||||
}
|
||||
|
||||
private void configureFab(@NonNull View view)
|
||||
{
|
||||
mFabViewOnMap = view.findViewById(R.id.fabViewOnMap);
|
||||
|
|
|
@ -18,6 +18,7 @@ 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;
|
||||
|
@ -873,6 +874,15 @@ public enum BookmarkManager
|
|||
nativeGetSortedCategory(catId, sortingType, hasMyPosition, lat, lon, timestamp);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<BookmarkCategory> getChildrenCategories(long catId){
|
||||
return Arrays.asList(nativeGetChildrenCategories(catId));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<BookmarkCategory> getChildrenCollections(long catId){
|
||||
return Arrays.asList(nativeGetChildrenCollections(catId));
|
||||
}
|
||||
@NonNull
|
||||
native BookmarkCategory[] nativeGetBookmarkCategories();
|
||||
@NonNull
|
||||
|
|
Loading…
Add table
Reference in a new issue