This commit is contained in:
androiddevkkotlin 2020-11-08 00:50:23 +02:00
parent 7ba46570a0
commit a007e8efc5
4 changed files with 44 additions and 10 deletions

View file

@ -92,6 +92,10 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment {
} }
} }
private boolean isValidToken() {
return authorizationAdapter.isValidToken();
}
@Override @Override
protected DialogButtonType getRightBottomButtonType() { protected DialogButtonType getRightBottomButtonType() {
return (DialogButtonType.SECONDARY); return (DialogButtonType.SECONDARY);

View file

@ -43,6 +43,8 @@ import net.osmand.osm.edit.Node;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.measurementtool.LoginBottomSheetFragment; 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.osmedit.oauth.OsmOAuthAuthorizationAdapter;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -626,17 +628,25 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
private void uploadItems(final OsmPoint[] items) { private void uploadItems(final OsmPoint[] items) {
FragmentActivity activity = getActivity(); FragmentActivity activity = getActivity();
if (activity != null) { if (activity != null) {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
boolean isPoi = getOsmEditsByGroup(Group.POI) instanceof OpenstreetmapPoint;
OsmOAuthAuthorizationAdapter authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); OsmOAuthAuthorizationAdapter authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
if (authorizationAdapter.isValidToken() if (authorizationAdapter.isValidToken()
|| !Algorithms.isEmpty(settings.USER_NAME.get()) || !Algorithms.isEmpty(settings.USER_NAME.get())
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get())) { && !Algorithms.isEmpty(settings.USER_PASSWORD.get())) {
SendPoiDialogFragment.createInstance(items, PoiUploaderType.FRAGMENT) if (isPoi) {
.show(getChildFragmentManager(), SendPoiDialogFragment.TAG); 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);}
} else { } else {
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this); LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this);
} }

View file

@ -1,7 +1,7 @@
package net.osmand.plus.osmedit.dialogs; package net.osmand.plus.osmedit.dialogs;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.View; import android.view.View;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
@ -20,6 +20,7 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.util.Algorithms;
public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment { public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment {
@ -39,14 +40,21 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
private boolean isLoginOAuth() {
return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get());
}
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
final boolean isNightMode = !getMyApplication().getSettings().isLightContent(); final boolean isNightMode = !getMyApplication().getSettings().isLightContent();
final View sendOsmNoteView = View.inflate(getContext(), R.layout.send_osm_note_fragment, null); 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); final LinearLayout accountBlockView = sendOsmNoteView.findViewById(R.id.account_block);
final SwitchCompat uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch); final SwitchCompat uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch);
final TextView accountName = sendOsmNoteView.findViewById(R.id.user_name); final TextView accountName = sendOsmNoteView.findViewById(R.id.user_name);
String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get(); settings = getMyApplication().getSettings();
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
String userNameOpenID = settings.USER_NAME.get();
String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID;
accountName.setText(userName); accountName.setText(userName);
accountBlockView.setVisibility(View.VISIBLE); accountBlockView.setVisibility(View.VISIBLE);
uploadAnonymously.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); uploadAnonymously.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg);

View file

@ -1,6 +1,7 @@
package net.osmand.plus.osmedit.dialogs; package net.osmand.plus.osmedit.dialogs;
import android.os.Bundle; import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.View; import android.view.View;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
@ -17,6 +18,8 @@ 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.OpenstreetmapPoint; import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.util.Algorithms;
public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
@ -25,6 +28,8 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; public static final String POI_UPLOADER_TYPE = "poi_uploader_type";
private OsmPoint[] poi; private OsmPoint[] poi;
protected OsmandSettings settings;
public enum PoiUploaderType { public enum PoiUploaderType {
SIMPLE, SIMPLE,
FRAGMENT FRAGMENT
@ -34,13 +39,20 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
private boolean isLoginOAuth() {
return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get());
}
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
final boolean isNightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); final boolean isNightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final View sendOsmPoiView = View.inflate(getContext(), R.layout.send_poi_fragment, null); 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 SwitchCompat closeChangset = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox);
final TextView accountName = (TextView) sendOsmPoiView.findViewById(R.id.user_name); final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name);
String userName = getMyApplication().getSettings().USER_DISPLAY_NAME.get(); settings = getMyApplication().getSettings();
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
String userNameOpenID = settings.USER_NAME.get();
String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID;
accountName.setText(userName); accountName.setText(userName);
closeChangset.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); closeChangset.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg);
closeChangset.setPadding(30, 0, 0, 0); closeChangset.setPadding(30, 0, 0, 0);
@ -80,8 +92,8 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
View view = getView(); View view = getView();
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
final SwitchCompat closeChangeSetCheckBox = final SwitchCompat closeChangeSetCheckBox =
(SwitchCompat) view.findViewById(R.id.close_change_set_checkbox); view.findViewById(R.id.close_change_set_checkbox);
final EditText messageEditText = (EditText) view.findViewById(R.id.message_field); final EditText messageEditText = view.findViewById(R.id.message_field);
final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name())); final SendPoiDialogFragment.PoiUploaderType poiUploaderType = SendPoiDialogFragment.PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, SendPoiDialogFragment.PoiUploaderType.SIMPLE.name()));
final SendPoiDialogFragment.ProgressDialogPoiUploader progressDialogPoiUploader; final SendPoiDialogFragment.ProgressDialogPoiUploader progressDialogPoiUploader;
if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) { if (poiUploaderType == SendPoiDialogFragment.PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) {