forked from organicmaps/organicmaps
[android] Added click listener on collection items.
This commit is contained in:
parent
eccd63c0e9
commit
ff7c0da926
5 changed files with 28 additions and 3 deletions
|
@ -177,6 +177,7 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
collectionViewHolder.setName(category.getName());
|
||||
bindSize(collectionViewHolder, category);
|
||||
collectionViewHolder.setVisibilityState(category.isVisible());
|
||||
collectionViewHolder.setOnClickListener(mClickListener);
|
||||
|
||||
// TODO (@velichkomarija): ToggleVisibilityClickListener for visibility.
|
||||
}
|
||||
|
|
|
@ -145,6 +145,11 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
List<BookmarkCategory> mCollectionItems = BookmarkManager.INSTANCE.getChildrenCollections(categoryId);
|
||||
|
||||
mBookmarkCollectionAdapter = new BookmarkCollectionAdapter(mCategoryItems, mCollectionItems);
|
||||
mBookmarkCollectionAdapter.setOnClickListener((v, item) -> {
|
||||
Intent intent = new Intent(getActivity(), BookmarkListActivity.class)
|
||||
.putExtra(BookmarksListFragment.EXTRA_CATEGORY, item);
|
||||
startActivityForResult(intent, 101);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.adapter.OnItemClickListener;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkInfo;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
@ -119,6 +120,8 @@ public class Holders
|
|||
|
||||
static class CollectionViewHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
@NonNull
|
||||
private final View mView;
|
||||
@NonNull
|
||||
private final TextView mName;
|
||||
@NonNull
|
||||
|
@ -131,11 +134,20 @@ public class Holders
|
|||
CollectionViewHolder(@NonNull View root)
|
||||
{
|
||||
super(root);
|
||||
mView = root;
|
||||
mName = root.findViewById(R.id.name);
|
||||
mVisibilityMarker = root.findViewById(R.id.checkbox);
|
||||
mSize = root.findViewById(R.id.size);
|
||||
}
|
||||
|
||||
void setOnClickListener(@Nullable OnItemClickListener<BookmarkCategory> listener)
|
||||
{
|
||||
mView.setOnClickListener(v -> {
|
||||
if (listener != null)
|
||||
listener.onItemClick(v,mEntity);
|
||||
});
|
||||
}
|
||||
|
||||
void setVisibilityState(boolean visible)
|
||||
{
|
||||
mVisibilityMarker.setChecked(visible);
|
||||
|
|
|
@ -45,6 +45,11 @@ public abstract class AbstractCategoriesSnapshot
|
|||
return indexOfThrowInternal(getItems(), category);
|
||||
}
|
||||
|
||||
public int indexOfOrInvalidIndex(@NonNull BookmarkCategory category)
|
||||
{
|
||||
return getItems().indexOf(category);
|
||||
}
|
||||
|
||||
private static int indexOfThrowInternal(@NonNull List<BookmarkCategory> categories,
|
||||
@NonNull BookmarkCategory category)
|
||||
{
|
||||
|
|
|
@ -29,8 +29,10 @@ public class CategoryDataSource extends RecyclerView.AdapterDataObserver impleme
|
|||
super.onChanged();
|
||||
AbstractCategoriesSnapshot.Default snapshot =
|
||||
BookmarkManager.INSTANCE.getCategoriesSnapshot(mCategory.getType().getFilterStrategy());
|
||||
|
||||
int index = snapshot.indexOfOrThrow(mCategory);
|
||||
mCategory = snapshot.getItems().get(index);
|
||||
int index = snapshot.indexOfOrInvalidIndex(mCategory);
|
||||
if (index >= 0)
|
||||
{
|
||||
mCategory = snapshot.getItems().get(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue