[bookmarks][android] View on map button, no results placeholder, bug fixes.

This commit is contained in:
Daria Volvenkova 2019-08-22 04:37:15 +03:00 committed by Aleksey Belousov
parent 04d3618614
commit c2aed46af1
16 changed files with 190 additions and 73 deletions

View file

@ -483,6 +483,13 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeShowBookmarkOnMap(
frm()->ShowBookmark(static_cast<kml::MarkId>(bmkId));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeShowBookmarkCategoryOnMap(
JNIEnv * env, jobject thiz, jlong catId)
{
frm()->ShowBookmarkCategory(static_cast<kml::MarkGroupId>(catId), true /* animated */);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeLoadBookmarks(JNIEnv * env, jobject)
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 967 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -13,7 +13,7 @@
android:layout_height="match_parent"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/viewOnMap"
android:id="@+id/fabViewOnMap"
mapsme:layout_constraintRight_toRightOf="parent"
mapsme:layout_constraintBottom_toBottomOf="parent"
android:layout_width="wrap_content"
@ -25,7 +25,7 @@
android:layout_marginRight="@dimen/margin_base"
android:layout_marginEnd="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_base"
android:src="?fabAdd"/>
android:src="?fabViewOnMap"/>
<com.mapswithme.maps.widget.PlaceholderView
android:id="@+id/placeholder"

View file

@ -65,6 +65,7 @@
<attr name="navigationTheme" format="reference"/>
<attr name="fabAdd" format="reference"/>
<attr name="fabViewOnMap" format="reference"/>
<attr name="routingButtonHint" format="color"/>
<attr name="routingButtonPressedHint" format="color"/>

View file

@ -79,6 +79,7 @@
<item name="navigationTheme">@style/MwmTheme.Navigation</item>
<item name="fabAdd">@drawable/ic_fab_add</item>
<item name="fabViewOnMap">@drawable/ic_fab_view_on_map</item>
<item name="routingButtonHint">@color/routing_button_tint</item>
<item name="routingButtonActivatedHint">?statusBar</item>
@ -240,6 +241,7 @@
<item name="navigationTheme">@style/MwmTheme.Navigation.Night</item>
<item name="fabAdd">@drawable/ic_fab_add_night</item>
<item name="fabViewOnMap">@drawable/ic_fab_view_on_map</item>
<item name="routingButtonHint">@color/routing_button_tint</item>
<item name="routingButtonActivatedHint">?statusBar</item>

View file

@ -99,6 +99,9 @@ public abstract class BaseMwmRecyclerFragment<T extends RecyclerView.Adapter> ex
return mRecycler;
}
@Nullable
public PlaceholderView getPlaceholder() { return mPlaceholder; }
@Override
public void onResume()
{

View file

@ -473,7 +473,10 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
int sectionsCount = mSectionsDataSource.getSectionsCount();
for (int i = 0; i < sectionsCount; ++i)
{
itemCount += mSectionsDataSource.getItemsCount(i);
int sectionItemsCount = mSectionsDataSource.getItemsCount(i);
if (sectionItemsCount == 0)
continue;
itemCount += sectionItemsCount;
if (mSectionsDataSource.hasTitle(i))
++itemCount;
}
@ -484,10 +487,16 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
{
SectionPosition sp = getSectionPosition(position);
mSectionsDataSource.onDelete(sp);
if (mSearchResults != null)
// In case of the search results editing reset cached sorted blocks.
if (isSearchResults())
mSortedResults = null;
}
public boolean isSearchResults()
{
return mSearchResults != null;
}
// FIXME: remove this heavy method and use BoomarkInfo class instead.
public Object getItem(int position)
{

View file

@ -5,6 +5,7 @@ import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
@ -34,7 +35,6 @@ import com.mapswithme.maps.search.SearchEngine;
import com.mapswithme.maps.ugc.routes.BaseUgcRouteActivity;
import com.mapswithme.maps.ugc.routes.UgcRouteEditSettingsActivity;
import com.mapswithme.maps.ugc.routes.UgcRouteSharingOptionsActivity;
import com.mapswithme.maps.widget.SearchToolbarController;
import com.mapswithme.maps.widget.placepage.EditBookmarkFragment;
import com.mapswithme.maps.widget.placepage.Sponsored;
import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory;
@ -46,10 +46,6 @@ import com.mapswithme.util.sharing.ShareOption;
import com.mapswithme.util.sharing.SharingHelper;
import com.mapswithme.util.statistics.Statistics;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListAdapter>
implements RecyclerLongClickListener,
RecyclerClickListener,
@ -71,9 +67,13 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
private CategoryDataSource mCategoryDataSource;
private int mSelectedPosition;
private boolean mSearchAllowed = false;
private boolean mSearchMode = false;
private boolean mNeedUpdateSorting = true;
private ViewGroup mSearchContainer;
private FloatingActionButton mFabViewOnMap;
@SuppressWarnings("NullableProblems")
@NonNull
private BookmarkManager.BookmarksCatalogListener mCatalogListener;
@ -87,6 +87,8 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
BookmarkCategory category = getCategoryOrThrow();
mCategoryDataSource = new CategoryDataSource(category);
mCatalogListener = new CatalogListenerDecorator(this);
mSearchAllowed = !category.isFromCatalog() &&
BookmarkManager.INSTANCE.isSearchAllowed(category.getId());
}
@NonNull
@ -121,15 +123,15 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
super.onViewCreated(view, savedInstanceState);
Crashlytics.log("onViewCreated");
configureAdapter();
configureFab(view);
setHasOptionsMenu(true);
boolean isEmpty = getAdapter().getItemCount() == 0;
UiUtils.showIf(!isEmpty, getRecyclerView());
showPlaceholder(isEmpty);
ActionBar bar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (bar != null)
bar.setTitle(mCategoryDataSource.getData().getName());
ViewGroup toolbar = ((AppCompatActivity) getActivity()).findViewById(R.id.toolbar);
mSearchContainer = toolbar.findViewById(R.id.toolbar_search_container);
mToolbarController = new BookmarksToolbarController(toolbar, getActivity(), this);
addRecyclerDecor();
@ -161,6 +163,8 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
BookmarkListAdapter adapter = getAdapter();
adapter.notifyDataSetChanged();
updateSorting();
updateSearchVisibility();
updateRecyclerVisibility();
}
@Override
@ -189,6 +193,63 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
adapter.setOnLongClickListener(isDownloadedCategory() ? null : this);
}
private void configureFab(@NonNull View view)
{
mFabViewOnMap = (FloatingActionButton) view.findViewById(R.id.fabViewOnMap);
mFabViewOnMap.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
final Intent i = new Intent(getActivity(), MwmActivity.class);
i.putExtra(MwmActivity.EXTRA_TASK,
new Factory.ShowBookmarkCategoryTask(mCategoryDataSource.getData().getId()));
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
});
}
private void updateRecyclerVisibility()
{
if (isEmptySearchResults())
{
getPlaceholder().setContent(R.drawable.img_search_nothing_found_light,
R.string.search_not_found,
R.string.search_not_found_query);
}
else if (isEmpty())
{
getPlaceholder().setContent(R.drawable.img_empty_bookmarks,
R.string.bookmarks_empty_list_title,
R.string.bookmarks_empty_list_message);
}
boolean isEmptyRecycler = isEmpty() || isEmptySearchResults();
UiUtils.showIf(!isEmptyRecycler, getRecyclerView());
showPlaceholder(isEmptyRecycler);
UiUtils.showIf(!isEmptyRecycler, mFabViewOnMap);
getActivity().invalidateOptionsMenu();
}
private void updateSearchVisibility()
{
if (!mSearchAllowed || isEmpty())
{
UiUtils.hide(mSearchContainer);
}
else
{
UiUtils.showIf(mSearchMode, mSearchContainer);
if (mSearchMode)
mToolbarController.activate();
else
mToolbarController.deactivate();
}
getActivity().invalidateOptionsMenu();
}
@Override
public void onItemClick(View v, int position)
{
@ -265,23 +326,6 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
return false;
}
private void updateControlsStatus()
{
ViewGroup toolbar = ((AppCompatActivity) getActivity()).findViewById(R.id.toolbar);
ViewGroup searchContainer = toolbar.findViewById(R.id.toolbar_search_container);
UiUtils.showIf(isSearchMode(), searchContainer);
if (isSearchMode())
{
mToolbarController.activate();
}
else
{
mToolbarController.deactivate();
}
getActivity().invalidateOptionsMenu();
}
public void runSearch(@NonNull String query)
{
SearchEngine.INSTANCE.cancel();
@ -318,15 +362,14 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
BookmarkListAdapter adapter = getAdapter();
adapter.setSearchResults(bookmarkIds);
adapter.notifyDataSetChanged();
updateRecyclerVisibility();
}
public void cancelSearch()
{
SearchEngine.INSTANCE.cancel();
mToolbarController.showProgress(false);
BookmarkListAdapter adapter = getAdapter();
adapter.setSearchResults(null);
adapter.notifyDataSetChanged();
updateSearchResults(null);
updateSorting();
}
@ -334,19 +377,14 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
{
mSearchMode = true;
BookmarkManager.INSTANCE.setNotificationsEnabled(true);
updateControlsStatus();
updateSearchVisibility();
}
public void deactivateSearch()
{
mSearchMode = false;
BookmarkManager.INSTANCE.setNotificationsEnabled(false);
updateControlsStatus();
}
public boolean isSearchMode()
{
return mSearchMode;
updateSearchVisibility();
}
@Override
@ -394,7 +432,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
adapter.notifyDataSetChanged();
}
public void updateSorting()
private void updateSorting()
{
if (!mNeedUpdateSorting)
return;
@ -408,18 +446,9 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
if (!BookmarkManager.INSTANCE.hasLastSortingType(catId))
return;
@BookmarkManager.SortingType int currentType =
BookmarkManager.INSTANCE.getLastSortingType(catId);
@BookmarkManager.SortingType int[] types =
BookmarkManager.INSTANCE.getAvailableSortingTypes(catId, false);
for (int i = 0; i < types.length; ++i)
{
if (types[i] == currentType)
{
onSort(currentType);
break;
}
}
int currentType = getLastAvailableSortingType();
if (currentType >= 0)
onSort(currentType);
}
@Override
@ -431,23 +460,22 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
@Override
public boolean onMenuItemClick(MenuItem menuItem)
{
long catId = getCategoryOrThrow().getId();
switch (menuItem.getItemId())
{
case R.id.sort:
long catId = getCategoryOrThrow().getId();
@BookmarkManager.SortingType int[] types =
BookmarkManager.INSTANCE.getAvailableSortingTypes(catId, false);
int currentType = -1;
if (BookmarkManager.INSTANCE.hasLastSortingType(catId))
currentType = (int)BookmarkManager.INSTANCE.getLastSortingType(catId);
ChooseBookmarksSortingTypeFragment.chooseSortingType(types, currentType, this,
ChooseBookmarksSortingTypeFragment.chooseSortingType(getAvailableSortingTypes(),
getLastSortingType(),
this,
getActivity(),
getChildFragmentManager());
return false;
case R.id.sharing_options:
openSharingOptionsScreen();
trackBookmarkListSharingOptions();
return false;
case R.id.share_category:
SharingHelper.INSTANCE.prepareBookmarkCategoryForSharing(getActivity(), catId);
return false;
case R.id.settings:
Intent intent = new Intent(getContext(), UgcRouteEditSettingsActivity.class).putExtra(
@ -481,6 +509,8 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
adapter.notifyDataSetChanged();
if (mSearchMode)
mNeedUpdateSorting = true;
updateSearchVisibility();
updateRecyclerVisibility();
break;
}
return false;
@ -491,19 +521,27 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
{
if (isDownloadedCategory())
return;
inflater.inflate(R.menu.option_menu_bookmarks, menu);
MenuItem itemSearch = menu.findItem(R.id.bookmarks_search);
itemSearch.setVisible(getCategoryOrThrow().isSearchAllowed());
itemSearch.setVisible(mSearchAllowed && !isEmpty());
MenuItem itemMore = menu.findItem(R.id.bookmarks_more);
itemMore.setVisible(!isEmpty());
}
@Override
public void onPrepareOptionsMenu(Menu menu)
{
if (isDownloadedCategory())
return;
super.onPrepareOptionsMenu(menu);
final boolean visible = !isSearchMode();
boolean visible = !mSearchMode && !isEmpty();
MenuItem itemSearch = menu.findItem(R.id.bookmarks_search);
itemSearch.setVisible(visible);
itemSearch.setVisible(mSearchAllowed && visible);
MenuItem itemMore = menu.findItem(R.id.bookmarks_more);
itemMore.setVisible(visible);
@ -519,6 +557,44 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
actionBar.setTitle(mCategoryDataSource.getData().getName());
}
@NonNull
@BookmarkManager.SortingType
private int[] getAvailableSortingTypes()
{
long catId = mCategoryDataSource.getData().getId();
return BookmarkManager.INSTANCE.getAvailableSortingTypes(catId, false);
}
private int getLastSortingType()
{
long catId = mCategoryDataSource.getData().getId();
if (BookmarkManager.INSTANCE.hasLastSortingType(catId))
return BookmarkManager.INSTANCE.getLastSortingType(catId);
return -1;
}
private int getLastAvailableSortingType()
{
int currentType = getLastSortingType();
@BookmarkManager.SortingType int[] types = getAvailableSortingTypes();
for (int i = 0; i < types.length; ++i)
{
if (types[i] == currentType)
return currentType;
}
return -1;
}
private boolean isEmpty()
{
return !getAdapter().isSearchResults() && (getAdapter().getItemCount() == 0);
}
private boolean isEmptySearchResults()
{
return getAdapter().isSearchResults() && (getAdapter().getItemCount() == 0);
}
private boolean isDownloadedCategory()
{
BookmarkCategory category = mCategoryDataSource.getData();
@ -536,13 +612,15 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
if (item.getItemId() == R.id.bookmarks_more)
{
//openSharingOptionsScreen();
//trackBookmarkListSharingOptions();
BottomSheet bs = BottomSheetHelper.create(getActivity(),
mCategoryDataSource.getData().getName())
.sheet(R.menu.menu_bookmarks_list)
.listener(this)
.build();
@BookmarkManager.SortingType int[] types = getAvailableSortingTypes();
bs.getMenu().findItem(R.id.sort).setVisible(types.length > 0);
BottomSheetHelper.tint(bs);
bs.show();
return true;

View file

@ -31,9 +31,6 @@ public class BookmarksToolbarController extends SearchToolbarController
@Override
protected void onTextChanged(String query)
{
if (!mFragment.isSearchMode())
return;
if (hasQuery())
mFragment.runSearch(getQuery());
else

View file

@ -181,11 +181,6 @@ public class BookmarkCategory implements Parcelable
return isLocal && size() > 0;
}
public boolean isSearchAllowed()
{
return true;
}
public static class CountAndPlurals {
private final int mCount;
@PluralsRes

View file

@ -536,6 +536,8 @@ public enum BookmarkManager
public void showBookmarkOnMap(long bmkId) { nativeShowBookmarkOnMap(bmkId); }
public void showBookmarkCategoryOnMap(long catId) { nativeShowBookmarkCategoryOnMap(catId); }
public long getLastEditedCategory() { return nativeGetLastEditedCategory(); }
@Icon.PredefinedColor
@ -598,6 +600,9 @@ public enum BookmarkManager
public boolean isEditableCategory(long catId) { return nativeIsEditableCategory(catId); }
// TODO(@darina) Implement in native BookmarkManager.
public boolean isSearchAllowed(long catId) { return true; }
public boolean areAllCatalogCategoriesVisible()
{
return areAllCategoriesVisible(BookmarkCategory.Type.DOWNLOADED);
@ -841,6 +846,8 @@ public enum BookmarkManager
private native void nativeShowBookmarkOnMap(long bmkId);
private native void nativeShowBookmarkCategoryOnMap(long catId);
@NonNull
private native Bookmark nativeAddBookmarkToLastEditedCategory(double lat, double lon);

View file

@ -847,6 +847,24 @@ public class Factory
}
}
public static class ShowBookmarkCategoryTask implements MapTask
{
private static final long serialVersionUID = 1L;
final long mCategoryId;
public ShowBookmarkCategoryTask(long categoryId)
{
mCategoryId = categoryId;
}
public boolean run(@NonNull MwmActivity target)
{
BookmarkManager.INSTANCE.showBookmarkCategoryOnMap(mCategoryId);
return true;
}
}
static abstract class BaseUserMarkTask implements MapTask
{
private static final long serialVersionUID = 1L;