diff --git a/android/res/layout/toolbar_with_search.xml b/android/res/layout/toolbar_with_search.xml index 50119cd311..ff812f0280 100644 --- a/android/res/layout/toolbar_with_search.xml +++ b/android/res/layout/toolbar_with_search.xml @@ -10,6 +10,7 @@ app:contentInsetLeft="@dimen/dp_0" app:contentInsetStart="@dimen/dp_0"> diff --git a/android/src/com/mapswithme/maps/downloader/DownloaderToolbarController.java b/android/src/com/mapswithme/maps/downloader/DownloaderToolbarController.java index 9b756b6f69..8eabdcb8d3 100644 --- a/android/src/com/mapswithme/maps/downloader/DownloaderToolbarController.java +++ b/android/src/com/mapswithme/maps/downloader/DownloaderToolbarController.java @@ -7,6 +7,7 @@ import android.view.View; import com.mapswithme.maps.R; import com.mapswithme.maps.widget.SearchToolbarController; +import com.mapswithme.util.UiUtils; import com.mapswithme.util.statistics.Statistics; class DownloaderToolbarController extends SearchToolbarController @@ -44,6 +45,10 @@ class DownloaderToolbarController extends SearchToolbarController String title = (showSearch ? "" : mFragment.getAdapter().getCurrentRootName()); showSearchControls(showSearch); + if (!showSearch) + UiUtils.setupHomeUpButtonAsNavigationIcon(getToolbar(), mNavigationClickListener); + else + UiUtils.clearHomeUpButton(getToolbar()); setTitle(title); } diff --git a/android/src/com/mapswithme/maps/editor/EditorHostFragment.java b/android/src/com/mapswithme/maps/editor/EditorHostFragment.java index c44973e7f9..4ed198595e 100644 --- a/android/src/com/mapswithme/maps/editor/EditorHostFragment.java +++ b/android/src/com/mapswithme/maps/editor/EditorHostFragment.java @@ -4,17 +4,17 @@ import android.app.Activity; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import androidx.annotation.CallSuper; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.fragment.app.Fragment; -import androidx.appcompat.app.AlertDialog; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.CallSuper; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.Fragment; import com.mapswithme.maps.MwmActivity; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; @@ -130,14 +130,8 @@ public class EditorHostFragment extends BaseMwmToolbarFragment super.onViewCreated(view, savedInstanceState); getToolbarController().getToolbar().findViewById(R.id.save).setOnClickListener(this); - getToolbarController().getToolbar().setNavigationOnClickListener(new View.OnClickListener() - { - @Override - public void onClick(View v) - { - onBackPressed(); - } - }); + UiUtils.setupHomeUpButtonAsNavigationIcon(getToolbarController().getToolbar(), + v -> onBackPressed()); if (getArguments() != null) mIsNewObject = getArguments().getBoolean(EditorActivity.EXTRA_NEW_OBJECT, false); diff --git a/android/src/com/mapswithme/maps/widget/SearchToolbarController.java b/android/src/com/mapswithme/maps/widget/SearchToolbarController.java index b99b7aab1e..95655ae7c9 100644 --- a/android/src/com/mapswithme/maps/widget/SearchToolbarController.java +++ b/android/src/com/mapswithme/maps/widget/SearchToolbarController.java @@ -43,6 +43,8 @@ public class SearchToolbarController extends ToolbarController FilterUtils.RoomsGuestsCountProvider { private static final int REQUEST_VOICE_RECOGNITION = 0xCA11; + @Nullable + private final View mToolbarContainer; @NonNull private final View mSearchContainer; @NonNull @@ -154,6 +156,7 @@ public class SearchToolbarController extends ToolbarController public SearchToolbarController(View root, Activity activity) { super(root, activity); + mToolbarContainer = getToolbar().findViewById(R.id.toolbar_container); mSearchContainer = getToolbar().findViewById(R.id.search_container); mQuery = mSearchContainer.findViewById(R.id.query); mQuery.setOnClickListener(this); @@ -356,6 +359,8 @@ public class SearchToolbarController extends ToolbarController public void showSearchControls(boolean show) { + if (mToolbarContainer != null) + UiUtils.showIf(show, mToolbarContainer); UiUtils.showIf(show, mSearchContainer); } diff --git a/android/src/com/mapswithme/maps/widget/ToolbarController.java b/android/src/com/mapswithme/maps/widget/ToolbarController.java index bf3bdcc486..2fefedd96e 100644 --- a/android/src/com/mapswithme/maps/widget/ToolbarController.java +++ b/android/src/com/mapswithme/maps/widget/ToolbarController.java @@ -22,7 +22,7 @@ public class ToolbarController implements Detachable @NonNull private final Toolbar mToolbar; @NonNull - private final View.OnClickListener mNavigationClickListener = view -> onUpClick(); + protected final View.OnClickListener mNavigationClickListener = view -> onUpClick(); public ToolbarController(@NonNull View root, @NonNull Activity activity) { diff --git a/android/src/com/mapswithme/util/UiUtils.java b/android/src/com/mapswithme/util/UiUtils.java index 51b0db5fda..e4d27188c1 100644 --- a/android/src/com/mapswithme/util/UiUtils.java +++ b/android/src/com/mapswithme/util/UiUtils.java @@ -486,11 +486,23 @@ public final class UiUtils } else { - UiUtils.showHomeUpButton(toolbar); - toolbar.setNavigationOnClickListener(listener); + setupHomeUpButtonAsNavigationIcon(toolbar, listener); } } + public static void setupHomeUpButtonAsNavigationIcon(@NonNull Toolbar toolbar, + @NonNull View.OnClickListener listener) + { + UiUtils.showHomeUpButton(toolbar); + toolbar.setNavigationOnClickListener(listener); + } + + public static void clearHomeUpButton(@NonNull Toolbar toolbar) + { + toolbar.setNavigationIcon(null); + toolbar.setNavigationOnClickListener(null); + } + public static int getCompassYOffset(@NonNull Context context) { return getStatusBarHeight(context);