[android] Improve show on map behavior (#2081)

* [android] Add show on map fab

Replaces the "View on map" button.

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>

* [android] Rename fab id to show_on_map_fab

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>

* [android] Use recycler view padding instead of auto hide fab

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>

* [android] Use xml icon instead of webp

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>

* [android] Add show in list fab

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>

* [android] Use variable instead of repeating function calls

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>

* [android] Show fab when no search results

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>

* [android] Put floating search toolbar at the bottom

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>

* [android] Put floating bookmark toolbar at the bottom

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>

* [android] Remove bookmark floating toolbar on map view

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>

* [android] Fix floating toolbar query touch detection

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>

* [android] Remove unused show in list icon

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>

* [android] Fix styling

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>
This commit is contained in:
Arnaud Vergnet 2022-03-03 08:13:51 +01:00 committed by GitHub
parent 09eb6a5ea0
commit 8cd8d161a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 131 additions and 357 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 404 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 346 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 B

View file

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20.5,3l-0.16,0.03L15,5.1 9,3 3.36,4.9c-0.21,0.07 -0.36,0.25 -0.36,0.48V20.5c0,0.28 0.22,0.5 0.5,0.5l0.16,-0.03L9,18.9l6,2.1 5.64,-1.9c0.21,-0.07 0.36,-0.25 0.36,-0.48V3.5c0,-0.28 -0.22,-0.5 -0.5,-0.5zM15,19l-6,-2.11V5l6,2.11V19z"/>
</vector>

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M20.5,3l-0.16,0.03L15,5.1 9,3 3.36,4.9c-0.21,0.07 -0.36,0.25 -0.36,0.48V20.5c0,0.28 0.22,0.5 0.5,0.5l0.16,-0.03L9,18.9l6,2.1 5.64,-1.9c0.21,-0.07 0.36,-0.25 0.36,-0.48V3.5c0,-0.28 -0.22,-0.5 -0.5,-0.5zM15,19l-6,-2.11V5l6,2.11V19z"/>
</vector>

View file

@ -34,6 +34,7 @@
layout="@layout/toolbar_with_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone"
tools:visibility="visible" />
@ -67,11 +68,6 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<include
layout="@layout/search_filter_panel"
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<com.mapswithme.maps.widget.placepage.PlacePageView
android:id="@+id/placepage"
@ -97,13 +93,4 @@
</FrameLayout>
<include layout="@layout/elevation_profile_bottom_sheet" />
<include layout="@layout/main_menu_bottom_sheet" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/bookmark_category_toolbar"
style="@style/MwmWidget.ToolbarStyle"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:elevation="0dp"
android:theme="@style/MwmWidget.ToolbarTheme"
android:visibility="gone"
tools:visibility="visible" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -3,50 +3,47 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapsme="http://schemas.android.com/apk/app"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical">
<include layout="@layout/recycler_with_fab"/>
</LinearLayout>
<include
layout="@layout/show_on_map_fab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?cardBackground" />
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabViewOnMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_above="@id/container"
android:layout_alignParentEnd="true"
android:layout_marginEnd="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_base"
android:src="?fabViewOnMap"
mapsme:layout_constraintBottom_toBottomOf="parent"
mapsme:layout_constraintEnd_toEndOf="parent"
tools:ignore="NotSibling" />
<com.mapswithme.maps.widget.PlaceholderView
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:paddingStart="@dimen/margin_double_and_half"
android:paddingTop="@dimen/placeholder_margin_top"
android:paddingEnd="@dimen/margin_double_and_half"
mapsme:imgSrcDefault="@drawable/img_empty_bookmarks"
mapsme:layout_constraintBottom_toBottomOf="parent"
mapsme:layout_constraintStart_toStartOf="parent"
mapsme:layout_constraintEnd_toEndOf="parent"
mapsme:layout_constraintTop_toTopOf="parent"
mapsme:subTitleDefault="@string/bookmarks_empty_list_message"
mapsme:titleDefault="@string/bookmarks_empty_list_title" />
<include
android:id="@+id/placeholder_loading"
layout="@layout/placeholder_with_progressbar_layout"
android:visibility="gone"
tools:visibility="visible" />
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/margin_base"/>
<com.mapswithme.maps.widget.PlaceholderView
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:paddingStart="@dimen/margin_double_and_half"
android:paddingTop="@dimen/placeholder_margin_top"
android:paddingEnd="@dimen/margin_double_and_half"
mapsme:imgSrcDefault="@drawable/img_empty_bookmarks"
mapsme:layout_constraintBottom_toBottomOf="parent"
mapsme:layout_constraintStart_toStartOf="parent"
mapsme:layout_constraintEnd_toEndOf="parent"
mapsme:layout_constraintTop_toTopOf="parent"
mapsme:subTitleDefault="@string/bookmarks_empty_list_message"
mapsme:titleDefault="@string/bookmarks_empty_list_title" />
<include
android:id="@+id/placeholder_loading"
layout="@layout/placeholder_with_progressbar_layout"
android:visibility="gone"
tools:visibility="visible" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</RelativeLayout>

View file

@ -24,7 +24,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"/>
<include layout="@layout/search_filter_panel"/>
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
@ -65,9 +64,7 @@
android:clickable="true"
android:focusable="true"
android:background="?cardBackground">
<include
layout="@layout/recycler_default"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<include layout="@layout/recycler_with_fab"/>
<com.mapswithme.maps.widget.PlaceholderView
android:id="@+id/placeholder"
@ -87,6 +84,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<include
layout="@layout/show_on_map_fab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/margin_base"/>
<com.mapswithme.maps.widget.FadeView
android:id="@+id/fade_view"
android:layout_width="match_parent"

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?cardBackground"
android:clipToPadding="false"
android:paddingBottom="@dimen/action_bar_extended_height"
android:scrollbars="vertical"/>

View file

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/filter_frame"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_double_and_half"
android:padding="@dimen/margin_quarter"
android:background="?cardBackground"
android:clipToPadding="false"
android:clickable="true"
android:visibility="gone"
tools:visibility="visible"
tools:showIn="@layout/fragment_search">
<TextView
android:id="@+id/show_on_map"
style="@style/MwmTextAppearance.Button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingStart="@dimen/margin_half"
android:paddingEnd="@dimen/margin_half"
android:layout_centerVertical="true"
android:gravity="center"
android:background="?clickableBackground"
android:fontFamily="@string/robotoMedium"
android:textSize="@dimen/text_size_caption"
android:text="@string/search_show_on_map"/>
<include
android:id="@+id/divider"
layout="@layout/divider_horizontal"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:layout_marginStart="@dimen/neg_margin_half"
android:layout_marginEnd="@dimen/neg_margin_half"
android:layout_marginBottom="@dimen/neg_margin_half"/>
</RelativeLayout>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.floatingactionbutton.FloatingActionButton
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/show_on_map_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/search_show_on_map"
android:src="?attr/showOnMapFab"
android:clickable="true"
android:focusable="true"
app:fabSize="normal"/>

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/close"
app:showAsAction="always"
android:icon="@drawable/ic_clear"/>
</menu>

View file

@ -51,7 +51,7 @@
<attr name="downloaderTheme" format="reference" />
<attr name="navigationTheme" format="reference" />
<attr name="fabAdd" format="reference" />
<attr name="fabViewOnMap" format="reference" />
<attr name="showOnMapFab" format="reference" />
<attr name="routingButtonHint" format="color" />
<attr name="routingButtonPressedHint" format="color" />
<attr name="routingButtonActivatedHint" format="color" />

View file

@ -82,7 +82,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="showOnMapFab">@drawable/ic_show_on_map_fab</item>
<item name="routingButtonHint">@color/routing_button_tint</item>
<item name="routingButtonActivatedHint">?statusBar</item>
@ -261,7 +261,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_night</item>
<item name="showOnMapFab">@drawable/ic_show_on_map_fab_night</item>
<item name="routingButtonHint">@color/routing_button_tint</item>
<item name="routingButtonActivatedHint">?statusBar</item>

View file

@ -11,7 +11,6 @@ import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
@ -38,7 +37,6 @@ import com.mapswithme.maps.base.CustomNavigateUpListener;
import com.mapswithme.maps.base.NoConnectionListener;
import com.mapswithme.maps.base.OnBackPressListener;
import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
import com.mapswithme.maps.bookmarks.data.BookmarkInfo;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.MapObject;
@ -79,7 +77,6 @@ import com.mapswithme.maps.routing.RoutingPlanInplaceController;
import com.mapswithme.maps.search.FloatingSearchToolbarController;
import com.mapswithme.maps.search.SearchActivity;
import com.mapswithme.maps.search.SearchEngine;
import com.mapswithme.maps.search.SearchFilterController;
import com.mapswithme.maps.search.SearchFragment;
import com.mapswithme.maps.settings.DrivingOptionsActivity;
import com.mapswithme.maps.settings.RoadType;
@ -197,8 +194,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
@SuppressWarnings("NullableProblems")
@NonNull
private MapLayerCompositeController mToggleMapLayerController;
@Nullable
private SearchFilterController mFilterController;
private boolean mIsTabletLayout;
private boolean mIsFullscreen;
@ -224,9 +219,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
@SuppressWarnings("NullableProblems")
@NonNull
private MenuController mMainMenuController;
@SuppressWarnings("NotNullFieldNotInitialized")
@NonNull
private Toolbar mBookmarkCategoryToolbar;
public interface LeftAnimationTrackListener
{
@ -326,14 +319,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
BookmarkCategoriesActivity.start(this);
}
private void showTabletSearch(@Nullable Intent data, @NonNull String query)
{
if (mFilterController == null || data == null)
return;
showSearch(query);
}
public void showSearch(String query)
{
if (mIsTabletLayout)
@ -440,11 +425,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
.addOnGlobalLayoutListener(new ToolbarLayoutChangeListener());
mSearchController.setVisibilityListener(this);
mBookmarkCategoryToolbar = findViewById(R.id.bookmark_category_toolbar);
mBookmarkCategoryToolbar.inflateMenu(R.menu.menu_bookmark_catalog);
mBookmarkCategoryToolbar.setOnMenuItemClickListener(this::onBookmarkToolbarMenuClicked);
UiUtils.extendViewWithStatusBar(mBookmarkCategoryToolbar);
boolean isLaunchByDeepLink = getIntent().getBooleanExtra(EXTRA_LAUNCH_BY_DEEP_LINK, false);
initViews(isLaunchByDeepLink);
@ -463,16 +443,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
}
}
private boolean onBookmarkToolbarMenuClicked(@NonNull MenuItem item)
{
if (item.getItemId() == R.id.close)
{
closeBookmarkCategoryToolbar();
return true;
}
return false;
}
@Override
public void onNoConnectionError()
{
@ -500,24 +470,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
initMainMenu();
initOnmapDownloader();
initPositionChooser();
initFilterViews();
}
private void initFilterViews()
{
View frame = findViewById(R.id.filter_frame);
if (frame != null)
{
mFilterController = new SearchFilterController(frame, new SearchFilterController
.DefaultFilterListener()
{
@Override
public void onShowOnMapClick()
{
showSearch(mSearchController.getQuery());
}
}, R.string.search_in_table);
}
}
private void initPositionChooser()
@ -552,7 +504,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
// Do not show the search tool bar if we are planning or navigating
if (!RoutingController.get().isNavigating() && !RoutingController.get().isPlanning())
{
mSearchController.show();
showSearchToolbar();
}
}
else
@ -561,6 +513,11 @@ public class MwmActivity extends BaseMwmFragmentActivity
}
}
private void showSearchToolbar()
{
mSearchController.show();
}
public void showPositionChooser(boolean isBusiness, boolean applyPosition)
{
closeFloatingToolbarsAndPanels(false);
@ -749,19 +706,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
return false;
}
/**
* @return False if the bookmark category toolbar was already closed, true otherwise
*/
private boolean closeBookmarkCategoryToolbar()
{
if (UiUtils.isVisible(mBookmarkCategoryToolbar))
{
hideBookmarkCategoryToolbar();
return true;
}
return false;
}
private void closeFloatingToolbarsAndPanels(boolean clearSearchText)
{
closeFloatingPanels();
@ -776,7 +720,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
private void closeFloatingToolbars(boolean clearSearchText, boolean stopSearch)
{
closeBookmarkCategoryToolbar();
closePositionChooser();
closeSearchToolbar(clearSearchText, stopSearch);
}
@ -1137,7 +1080,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
RoutingController routingController = RoutingController.get();
if (!closeMenu() && !closePlacePage() && !closeSearchToolbar(true, true) &&
!closeBookmarkCategoryToolbar() && !closeSidePanel() && !closePositionChooser() &&
!closeSidePanel() && !closePositionChooser() &&
!routingController.resetToPlanningStateIfNavigating() && !routingController.cancel())
{
try
@ -1268,9 +1211,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
|| RoutingController.get().isPlanning())
return;
if (UiUtils.isVisible(mBookmarkCategoryToolbar))
return;
mIsFullscreen = isFullscreen;
final BaseMenu menu = getCurrentMenu();
@ -1466,12 +1406,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
return false;
}
if (UiUtils.isVisible(mBookmarkCategoryToolbar))
{
showLineFrame(false);
return false;
}
hideRoutingActionFrame();
showLineFrame(true);
return true;
@ -1658,17 +1592,9 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (mNavAnimationController == null)
return;
adjustCompassAndTraffic(visible ? calcFloatingViewsOffset()
: UiUtils.getStatusBarHeight(getApplicationContext()));
int toolbarHeight = mSearchController.getToolbar().getHeight();
setNavButtonsTopLimit(visible ? toolbarHeight : 0);
if (mFilterController != null)
{
boolean show = visible && !TextUtils.isEmpty(SearchEngine.INSTANCE.getQuery())
&& !RoutingController.get().isNavigating();
mFilterController.show(show);
mMainMenu.show(!show);
}
boolean show = visible && !TextUtils.isEmpty(SearchEngine.INSTANCE.getQuery())
&& !RoutingController.get().isNavigating();
mMainMenu.show(!show);
}
private int calcFloatingViewsOffset()
@ -1690,11 +1616,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
refreshFade();
if (mOnmapDownloader != null)
mOnmapDownloader.updateState(false);
if (show)
{
if (mFilterController != null)
mFilterController.show(false);
}
}
@Override
@ -2021,6 +1942,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
@Override
public void onSearchQueryClick(@Nullable String query)
{
closeFloatingToolbarsAndPanels(true);
showSearch(query);
}
@ -2069,7 +1991,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
Track track = BookmarkManager.INSTANCE.getTrack(trackId);
Objects.requireNonNull(track);
setupBookmarkCategoryToolbar(track.getCategoryId());
Framework.nativeShowTrackRect(trackId);
}
@ -2077,43 +1998,14 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
BookmarkInfo info = BookmarkManager.INSTANCE.getBookmarkInfo(bookmarkId);
Objects.requireNonNull(info);
setupBookmarkCategoryToolbar(info.getCategoryId());
BookmarkManager.INSTANCE.showBookmarkOnMap(bookmarkId);
}
public void showBookmarkCategoryOnMap(long categoryId)
{
setupBookmarkCategoryToolbar(categoryId);
BookmarkManager.INSTANCE.showBookmarkCategoryOnMap(categoryId);
}
private void setupBookmarkCategoryToolbar(long categoryId)
{
final BookmarkCategory category = BookmarkManager.INSTANCE.getCategoryById(categoryId);
mBookmarkCategoryToolbar.setTitle(category.getName());
UiUtils.setupNavigationIcon(mBookmarkCategoryToolbar, v -> {
BookmarkCategoriesActivity.start(MwmActivity.this, category);
closePlacePage();
closeBookmarkCategoryToolbar();
});
showBookmarkCategoryToolbar();
}
private void showBookmarkCategoryToolbar()
{
UiUtils.show(mBookmarkCategoryToolbar);
adjustCompassAndTraffic(mBookmarkCategoryToolbar.getHeight());
adjustMenuLineFrameVisibility();
}
private void hideBookmarkCategoryToolbar()
{
UiUtils.hide(mBookmarkCategoryToolbar);
adjustCompassAndTraffic(UiUtils.getStatusBarHeight(MwmActivity.this));
adjustMenuLineFrameVisibility();
}
private class CurrentPositionClickListener implements OnClickListener
{
@Override

View file

@ -249,7 +249,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<ConcatAdapter
private void configureFab(@NonNull View view)
{
mFabViewOnMap = view.findViewById(R.id.fabViewOnMap);
mFabViewOnMap = view.findViewById(R.id.show_on_map_fab);
mFabViewOnMap.setOnClickListener(v ->
{
final Intent i = makeMwmActivityIntent();
@ -802,7 +802,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<ConcatAdapter
private void updateLoadingPlaceholder(@NonNull View root, boolean isShowLoadingPlaceholder)
{
View loadingPlaceholder = root.findViewById(R.id.placeholder_loading);
UiUtils.showIf(!isShowLoadingPlaceholder, root, R.id.fabViewOnMap);
UiUtils.showIf(!isShowLoadingPlaceholder, root, R.id.show_on_map_fab);
UiUtils.showIf(isShowLoadingPlaceholder, loadingPlaceholder);
}
}

View file

@ -39,10 +39,8 @@ public class FloatingSearchToolbarController extends SearchToolbarController
@Override
protected void onQueryClick(@Nullable String query)
{
super.onQueryClick(query);
if (mListener != null)
mListener.onSearchQueryClick(getQuery());
hide();
}
@Override
@ -101,6 +99,11 @@ public class FloatingSearchToolbarController extends SearchToolbarController
mVisibilityListener = visibilityListener;
}
@Override
protected boolean useExtendedToolbar()
{
return false;
}
public interface SearchToolbarListener
{

View file

@ -1,74 +0,0 @@
package com.mapswithme.maps.search;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import com.mapswithme.maps.R;
import com.mapswithme.util.UiUtils;
public class SearchFilterController
{
@NonNull
private final View mFrame;
@NonNull
private final TextView mShowOnMap;
@NonNull
private final View mDivider;
@Nullable
private final FilterListener mFilterListener;
interface FilterListener
{
void onShowOnMapClick();
}
public SearchFilterController(@NonNull View frame, @Nullable FilterListener listener,
@StringRes int populateButtonText)
{
mFrame = frame;
mFilterListener = listener;
mShowOnMap = mFrame.findViewById(R.id.show_on_map);
mShowOnMap.setText(populateButtonText);
mDivider = mFrame.findViewById(R.id.divider);
initListeners();
}
public void show(boolean show)
{
UiUtils.showIf(show, mFrame);
showPopulateButton(true);
}
void showPopulateButton(boolean show)
{
UiUtils.showIf(show, mShowOnMap);
}
void showDivider(boolean show)
{
UiUtils.showIf(show, mDivider);
}
private void initListeners()
{
mShowOnMap.setOnClickListener(v ->
{
if (mFilterListener != null)
mFilterListener.onShowOnMapClick();
});
}
public static class DefaultFilterListener implements FilterListener
{
@Override
public void onShowOnMapClick()
{
}
}
}

View file

@ -14,6 +14,7 @@ import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -21,6 +22,8 @@ import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmActivity;
@ -72,7 +75,7 @@ public class SearchFragment extends BaseMwmFragment
{
public ToolbarController(View root)
{
super(root, SearchFragment.this.getActivity());
super(root, SearchFragment.this.requireActivity());
}
@Override
@ -144,13 +147,9 @@ public class SearchFragment extends BaseMwmFragment
}
}
private View mTabFrame;
private View mResultsFrame;
private PlaceholderView mResultsPlaceholder;
private RecyclerView mResults;
private AppBarLayout mAppBarLayout;
@Nullable
private SearchFilterController mFilterController;
private FloatingActionButton mShowOnMapFab;
private SearchToolbarController mToolbarController;
@ -162,7 +161,7 @@ public class SearchFragment extends BaseMwmFragment
private final RecyclerView.OnScrollListener mRecyclerListener = new RecyclerView.OnScrollListener()
{
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState)
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState)
{
if (newState == RecyclerView.SCROLL_STATE_DRAGGING)
mToolbarController.deactivate();
@ -188,19 +187,6 @@ public class SearchFragment extends BaseMwmFragment
}
};
private final AppBarLayout.OnOffsetChangedListener mOffsetListener =
new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset)
{
if (mFilterController == null)
return;
boolean show = !(Math.abs(verticalOffset) == appBarLayout.getTotalScrollRange());
mFilterController.showDivider(show);
}
};
private static boolean doShowDownloadSuggest()
{
return (MapManager.nativeGetDownloadedCount() == 0 && !MapManager.nativeIsDownloading());
@ -214,7 +200,7 @@ public class SearchFragment extends BaseMwmFragment
if (fragment == null || fragment.isDetached() || fragment.isRemoving())
{
fragment = Fragment.instantiate(getActivity(), fragmentName, null);
fragment = Fragment.instantiate(requireActivity(), fragmentName, null);
fm.beginTransaction()
.add(R.id.download_suggest_frame, fragment, fragmentName)
.commit();
@ -237,15 +223,14 @@ public class SearchFragment extends BaseMwmFragment
private void updateFrames()
{
final boolean hasQuery = mToolbarController.hasQuery();
UiUtils.showIf(hasQuery, mResultsFrame);
Toolbar toolbar = mToolbarController.getToolbar();
AppBarLayout.LayoutParams lp = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
lp.setScrollFlags(hasQuery ? AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS
| AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL : 0);
toolbar.setLayoutParams(lp);
if (mFilterController != null)
mFilterController.show(hasQuery);
UiUtils.showIf(hasQuery, mResultsFrame);
UiUtils.showIf(hasQuery, mShowOnMapFab);
if (hasQuery)
hideDownloadSuggest();
else if (doShowDownloadSuggest())
@ -261,8 +246,6 @@ public class SearchFragment extends BaseMwmFragment
&& mToolbarController.hasQuery();
UiUtils.showIf(show, mResultsPlaceholder);
if (mFilterController != null)
mFilterController.showPopulateButton(!isTabletSearch());
}
@Override
@ -280,8 +263,7 @@ public class SearchFragment extends BaseMwmFragment
readArguments();
ViewGroup root = (ViewGroup) view;
mAppBarLayout = root.findViewById(R.id.app_bar);
mTabFrame = root.findViewById(R.id.tab_frame);
View mTabFrame = root.findViewById(R.id.tab_frame);
ViewPager pager = mTabFrame.findViewById(R.id.pages);
mToolbarController = new ToolbarController(view);
@ -289,20 +271,10 @@ public class SearchFragment extends BaseMwmFragment
final TabAdapter tabAdapter = new TabAdapter(getChildFragmentManager(), pager, tabLayout);
mResultsFrame = root.findViewById(R.id.results_frame);
mResults = mResultsFrame.findViewById(R.id.recycler);
RecyclerView mResults = mResultsFrame.findViewById(R.id.recycler);
setRecyclerScrollListener(mResults);
mResultsPlaceholder = mResultsFrame.findViewById(R.id.placeholder);
mResultsPlaceholder.setContent(R.string.search_not_found, R.string.search_not_found_query);
mFilterController = new SearchFilterController(root.findViewById(R.id.filter_frame),
new SearchFilterController.DefaultFilterListener()
{
@Override
public void onShowOnMapClick()
{
showAllResultsOnMap();
}
}, R.string.search_show_on_map);
mSearchAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver()
{
@ -312,6 +284,8 @@ public class SearchFragment extends BaseMwmFragment
updateResultsPlaceholder();
}
});
mShowOnMapFab = root.findViewById(R.id.show_on_map_fab);
mShowOnMapFab.setOnClickListener(v -> showAllResultsOnMap());
mResults.setLayoutManager(new LinearLayoutManager(view.getContext()));
mResults.setAdapter(mSearchAdapter);
@ -347,7 +321,6 @@ public class SearchFragment extends BaseMwmFragment
{
super.onResume();
LocationHelper.INSTANCE.addListener(mLocationListener);
mAppBarLayout.addOnOffsetChangedListener(mOffsetListener);
}
@Override
@ -355,7 +328,6 @@ public class SearchFragment extends BaseMwmFragment
{
LocationHelper.INSTANCE.removeListener(mLocationListener);
super.onPause();
mAppBarLayout.removeOnOffsetChangedListener(mOffsetListener);
}
@Override
@ -434,7 +406,7 @@ public class SearchFragment extends BaseMwmFragment
{
SearchResult.Description description = result.description;
String subtitle = description != null
? Utils.getLocalizedFeatureType(getContext(), description.featureType)
? Utils.getLocalizedFeatureType(requireContext(), description.featureType)
: "";
String title = TextUtils.isEmpty(result.name) ? subtitle : "";
@ -562,9 +534,6 @@ public class SearchFragment extends BaseMwmFragment
{
super.onActivityResult(requestCode, resultCode, data);
mToolbarController.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_OK)
return;
}
@Override
@ -593,8 +562,9 @@ public class SearchFragment extends BaseMwmFragment
private void closeSearch()
{
getActivity().finish();
getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
final Activity activity = requireActivity();
activity.finish();
activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
public void setRecyclerScrollListener(RecyclerView recycler)

View file

@ -20,7 +20,7 @@ import com.mapswithme.util.StringUtils;
import com.mapswithme.util.UiUtils;
public class SearchToolbarController extends ToolbarController
implements View.OnClickListener
implements View.OnClickListener, View.OnFocusChangeListener
{
private static final int REQUEST_VOICE_RECOGNITION = 0xCA11;
@Nullable
@ -62,7 +62,7 @@ public class SearchToolbarController extends ToolbarController
mSearchContainer = getToolbar().findViewById(R.id.search_container);
mBack = mSearchContainer.findViewById(R.id.back);
mQuery = mSearchContainer.findViewById(R.id.query);
mQuery.setOnClickListener(this);
mQuery.setOnFocusChangeListener(this);
mQuery.addTextChangedListener(mTextWatcher);
mQuery.setOnEditorActionListener(
(v, actionId, event) ->
@ -185,15 +185,18 @@ public class SearchToolbarController extends ToolbarController
UiUtils.showIf(show, mProgress);
}
@Override
public void onFocusChange(View view, boolean b)
{
if (view.getId()== R.id.query && b)
onQueryClick(getQuery());
}
@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.query:
onQueryClick(getQuery());
break;
case R.id.clear:
onClearClick();
break;