From e44712f9e5898d48006ccdd82b791249773576e1 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet <80701113+arnaudvergnet@users.noreply.github.com> Date: Wed, 8 Dec 2021 15:16:10 +0100 Subject: [PATCH] [android] Make editor toolbar title visible if search is hidden (#1672) * [android] Make editor toolbar title visible if search is hidden Resizes the toolbar layout to contain only the save button when the search controls are hidden, to leave room for the toolbar title Signed-off-by: Arnaud Vergnet * [android] Improve editor code style Signed-off-by: Arnaud Vergnet --- android/res/layout/fragment_editor_host.xml | 2 ++ .../maps/editor/EditorHostFragment.java | 25 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/android/res/layout/fragment_editor_host.xml b/android/res/layout/fragment_editor_host.xml index 91ac58ecd5..22362ef060 100644 --- a/android/res/layout/fragment_editor_host.xml +++ b/android/res/layout/fragment_editor_host.xml @@ -14,6 +14,8 @@ android:theme="@style/MwmWidget.ToolbarTheme"> diff --git a/android/src/com/mapswithme/maps/editor/EditorHostFragment.java b/android/src/com/mapswithme/maps/editor/EditorHostFragment.java index 45a733586f..6002056cb8 100644 --- a/android/src/com/mapswithme/maps/editor/EditorHostFragment.java +++ b/android/src/com/mapswithme/maps/editor/EditorHostFragment.java @@ -42,6 +42,10 @@ public class EditorHostFragment extends BaseMwmToolbarFragment implements OnBackPressListener, View.OnClickListener, LanguagesFragment.Listener { private boolean mIsNewObject; + @Nullable + private View mToolbarInnerLayout; + @Nullable + private View mSave; enum Mode { @@ -131,7 +135,10 @@ public class EditorHostFragment extends BaseMwmToolbarFragment { super.onViewCreated(view, savedInstanceState); - getToolbarController().getToolbar().findViewById(R.id.save).setOnClickListener(this); + final View toolbar = getToolbarController().getToolbar(); + mToolbarInnerLayout = toolbar.findViewById(R.id.toolbar_inner_layout); + mSave = toolbar.findViewById(R.id.save); + mSave.setOnClickListener(this); UiUtils.setupHomeUpButtonAsNavigationIcon(getToolbarController().getToolbar(), v -> onBackPressed()); @@ -196,7 +203,7 @@ public class EditorHostFragment extends BaseMwmToolbarFragment protected void editMapObject(boolean focusToLastName) { mMode = Mode.MAP_OBJECT; - ((SearchToolbarController) getToolbarController()).showSearchControls(false); + showSearchControls(false); getToolbarController().setTitle(getTitle()); UiUtils.show(getToolbarController().getToolbar().findViewById(R.id.save)); Bundle args = new Bundle(); @@ -249,7 +256,7 @@ public class EditorHostFragment extends BaseMwmToolbarFragment mMode = newMode; getToolbarController().setTitle(toolbarTitle); - ((SearchToolbarController) getToolbarController()).showSearchControls(showSearch); + showSearchControls(showSearch); final Fragment fragment = Fragment.instantiate(getActivity(), fragmentClass.getName(), args); getChildFragmentManager().beginTransaction() .replace(R.id.fragment_container, fragment, fragmentClass.getName()) @@ -266,6 +273,18 @@ public class EditorHostFragment extends BaseMwmToolbarFragment startActivity(new Intent(host, FeatureCategoryActivity.class)); } + private void showSearchControls(boolean showSearch) + { + ((SearchToolbarController) getToolbarController()).showSearchControls(showSearch); + if (mToolbarInnerLayout != null && mSave != null) + { + // Make room for the toolbar title if the search controls are hidden. + mToolbarInnerLayout.getLayoutParams().width = showSearch + ? ViewGroup.LayoutParams.MATCH_PARENT + : mSave.getLayoutParams().width; + } + } + private boolean setEdits() { return ((EditorFragment) getChildFragmentManager().findFragmentByTag(EditorFragment.class.getName())).setEdits();