From 0f115ecfb5b89ef0b7e00f03b3bce3b9b016e5a8 Mon Sep 17 00:00:00 2001 From: Jean-BaptisteC Date: Tue, 26 Dec 2023 10:18:24 +0100 Subject: [PATCH] Add phone FAB in editor Signed-off-by: Jean-BaptisteC --- .../editor/EditorHostFragment.java | 2 ++ .../editor/data/PhoneFragment.java | 20 +++++++++-- .../app/src/main/res/layout/add_phone_fab.xml | 12 +++++++ .../src/main/res/layout/fragment_phone.xml | 35 ++++++------------- 4 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 android/app/src/main/res/layout/add_phone_fab.xml diff --git a/android/app/src/main/java/app/organicmaps/editor/EditorHostFragment.java b/android/app/src/main/java/app/organicmaps/editor/EditorHostFragment.java index 69e3634347..1a95c42d26 100644 --- a/android/app/src/main/java/app/organicmaps/editor/EditorHostFragment.java +++ b/android/app/src/main/java/app/organicmaps/editor/EditorHostFragment.java @@ -25,6 +25,7 @@ import app.organicmaps.editor.data.LocalizedName; import app.organicmaps.editor.data.LocalizedStreet; import app.organicmaps.editor.data.NamesDataSource; import app.organicmaps.editor.data.PhoneFragment; +import app.organicmaps.util.InputUtils; import app.organicmaps.widget.SearchToolbarController; import app.organicmaps.widget.ToolbarController; import app.organicmaps.util.ConnectionState; @@ -132,6 +133,7 @@ public class EditorHostFragment extends BaseMwmToolbarFragment implements View.O mSave.setOnClickListener(this); UiUtils.setupHomeUpButtonAsNavigationIcon(getToolbarController().getToolbar(), v -> onBackPressed()); + InputUtils.hideKeyboard(requireView()); if (getArguments() != null) mIsNewObject = getArguments().getBoolean(EditorActivity.EXTRA_NEW_OBJECT, false); diff --git a/android/app/src/main/java/app/organicmaps/editor/data/PhoneFragment.java b/android/app/src/main/java/app/organicmaps/editor/data/PhoneFragment.java index 2707736e73..07e90d1119 100644 --- a/android/app/src/main/java/app/organicmaps/editor/data/PhoneFragment.java +++ b/android/app/src/main/java/app/organicmaps/editor/data/PhoneFragment.java @@ -13,12 +13,15 @@ import androidx.recyclerview.widget.RecyclerView; import app.organicmaps.R; import app.organicmaps.base.BaseMwmFragment; import app.organicmaps.editor.PhoneListAdapter; +import app.organicmaps.util.InputUtils; +import com.google.android.material.floatingactionbutton.FloatingActionButton; public class PhoneFragment extends BaseMwmFragment implements View.OnClickListener { public static final String EXTRA_PHONE_LIST = "Phone"; private PhoneListAdapter mAdapter; private RecyclerView mPhonesRecycler; + final Integer maxAdapter = 5; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) @@ -26,6 +29,14 @@ public class PhoneFragment extends BaseMwmFragment implements View.OnClickListen return inflater.inflate(R.layout.fragment_phone, container, false); } + @Override + public boolean onBackPressed() + { + super.onBackPressed(); + InputUtils.hideKeyboard(requireView()); + return true; + } + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { @@ -38,12 +49,17 @@ public class PhoneFragment extends BaseMwmFragment implements View.OnClickListen mAdapter = new PhoneListAdapter(phoneList); mAdapter.setHasStableIds(true); - view.findViewById(R.id.tv__append_phone).setOnClickListener(this); + FloatingActionButton phoneFab = view.findViewById(R.id.tv__append_phone); + phoneFab.setOnClickListener(this); mPhonesRecycler = view.findViewById(R.id.phones_recycler); LinearLayoutManager manager = new LinearLayoutManager(view.getContext()); manager.setSmoothScrollbarEnabled(true); mPhonesRecycler.setLayoutManager(manager); mPhonesRecycler.setAdapter(mAdapter); + //int last_position = mAdapter.getItemCount() - 1; + //mPhonesRecycler.requestFocus(last_position); + mPhonesRecycler.smoothScrollToPosition(mPhonesRecycler.getBottom()); + InputUtils.showKeyboard(requireView()); } public String getPhone() @@ -56,7 +72,7 @@ public class PhoneFragment extends BaseMwmFragment implements View.OnClickListen { if (view.getId() == R.id.tv__append_phone) { - if (mAdapter != null) mAdapter.appendPhone(); + if (mAdapter != null && mAdapter.getItemCount() <= maxAdapter) mAdapter.appendPhone(); } } } diff --git a/android/app/src/main/res/layout/add_phone_fab.xml b/android/app/src/main/res/layout/add_phone_fab.xml new file mode 100644 index 0000000000..641f412cf0 --- /dev/null +++ b/android/app/src/main/res/layout/add_phone_fab.xml @@ -0,0 +1,12 @@ + diff --git a/android/app/src/main/res/layout/fragment_phone.xml b/android/app/src/main/res/layout/fragment_phone.xml index fecbdc8c56..d6964430c8 100644 --- a/android/app/src/main/res/layout/fragment_phone.xml +++ b/android/app/src/main/res/layout/fragment_phone.xml @@ -1,10 +1,9 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:fitsSystemWindows="true"> + - - - - -- 2.45.3