diff --git a/OsmAnd/res/layout/fragment_on_save_current_track.xml b/OsmAnd/res/layout/save_gpx_fragment.xml similarity index 73% rename from OsmAnd/res/layout/fragment_on_save_current_track.xml rename to OsmAnd/res/layout/save_gpx_fragment.xml index bc333b7c7a..b2f953a6f0 100644 --- a/OsmAnd/res/layout/fragment_on_save_current_track.xml +++ b/OsmAnd/res/layout/save_gpx_fragment.xml @@ -59,31 +59,4 @@ android:padding="@dimen/content_padding" /> - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 05dbd85340..2af2d9673b 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -16,6 +16,7 @@ import android.view.ViewTreeObserver.OnScrollChangedListener; import android.view.Window; import android.view.WindowManager; import android.widget.LinearLayout; +import android.widget.ScrollView; import androidx.annotation.ColorInt; import androidx.annotation.ColorRes; @@ -192,6 +193,15 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra }); } + protected ViewTreeObserver.OnGlobalLayoutListener getShadowLayoutListener(){ + return new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + setShadowOnScrollableView(); + } + }; + } + protected void drawTopShadow(boolean showTopShadow) { final Activity activity = getActivity(); View mainView = getView(); @@ -478,4 +488,15 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } }); } + + protected void setShadowOnScrollableView() { + ScrollView scrollView = getView().findViewById(R.id.scroll_view); + boolean isScrollable = scrollView.getChildAt(0).getHeight() >= scrollView.getHeight();; + if (isScrollable) { + drawTopShadow(false); + scrollView.getChildAt(0).setPadding(0,8,0,0); + } else { + drawTopShadow(true); + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index e6c5f2ff1b..26d186782d 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -461,7 +461,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { if (activityRef != null && !Algorithms.isEmpty(result.getFilenames())) { final Activity a = activityRef.get(); if (a instanceof FragmentActivity && !a.isFinishing()) { - OnSaveCurrentTrackFragment.showInstance(((FragmentActivity) a).getSupportFragmentManager(), result.getFilenames()); + SaveGPXBottomSheetFragment.showInstance(((FragmentActivity) a).getSupportFragmentManager(), result.getFilenames()); } } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/SaveGPXBottomSheetFragment.java similarity index 80% rename from OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java rename to OsmAnd/src/net/osmand/plus/monitoring/SaveGPXBottomSheetFragment.java index e84c89ffb5..0b38cb6853 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/SaveGPXBottomSheetFragment.java @@ -6,18 +6,13 @@ import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.KeyEvent; -import android.view.LayoutInflater; import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.ContextCompat; import androidx.fragment.app.FragmentActivity; @@ -25,17 +20,15 @@ import androidx.fragment.app.FragmentManager; import net.osmand.FileUtils; import net.osmand.GPXUtilities; -import net.osmand.GPXUtilities.WptPt; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; -import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.base.BottomSheetDialogFragment; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.myplaces.AvailableGPXFragment; -import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.widgets.OsmandTextFieldBoxes; import net.osmand.util.Algorithms; @@ -48,11 +41,10 @@ import java.util.List; import static net.osmand.FileUtils.ILLEGAL_FILE_NAME_CHARACTERS; -public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { - - public static final String TAG = "OnSaveCurrentTrackBottomSheetFragment"; +public class SaveGPXBottomSheetFragment extends MenuBottomSheetDialogFragment { + public static final String TAG = "SaveGPXBottomSheetFragment"; public static final String SAVED_TRACKS_KEY = "saved_track_filename"; - private static final Log LOG = PlatformUtil.getLog(OnSaveCurrentTrackFragment.class); + private static final Log LOG = PlatformUtil.getLog(SaveGPXBottomSheetFragment.class); private boolean openTrack = false; private File file; @@ -60,9 +52,8 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { private String savedGpxName = ""; private String newGpxName = ""; - @Nullable @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { final OsmandApplication app = requiredMyApplication(); Bundle args = getArguments(); if (args != null && args.containsKey(SAVED_TRACKS_KEY)) { @@ -81,7 +72,7 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { file = new File(app.getAppCustomization().getTracksDir(), savedGpxName + IndexConstants.GPX_FILE_EXT); final boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); final int textPrimaryColor = nightMode ? R.color.text_color_primary_dark : R.color.text_color_primary_light; - View mainView = UiUtilities.getInflater(ctx, nightMode).inflate(R.layout.fragment_on_save_current_track, container); + View mainView = UiUtilities.getInflater(ctx, nightMode).inflate(R.layout.save_gpx_fragment, null); OsmandTextFieldBoxes textBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.name_text_box); if (nightMode) { @@ -131,25 +122,11 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { app.getSettings().SHOW_SAVED_TRACK_REMEMBER.set(isChecked); } }); - View openTrackBtn = mainView.findViewById(R.id.open_track_button); - UiUtilities.setupDialogButton(nightMode, openTrackBtn, DialogButtonType.SECONDARY, R.string.shared_string_open_track); - final View showOnMapBtn = mainView.findViewById(R.id.close_button); - UiUtilities.setupDialogButton(nightMode, showOnMapBtn, DialogButtonType.SECONDARY, R.string.shared_string_close); - openTrackBtn.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - doRename(true); - } - }); - - showOnMapBtn.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - doRename(false); - } - }); - return mainView; + SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + .setCustomView(mainView) + .create(); + items.add(titleItem); } private void doRename(boolean openTrack) { @@ -160,6 +137,26 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { } } + @Override + protected UiUtilities.DialogButtonType getRightBottomButtonType() { + return UiUtilities.DialogButtonType.SECONDARY; + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_open_track; + } + + @Override + protected void onRightBottomButtonClick() { + doRename(true); + } + + @Override + protected void onDismissButtonClickAction() { + doRename(false); + } + @Override public void onDismiss(DialogInterface dialog) { super.onDismiss(dialog); @@ -199,10 +196,10 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { } OsmandApplication app = (OsmandApplication) activity.getApplication(); - GpxInfo gpxInfo = new GpxInfo(); + AvailableGPXFragment.GpxInfo gpxInfo = new AvailableGPXFragment.GpxInfo(); gpxInfo.setGpx(GPXUtilities.loadGPXFile(f)); if (gpxInfo.gpx != null) { - WptPt loc = gpxInfo.gpx.findPointToShow(); + GPXUtilities.WptPt loc = gpxInfo.gpx.findPointToShow(); if (loc != null) { app.getSelectedGpxHelper().setGpxFileToDisplay(gpxInfo.gpx); if (activity instanceof MapActivity) { @@ -223,7 +220,7 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { if (fragmentManager.isStateSaved()) { return; } - OnSaveCurrentTrackFragment f = new OnSaveCurrentTrackFragment(); + SaveGPXBottomSheetFragment f = new SaveGPXBottomSheetFragment(); Bundle b = new Bundle(); b.putStringArrayList(SAVED_TRACKS_KEY, new ArrayList<>(filenames)); f.setArguments(b); @@ -234,3 +231,4 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { } } } + diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/BugBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/BugBottomSheetDialog.java index 38bb8da5fe..7b4067c2f7 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/BugBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/BugBottomSheetDialog.java @@ -56,6 +56,7 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment { View osmNoteView = View.inflate(UiUtilities.getThemedContext(app, nightMode), R.layout.open_osm_note_text, null); + osmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener()); TextInputLayout textBox = osmNoteView.findViewById(R.id.name_text_box); textBox.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name)); ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat @@ -85,9 +86,9 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment { } public static void showInstance(@NonNull FragmentManager fm, OsmBugsUtil osmBugsUtil, OsmBugsUtil local, - String text, int titleTextId, int posButtonTextId, final OsmPoint.Action action, - final OsmBugsLayer.OpenStreetNote bug, final OsmNotesPoint point, - HandleOsmNoteAsyncTask.HandleBugListener handleBugListener) { + String text, int titleTextId, int posButtonTextId, final OsmPoint.Action action, + final OsmBugsLayer.OpenStreetNote bug, final OsmNotesPoint point, + HandleOsmNoteAsyncTask.HandleBugListener handleBugListener) { try { if (!fm.isStateSaved()) { BugBottomSheetDialog fragment = new BugBottomSheetDialog(); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java index 759f924d10..cc1fab7554 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java @@ -1,14 +1,11 @@ package net.osmand.plus.osmedit.dialogs; -import android.graphics.Rect; import android.os.AsyncTask; import android.os.Bundle; import android.text.Editable; import android.view.LayoutInflater; import android.view.View; -import android.view.ViewTreeObserver; import android.widget.LinearLayout; -import android.widget.ScrollView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -54,10 +51,6 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { private TextInputEditText tagsField; private TextInputEditText messageField; - private int contentHeightPrevious = 0; - private int buttonsHeight; - private int shadowHeight; - private ScrollView scrollView; public void setGpxInfos(GpxInfo[] gpxInfos) { this.gpxInfos = gpxInfos; @@ -69,13 +62,13 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { OsmandSettings settings = app.getSettings(); LayoutInflater themedInflater = UiUtilities.getInflater(app, nightMode); - View sendOsmPoiView = themedInflater.inflate(R.layout.send_gpx_fragment, null); - sendOsmPoiView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener()); + View sendGpxView = themedInflater.inflate(R.layout.send_gpx_fragment, null); + sendGpxView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener()); - tagsField = sendOsmPoiView.findViewById(R.id.tags_field); - messageField = sendOsmPoiView.findViewById(R.id.message_field); + tagsField = sendGpxView.findViewById(R.id.tags_field); + messageField = sendGpxView.findViewById(R.id.message_field); - TextView accountName = sendOsmPoiView.findViewById(R.id.user_name); + TextView accountName = sendGpxView.findViewById(R.id.user_name); if (!Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get())) { accountName.setText(settings.USER_DISPLAY_NAME.get()); } else { @@ -86,8 +79,8 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { messageField.setText(Algorithms.getFileNameWithoutExtension(fileName)); messageField.setSelection(messageField.getText().length()); - final TextView visibilityName = sendOsmPoiView.findViewById(R.id.visibility_name); - final TextView visibilityDescription = sendOsmPoiView.findViewById(R.id.visibility_description); + final TextView visibilityName = sendGpxView.findViewById(R.id.visibility_name); + final TextView visibilityDescription = sendGpxView.findViewById(R.id.visibility_description); visibilityName.setText(selectedUploadVisibility.getTitleId()); visibilityDescription.setText(selectedUploadVisibility.getDescriptionId()); @@ -110,7 +103,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { horizontalSelectionAdapter.notifyDataSetChanged(); } }); - LinearLayout account = sendOsmPoiView.findViewById(R.id.account_container); + LinearLayout account = sendGpxView.findViewById(R.id.account_container); account.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -121,39 +114,17 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { dismiss(); } }); - RecyclerView iconCategoriesRecyclerView = sendOsmPoiView.findViewById(R.id.description_view); + RecyclerView iconCategoriesRecyclerView = sendGpxView.findViewById(R.id.description_view); iconCategoriesRecyclerView.setAdapter(horizontalSelectionAdapter); iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false)); horizontalSelectionAdapter.notifyDataSetChanged(); SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() - .setCustomView(sendOsmPoiView) + .setCustomView(sendGpxView) .create(); items.add(titleItem); } - private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() { - return new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - Rect visibleDisplayFrame = new Rect(); - buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width); - shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height); - scrollView = getView().findViewById(R.id.scroll_view); - scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame); - int viewHeight = scrollView.getHeight(); - int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight; - if (contentHeightPrevious != contentHeight) { - boolean showTopShadow; - showTopShadow = viewHeight + shadowHeight < contentHeight; - scrollView.requestLayout(); - contentHeightPrevious = contentHeight; - drawTopShadow(showTopShadow); - } - } - }; - } - protected static void showOpenStreetMapScreen(@NonNull FragmentActivity activity) { if (activity instanceof MapActivity) { BaseSettingsFragment.showInstance(activity, OPEN_STREET_MAP_EDITING); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java index 7ab3d9149b..f4f657c099 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java @@ -77,6 +77,7 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_osm_note_fragment, null); + sendOsmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener()); noteText = sendOsmNoteView.findViewById(R.id.note_text); noteText.setText(((OsmNotesPoint) poi[0]).getText()); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java index 35a998e1bb..a715c33354 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java @@ -37,221 +37,222 @@ import static net.osmand.plus.osmedit.dialogs.SendGpxBottomSheetFragment.showOpe public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { - public static final String TAG = SendPoiBottomSheetFragment.class.getSimpleName(); - private static final Log LOG = PlatformUtil.getLog(SendPoiBottomSheetFragment.class); - public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; - private OsmPoint[] poi; + public static final String TAG = SendPoiBottomSheetFragment.class.getSimpleName(); + private static final Log LOG = PlatformUtil.getLog(SendPoiBottomSheetFragment.class); + public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; + private OsmPoint[] poi; - private SwitchCompat closeChangeSet; - private EditText messageEditText; + private SwitchCompat closeChangeSet; + private EditText messageEditText; - private boolean isLoginOAuth(OsmandSettings settings) { - return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get()); - } + private boolean isLoginOAuth(OsmandSettings settings) { + return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get()); + } - @Override - public void createMenuItems(Bundle savedInstanceState) { - OsmandApplication app = getMyApplication(); - if (app == null) { - return; - } - poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); - final boolean isNightMode = app.getDaynightHelper().isNightModeForMapControls(); - final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), - R.layout.send_poi_fragment, null); - closeChangeSet = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox); - messageEditText = sendOsmPoiView.findViewById(R.id.message_field); - String defaultChangeSet = createDefaultChangeSet(app); - messageEditText.setText(defaultChangeSet); - messageEditText.setSelection(messageEditText.getText().length()); - final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name); - OsmandSettings settings = app.getSettings(); - String userNameOAuth = settings.USER_DISPLAY_NAME.get(); - String userNameOpenID = settings.USER_NAME.get(); - String userName = isLoginOAuth(settings) ? userNameOAuth : userNameOpenID; - accountName.setText(userName); - closeChangeSet.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); - final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); - closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0); - closeChangeSet.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isNightMode) { - closeChangeSet.setBackgroundResource( - isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); - } else { - closeChangeSet.setBackgroundResource( - isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); - } - closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0); - } - }); - LinearLayout account = sendOsmPoiView.findViewById(R.id.account_container); - account.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - FragmentActivity activity = getActivity(); - if (activity != null) { - showOpenStreetMapScreen(activity); - } - dismiss(); - } - }); - final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() - .setCustomView(sendOsmPoiView) - .create(); - items.add(titleItem); - } + @Override + public void createMenuItems(Bundle savedInstanceState) { + OsmandApplication app = getMyApplication(); + if (app == null) { + return; + } + poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); + final boolean isNightMode = app.getDaynightHelper().isNightModeForMapControls(); + final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), + R.layout.send_poi_fragment, null); + sendOsmPoiView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener()); + closeChangeSet = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox); + messageEditText = sendOsmPoiView.findViewById(R.id.message_field); + String defaultChangeSet = createDefaultChangeSet(app); + messageEditText.setText(defaultChangeSet); + messageEditText.setSelection(messageEditText.getText().length()); + final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name); + OsmandSettings settings = app.getSettings(); + String userNameOAuth = settings.USER_DISPLAY_NAME.get(); + String userNameOpenID = settings.USER_NAME.get(); + String userName = isLoginOAuth(settings) ? userNameOAuth : userNameOpenID; + accountName.setText(userName); + closeChangeSet.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); + final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); + closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0); + closeChangeSet.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isNightMode) { + closeChangeSet.setBackgroundResource( + isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); + } else { + closeChangeSet.setBackgroundResource( + isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); + } + closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0); + } + }); + LinearLayout account = sendOsmPoiView.findViewById(R.id.account_container); + account.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FragmentActivity activity = getActivity(); + if (activity != null) { + showOpenStreetMapScreen(activity); + } + dismiss(); + } + }); + final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + .setCustomView(sendOsmPoiView) + .create(); + items.add(titleItem); + } - public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) { - try { - if (!fm.isStateSaved()) { - SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putSerializable(OPENSTREETMAP_POINT, points); - fragment.setArguments(bundle); - fragment.show(fm, TAG); - } - } catch (RuntimeException e) { - LOG.error("showInstance", e); - } - } + public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) { + try { + if (!fm.isStateSaved()) { + SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putSerializable(OPENSTREETMAP_POINT, points); + fragment.setArguments(bundle); + fragment.show(fm, TAG); + } + } catch (RuntimeException e) { + LOG.error("showInstance", e); + } + } - @Override - protected UiUtilities.DialogButtonType getRightBottomButtonType() { - return (UiUtilities.DialogButtonType.PRIMARY); - } + @Override + protected UiUtilities.DialogButtonType getRightBottomButtonType() { + return (UiUtilities.DialogButtonType.PRIMARY); + } - @Override - protected void onRightBottomButtonClick() { - ProgressDialogPoiUploader progressDialogPoiUploader = null; - Activity activity = getActivity(); - if (activity instanceof MapActivity) { - progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) activity); - } else if (getParentFragment() instanceof ProgressDialogPoiUploader) { - progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment(); - } - if (progressDialogPoiUploader != null) { - String comment = messageEditText.getText().toString(); - if (comment.length() > 0) { - for (OsmPoint osmPoint : poi) { - if (osmPoint.getGroup() == OsmPoint.Group.POI) { - ((OpenstreetmapPoint) osmPoint).setComment(comment); - break; - } - } - } - progressDialogPoiUploader.showProgressDialog(poi, closeChangeSet.isChecked(), false); - } - dismiss(); - } + @Override + protected void onRightBottomButtonClick() { + ProgressDialogPoiUploader progressDialogPoiUploader = null; + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) activity); + } else if (getParentFragment() instanceof ProgressDialogPoiUploader) { + progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment(); + } + if (progressDialogPoiUploader != null) { + String comment = messageEditText.getText().toString(); + if (comment.length() > 0) { + for (OsmPoint osmPoint : poi) { + if (osmPoint.getGroup() == OsmPoint.Group.POI) { + ((OpenstreetmapPoint) osmPoint).setComment(comment); + break; + } + } + } + progressDialogPoiUploader.showProgressDialog(poi, closeChangeSet.isChecked(), false); + } + dismiss(); + } - @Override - protected int getRightBottomButtonTextId() { - return R.string.shared_string_upload; - } + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_upload; + } - private String createDefaultChangeSet(OsmandApplication app) { - Map allTranslatedSubTypes = app.getPoiTypes().getAllTranslatedNames(true); - if (allTranslatedSubTypes == null) { - return ""; - } - Map addGroup = new HashMap<>(); - Map editGroup = new HashMap<>(); - Map deleteGroup = new HashMap<>(); - Map reopenGroup = new HashMap<>(); - String comment = ""; - for (OsmPoint p : poi) { - if (p.getGroup() == OsmPoint.Group.POI) { - OsmPoint.Action action = p.getAction(); - String type = ((OpenstreetmapPoint) p).getEntity().getTag(Entity.POI_TYPE_TAG); - if (type == null) { - continue; - } - PoiType localizedPoiType = allTranslatedSubTypes.get(type.toLowerCase().trim()); - if (localizedPoiType != null) { - type = Algorithms.capitalizeFirstLetter(localizedPoiType.getKeyName().replace('_', ' ')); - } - if (action == OsmPoint.Action.CREATE) { - if (!addGroup.containsKey(type)) { - addGroup.put(type, 1); - } else { - addGroup.put(type, addGroup.get(type) + 1); - } - } else if (action == OsmPoint.Action.MODIFY) { - if (!editGroup.containsKey(type)) { - editGroup.put(type, 1); - } else { - editGroup.put(type, editGroup.get(type) + 1); - } - } else if (action == OsmPoint.Action.DELETE) { - if (!deleteGroup.containsKey(type)) { - deleteGroup.put(type, 1); - } else { - deleteGroup.put(type, deleteGroup.get(type) + 1); - } - } else if (action == OsmPoint.Action.REOPEN) { - if (!reopenGroup.containsKey(type)) { - reopenGroup.put(type, 1); - } else { - reopenGroup.put(type, reopenGroup.get(type) + 1); - } - } - } - } - int modifiedItemsOutOfLimit = 0; - for (int i = 0; i < 4; i++) { - String action; - Map group; - switch (i) { - case 0: - action = getString(R.string.default_changeset_add); - group = addGroup; - break; - case 1: - action = getString(R.string.default_changeset_edit); - group = editGroup; - break; - case 2: - action = getString(R.string.default_changeset_delete); - group = deleteGroup; - break; - case 3: - action = getString(R.string.default_changeset_reopen); - group = reopenGroup; - break; - default: - action = ""; - group = new HashMap<>(); - } + private String createDefaultChangeSet(OsmandApplication app) { + Map allTranslatedSubTypes = app.getPoiTypes().getAllTranslatedNames(true); + if (allTranslatedSubTypes == null) { + return ""; + } + Map addGroup = new HashMap<>(); + Map editGroup = new HashMap<>(); + Map deleteGroup = new HashMap<>(); + Map reopenGroup = new HashMap<>(); + String comment = ""; + for (OsmPoint p : poi) { + if (p.getGroup() == OsmPoint.Group.POI) { + OsmPoint.Action action = p.getAction(); + String type = ((OpenstreetmapPoint) p).getEntity().getTag(Entity.POI_TYPE_TAG); + if (type == null) { + continue; + } + PoiType localizedPoiType = allTranslatedSubTypes.get(type.toLowerCase().trim()); + if (localizedPoiType != null) { + type = Algorithms.capitalizeFirstLetter(localizedPoiType.getKeyName().replace('_', ' ')); + } + if (action == OsmPoint.Action.CREATE) { + if (!addGroup.containsKey(type)) { + addGroup.put(type, 1); + } else { + addGroup.put(type, addGroup.get(type) + 1); + } + } else if (action == OsmPoint.Action.MODIFY) { + if (!editGroup.containsKey(type)) { + editGroup.put(type, 1); + } else { + editGroup.put(type, editGroup.get(type) + 1); + } + } else if (action == OsmPoint.Action.DELETE) { + if (!deleteGroup.containsKey(type)) { + deleteGroup.put(type, 1); + } else { + deleteGroup.put(type, deleteGroup.get(type) + 1); + } + } else if (action == OsmPoint.Action.REOPEN) { + if (!reopenGroup.containsKey(type)) { + reopenGroup.put(type, 1); + } else { + reopenGroup.put(type, reopenGroup.get(type) + 1); + } + } + } + } + int modifiedItemsOutOfLimit = 0; + for (int i = 0; i < 4; i++) { + String action; + Map group; + switch (i) { + case 0: + action = getString(R.string.default_changeset_add); + group = addGroup; + break; + case 1: + action = getString(R.string.default_changeset_edit); + group = editGroup; + break; + case 2: + action = getString(R.string.default_changeset_delete); + group = deleteGroup; + break; + case 3: + action = getString(R.string.default_changeset_reopen); + group = reopenGroup; + break; + default: + action = ""; + group = new HashMap<>(); + } - if (!group.isEmpty()) { - int pos = 0; - for (Map.Entry entry : group.entrySet()) { - String type = entry.getKey(); - int quantity = entry.getValue(); - if (comment.length() > 200) { - modifiedItemsOutOfLimit += quantity; - } else { - if (pos == 0) { - comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ") - .concat(quantity == 1 ? "" : quantity + " ").concat(type); - } else { - comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + " ").concat(type); - } - } - pos++; - } - } - } - if (modifiedItemsOutOfLimit != 0) { - comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ") - .concat(getString(R.string.items_modified)).concat("."); - } else if (!comment.isEmpty()) { - comment = comment.concat("."); - } - return comment; - } + if (!group.isEmpty()) { + int pos = 0; + for (Map.Entry entry : group.entrySet()) { + String type = entry.getKey(); + int quantity = entry.getValue(); + if (comment.length() > 200) { + modifiedItemsOutOfLimit += quantity; + } else { + if (pos == 0) { + comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ") + .concat(quantity == 1 ? "" : quantity + " ").concat(type); + } else { + comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + " ").concat(type); + } + } + pos++; + } + } + } + if (modifiedItemsOutOfLimit != 0) { + comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ") + .concat(getString(R.string.items_modified)).concat("."); + } else if (!comment.isEmpty()) { + comment = comment.concat("."); + } + return comment; + } } diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java index 622fc11977..384f5457da 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java @@ -6,10 +6,10 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.EditText; +import android.widget.ScrollView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.content.res.AppCompatResources; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -44,6 +44,7 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet { LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode); View view = themedInflater.inflate(R.layout.osm_login_data, null); + view.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener()); userNameEditText = view.findViewById(R.id.name_edit_text); passwordEditText = view.findViewById(R.id.password_edit_text); @@ -73,6 +74,7 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet { items.add(titleItem); } + @Override public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); @@ -107,7 +109,7 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet { } public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target, - boolean usedOnMap, @Nullable ApplicationMode appMode) { + boolean usedOnMap, @Nullable ApplicationMode appMode) { try { Bundle args = new Bundle(); args.putString(PREFERENCE_ID, key);