[android] Make editor toolbar title visible if search is hidden #1672

Merged
arnaudvergnet merged 2 commits from editor-header-title into master 2021-12-08 14:16:11 +00:00
2 changed files with 24 additions and 3 deletions

View file

@ -14,6 +14,8 @@
android:theme="@style/MwmWidget.ToolbarTheme">
<RelativeLayout
android:id="@+id/toolbar_inner_layout"
android:layout_gravity="end|center_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

View file

@ -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());
@ -190,7 +197,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();
@ -243,7 +250,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())
@ -260,6 +267,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();