From 320ac5f380189285f61dc06f49a41dc1ca370749 Mon Sep 17 00:00:00 2001
From: 0xRe1nk0 <0xre1nk0@gmail.com>
Date: Fri, 27 Sep 2024 11:28:26 +0300
Subject: [PATCH 1/7] fling fix
---
OsmAnd/res/layout/fragment_edit_poi.xml | 2 +-
.../res/layout/fragment_edit_poi_advanced.xml | 4 +-
.../res/layout/fragment_edit_poi_normal.xml | 4 +-
.../dialogs/EditPoiDialogFragment.java | 75 ++++++++-----------
4 files changed, 37 insertions(+), 48 deletions(-)
diff --git a/OsmAnd/res/layout/fragment_edit_poi.xml b/OsmAnd/res/layout/fragment_edit_poi.xml
index 5e9f3a7bf5e..6ab89aa1b2e 100644
--- a/OsmAnd/res/layout/fragment_edit_poi.xml
+++ b/OsmAnd/res/layout/fragment_edit_poi.xml
@@ -131,7 +131,7 @@
app:tabTextColor="@android:color/darker_gray" />
-
diff --git a/OsmAnd/res/layout/fragment_edit_poi_advanced.xml b/OsmAnd/res/layout/fragment_edit_poi_advanced.xml
index 86a1a7f719a..1b1bda9cd41 100644
--- a/OsmAnd/res/layout/fragment_edit_poi_advanced.xml
+++ b/OsmAnd/res/layout/fragment_edit_poi_advanced.xml
@@ -1,5 +1,5 @@
-
-
+
diff --git a/OsmAnd/res/layout/fragment_edit_poi_normal.xml b/OsmAnd/res/layout/fragment_edit_poi_normal.xml
index 6d3ea608b0f..ba640930279 100644
--- a/OsmAnd/res/layout/fragment_edit_poi_normal.xml
+++ b/OsmAnd/res/layout/fragment_edit_poi_normal.xml
@@ -1,5 +1,5 @@
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/plugins/osmedit/dialogs/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/plugins/osmedit/dialogs/EditPoiDialogFragment.java
index a23fe3c8a5d..c67c562e7dd 100644
--- a/OsmAnd/src/net/osmand/plus/plugins/osmedit/dialogs/EditPoiDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/plugins/osmedit/dialogs/EditPoiDialogFragment.java
@@ -28,14 +28,14 @@
import androidx.appcompat.widget.AppCompatImageButton;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.ViewCompat;
-import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
-import androidx.fragment.app.FragmentPagerAdapter;
import androidx.fragment.app.FragmentTransaction;
-import androidx.viewpager.widget.ViewPager;
+import androidx.viewpager2.adapter.FragmentStateAdapter;
+import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.tabs.TabLayout;
+import com.google.android.material.tabs.TabLayoutMediator;
import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil;
@@ -54,7 +54,6 @@
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.plugins.PluginsHelper;
-import net.osmand.plus.plugins.osmedit.EditPoiViewPager;
import net.osmand.plus.plugins.osmedit.OsmEditingPlugin;
import net.osmand.plus.plugins.osmedit.data.EditPoiData;
import net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint;
@@ -105,7 +104,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
private OpenstreetmapUtil openstreetmapUtil;
private EditPoiData editPoiData;
- private EditPoiViewPager viewPager;
+ private ViewPager2 viewPager;
private ExtendedEditText poiTypeEditText;
private OnSaveButtonClickListener onSaveButtonClickListener;
@@ -151,17 +150,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
viewPager = view.findViewById(R.id.viewpager);
String basicTitle = getResources().getString(R.string.tab_title_basic);
String extendedTitle = getResources().getString(R.string.tab_title_advanced);
- PoiInfoPagerAdapter pagerAdapter = new PoiInfoPagerAdapter(getChildFragmentManager(), basicTitle, extendedTitle);
+ TabLayout tabLayout = view.findViewById(R.id.tab_layout);
+ PoiInfoPagerAdapter pagerAdapter = new PoiInfoPagerAdapter(this, basicTitle, extendedTitle);
viewPager.setAdapter(pagerAdapter);
- viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
+ viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
- public void onPageScrolled(int i, float v, int i1) {
-
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+ super.onPageScrolled(position, positionOffset, positionOffsetPixels);
}
@Override
- public void onPageSelected(int i) {
- Fragment pageFragment = pagerAdapter.getItem(i);
+ public void onPageSelected(int position) {
+ Fragment pageFragment = pagerAdapter.createFragment(position);
((OnFragmentActivatedListener) pageFragment).onFragmentActivated();
if (pageFragment instanceof OnSaveButtonClickListener) {
onSaveButtonClickListener = (OnSaveButtonClickListener) pageFragment;
@@ -171,40 +171,29 @@ public void onPageSelected(int i) {
}
@Override
- public void onPageScrollStateChanged(int i) {
-
+ public void onPageScrollStateChanged(int state) {
+ super.onPageScrollStateChanged(state);
}
});
- TabLayout tabLayout = view.findViewById(R.id.tab_layout);
+
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
// tabLayout.setupWithViewPager(viewPager);
// Hack due to bug in design support library v22.2.1
// https://code.google.com/p/android/issues/detail?id=180462
// TODO remove in new version
- if (Build.VERSION.SDK_INT >= 11) {
- if (ViewCompat.isLaidOut(tabLayout)) {
- tabLayout.setupWithViewPager(viewPager);
- } else {
- tabLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
- @Override
- public void onLayoutChange(View v, int left, int top, int right, int bottom,
- int oldLeft, int oldTop, int oldRight, int oldBottom) {
- tabLayout.setupWithViewPager(viewPager);
- tabLayout.removeOnLayoutChangeListener(this);
- }
- });
- }
+ if (ViewCompat.isLaidOut(tabLayout)) {
+ TabLayoutMediator mediator = new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> tab.setText(pagerAdapter.getPageTitle(position)));
+ mediator.attach();
} else {
- ViewTreeObserver vto = view.getViewTreeObserver();
- vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
-
+ tabLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
- public void onGlobalLayout() {
- if (getActivity() != null) {
- tabLayout.setupWithViewPager(viewPager);
- }
+ public void onLayoutChange(View v, int left, int top, int right, int bottom,
+ int oldLeft, int oldTop, int oldRight, int oldBottom) {
+ TabLayoutMediator mediator = new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> tab.setText(pagerAdapter.getPageTitle(position)));
+ mediator.attach();
+ tabLayout.removeOnLayoutChangeListener(this);
}
});
}
@@ -714,29 +703,29 @@ private Entity getExistingOsmEditEntity(@NonNull OsmEditingPlugin osmEditingPlug
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
- public static class PoiInfoPagerAdapter extends FragmentPagerAdapter {
+ public static class PoiInfoPagerAdapter extends FragmentStateAdapter {
private final Fragment[] fragments = {new BasicEditPoiFragment(), new AdvancedEditPoiFragment()};
private final String[] titles;
- PoiInfoPagerAdapter(FragmentManager fm, String basicTitle, String extendedTitle) {
- super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
+ PoiInfoPagerAdapter(Fragment fm, String basicTitle, String extendedTitle) {
+ super(fm);
titles = new String[] {basicTitle, extendedTitle};
}
- @Override
- public int getCount() {
- return fragments.length;
+ public CharSequence getPageTitle(int position) {
+ return titles[position];
}
+ @NonNull
@Override
- public Fragment getItem(int position) {
+ public Fragment createFragment(int position) {
return fragments[position];
}
@Override
- public CharSequence getPageTitle(int position) {
- return titles[position];
+ public int getItemCount() {
+ return fragments.length;
}
}
From 982e55ff425afa87df7ca265397109097f1c2d6a Mon Sep 17 00:00:00 2001
From: 0xRe1nk0 <0xre1nk0@gmail.com>
Date: Thu, 12 Dec 2024 10:21:12 +0200
Subject: [PATCH 2/7] init refactor commit
---
OsmAnd/res/layout/fragment_edit_poi.xml | 7 ++++---
.../osmedit/dialogs/EditPoiDialogFragment.java | 15 +++++++++------
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/OsmAnd/res/layout/fragment_edit_poi.xml b/OsmAnd/res/layout/fragment_edit_poi.xml
index 6ab89aa1b2e..3f1d7c34bc0 100644
--- a/OsmAnd/res/layout/fragment_edit_poi.xml
+++ b/OsmAnd/res/layout/fragment_edit_poi.xml
@@ -21,7 +21,7 @@
app:contentInsetRight="0dp"
app:contentInsetStart="@dimen/divider_color_light_margin_start" />
-
+ android:layout_height="0dp"
+ android:layout_weight="1"/>
-
+
map = (Map) AndroidUtils.getSerializable(savedInstanceState, TAGS_LIST, LinkedHashMap.class);
editPoiData.updateTags(map);
@@ -512,11 +514,12 @@ public void setSubCategory(String subCategory) {
}
public void smoothScrollToBottom() {
- ScrollView scrollView = view.findViewById(R.id.scroll_view);
- int height = scrollView.getHeight();
+ NestedScrollView scrollView = view.findViewById(R.id.scroll_view);
+ scrollView.post(() -> scrollView.fullScroll(View.FOCUS_DOWN));
+/* int height = scrollView.getHeight();
int bottom = scrollView.getChildAt(0).getBottom();
int maxScrollY = Math.max(0, bottom - height);
- scrollView.smoothScrollTo(0, maxScrollY);
+ scrollView.smoothScrollTo(0, maxScrollY);*/
}
public static void commitEntity(Action action,
@@ -705,7 +708,7 @@ private Entity getExistingOsmEditEntity(@NonNull OsmEditingPlugin osmEditingPlug
public static class PoiInfoPagerAdapter extends FragmentStateAdapter {
- private final Fragment[] fragments = {new BasicEditPoiFragment(), new AdvancedEditPoiFragment()};
+ private final Fragment[] fragments = {new NewBasicEditPoiFragment(), new NewAdvancedEditPoiFragment()};
private final String[] titles;
PoiInfoPagerAdapter(Fragment fm, String basicTitle, String extendedTitle) {
From 39c73d19e845e74d7b525e68a609635a7c530a2d Mon Sep 17 00:00:00 2001
From: 0xRe1nk0 <0xre1nk0@gmail.com>
Date: Thu, 12 Dec 2024 10:23:37 +0200
Subject: [PATCH 3/7] refactor advanced fragment tab
---
OsmAnd/res/layout/edit_poi_add_item.xml | 18 +
.../res/layout/edit_poi_description_item.xml | 96 +++
.../layout/fragment_edit_poi_advanced_new.xml | 10 +
.../fragments/EditPoiContentAdapter.java | 574 ++++++++++++++++++
.../fragments/NewAdvancedEditPoiFragment.java | 325 ++++++++++
5 files changed, 1023 insertions(+)
create mode 100644 OsmAnd/res/layout/edit_poi_add_item.xml
create mode 100644 OsmAnd/res/layout/edit_poi_description_item.xml
create mode 100644 OsmAnd/res/layout/fragment_edit_poi_advanced_new.xml
create mode 100644 OsmAnd/src/net/osmand/plus/plugins/osmedit/fragments/EditPoiContentAdapter.java
create mode 100644 OsmAnd/src/net/osmand/plus/plugins/osmedit/fragments/NewAdvancedEditPoiFragment.java
diff --git a/OsmAnd/res/layout/edit_poi_add_item.xml b/OsmAnd/res/layout/edit_poi_add_item.xml
new file mode 100644
index 00000000000..a0b537a4bed
--- /dev/null
+++ b/OsmAnd/res/layout/edit_poi_add_item.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/edit_poi_description_item.xml b/OsmAnd/res/layout/edit_poi_description_item.xml
new file mode 100644
index 00000000000..4c4b4bd10df
--- /dev/null
+++ b/OsmAnd/res/layout/edit_poi_description_item.xml
@@ -0,0 +1,96 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OsmAnd/res/layout/fragment_edit_poi_advanced_new.xml b/OsmAnd/res/layout/fragment_edit_poi_advanced_new.xml
new file mode 100644
index 00000000000..a9f212ad8e8
--- /dev/null
+++ b/OsmAnd/res/layout/fragment_edit_poi_advanced_new.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
diff --git a/OsmAnd/src/net/osmand/plus/plugins/osmedit/fragments/EditPoiContentAdapter.java b/OsmAnd/src/net/osmand/plus/plugins/osmedit/fragments/EditPoiContentAdapter.java
new file mode 100644
index 00000000000..794ab9f4839
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/plugins/osmedit/fragments/EditPoiContentAdapter.java
@@ -0,0 +1,574 @@
+package net.osmand.plus.plugins.osmedit.fragments;
+
+import static net.osmand.plus.plugins.osmedit.dialogs.EditPoiDialogFragment.AMENITY_TEXT_LENGTH;
+import static net.osmand.plus.plugins.osmedit.fragments.NewAdvancedEditPoiFragment.*;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.graphics.drawable.Drawable;
+import android.text.Editable;
+import android.text.InputFilter;
+import android.text.TextUtils;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.AutoCompleteTextView;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.FragmentManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import net.osmand.osm.PoiCategory;
+import net.osmand.osm.PoiType;
+import net.osmand.osm.edit.OSMSettings;
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.R;
+import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.plugins.osmedit.data.EditPoiData;
+import net.osmand.plus.plugins.osmedit.dialogs.EditPoiDialogFragment;
+import net.osmand.plus.plugins.osmedit.dialogs.NewBasicEditPoiFragment.OpenHoursItem;
+import net.osmand.plus.plugins.osmedit.dialogs.NewBasicEditPoiFragment.OpeningHoursAdapter;
+import net.osmand.plus.plugins.osmedit.dialogs.OpeningHoursDaysDialogFragment;
+import net.osmand.plus.plugins.osmedit.dialogs.OpeningHoursHoursDialogFragment;
+import net.osmand.plus.plugins.osmedit.fragments.NewAdvancedEditPoiFragment.OsmTagsArrayAdapter;
+import net.osmand.plus.utils.AndroidUtils;
+import net.osmand.plus.utils.UiUtilities;
+import net.osmand.plus.widgets.OsmandTextFieldBoxes;
+import net.osmand.plus.widgets.tools.SimpleTextWatcher;
+import net.osmand.util.Algorithms;
+import net.osmand.util.OpeningHoursParser;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import gnu.trove.list.array.TIntArrayList;
+import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
+
+public class EditPoiContentAdapter extends RecyclerView.Adapter {
+ public static final int TYPE_DESCRIPTION_ITEM = 1;
+ public static final int TYPE_TAG_ITEM = 2;
+ public static final int TYPE_ADD_TAG = 3;
+ public static final int TYPE_ADD_OPENING_HOURS = 4;
+ public static final int TYPE_BASIC_INFO = 5;
+ public static final int TYPE_OPEN_TIME_LIST_ITEM = 6;
+
+ public static final int PAYLOAD_NAME = 0;
+ public static final int PAYLOAD_AMENITY = 1;
+ public static final int PAYLOAD_FOCUS_ON_ITEM = 2;
+
+ private final LayoutInflater themedInflater;
+ private final OsmandApplication app;
+ private final boolean nightMode;
+
+ private final EditPoiDialogFragment editPoiDialogFragment;
+
+ private List