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_add_opening_hours_item.xml b/OsmAnd/res/layout/edit_poi_add_opening_hours_item.xml
new file mode 100644
index 00000000000..30a5103451a
--- /dev/null
+++ b/OsmAnd/res/layout/edit_poi_add_opening_hours_item.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/edit_poi_basic_info_item.xml b/OsmAnd/res/layout/edit_poi_basic_info_item.xml
new file mode 100644
index 00000000000..7f0097c30dd
--- /dev/null
+++ b/OsmAnd/res/layout/edit_poi_basic_info_item.xml
@@ -0,0 +1,112 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ 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.xml b/OsmAnd/res/layout/fragment_edit_poi.xml
index 5e9f3a7bf5e..fd71191e90d 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="match_parent"/>
-
+
+
+
+
+
diff --git a/OsmAnd/res/layout/list_item_poi_tag.xml b/OsmAnd/res/layout/list_item_poi_tag.xml
index b5e5fc0118b..d509f4c5162 100644
--- a/OsmAnd/res/layout/list_item_poi_tag.xml
+++ b/OsmAnd/res/layout/list_item_poi_tag.xml
@@ -2,7 +2,7 @@
{
+ scrollView.scrollTo(0, 0);
+ scrollView.requestLayout();
+ });
+ }
+
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
updateNightMode();
view = themedInflater.inflate(R.layout.fragment_edit_poi, container, false);
+ scrollView = view.findViewById(R.id.scroll_view);
+ scrollView.setNestedScrollingEnabled(false);
if (savedInstanceState != null) {
Map map = (Map) AndroidUtils.getSerializable(savedInstanceState, TAGS_LIST, LinkedHashMap.class);
editPoiData.updateTags(map);
@@ -151,60 +160,51 @@ 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;
} else {
onSaveButtonClickListener = null;
}
+ resetNestedScrollView();
}
@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);
}
});
}
@@ -523,11 +523,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,
@@ -714,29 +715,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 Fragment[] fragments = {new NewBasicEditPoiFragment(), new NewAdvancedEditPoiFragment()};
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;
}
}
diff --git a/OsmAnd/src/net/osmand/plus/plugins/osmedit/dialogs/NewBasicEditPoiFragment.java b/OsmAnd/src/net/osmand/plus/plugins/osmedit/dialogs/NewBasicEditPoiFragment.java
new file mode 100644
index 00000000000..0e850a67cd8
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/plugins/osmedit/dialogs/NewBasicEditPoiFragment.java
@@ -0,0 +1,268 @@
+package net.osmand.plus.plugins.osmedit.dialogs;
+
+import static net.osmand.plus.plugins.osmedit.dialogs.EditPoiDialogFragment.AMENITY_TEXT_LENGTH;
+import static net.osmand.plus.plugins.osmedit.fragments.EditPoiContentAdapter.TYPE_ADD_OPENING_HOURS;
+import static net.osmand.plus.plugins.osmedit.fragments.EditPoiContentAdapter.TYPE_BASIC_INFO;
+
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.text.InputFilter;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.FragmentManager;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+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.base.BaseOsmAndFragment;
+import net.osmand.plus.helpers.LocaleHelper;
+import net.osmand.plus.plugins.osmedit.data.EditPoiData;
+import net.osmand.plus.plugins.osmedit.fragments.EditPoiContentAdapter;
+import net.osmand.plus.utils.AndroidUtils;
+import net.osmand.plus.utils.ColorUtilities;
+import net.osmand.util.OpeningHoursParser;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+public class NewBasicEditPoiFragment extends BaseOsmAndFragment implements EditPoiDialogFragment.OnFragmentActivatedListener {
+
+ private static final String OPENING_HOURS = "opening_hours";
+ private OpeningHoursAdapter openingHoursAdapter;
+
+ private boolean basicTagsInitialized;
+ private EditPoiContentAdapter contentAdapter;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ updateNightMode();
+ View view = themedInflater.inflate(R.layout.fragment_edit_poi_advanced_new, container, false);
+
+ RecyclerView recyclerView = view.findViewById(R.id.content_recycler_view);
+ recyclerView.setNestedScrollingEnabled(true);
+ InputFilter[] lengthLimit = {
+ new InputFilter.LengthFilter(AMENITY_TEXT_LENGTH)
+ };
+
+ int iconColor = ColorUtilities.getSecondaryTextColor(app, nightMode);
+ Drawable clockDrawable = getPaintedContentIcon(R.drawable.ic_action_time, iconColor);
+ Drawable deleteDrawable = getPaintedContentIcon(R.drawable.ic_action_remove_dark, iconColor);
+ if (savedInstanceState != null && savedInstanceState.containsKey(OPENING_HOURS)) {
+ OpeningHoursParser.OpeningHours openingHours = AndroidUtils.getSerializable(savedInstanceState, OPENING_HOURS, OpeningHoursParser.OpeningHours.class);
+ openingHoursAdapter = new OpeningHoursAdapter(app, openingHours,
+ getData(), clockDrawable, deleteDrawable);
+ openingHoursAdapter.updateHoursData();
+ } else {
+ openingHoursAdapter = new OpeningHoursAdapter(app, new OpeningHoursParser.OpeningHours(),
+ getData(), clockDrawable, deleteDrawable);
+ }
+
+ EditPoiContentAdapter.EditPoiListener editPoiListener = new EditPoiContentAdapter.EditPoiListener() {
+ @Override
+ public void onAddNewItem(int position, int buttonType) {
+ if (buttonType == TYPE_ADD_OPENING_HOURS) {
+ OpeningHoursParser.BasicOpeningHourRule rule = new OpeningHoursParser.BasicOpeningHourRule();
+ rule.setStartTime(9 * 60);
+ rule.setEndTime(18 * 60);
+ if (openingHoursAdapter.openingHours.getRules().isEmpty()) {
+ rule.setDays(new boolean[]{true, true, true, true, true, false, false});
+ }
+ OpeningHoursDaysDialogFragment fragment = OpeningHoursDaysDialogFragment.createInstance(rule, -1);
+ fragment.show(getChildFragmentManager(), "OpenTimeDialogFragment");
+ }
+ }
+
+ @Override
+ public void onDeleteItem(int position) {
+
+ }
+
+ @Override
+ public InputFilter[] getLengthLimit() {
+ return lengthLimit;
+ }
+
+ @Override
+ public FragmentManager getChildFragmentManager() {
+ return NewBasicEditPoiFragment.this.getChildFragmentManager();
+ }
+
+ @Override
+ public boolean isFragmentResumed() {
+ return NewBasicEditPoiFragment.this.isResumed();
+ }
+
+ @Override
+ public boolean isBasicTagsInitialized() {
+ return NewBasicEditPoiFragment.this.basicTagsInitialized;
+ }
+ };
+
+ contentAdapter = new EditPoiContentAdapter((MapActivity) requireActivity(), getContentList(),
+ null, null, openingHoursAdapter, nightMode, getEditPoiFragment(), editPoiListener);
+ recyclerView.setLayoutManager(new LinearLayoutManager(app));
+ recyclerView.setAdapter(contentAdapter);
+ onFragmentActivated();
+
+ return view;
+ }
+
+ private EditPoiDialogFragment getEditPoiFragment() {
+ return (EditPoiDialogFragment) getParentFragment();
+ }
+
+ private void updateViews() {
+ if (contentAdapter != null) {
+ contentAdapter.setItems(getContentList());
+ }
+ }
+
+ public record OpenHoursItem(int position, long id) {
+ }
+
+ private List