From f4edc8dc83553e47d1ba5f1d6996331d81115e37 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 11 Nov 2020 23:55:20 +0200 Subject: [PATCH] Refactoring Upload OSM note fragment --- OsmAnd/res/drawable/layout_bg.xml | 2 +- OsmAnd/res/layout/send_osm_note_fragment.xml | 175 +++++++++++------- OsmAnd/res/layout/send_poi_fragment.xml | 9 +- OsmAnd/res/values/strings.xml | 1 + .../LoginBottomSheetFragment.java | 5 +- .../plus/osmedit/EditPOIMenuController.java | 29 ++- .../plus/osmedit/OsmEditingFragment.java | 2 +- .../osmand/plus/osmedit/OsmEditsFragment.java | 15 +- .../SendOsmNoteBottomSheetFragment.java | 127 ++++++++++--- .../dialogs/SendPoiBottomSheetFragment.java | 47 +++-- 10 files changed, 271 insertions(+), 141 deletions(-) diff --git a/OsmAnd/res/drawable/layout_bg.xml b/OsmAnd/res/drawable/layout_bg.xml index a784ae5701..214e67e852 100644 --- a/OsmAnd/res/drawable/layout_bg.xml +++ b/OsmAnd/res/drawable/layout_bg.xml @@ -1,6 +1,6 @@ - + diff --git a/OsmAnd/res/layout/send_osm_note_fragment.xml b/OsmAnd/res/layout/send_osm_note_fragment.xml index 4ce16dc2e8..6cc897ee89 100644 --- a/OsmAnd/res/layout/send_osm_note_fragment.xml +++ b/OsmAnd/res/layout/send_osm_note_fragment.xml @@ -2,7 +2,6 @@ @@ -12,111 +11,159 @@ android:orientation="vertical" android:paddingStart="@dimen/content_padding" android:paddingLeft="@dimen/content_padding" - android:paddingTop="@dimen/bottom_sheet_content_margin" android:paddingEnd="@dimen/content_padding" android:paddingRight="@dimen/content_padding"> - - - + osmand:typeface="@string/font_roboto_regular" /> - - + android:orientation="vertical"> - + + android:layout_marginTop="@dimen/content_padding_half" + android:minHeight="@dimen/context_menu_buttons_bottom_height"> - + - + android:layout_gravity="center_vertical" + android:layout_weight="1" + android:orientation="vertical" + android:paddingLeft="@dimen/content_padding" + android:paddingRight="@dimen/content_padding" + android:paddingStart="@dimen/content_padding" + android:paddingEnd="@dimen/content_padding"> + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/send_poi_fragment.xml b/OsmAnd/res/layout/send_poi_fragment.xml index dbc4766d52..8a7809ffbd 100644 --- a/OsmAnd/res/layout/send_poi_fragment.xml +++ b/OsmAnd/res/layout/send_poi_fragment.xml @@ -41,18 +41,19 @@ android:imeOptions="actionDone" /> - + android:letterSpacing="@dimen/text_button_letter_spacing" /> @@ -62,7 +63,7 @@ android:background="?attr/dashboard_divider" /> + You can log in using the safe OAuth method or use your login and password. Comment OSM Note Close OSM Note Closed changset diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java index 83e8bc1d13..acf0e4579f 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java @@ -18,9 +18,7 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; -import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet; import org.apache.commons.logging.Log; @@ -29,11 +27,12 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.concurrent.ExecutionException; +import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA; + public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { public static final String TAG = LoginBottomSheetFragment.class.getSimpleName(); private static final Log log = PlatformUtil.getLog(LoginBottomSheetFragment.class); - private static final String OSM_LOGIN_DATA = "osm_login_data"; private OsmOAuthAuthorizationAdapter authorizationAdapter; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java index 237a503e1a..4732b36fe1 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java @@ -17,8 +17,6 @@ import net.osmand.plus.measurementtool.LoginBottomSheetFragment; import net.osmand.plus.osmedit.OsmPoint.Action; import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment; import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment; -import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; -import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.SimpleProgressDialogPoiUploader; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.settings.backend.OsmandSettings; @@ -48,23 +46,24 @@ public class EditPOIMenuController extends MenuController { public void buttonPressed() { MapActivity activity = getMapActivity(); if (plugin != null && activity != null) { + OsmPoint point = getOsmPoint(); OsmandApplication app = activity.getMyApplication(); OsmandSettings settings = app.getSettings(); OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app); - OsmPoint point = getOsmPoint(); - if (client.isValidToken() + boolean isLogin = client.isValidToken() || !Algorithms.isEmpty(settings.USER_NAME.get()) - && !Algorithms.isEmpty(settings.USER_PASSWORD.get())) { - if (point instanceof OpenstreetmapPoint) { - SendPoiBottomSheetFragment sendPoiBottomSheetFragment = - SendPoiBottomSheetFragment.showInstance(new OsmPoint[]{getOsmPoint()}, SendPoiBottomSheetFragment.PoiUploaderType.SIMPLE); - sendPoiBottomSheetFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG); - } else if ( point instanceof OsmNotesPoint) { - SendOsmNoteBottomSheetFragment sendOsmNoteBottomSheetFragment = - SendOsmNoteBottomSheetFragment.showInstance(new OsmPoint[]{getOsmPoint()}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE); - sendOsmNoteBottomSheetFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG);} - } else { - LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null); + && !Algorithms.isEmpty(settings.USER_PASSWORD.get()); + + if (point instanceof OpenstreetmapPoint) { + if (isLogin) { + SendPoiBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), + new OsmPoint[]{getOsmPoint()}, SendPoiBottomSheetFragment.PoiUploaderType.SIMPLE); + } else { + LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null); + } + } else if (point instanceof OsmNotesPoint) { + SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), + new OsmPoint[]{getOsmPoint()}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE); } } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java index 3435ad1561..581e42152d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java @@ -40,7 +40,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer private static final String OSM_LOGOUT = "osm_logout"; private static final String OPEN_OSM_EDITS = "open_osm_edits"; - private static final String OSM_LOGIN_DATA = "osm_login_data"; + public static final String OSM_LOGIN_DATA = "osm_login_data"; private static final String OSM_EDITING_INFO = "osm_editing_info"; private OsmOAuthAuthorizationAdapter authorizationAdapter; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index f0abe4eb03..90ff1952b2 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -43,8 +43,6 @@ import net.osmand.osm.edit.Node; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.measurementtool.LoginBottomSheetFragment; -import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment; -import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; @@ -623,30 +621,21 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo return info; } - public OsmandApplication getMyApplication() { return (OsmandApplication) getActivity().getApplication(); } - private void uploadItems(final OsmPoint[] items) { FragmentActivity activity = getActivity(); if (activity != null) { OsmandApplication app = getMyApplication(); OsmandSettings settings = app.getSettings(); - boolean isPoi = getOsmEditsByGroup(Group.POI) instanceof OpenstreetmapPoint; OsmOAuthAuthorizationAdapter authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); if (authorizationAdapter.isValidToken() || !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get())) { - if (isPoi) { - SendOsmNoteBottomSheetFragment sendOsmNoteBottomSheetFragment = - SendOsmNoteBottomSheetFragment.showInstance(new OsmPoint[]{}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE); - sendOsmNoteBottomSheetFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG); - } else { - SendOsmNoteBottomSheetFragment sendOsmNoteBottomSheetFragment = - SendOsmNoteBottomSheetFragment.showInstance(new OsmPoint[]{}, SendOsmNoteBottomSheetFragment.PoiUploaderType.SIMPLE); - sendOsmNoteBottomSheetFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG);} + SendPoiDialogFragment.createInstance(items, PoiUploaderType.FRAGMENT) + .show(getChildFragmentManager(), SendPoiDialogFragment.TAG); } else { LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java index 2f7868a8e5..69b299c28c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.osmedit.dialogs; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.ContextThemeWrapper; import android.view.View; @@ -10,26 +11,41 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.SwitchCompat; +import androidx.fragment.app.FragmentManager; +import com.google.android.material.textfield.TextInputLayout; + +import net.osmand.AndroidUtils; +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.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.osmedit.OpenstreetmapPoint; +import net.osmand.plus.osmedit.OsmNotesPoint; import net.osmand.plus.osmedit.OsmPoint; +import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; + +import static net.osmand.plus.UiUtilities.setupDialogButton; +import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA; import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.*; public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment { public static final String TAG = SendOsmNoteBottomSheetFragment.class.getSimpleName(); + private static final Log LOG = PlatformUtil.getLog(SendOsmNoteBottomSheetFragment.class); public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; private OsmPoint[] poi; + private boolean isLogin; protected OsmandSettings settings; @@ -48,55 +64,107 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen @Override public void createMenuItems(Bundle savedInstanceState) { - final boolean isNightMode = !getMyApplication().getSettings().isLightContent(); - final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_osm_note_fragment, null); - final LinearLayout accountBlockView = sendOsmNoteView.findViewById(R.id.account_block); + isLogin = isLogin(); + poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); + OsmandApplication app = getMyApplication(); + + items.add(new TitleItem(getString(R.string.upload_osm_note))); + + final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), + R.layout.send_osm_note_fragment, null); + + TextView noteText = sendOsmNoteView.findViewById(R.id.note_text); + noteText.setText(((OsmNotesPoint) poi[0]).getText()); + TextInputLayout noteHint = sendOsmNoteView.findViewById(R.id.note_hint); + noteHint.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name)); + final LinearLayout accountBlockView = sendOsmNoteView.findViewById(R.id.account_container); + final LinearLayout signInView = sendOsmNoteView.findViewById(R.id.sign_in_container); final SwitchCompat uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch); final TextView accountName = sendOsmNoteView.findViewById(R.id.user_name); - settings = getMyApplication().getSettings(); + + settings = app.getSettings(); String userNameOAuth = settings.USER_DISPLAY_NAME.get(); String userNameOpenID = settings.USER_NAME.get(); String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID; accountName.setText(userName); - accountBlockView.setVisibility(View.VISIBLE); - uploadAnonymously.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); - uploadAnonymously.setPadding(30, 0, 0, 0); + View signInButton = sendOsmNoteView.findViewById(R.id.sign_in_button); + setupButton(signInButton, R.string.sing_in_with_open_street_map, DialogButtonType.PRIMARY, + R.drawable.ic_action_openstreetmap_logo); + signInButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + } + }); + View loginButton = sendOsmNoteView.findViewById(R.id.login_button); + setupButton(loginButton, R.string.use_login_password, DialogButtonType.SECONDARY, -1); + loginButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OsmLoginDataBottomSheet.showInstance(getFragmentManager(), OSM_LOGIN_DATA, getTargetFragment(), + usedOnMap, null); + } + }); + accountBlockView.setVisibility(!isLogin ? View.GONE : View.VISIBLE); + signInView.setVisibility(isLogin ? View.GONE : View.VISIBLE); + uploadAnonymously.setBackgroundResource(nightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); + final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); + uploadAnonymously.setPadding(paddingSmall, 0, paddingSmall, 0); uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - accountBlockView.setVisibility(isChecked ? View.GONE : View.VISIBLE); - if (isNightMode) { - uploadAnonymously.setBackgroundResource(isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); + accountBlockView.setVisibility(isChecked || !isLogin ? View.GONE : View.VISIBLE); + signInView.setVisibility(isChecked || isLogin ? View.GONE : View.VISIBLE); + if (nightMode) { + uploadAnonymously.setBackgroundResource( + isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); } else { - uploadAnonymously.setBackgroundResource(isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); + uploadAnonymously.setBackgroundResource( + isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); } - uploadAnonymously.setPadding(30, 0, 0, 0); + uploadAnonymously.setPadding(paddingSmall, 0, paddingSmall, 0); } }); - final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + final SimpleBottomSheetItem bottomSheetItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() .setCustomView(sendOsmNoteView) .create(); - items.add(titleItem); + items.add(bottomSheetItem); } - public static SendOsmNoteBottomSheetFragment showInstance(@NonNull OsmPoint[] points, @NonNull PoiUploaderType uploaderType) { - SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putSerializable(OPENSTREETMAP_POINT, points); - bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); - fragment.setArguments(bundle); - return fragment; + private void setupButton(View buttonView, int buttonTextId, DialogButtonType buttonType, int drawableId) { + Drawable icon = null; + if (drawableId != -1) { + icon = getMyApplication().getUIUtilities().getIcon(drawableId, R.color.popup_text_color); + } + TextView buttonText = buttonView.findViewById(R.id.button_text); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(buttonText, icon, null, null, null); + setupDialogButton(nightMode, buttonView, buttonType, buttonTextId); + } + + public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points, + @NonNull PoiUploaderType uploaderType) { + try { + if (!fm.isStateSaved()) { + SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putSerializable(OPENSTREETMAP_POINT, points); + bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); + fragment.setArguments(bundle); + fragment.show(fm, TAG); + } + } catch (RuntimeException e) { + LOG.error("showInstance", e); + } } @Override - protected UiUtilities.DialogButtonType getRightBottomButtonType() { - return (UiUtilities.DialogButtonType.PRIMARY); + protected DialogButtonType getRightBottomButtonType() { + return (DialogButtonType.PRIMARY); } @Override protected void onRightBottomButtonClick() { View view = getView(); - poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); boolean hasPoiGroup = false; assert poi != null; for (OsmPoint p : poi) { @@ -136,4 +204,13 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen protected int getRightBottomButtonTextId() { return R.string.shared_string_upload; } + + private boolean isLogin() { + OsmandApplication app = getMyApplication(); + OsmandSettings settings = app.getSettings(); + OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app); + return client.isValidToken() + || !Algorithms.isEmpty(settings.USER_NAME.get()) + && !Algorithms.isEmpty(settings.USER_PASSWORD.get()); + } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java index fd9655ebb8..7b20db7b66 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java @@ -9,7 +9,9 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.SwitchCompat; +import androidx.fragment.app.FragmentManager; +import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; @@ -21,9 +23,12 @@ import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; + public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { - public static final String TAG = "SendPoiBottomSheetFragment"; + 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"; public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; private OsmPoint[] poi; @@ -45,26 +50,31 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { @Override public void createMenuItems(Bundle savedInstanceState) { - final boolean isNightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_poi_fragment, null); + OsmandApplication app = getMyApplication(); + final boolean isNightMode = app.getDaynightHelper().isNightModeForMapControls(); + final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), + R.layout.send_poi_fragment, null); final SwitchCompat closeChangset = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox); final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name); - settings = getMyApplication().getSettings(); + settings = app.getSettings(); String userNameOAuth = settings.USER_DISPLAY_NAME.get(); String userNameOpenID = settings.USER_NAME.get(); String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID; accountName.setText(userName); closeChangset.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); - closeChangset.setPadding(30, 0, 0, 0); + final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); + closeChangset.setPadding(paddingSmall, 0, paddingSmall, 0); closeChangset.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isNightMode) { - closeChangset.setBackgroundResource(isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); + closeChangset.setBackgroundResource( + isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); } else { - closeChangset.setBackgroundResource(isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); + closeChangset.setBackgroundResource( + isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); } - closeChangset.setPadding(30, 0, 0, 0); + closeChangset.setPadding(paddingSmall, 0, paddingSmall, 0); } }); final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() @@ -73,14 +83,21 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { items.add(titleItem); } - public static SendPoiBottomSheetFragment showInstance(@NonNull OsmPoint[] points, @NonNull SendPoiBottomSheetFragment.PoiUploaderType uploaderType) { - SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putSerializable(OPENSTREETMAP_POINT, points); - bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); - fragment.setArguments(bundle); - return fragment; + public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points, + @NonNull SendPoiBottomSheetFragment.PoiUploaderType uploaderType) { + try { + if (!fm.isStateSaved()) { + SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putSerializable(OPENSTREETMAP_POINT, points); + bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); + fragment.setArguments(bundle); + fragment.show(fm, TAG); + } + } catch (RuntimeException e) { + LOG.error("showInstance", e); } + } @Override protected UiUtilities.DialogButtonType getRightBottomButtonType() {