Refactoring Upload OSM note fragment

This commit is contained in:
Dima-1 2020-11-11 23:55:20 +02:00
parent a33b703cf7
commit f4edc8dc83
10 changed files with 271 additions and 141 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp" android:color="#F0F0F0" />
<stroke android:width="1dp" android:color="#CCCCCC" />
<corners android:radius="6dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View file

@ -2,7 +2,6 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
@ -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">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
android:text = "@string/osm_notes"
android:letterSpacing="@dimen/text_button_letter_spacing"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/message_label"
android:id="@+id/note_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/bottom_sheet_content_margin"
android:hint="@string/osn_bug_name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/message_field"
android:id="@+id/note_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.switchmaterial.SwitchMaterial
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/upload_anonymously_switch"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="@dimen/context_menu_buttons_bottom_height"
android:layout_marginBottom="@dimen/bottom_sheet_content_margin"
android:layout_marginBottom="@dimen/content_padding_small"
android:paddingBottom="@dimen/content_padding_small"
android:paddingTop="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:text="@string/upload_anonymously"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:letterSpacing="@dimen/text_button_letter_spacing"
osmand:typeface="@string/font_roboto_regular"/>
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
<LinearLayout
android:id="@+id/account_block"
android:id="@+id/account_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/text_margin_small"
android:minHeight="@dimen/context_menu_buttons_bottom_height"
tools:background="?android:attr/selectableItemBackground">
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@android:id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/bottom_sheet_icon_margin"
osmand:srcCompat="@drawable/ic_action_user_account"
android:tint="@color/active_buttons_and_links_text_disabled_light"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginStart="@dimen/content_padding" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
<LinearLayout
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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">
android:layout_marginTop="@dimen/content_padding_half"
android:minHeight="@dimen/context_menu_buttons_bottom_height">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/account_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:singleLine="true"
android:text="@string/login_account"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@android:id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
osmand:srcCompat="@drawable/ic_action_user_account"
android:tint="@color/active_buttons_and_links_text_disabled_light"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginStart="@dimen/content_padding" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/user_name"
android:layout_width="match_parent"
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:letterSpacing="@dimen/description_letter_spacing"
android:maxLines="4"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" />
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">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/account_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:singleLine="true"
android:text="@string/login_account"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:letterSpacing="@dimen/description_letter_spacing"
android:maxLines="4"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/sign_in_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/text_margin_small"
android:minHeight="@dimen/context_menu_buttons_bottom_height"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier"
android:textColor="?android:textColorPrimary"
android:paddingTop="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding"
android:paddingStart="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding_small"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular"
android:text="@string/osm_login_descr" />
<include
android:id="@+id/sign_in_button"
layout="@layout/bottom_sheet_dialog_button"
android:layout_marginBottom="@dimen/content_padding_half"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_height" />
<include
android:id="@+id/login_button"
layout="@layout/bottom_sheet_dialog_button"
android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginBottom="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_height" />
</LinearLayout>
</LinearLayout>

View file

@ -41,18 +41,19 @@
android:imeOptions="actionDone" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.switchmaterial.SwitchMaterial
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/close_change_set_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding"
android:minHeight="@dimen/context_menu_buttons_bottom_height"
android:text="@string/close_changset"
android:paddingLeft="50dp"
android:paddingLeft="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular"
android:letterSpacing="@dimen/text_button_letter_spacing"/>
android:letterSpacing="@dimen/text_button_letter_spacing" />
</LinearLayout>
@ -62,7 +63,7 @@
android:background="?attr/dashboard_divider" />
<LinearLayout
android:id="@+id/account_block"
android:id="@+id/account_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/context_menu_buttons_bottom_height"

View file

@ -11,6 +11,7 @@
Thx - Hardy
-->
<string name="osm_login_descr">You can log in using the safe OAuth method or use your login and password.</string>
<string name="osm_edit_comment_note">Comment OSM Note</string>
<string name="osm_edit_close_note">Close OSM Note</string>
<string name="close_changset">Closed changset</string>

View file

@ -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;

View file

@ -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);
}
}
}

View file

@ -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;

View file

@ -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);
}

View file

@ -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());
}
}

View file

@ -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() {