OpenStreetMap editing, plugin settings
This commit is contained in:
parent
48bcb696c4
commit
5196977a33
10 changed files with 345 additions and 56 deletions
49
OsmAnd/res/layout/bottom_sheet_login.xml
Normal file
49
OsmAnd/res/layout/bottom_sheet_login.xml
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
|
||||||
|
android:paddingLeft="@dimen/content_padding"
|
||||||
|
android:paddingRight="@dimen/content_padding"
|
||||||
|
android:paddingTop="@dimen/measurement_tool_menu_title_padding_top"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingEnd="@dimen/content_padding"
|
||||||
|
android:paddingStart="@dimen/content_padding">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/header"
|
||||||
|
osmand:srcCompat="@drawable/ic_action_openstreetmap_logo_colored"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_gravity="center"/>
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:drawablePadding="@dimen/content_padding_small"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:gravity="center"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:paddingBottom="@dimen/content_padding_small"
|
||||||
|
android:textColor="?android:textColorPrimary"
|
||||||
|
android:textSize="@dimen/default_list_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_medium"
|
||||||
|
tools:text="Some title" />
|
||||||
|
|
||||||
|
<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:textSize="@dimen/default_list_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_regular"
|
||||||
|
tools:text="Some description" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
81
OsmAnd/res/layout/preference_login.xml
Normal file
81
OsmAnd/res/layout/preference_login.xml
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/list_background_color"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/selectable_list_item"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="@dimen/setting_list_item_large_height"
|
||||||
|
tools:background="?android:attr/selectableItemBackground">
|
||||||
|
|
||||||
|
|
||||||
|
<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"
|
||||||
|
tools:src="@drawable/ic_action_user_account"
|
||||||
|
android:layout_marginEnd="@dimen/content_padding"
|
||||||
|
android:layout_marginStart="@dimen/content_padding" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
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">
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@android:id/title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:letterSpacing="@dimen/text_button_letter_spacing"
|
||||||
|
android:textColor="?android:textColorPrimary"
|
||||||
|
android:textSize="@dimen/default_list_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_regular" />
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@android:id/summary"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
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" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@android:id/icon2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="@dimen/standard_icon_size"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginStart="@dimen/content_padding"
|
||||||
|
android:layout_marginLeft="@dimen/content_padding"
|
||||||
|
android:layout_marginTop="@dimen/bottom_sheet_icon_margin"
|
||||||
|
android:layout_marginEnd="@dimen/content_padding"
|
||||||
|
android:layout_marginRight="@dimen/content_padding"
|
||||||
|
android:layout_marginBottom="@dimen/bottom_sheet_icon_margin"
|
||||||
|
osmand:srcCompat="@drawable/ic_action_logout"
|
||||||
|
android:tint="@color/active_buttons_and_links_text_disabled_light"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -11,6 +11,14 @@
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
<string name="login_account">Account</string>
|
||||||
|
<string name="use_login_password">Use login and password</string>
|
||||||
|
<string name="open_street_map_login_mode">You need to login to upload new or modified changes. \n\nYou can log in using the safe OAuth method or use your login and password.</string>
|
||||||
|
<string name="osm_edits_view_descr">You can view all your unloaded edits or OSM bugs in %1$s. Uploaded points don’t show in OsmAnd.</string>
|
||||||
|
<string name="sing_in_with_open_street_map">Sing in with OpenStreetMap</string>
|
||||||
|
<string name="login_open_street_map_org">Login to OpenStreetMap.org</string>
|
||||||
|
<string name="login_open_street_map">Login to OpenStreetMap</string>
|
||||||
|
<string name="plugin_global_prefs_info">These plugin setting are global, and apply to all profiles</string>
|
||||||
<string name="icon_group_travel">Travel</string>
|
<string name="icon_group_travel">Travel</string>
|
||||||
<string name="icon_group_emergency">Emergency</string>
|
<string name="icon_group_emergency">Emergency</string>
|
||||||
<string name="icon_group_sport">Sport</string>
|
<string name="icon_group_sport">Sport</string>
|
||||||
|
@ -481,9 +489,7 @@
|
||||||
<string name="route_recalculation">Route recalculation</string>
|
<string name="route_recalculation">Route recalculation</string>
|
||||||
<string name="accessibility_announce">Announce</string>
|
<string name="accessibility_announce">Announce</string>
|
||||||
<string name="login_and_pass">Username and password</string>
|
<string name="login_and_pass">Username and password</string>
|
||||||
<string name="plugin_global_prefs_info">These settings apply to all profiles.</string>
|
|
||||||
<string name="osm_editing">OSM editing</string>
|
<string name="osm_editing">OSM editing</string>
|
||||||
<string name="osm_edits_view_descr">View your edits or OSM bugs not yet uploaded in %1$s. Uploaded points will not show any more.</string>
|
|
||||||
<string name="app_mode_osm">OSM</string>
|
<string name="app_mode_osm">OSM</string>
|
||||||
<string name="select_nav_icon_descr">Icon shown while navigating or moving.</string>
|
<string name="select_nav_icon_descr">Icon shown while navigating or moving.</string>
|
||||||
<string name="select_map_icon_descr">Icon shown at rest.</string>
|
<string name="select_map_icon_descr">Icon shown at rest.</string>
|
||||||
|
|
|
@ -16,9 +16,13 @@
|
||||||
android:key="osm_login_data"
|
android:key="osm_login_data"
|
||||||
android:layout="@layout/preference_with_descr"
|
android:layout="@layout/preference_with_descr"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/login_and_pass"
|
android:title="@string/login_open_street_map" />
|
||||||
tools:icon="@drawable/ic_action_openstreetmap_logo"
|
|
||||||
tools:summary="@string/open_street_map_login_descr" />
|
<Preference
|
||||||
|
android:key="osm_login_exit"
|
||||||
|
android:layout="@layout/preference_login"
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/login_account" />
|
||||||
|
|
||||||
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
|
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
|
||||||
android:key="offline_osm_editing"
|
android:key="offline_osm_editing"
|
||||||
|
|
|
@ -377,7 +377,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
||||||
return getResources().getDimensionPixelSize(R.dimen.content_padding);
|
return getResources().getDimensionPixelSize(R.dimen.content_padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupThirdButton() {
|
protected void setupThirdButton() {
|
||||||
thirdButton = buttonsContainer.findViewById(R.id.third_button);
|
thirdButton = buttonsContainer.findViewById(R.id.third_button);
|
||||||
int buttonTextId = getThirdBottomButtonTextId();
|
int buttonTextId = getThirdBottomButtonTextId();
|
||||||
if (buttonTextId != DEFAULT_VALUE) {
|
if (buttonTextId != DEFAULT_VALUE) {
|
||||||
|
|
|
@ -0,0 +1,135 @@
|
||||||
|
package net.osmand.plus.measurementtool;
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.graphics.drawable.DrawableCompat;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.UiUtilities.DialogButtonType;
|
||||||
|
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
|
||||||
|
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
||||||
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
|
import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet;
|
||||||
|
|
||||||
|
public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
|
private ApplicationMode appMode;
|
||||||
|
private OsmOAuthAuthorizationAdapter client;
|
||||||
|
private static final String OSM_LOGIN_DATA = "osm_login_data";
|
||||||
|
|
||||||
|
public static final String TAG = ExitBottomSheetDialogFragment.class.getSimpleName();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
items.add(new ShortDescriptionItem.Builder()
|
||||||
|
.setDescription(getString(R.string.open_street_map_login_mode))
|
||||||
|
.setTitle(getString(R.string.login_open_street_map_org))
|
||||||
|
.setLayoutId(R.layout.bottom_sheet_login)
|
||||||
|
.create());
|
||||||
|
|
||||||
|
items.add(new DividerSpaceItem(getContext(),
|
||||||
|
getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_margin)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getDismissButtonTextId() {
|
||||||
|
return R.string.shared_string_cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getRightBottomButtonTextId() {
|
||||||
|
return R.string.use_login_password;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setupThirdButton() {
|
||||||
|
super.setupThirdButton();
|
||||||
|
TextView textViewIcon = thirdButton.findViewById(R.id.button_text);
|
||||||
|
Drawable drawable = getResources().getDrawable(R.drawable.ic_action_openstreetmap_logo);
|
||||||
|
drawable = DrawableCompat.wrap(drawable);
|
||||||
|
DrawableCompat.setTint(drawable, getResources().getColor(R.color.popup_text_color));
|
||||||
|
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
|
||||||
|
textViewIcon,
|
||||||
|
drawable,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null);
|
||||||
|
textViewIcon.setCompoundDrawablePadding(AndroidUtils.dpToPx(getActivity(), 8f));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getThirdBottomButtonTextId() {
|
||||||
|
return R.string.sing_in_with_open_street_map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFirstDividerHeight() {
|
||||||
|
return getResources().getDimensionPixelSize(R.dimen.card_content_padding_large);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSecondDividerHeight() {
|
||||||
|
return getResources().getDimensionPixelSize(R.dimen.content_padding_small);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationMode getSelectedAppMode() {
|
||||||
|
return appMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRightBottomButtonClick() {
|
||||||
|
ApplicationMode appMode = getSelectedAppMode();
|
||||||
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
|
if (fragmentManager != null) {
|
||||||
|
OsmLoginDataBottomSheet.showInstance(fragmentManager, OSM_LOGIN_DATA, getTargetFragment(), false, appMode);
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsmOAuthAuthorizationAdapter getClient() {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onThirdBottomButtonClick() {
|
||||||
|
View view = getView();
|
||||||
|
client = new OsmOAuthAuthorizationAdapter(getMyApplication());
|
||||||
|
if (view != null) {
|
||||||
|
client.startOAuth((ViewGroup) view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected DialogButtonType getThirdBottomButtonType() {
|
||||||
|
return (DialogButtonType.PRIMARY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected DialogButtonType getRightBottomButtonType() {
|
||||||
|
return (DialogButtonType.SECONDARY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment) {
|
||||||
|
if (!fragmentManager.isStateSaved()) {
|
||||||
|
LoginBottomSheetFragment fragment = new LoginBottomSheetFragment();
|
||||||
|
fragment.setTargetFragment(targetFragment, 0);
|
||||||
|
fragment.show(fragmentManager, TAG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.osmand.plus.osmedit;
|
package net.osmand.plus.osmedit;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
@ -13,7 +12,6 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
@ -21,13 +19,14 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
import net.osmand.plus.helpers.FontCache;
|
import net.osmand.plus.helpers.FontCache;
|
||||||
|
import net.osmand.plus.measurementtool.LoginBottomSheetFragment;
|
||||||
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
||||||
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
|
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
|
||||||
import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet;
|
|
||||||
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
|
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
|
||||||
import net.osmand.plus.settings.fragments.OnPreferenceChanged;
|
import net.osmand.plus.settings.fragments.OnPreferenceChanged;
|
||||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||||
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
|
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
@ -41,7 +40,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
||||||
private static final String OSM_EDITING_INFO = "osm_editing_info";
|
private static final String OSM_EDITING_INFO = "osm_editing_info";
|
||||||
private static final String OPEN_OSM_EDITS = "open_osm_edits";
|
private static final String OPEN_OSM_EDITS = "open_osm_edits";
|
||||||
private static final String OSM_LOGIN_DATA = "osm_login_data";
|
private static final String OSM_LOGIN_DATA = "osm_login_data";
|
||||||
private static final String OSM_OAUTH_SUCCESS = "osm_oauth_success";
|
private static final String OSM_LOGIN_EXIT = "osm_login_exit";
|
||||||
private static final String OSM_OAUTH_CLEAR = "osm_oauth_clear";
|
private static final String OSM_OAUTH_CLEAR = "osm_oauth_clear";
|
||||||
private static final String OSM_OAUTH_LOGIN = "osm_oauth_login";
|
private static final String OSM_OAUTH_LOGIN = "osm_oauth_login";
|
||||||
|
|
||||||
|
@ -59,10 +58,11 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
||||||
osmEditingInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
|
osmEditingInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
|
||||||
|
|
||||||
setupNameAndPasswordPref();
|
setupNameAndPasswordPref();
|
||||||
|
setupExitPref();
|
||||||
|
|
||||||
setupOfflineEditingPref();
|
setupOfflineEditingPref();
|
||||||
setupOsmEditsDescrPref();
|
setupOsmEditsDescrPref();
|
||||||
setupOsmEditsPref();
|
setupOsmEditsPref();
|
||||||
setupOAuthPrefs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -85,8 +85,24 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
||||||
|
|
||||||
private void setupNameAndPasswordPref() {
|
private void setupNameAndPasswordPref() {
|
||||||
Preference nameAndPasswordPref = findPreference(OSM_LOGIN_DATA);
|
Preference nameAndPasswordPref = findPreference(OSM_LOGIN_DATA);
|
||||||
|
nameAndPasswordPref.setTitle(R.string.login_open_street_map);
|
||||||
|
nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account));
|
||||||
|
|
||||||
|
boolean validToken = client.isValidToken();
|
||||||
|
boolean loginExists = !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get());
|
||||||
|
boolean visible = !validToken && !loginExists;
|
||||||
|
nameAndPasswordPref.setVisible(visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupExitPref() {
|
||||||
|
Preference nameAndPasswordPref = findPreference(OSM_LOGIN_EXIT);
|
||||||
nameAndPasswordPref.setSummary(settings.USER_NAME.get());
|
nameAndPasswordPref.setSummary(settings.USER_NAME.get());
|
||||||
nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_openstreetmap_logo));
|
nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account));
|
||||||
|
|
||||||
|
boolean validToken = client.isValidToken();
|
||||||
|
boolean loginExists = !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get());
|
||||||
|
boolean visible = validToken || loginExists;
|
||||||
|
nameAndPasswordPref.setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupOfflineEditingPref() {
|
private void setupOfflineEditingPref() {
|
||||||
|
@ -122,33 +138,6 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
||||||
createProfile.setIcon(getActiveIcon(R.drawable.ic_action_folder));
|
createProfile.setIcon(getActiveIcon(R.drawable.ic_action_folder));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupOAuthPrefs() {
|
|
||||||
Context ctx = getContext();
|
|
||||||
if (ctx != null) {
|
|
||||||
PreferenceScreen screen = getPreferenceScreen();
|
|
||||||
if (client.isValidToken()) {
|
|
||||||
Preference prefOAuth = new Preference(ctx);
|
|
||||||
prefOAuth.setTitle(R.string.osm_authorization_success);
|
|
||||||
prefOAuth.setSummary(R.string.osm_authorization_success);
|
|
||||||
prefOAuth.setKey(OSM_OAUTH_SUCCESS);
|
|
||||||
|
|
||||||
Preference prefClearToken = new Preference(ctx);
|
|
||||||
prefClearToken.setTitle(R.string.shared_string_logoff);
|
|
||||||
prefClearToken.setSummary(R.string.clear_osm_token);
|
|
||||||
prefClearToken.setKey(OSM_OAUTH_CLEAR);
|
|
||||||
|
|
||||||
screen.addPreference(prefOAuth);
|
|
||||||
screen.addPreference(prefClearToken);
|
|
||||||
} else {
|
|
||||||
Preference prefOAuth = new Preference(ctx);
|
|
||||||
prefOAuth.setTitle(R.string.perform_oauth_authorization);
|
|
||||||
prefOAuth.setSummary(R.string.perform_oauth_authorization_description);
|
|
||||||
prefOAuth.setKey(OSM_OAUTH_LOGIN);
|
|
||||||
screen.addPreference(prefOAuth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
String prefId = preference.getKey();
|
String prefId = preference.getKey();
|
||||||
|
@ -165,9 +154,23 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
||||||
} else if (OSM_LOGIN_DATA.equals(prefId)) {
|
} else if (OSM_LOGIN_DATA.equals(prefId)) {
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
if (fragmentManager != null) {
|
if (fragmentManager != null) {
|
||||||
OsmLoginDataBottomSheet.showInstance(fragmentManager, OSM_LOGIN_DATA, this, false, getSelectedAppMode());
|
LoginBottomSheetFragment.showInstance(fragmentManager, this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else if (OSM_LOGIN_EXIT.equals(prefId)) {
|
||||||
|
if (client.isValidToken()) {
|
||||||
|
settings.USER_ACCESS_TOKEN.set("");
|
||||||
|
settings.USER_ACCESS_TOKEN_SECRET.set("");
|
||||||
|
|
||||||
|
client.resetToken();
|
||||||
|
client = new OsmOAuthAuthorizationAdapter(app);
|
||||||
|
} else {
|
||||||
|
settings.USER_NAME.set("");
|
||||||
|
settings.USER_PASSWORD.set("");
|
||||||
|
}
|
||||||
|
app.showShortToastMessage(R.string.osm_edit_logout_success);
|
||||||
|
updateAllSettings();
|
||||||
|
return true;
|
||||||
} else if (OSM_OAUTH_CLEAR.equals(prefId)) {
|
} else if (OSM_OAUTH_CLEAR.equals(prefId)) {
|
||||||
settings.USER_ACCESS_TOKEN.set("");
|
settings.USER_ACCESS_TOKEN.set("");
|
||||||
settings.USER_ACCESS_TOKEN_SECRET.set("");
|
settings.USER_ACCESS_TOKEN_SECRET.set("");
|
||||||
|
@ -191,15 +194,19 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPreferenceChanged(String prefId) {
|
public void onPreferenceChanged(String prefId) {
|
||||||
if (OSM_LOGIN_DATA.equals(prefId)) {
|
updateAllSettings();
|
||||||
Preference nameAndPasswordPref = findPreference(OSM_LOGIN_DATA);
|
|
||||||
nameAndPasswordPref.setSummary(settings.USER_NAME.get());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void authorize(String oauthVerifier) {
|
public void authorize(String oauthVerifier) {
|
||||||
if (client != null) {
|
FragmentManager fragmentManager = getMapActivity().getSupportFragmentManager();
|
||||||
client.authorize(oauthVerifier);
|
LoginBottomSheetFragment fragment = (LoginBottomSheetFragment) fragmentManager.findFragmentByTag(LoginBottomSheetFragment.TAG);
|
||||||
|
if (fragment != null) {
|
||||||
|
OsmOAuthAuthorizationAdapter authorizationAdapter = fragment.getClient();
|
||||||
|
if (authorizationAdapter != null) {
|
||||||
|
authorizationAdapter.authorize(oauthVerifier);
|
||||||
|
}
|
||||||
|
fragment.dismiss();
|
||||||
|
client = new OsmOAuthAuthorizationAdapter(app);
|
||||||
}
|
}
|
||||||
updateAllSettings();
|
updateAllSettings();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,16 @@ import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.osmedit.OsmBugsUtil.OsmBugResult;
|
import net.osmand.plus.osmedit.OsmBugsUtil.OsmBugResult;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
public class ValidateOsmLoginDetailsTask extends AsyncTask<Void, Void, OsmBugResult> {
|
public class ValidateOsmLoginDetailsTask extends AsyncTask<Void, Void, OsmBugResult> {
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
private final WeakReference<OsmEditingFragment> fragmentRef;
|
||||||
|
|
||||||
public ValidateOsmLoginDetailsTask(OsmandApplication app) {
|
public ValidateOsmLoginDetailsTask(OsmandApplication app, OsmEditingFragment targetfragment) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
this.fragmentRef = new WeakReference<>(targetfragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,9 +30,15 @@ public class ValidateOsmLoginDetailsTask extends AsyncTask<Void, Void, OsmBugRes
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(OsmBugResult osmBugResult) {
|
protected void onPostExecute(OsmBugResult osmBugResult) {
|
||||||
if (osmBugResult.warning != null) {
|
if (osmBugResult.warning != null) {
|
||||||
|
app.getSettings().USER_NAME.set("");
|
||||||
|
app.getSettings().USER_PASSWORD.set("");
|
||||||
app.showToastMessage(osmBugResult.warning);
|
app.showToastMessage(osmBugResult.warning);
|
||||||
} else {
|
} else {
|
||||||
app.showToastMessage(R.string.osm_authorization_success);
|
app.showToastMessage(R.string.osm_authorization_success);
|
||||||
}
|
}
|
||||||
|
OsmEditingFragment targetfragment = fragmentRef.get();
|
||||||
|
if (targetfragment != null) {
|
||||||
|
targetfragment.updateAllSettings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,6 +12,7 @@ import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import net.osmand.plus.osmedit.OsmEditingFragment;
|
||||||
import net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask;
|
import net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
@ -21,6 +22,8 @@ import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||||
import net.osmand.plus.settings.fragments.OnPreferenceChanged;
|
import net.osmand.plus.settings.fragments.OnPreferenceChanged;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
|
public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
|
||||||
|
|
||||||
public static final String TAG = EditTextPreferenceBottomSheet.class.getSimpleName();
|
public static final String TAG = EditTextPreferenceBottomSheet.class.getSimpleName();
|
||||||
|
@ -84,19 +87,13 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
|
||||||
|
|
||||||
app.getSettings().USER_NAME.set(userNameEditText.getText().toString());
|
app.getSettings().USER_NAME.set(userNameEditText.getText().toString());
|
||||||
app.getSettings().USER_PASSWORD.set(passwordEditText.getText().toString());
|
app.getSettings().USER_PASSWORD.set(passwordEditText.getText().toString());
|
||||||
new ValidateOsmLoginDetailsTask(app).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
new ValidateOsmLoginDetailsTask(app, (OsmEditingFragment) getTargetFragment()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
|
||||||
Fragment target = getTargetFragment();
|
|
||||||
Preference preference = getPreference();
|
|
||||||
if (target instanceof OnPreferenceChanged && preference != null) {
|
|
||||||
((OnPreferenceChanged) target).onPreferenceChanged(preference.getKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target,
|
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target,
|
||||||
boolean usedOnMap, @Nullable ApplicationMode appMode) {
|
boolean usedOnMap, @Nullable ApplicationMode appMode) {
|
||||||
try {
|
try {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(PREFERENCE_ID, key);
|
args.putString(PREFERENCE_ID, key);
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment {
|
||||||
View root = inflater.inflate(R.layout.fragment_import_complete, container, false);
|
View root = inflater.inflate(R.layout.fragment_import_complete, container, false);
|
||||||
TextView description = root.findViewById(R.id.description);
|
TextView description = root.findViewById(R.id.description);
|
||||||
TextView btnClose = root.findViewById(R.id.button_close);
|
TextView btnClose = root.findViewById(R.id.button_close);
|
||||||
final LinearLayout buttonContainer = root.findViewById(R.id.button_container);
|
final ViewGroup buttonContainer = root.findViewById(R.id.button_container);
|
||||||
recyclerView = root.findViewById(R.id.list);
|
recyclerView = root.findViewById(R.id.list);
|
||||||
description.setText(UiUtilities.createSpannableString(
|
description.setText(UiUtilities.createSpannableString(
|
||||||
String.format(getString(R.string.import_complete_description), fileName),
|
String.format(getString(R.string.import_complete_description), fileName),
|
||||||
|
|
Loading…
Reference in a new issue