[android] Implemented hide/show all logic in bookmark category list

This commit is contained in:
Александр Зацепин 2018-03-22 14:45:01 +03:00 committed by Arsentiy Milchakov
parent 8f5205a389
commit 6ce3053bce
4 changed files with 102 additions and 18 deletions

View file

@ -17,7 +17,7 @@
android:fontFamily="@string/robotoMedium"
tools:targetApi="jelly_bean"/>
<TextView
android:id="@+id/hide_btn"
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/MwmTextAppearance.Body3"

View file

@ -7,7 +7,6 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
@ -15,12 +14,14 @@ import com.mapswithme.maps.widget.recycler.RecyclerClickListener;
import com.mapswithme.maps.widget.recycler.RecyclerLongClickListener;
import static com.mapswithme.maps.bookmarks.Holders.CategoryViewHolder;
import static com.mapswithme.maps.bookmarks.Holders.HeaderViewHolder;
public class BookmarkCategoriesAdapter extends BaseBookmarkCategoryAdapter<RecyclerView.ViewHolder>
{
private final static int TYPE_CATEGORY_ITEM = 0;
private final static int TYPE_ACTION_CREATE_GROUP = 1;
private final static int TYPE_ACTION_HIDE_ALL = 2;
private final static int TYPE_ACTION_HEADER = 2;
private final static int HEADER_POSITION = 0;
@Nullable
private RecyclerLongClickListener mLongClickListener;
@Nullable
@ -52,15 +53,10 @@ public class BookmarkCategoriesAdapter extends BaseBookmarkCategoryAdapter<Recyc
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
LayoutInflater inflater = LayoutInflater.from(getContext());
if (viewType == TYPE_ACTION_HIDE_ALL)
if (viewType == TYPE_ACTION_HEADER)
{
View hideAllView = inflater.inflate(R.layout.item_bookmark_hide_all, parent, false);
hideAllView.findViewById(R.id.hide_btn).setOnClickListener
(v ->
{
Toast.makeText(getContext(), "Coming soon", Toast.LENGTH_SHORT).show();
});
return new Holders.GeneralViewHolder(hideAllView);
View header = inflater.inflate(R.layout.item_bookmark_group_list_header, parent, false);
return new Holders.HeaderViewHolder(header);
}
if (viewType == TYPE_ACTION_CREATE_GROUP)
@ -99,9 +95,32 @@ public class BookmarkCategoriesAdapter extends BaseBookmarkCategoryAdapter<Recyc
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position)
{
int type = getItemViewType(position);
if (type == TYPE_ACTION_CREATE_GROUP || type == TYPE_ACTION_HIDE_ALL)
if (type == TYPE_ACTION_CREATE_GROUP)
return;
if (type == TYPE_ACTION_HEADER)
{
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
headerHolder.setActionText(BookmarkManager.INSTANCE.areAllCategoriesInvisible());
headerHolder.setAction(new HeaderViewHolder.HeaderAction()
{
@Override
public void onHideAll()
{
BookmarkManager.INSTANCE.setAllCategoriesVisibility(false);
notifyDataSetChanged();
}
@Override
public void onShowAll()
{
BookmarkManager.INSTANCE.setAllCategoriesVisibility(true);
notifyDataSetChanged();
}
});
return;
}
CategoryViewHolder categoryHolder = (CategoryViewHolder) holder;
final BookmarkManager bmManager = BookmarkManager.INSTANCE;
final long catId = getCategoryIdByPosition(toCategoryPosition(position));
@ -113,6 +132,7 @@ public class BookmarkCategoriesAdapter extends BaseBookmarkCategoryAdapter<Recyc
{
BookmarkManager.INSTANCE.toggleCategoryVisibility(catId);
categoryHolder.setVisibilityState(bmManager.isVisible(catId));
notifyItemChanged(HEADER_POSITION);
});
categoryHolder.setMoreListener(v -> {
if (mCategoryListInterface != null)
@ -124,7 +144,7 @@ public class BookmarkCategoriesAdapter extends BaseBookmarkCategoryAdapter<Recyc
public int getItemViewType(int position)
{
if (position == 0)
return TYPE_ACTION_HIDE_ALL;
return TYPE_ACTION_HEADER;
return (position == getItemCount() - 1) ? TYPE_ACTION_CREATE_GROUP : TYPE_CATEGORY_ITEM;
}

View file

@ -1,5 +1,6 @@
package com.mapswithme.maps.bookmarks;
import android.content.res.Resources;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
@ -21,6 +22,46 @@ public class Holders
}
}
static class HeaderViewHolder extends RecyclerView.ViewHolder
{
@NonNull
private TextView mButton;
public HeaderViewHolder(@NonNull View itemView)
{
super(itemView);
mButton = itemView.findViewById(R.id.button);
}
void setActionText(boolean showAll)
{
mButton.setText(showAll ? R.string.bookmarks_groups_show_all :
R.string.bookmarks_groups_hide_all);
}
void setAction(@Nullable HeaderAction action)
{
mButton.setOnClickListener
(v ->
{
if (action == null)
return;
Resources res = mButton.getResources();
if (mButton.getText().equals(res.getString(R.string.bookmarks_groups_show_all)))
action.onShowAll();
else
action.onHideAll();
});
}
public interface HeaderAction
{
void onHideAll();
void onShowAll();
}
}
static class CategoryViewHolder extends RecyclerView.ViewHolder
{
@NonNull

View file

@ -240,6 +240,26 @@ public enum BookmarkManager
return nativeIsAsyncBookmarksLoadingInProgress();
}
public boolean isUsedCategoryName(@NonNull String name)
{
return nativeIsUsedCategoryName(name);
}
public boolean areAllCategoriesVisible()
{
return nativeAreAllCategoriesVisible();
}
public boolean areAllCategoriesInvisible()
{
return nativeAreAllCategoriesInvisible();
}
public void setAllCategoriesVisibility(boolean visible)
{
nativeSetAllCategoriesVisibility(visible);
}
private native int nativeGetCategoriesCount();
private native int nativeGetCategoryPositionById(long catId);
@ -311,15 +331,18 @@ public enum BookmarkManager
private static native boolean nativeIsAsyncBookmarksLoadingInProgress();
private static native boolean nativeIsUsedCategoryName(@NonNull String name);
private static native boolean nativeAreAllCategoriesVisible();
private static native boolean nativeAreAllCategoriesInvisible();
private static native void nativeSetAllCategoriesVisibility(boolean visible);
public interface BookmarksLoadingListener
{
void onBookmarksLoadingStarted();
void onBookmarksLoadingFinished();
void onBookmarksFileLoaded(boolean success);
}
private static native boolean nativeIsUsedCategoryName(@NonNull String name);
private static native boolean nativeAreAllCategoriesVisible();
private static native boolean nativeAreAllCategoriesInvisible();
private static native void nativeSetAllCategoriesVisibility(boolean visible);
}