forked from organicmaps/organicmaps
[android] Refactored bookmarks list, i.e. replaced nested scrollview with two recyclers and description view by one recycler configured with merge adapter
This commit is contained in:
parent
2d6cb02544
commit
5ec12f512e
8 changed files with 214 additions and 137 deletions
|
@ -153,7 +153,7 @@ configurations.all {
|
|||
force "androidx.annotation:annotation:1.1.0"
|
||||
force "androidx.core:core:1.3.1"
|
||||
force "androidx.versionedparcelable:versionedparcelable:1.1.0"
|
||||
force "androidx.recyclerview:recyclerview:1.1.0"
|
||||
force "androidx.recyclerview:recyclerview:1.2.0-alpha02"
|
||||
|
||||
failOnVersionConflict();
|
||||
}
|
||||
|
|
|
@ -5,35 +5,17 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/scroll_view"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?windowBackgroundForced"
|
||||
android:fillViewport="true">
|
||||
<LinearLayout
|
||||
android:focusableInTouchMode="true"
|
||||
android:orientation="vertical">
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusableInTouchMode="true"
|
||||
android:orientation="vertical">
|
||||
<com.mapswithme.maps.bookmarks.BookmarkHeaderView
|
||||
android:id="@+id/guide_info"
|
||||
android:background="?cardBackground"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/collections_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:overScrollMode="never"
|
||||
android:background="?cardBackground"/>
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?cardBackground"/>
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
android:background="?cardBackground" />
|
||||
</LinearLayout>
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fabViewOnMap"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.mapswithme.maps.R;
|
|||
import com.mapswithme.maps.adapter.OnItemClickListener;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -40,6 +41,8 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
private int mCollectionSectionIndex = SectionPosition.INVALID_POSITION;
|
||||
private int mCategorySectionIndex = SectionPosition.INVALID_POSITION;
|
||||
|
||||
private boolean mVisible;
|
||||
|
||||
@Nullable
|
||||
private OnItemClickListener<BookmarkCategory> mClickListener;
|
||||
@NonNull
|
||||
|
@ -209,6 +212,7 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
collectionViewHolder.setOnClickListener(mClickListener);
|
||||
ToggleVisibilityClickListener listener = new ToggleVisibilityClickListener(collectionViewHolder);
|
||||
collectionViewHolder.setVisibilityListener(listener);
|
||||
updateVisibility(collectionViewHolder.itemView);
|
||||
}
|
||||
|
||||
private void bindSize(Holders.CollectionViewHolder holder, BookmarkCategory category)
|
||||
|
@ -229,6 +233,12 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
mBookmarkCategory.getId(), compilationType);
|
||||
headerViewHolder.setAction(mMassOperationAction, visibility, compilationType,
|
||||
mBookmarkCategory.getServerId());
|
||||
updateVisibility(headerViewHolder.itemView);
|
||||
}
|
||||
|
||||
private void updateVisibility(@NonNull View itemView)
|
||||
{
|
||||
UiUtils.showRecyclerItemView(mVisible, itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -260,6 +270,12 @@ public class BookmarkCollectionAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
mItemsCategory = BookmarkManager.INSTANCE.getChildrenCategories(mBookmarkCategory.getId());
|
||||
}
|
||||
|
||||
void show(boolean visible)
|
||||
{
|
||||
mVisible = visible;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
class MassOperationAction implements Holders.HeaderViewHolder.HeaderActionChildCategories
|
||||
{
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
class BookmarkDescriptionAdapter extends RecyclerView.Adapter<Holders.BookmarkDescriptionHolder>
|
||||
{
|
||||
@NonNull
|
||||
private final BookmarkCategory mCategory;
|
||||
private boolean mVisible;
|
||||
@NonNull
|
||||
private final View.OnClickListener mOnClickListener;
|
||||
|
||||
BookmarkDescriptionAdapter(@NonNull BookmarkCategory category,
|
||||
@NonNull View.OnClickListener onClickListener)
|
||||
{
|
||||
mCategory = category;
|
||||
mOnClickListener = onClickListener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Holders.BookmarkDescriptionHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
|
||||
{
|
||||
BookmarkHeaderView view = new BookmarkHeaderView(parent.getContext());
|
||||
return new Holders.BookmarkDescriptionHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull Holders.BookmarkDescriptionHolder holder, int position)
|
||||
{
|
||||
holder.bind(mCategory);
|
||||
View button = holder.itemView.findViewById(R.id.btn_description);
|
||||
button.setOnClickListener(mOnClickListener);
|
||||
UiUtils.showRecyclerItemView(mVisible, holder.itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void show(boolean visible)
|
||||
{
|
||||
mVisible = visible;
|
||||
notifyItemChanged(0);
|
||||
}
|
||||
}
|
|
@ -21,20 +21,26 @@ public class BookmarkHeaderView extends LinearLayout
|
|||
|
||||
public static final String AUTHOR_LONELY_PLANET_ID = "28035594-6457-466d-8f6f-8499607df570";
|
||||
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NonNull
|
||||
private ImageView mImageView;
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NonNull
|
||||
private TextView mTitle;
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NonNull
|
||||
private TextView mDescriptionBtn;
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NonNull
|
||||
private ImageView mImageViewLogo;
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NonNull
|
||||
private TextView mAuthorTextView;
|
||||
|
||||
public BookmarkHeaderView(@NonNull Context context)
|
||||
{
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public BookmarkHeaderView(@NonNull Context context, @Nullable AttributeSet attrs)
|
||||
|
@ -58,12 +64,6 @@ public class BookmarkHeaderView extends LinearLayout
|
|||
private void init() {
|
||||
setOrientation(LinearLayout.VERTICAL);
|
||||
View.inflate(getContext(), R.layout.item_guide_info, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate()
|
||||
{
|
||||
super.onFinishInflate();
|
||||
mImageView = findViewById(R.id.guide_image);
|
||||
mTitle = findViewById(R.id.guide_title);
|
||||
mDescriptionBtn = findViewById(R.id.btn_description);
|
||||
|
@ -71,11 +71,12 @@ public class BookmarkHeaderView extends LinearLayout
|
|||
mImageViewLogo = findViewById(R.id.logo);
|
||||
}
|
||||
|
||||
public void setCategory(@NonNull BookmarkCategory category) {
|
||||
Context context = getContext();
|
||||
public void setCategory(@NonNull BookmarkCategory category)
|
||||
{
|
||||
if (!category.isMyCategory())
|
||||
{
|
||||
String imageUrl = category.getImageUrl();
|
||||
final Context context = getContext();
|
||||
final String imageUrl = category.getImageUrl();
|
||||
if (TextUtils.isEmpty(imageUrl) || !ConnectionState.isConnected())
|
||||
{
|
||||
UiUtils.hide(mImageView);
|
||||
|
@ -106,7 +107,7 @@ public class BookmarkHeaderView extends LinearLayout
|
|||
}
|
||||
else
|
||||
{
|
||||
UiUtils.hide(findViewById(R.id.guide_info));
|
||||
UiUtils.hide(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,15 +11,13 @@ import android.view.MenuInflater;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.widget.NestedScrollView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.MergeAdapter;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
import com.cocosw.bottomsheet.BottomSheet;
|
||||
|
@ -56,7 +54,7 @@ import com.mapswithme.util.statistics.Statistics;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListAdapter>
|
||||
public class BookmarksListFragment extends BaseMwmRecyclerFragment<MergeAdapter>
|
||||
implements BookmarkManager.BookmarksSharingListener,
|
||||
BookmarkManager.BookmarksSortingListener,
|
||||
BookmarkManager.BookmarksLoadingListener,
|
||||
|
@ -66,27 +64,22 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
public static final String TAG = BookmarksListFragment.class.getSimpleName();
|
||||
public static final String EXTRA_CATEGORY = "bookmark_category";
|
||||
public static final String EXTRA_BUNDLE = "bookmark_bundle";
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private SearchToolbarController mToolbarController;
|
||||
|
||||
private long mLastQueryTimestamp = 0;
|
||||
private long mLastSortTimestamp = 0;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private CategoryDataSource mCategoryDataSource;
|
||||
private int mSelectedPosition;
|
||||
|
||||
private boolean mSearchMode = false;
|
||||
private boolean mNeedUpdateSorting = true;
|
||||
private static final int INDEX_BOOKMARKS_DESCRIPTION_ADAPTER = 0;
|
||||
private static final int INDEX_BOOKMARKS_COLLECTION_ADAPTER = 1;
|
||||
private static final int INDEX_BOOKMARKS_LIST_ADAPTER = 2;
|
||||
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NonNull
|
||||
private BookmarkCollectionAdapter mBookmarkCollectionAdapter;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
private SearchToolbarController mToolbarController;
|
||||
private long mLastQueryTimestamp = 0;
|
||||
private long mLastSortTimestamp = 0;
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NonNull
|
||||
private CategoryDataSource mCategoryDataSource;
|
||||
private int mSelectedPosition;
|
||||
private boolean mSearchMode = false;
|
||||
private boolean mNeedUpdateSorting = true;
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NonNull
|
||||
private ViewGroup mSearchContainer;
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
|
@ -94,14 +87,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
private FloatingActionButton mFabViewOnMap;
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NonNull
|
||||
private BookmarkHeaderView mDescriptionView;
|
||||
@NonNull
|
||||
private RecyclerView mCollectionRecyclerView;
|
||||
@NonNull
|
||||
private BookmarkManager.BookmarksCatalogListener mCatalogListener;
|
||||
@NonNull
|
||||
private NestedScrollView mNestedScrollView;
|
||||
|
||||
@NonNull
|
||||
private final RecyclerView.OnScrollListener mRecyclerListener = new RecyclerView.OnScrollListener()
|
||||
{
|
||||
|
@ -112,9 +98,11 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
mToolbarController.deactivate();
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
private Bundle mSavedInstanceState;
|
||||
@NonNull
|
||||
private final View.OnClickListener mBookmarksDescriptionClickListener
|
||||
= view -> openDescriptionScreen();
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
|
@ -141,19 +129,23 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
|
||||
@NonNull
|
||||
@Override
|
||||
protected BookmarkListAdapter createAdapter()
|
||||
protected MergeAdapter createAdapter()
|
||||
{
|
||||
return new BookmarkListAdapter(mCategoryDataSource);
|
||||
BookmarkCategory category = mCategoryDataSource.getData();
|
||||
return new MergeAdapter(new BookmarkDescriptionAdapter(category, mBookmarksDescriptionClickListener),
|
||||
initAndGetCollectionAdapter(category.getId()),
|
||||
new BookmarkListAdapter(mCategoryDataSource));
|
||||
}
|
||||
|
||||
private void initAdditionalCollectionAdapter(long categoryId)
|
||||
@NonNull
|
||||
private RecyclerView.Adapter<RecyclerView.ViewHolder> initAndGetCollectionAdapter(long categoryId)
|
||||
{
|
||||
List<BookmarkCategory> mCategoryItems = BookmarkManager.INSTANCE.getChildrenCategories(categoryId);
|
||||
List<BookmarkCategory> mCollectionItems = BookmarkManager.INSTANCE.getChildrenCollections(categoryId);
|
||||
|
||||
mBookmarkCollectionAdapter = new BookmarkCollectionAdapter(getCategoryOrThrow(),
|
||||
mCategoryItems, mCollectionItems);
|
||||
mBookmarkCollectionAdapter.setOnClickListener((v, item) -> {
|
||||
BookmarkCollectionAdapter adapter = new BookmarkCollectionAdapter(getCategoryOrThrow(),
|
||||
mCategoryItems, mCollectionItems);
|
||||
adapter.setOnClickListener((v, item) -> {
|
||||
Intent intent = BookmarkListActivity.getStartIntent(requireContext(), item);
|
||||
|
||||
final boolean isCategory = BookmarkManager.INSTANCE.getCompilationType(item.getId()) ==
|
||||
|
@ -162,6 +154,8 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
isCategory);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -190,19 +184,10 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
|
||||
private void onViewCreatedInternal(@NonNull View view)
|
||||
{
|
||||
initAdditionalCollectionAdapter(getCategoryOrThrow().getId());
|
||||
|
||||
configureAdapter();
|
||||
|
||||
configureCollectionRecycler(view);
|
||||
configureBookmarksListAdapter();
|
||||
|
||||
configureFab(view);
|
||||
|
||||
mDescriptionView = view.findViewById(R.id.guide_info);
|
||||
configureGuidesInfoLayout();
|
||||
|
||||
mNestedScrollView = view.findViewById(R.id.scroll_view);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
ActionBar bar = ((AppCompatActivity) requireActivity()).getSupportActionBar();
|
||||
|
@ -215,12 +200,9 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
|
||||
mToolbarController = new BookmarksToolbarController(toolbar, requireActivity(), this);
|
||||
mToolbarController.setHint(R.string.search_in_the_list);
|
||||
configureRecyclerDividers(getRecyclerView());
|
||||
|
||||
TextView description = requireActivity().findViewById(R.id.btn_description);
|
||||
description.setOnClickListener((btnView) -> {
|
||||
openDescriptionScreen();
|
||||
});
|
||||
configureRecyclerAnimations();
|
||||
configureRecyclerDividers();
|
||||
|
||||
updateLoadingPlaceholder(view, false);
|
||||
}
|
||||
|
@ -245,7 +227,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
if (BookmarkManager.INSTANCE.isAsyncBookmarksLoadingInProgress())
|
||||
return;
|
||||
|
||||
BookmarkListAdapter adapter = getAdapter();
|
||||
BookmarkListAdapter adapter = getBookmarkListAdapter();
|
||||
adapter.notifyDataSetChanged();
|
||||
updateSorting();
|
||||
updateSearchVisibility();
|
||||
|
@ -271,15 +253,9 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
BookmarkManager.INSTANCE.removeCatalogListener(mCatalogListener);
|
||||
}
|
||||
|
||||
private void configureGuidesInfoLayout()
|
||||
private void configureBookmarksListAdapter()
|
||||
{
|
||||
BookmarkCategory category = mCategoryDataSource.getData();
|
||||
mDescriptionView.setCategory(category);
|
||||
}
|
||||
|
||||
private void configureAdapter()
|
||||
{
|
||||
BookmarkListAdapter adapter = getAdapter();
|
||||
BookmarkListAdapter adapter = getBookmarkListAdapter();
|
||||
adapter.registerAdapterDataObserver(mCategoryDataSource);
|
||||
adapter.setOnClickListener((v, position) ->
|
||||
{
|
||||
|
@ -295,21 +271,6 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
});
|
||||
}
|
||||
|
||||
private void configureCollectionRecycler(@NonNull View view)
|
||||
{
|
||||
mCollectionRecyclerView = view.findViewById(R.id.collections_recycler);
|
||||
LinearLayoutManager manager = new LinearLayoutManager(view.getContext());
|
||||
manager.setSmoothScrollbarEnabled(true);
|
||||
mCollectionRecyclerView.setLayoutManager(manager);
|
||||
|
||||
RecyclerView.ItemAnimator itemAnimator = mCollectionRecyclerView.getItemAnimator();
|
||||
if (itemAnimator != null)
|
||||
((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
|
||||
|
||||
mCollectionRecyclerView.setAdapter(mBookmarkCollectionAdapter);
|
||||
configureRecyclerDividers(mCollectionRecyclerView);
|
||||
}
|
||||
|
||||
private void configureFab(@NonNull View view)
|
||||
{
|
||||
mFabViewOnMap = view.findViewById(R.id.fabViewOnMap);
|
||||
|
@ -323,12 +284,19 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
});
|
||||
}
|
||||
|
||||
private void configureRecyclerDividers(@NonNull RecyclerView recyclerView)
|
||||
private void configureRecyclerAnimations()
|
||||
{
|
||||
RecyclerView.ItemAnimator itemAnimator = getRecyclerView().getItemAnimator();
|
||||
if (itemAnimator != null)
|
||||
((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
|
||||
}
|
||||
|
||||
private void configureRecyclerDividers()
|
||||
{
|
||||
RecyclerView.ItemDecoration decorWithPadding = ItemDecoratorFactory
|
||||
.createDecoratorWithPadding(requireContext());
|
||||
recyclerView.addItemDecoration(decorWithPadding);
|
||||
recyclerView.addOnScrollListener(mRecyclerListener);
|
||||
getRecyclerView().addItemDecoration(decorWithPadding);
|
||||
getRecyclerView().addOnScrollListener(mRecyclerListener);
|
||||
}
|
||||
|
||||
private void updateRecyclerVisibility()
|
||||
|
@ -349,11 +317,12 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
boolean isEmptyRecycler = isEmpty() || isEmptySearchResults();
|
||||
|
||||
showPlaceholder(isEmptyRecycler);
|
||||
UiUtils.hideIf(getAdapter().isSearchResults(), mCollectionRecyclerView, mDescriptionView);
|
||||
UiUtils.showIf(!isEmptyRecycler, getRecyclerView(), mFabViewOnMap, mDescriptionView);
|
||||
|
||||
if (getCategoryOrThrow().isMyCategory())
|
||||
UiUtils.hide(mDescriptionView);
|
||||
getDescriptionAdapter().show(!getBookmarkListAdapter().isSearchResults()
|
||||
&& !isEmptyRecycler && !getCategoryOrThrow().isMyCategory());
|
||||
getBookmarkCollectionAdapter().show(!getBookmarkListAdapter().isSearchResults());
|
||||
|
||||
UiUtils.showIf(!isEmptyRecycler, getRecyclerView(), mFabViewOnMap);
|
||||
|
||||
requireActivity().invalidateOptionsMenu();
|
||||
}
|
||||
|
@ -409,10 +378,9 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
|
||||
private void updateSearchResults(@Nullable long[] bookmarkIds)
|
||||
{
|
||||
BookmarkListAdapter adapter = getAdapter();
|
||||
BookmarkListAdapter adapter = getBookmarkListAdapter();
|
||||
adapter.setSearchResults(bookmarkIds);
|
||||
adapter.notifyDataSetChanged();
|
||||
mNestedScrollView.smoothScrollTo(0, 0);
|
||||
updateRecyclerVisibility();
|
||||
}
|
||||
|
||||
|
@ -447,7 +415,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
return;
|
||||
mLastSortTimestamp = 0;
|
||||
|
||||
BookmarkListAdapter adapter = getAdapter();
|
||||
BookmarkListAdapter adapter = getBookmarkListAdapter();
|
||||
adapter.setSortedResults(sortedBlocks);
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
|
@ -461,7 +429,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
return;
|
||||
mLastSortTimestamp = 0;
|
||||
|
||||
BookmarkListAdapter adapter = getAdapter();
|
||||
BookmarkListAdapter adapter = getBookmarkListAdapter();
|
||||
adapter.setSortedResults(null);
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
|
@ -489,6 +457,26 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
updateSortingProgressBar();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private BookmarkListAdapter getBookmarkListAdapter()
|
||||
{
|
||||
return (BookmarkListAdapter) getAdapter().getAdapters().get(INDEX_BOOKMARKS_LIST_ADAPTER);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private BookmarkDescriptionAdapter getDescriptionAdapter()
|
||||
{
|
||||
return (BookmarkDescriptionAdapter) getAdapter().getAdapters()
|
||||
.get(INDEX_BOOKMARKS_DESCRIPTION_ADAPTER);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private BookmarkCollectionAdapter getBookmarkCollectionAdapter()
|
||||
{
|
||||
return (BookmarkCollectionAdapter) getAdapter().getAdapters()
|
||||
.get(INDEX_BOOKMARKS_COLLECTION_ADAPTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResetSorting()
|
||||
{
|
||||
|
@ -496,7 +484,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
long catId = mCategoryDataSource.getData().getId();
|
||||
BookmarkManager.INSTANCE.resetLastSortingType(catId);
|
||||
|
||||
BookmarkListAdapter adapter = getAdapter();
|
||||
BookmarkListAdapter adapter = getBookmarkListAdapter();
|
||||
adapter.setSortedResults(null);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
@ -529,7 +517,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
|
||||
private void resetSearchAndSort()
|
||||
{
|
||||
BookmarkListAdapter adapter = getAdapter();
|
||||
BookmarkListAdapter adapter = getBookmarkListAdapter();
|
||||
adapter.setSortedResults(null);
|
||||
adapter.setSearchResults(null);
|
||||
adapter.notifyDataSetChanged();
|
||||
|
@ -575,12 +563,14 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
|
||||
private boolean isEmpty()
|
||||
{
|
||||
return !getAdapter().isSearchResults() && getAdapter().getItemCount() == 0;
|
||||
return !getBookmarkListAdapter().isSearchResults()
|
||||
&& getBookmarkListAdapter().getItemCount() == 0;
|
||||
}
|
||||
|
||||
private boolean isEmptySearchResults()
|
||||
{
|
||||
return getAdapter().isSearchResults() && getAdapter().getItemCount() == 0;
|
||||
return getBookmarkListAdapter().isSearchResults()
|
||||
&& getBookmarkListAdapter().getItemCount() == 0;
|
||||
}
|
||||
|
||||
private boolean isDownloadedCategory()
|
||||
|
@ -616,7 +606,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
{
|
||||
final Intent intent = makeMwmActivityIntent();
|
||||
|
||||
BookmarkListAdapter adapter = getAdapter();
|
||||
BookmarkListAdapter adapter = getBookmarkListAdapter();
|
||||
|
||||
switch (adapter.getItemViewType(position))
|
||||
{
|
||||
|
@ -655,7 +645,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
private void onBookmarkClicked(int position, @NonNull Intent i,
|
||||
@NonNull BookmarkListAdapter adapter)
|
||||
{
|
||||
if (getAdapter().isSearchResults())
|
||||
if (getBookmarkListAdapter().isSearchResults())
|
||||
trackBookmarksSearchResultSelected();
|
||||
|
||||
final BookmarkInfo bookmark = (BookmarkInfo) adapter.getItem(position);
|
||||
|
@ -668,7 +658,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
|
||||
public void onItemMore(int position)
|
||||
{
|
||||
BookmarkListAdapter adapter = getAdapter();
|
||||
BookmarkListAdapter adapter = getBookmarkListAdapter();
|
||||
|
||||
mSelectedPosition = position;
|
||||
int type = adapter.getItemViewType(mSelectedPosition);
|
||||
|
@ -715,7 +705,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
|
||||
public boolean onBookmarkMenuItemClicked(@NonNull MenuItem menuItem)
|
||||
{
|
||||
BookmarkListAdapter adapter = getAdapter();
|
||||
BookmarkListAdapter adapter = getBookmarkListAdapter();
|
||||
BookmarkInfo item = (BookmarkInfo) adapter.getItem(mSelectedPosition);
|
||||
switch (menuItem.getItemId())
|
||||
{
|
||||
|
@ -882,7 +872,6 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
Statistics.INSTANCE.trackBookmarksListSearchResultSelected();
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
|
@ -907,6 +896,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
|
||||
super.onViewCreated(view, mSavedInstanceState);
|
||||
onViewCreatedInternal(view);
|
||||
updateRecyclerVisibility();
|
||||
updateLoadingPlaceholder(view, false);
|
||||
}
|
||||
|
||||
|
@ -919,7 +909,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
private void updateLoadingPlaceholder(@NonNull View root, boolean isShowLoadingPlaceholder)
|
||||
{
|
||||
View loadingPlaceholder = root.findViewById(R.id.placeholder_loading);
|
||||
UiUtils.showIf(!isShowLoadingPlaceholder, root, R.id.scroll_view, R.id.fabViewOnMap);
|
||||
UiUtils.showIf(!isShowLoadingPlaceholder, root, R.id.fabViewOnMap);
|
||||
UiUtils.showIf(isShowLoadingPlaceholder, loadingPlaceholder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,6 @@ package com.mapswithme.maps.bookmarks;
|
|||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.location.Location;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.PluralsRes;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.text.Html;
|
||||
import android.text.Layout;
|
||||
import android.text.Spanned;
|
||||
|
@ -18,6 +13,10 @@ import android.widget.CheckBox;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.PluralsRes;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.adapter.OnItemClickListener;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
|
@ -330,6 +329,23 @@ public class Holders
|
|||
}
|
||||
}
|
||||
|
||||
static class BookmarkDescriptionHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
@NonNull
|
||||
private final BookmarkHeaderView mDescriptionView;
|
||||
|
||||
public BookmarkDescriptionHolder(@NonNull BookmarkHeaderView itemView)
|
||||
{
|
||||
super(itemView);
|
||||
mDescriptionView = itemView;
|
||||
}
|
||||
|
||||
void bind(@NonNull BookmarkCategory category)
|
||||
{
|
||||
mDescriptionView.setCategory(category);
|
||||
}
|
||||
}
|
||||
|
||||
static abstract class BaseBookmarkHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
@NonNull
|
||||
|
|
|
@ -40,6 +40,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
|
@ -579,6 +580,22 @@ public final class UiUtils
|
|||
toast.show();
|
||||
}
|
||||
|
||||
public static void showRecyclerItemView(boolean show, @NonNull View view)
|
||||
{
|
||||
if (show)
|
||||
{
|
||||
view.setLayoutParams(new RecyclerView.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
UiUtils.show(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view.setLayoutParams(new RecyclerView.LayoutParams(0, 0));
|
||||
UiUtils.hide(view);
|
||||
}
|
||||
}
|
||||
|
||||
// utility class
|
||||
private UiUtils() {}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue