From 5196977a33e2de08b20be1ae373ed1821185009f Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Sun, 1 Nov 2020 18:38:18 +0200 Subject: [PATCH 01/16] OpenStreetMap editing, plugin settings --- OsmAnd/res/layout/bottom_sheet_login.xml | 49 +++++++ OsmAnd/res/layout/preference_login.xml | 81 +++++++++++ OsmAnd/res/values/strings.xml | 10 +- OsmAnd/res/xml/osm_editing.xml | 10 +- .../base/MenuBottomSheetDialogFragment.java | 2 +- .../LoginBottomSheetFragment.java | 135 ++++++++++++++++++ .../plus/osmedit/OsmEditingFragment.java | 87 +++++------ .../osmedit/ValidateOsmLoginDetailsTask.java | 12 +- .../bottomsheets/OsmLoginDataBottomSheet.java | 13 +- .../fragments/ImportCompleteFragment.java | 2 +- 10 files changed, 345 insertions(+), 56 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_login.xml create mode 100644 OsmAnd/res/layout/preference_login.xml create mode 100644 OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java diff --git a/OsmAnd/res/layout/bottom_sheet_login.xml b/OsmAnd/res/layout/bottom_sheet_login.xml new file mode 100644 index 0000000000..e8bf2a3ee5 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_login.xml @@ -0,0 +1,49 @@ + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/preference_login.xml b/OsmAnd/res/layout/preference_login.xml new file mode 100644 index 0000000000..01c566a969 --- /dev/null +++ b/OsmAnd/res/layout/preference_login.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 7861393b31..790280186c 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,14 @@ Thx - Hardy --> + Account + Use login and password + 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. + You can view all your unloaded edits or OSM bugs in %1$s. Uploaded points don’t show in OsmAnd. + Sing in with OpenStreetMap + Login to OpenStreetMap.org + Login to OpenStreetMap + These plugin setting are global, and apply to all profiles Travel Emergency Sport @@ -481,9 +489,7 @@ Route recalculation Announce Username and password - These settings apply to all profiles. OSM editing - View your edits or OSM bugs not yet uploaded in %1$s. Uploaded points will not show any more. OSM Icon shown while navigating or moving. Icon shown at rest. diff --git a/OsmAnd/res/xml/osm_editing.xml b/OsmAnd/res/xml/osm_editing.xml index 990a15349c..53f20cb7a0 100644 --- a/OsmAnd/res/xml/osm_editing.xml +++ b/OsmAnd/res/xml/osm_editing.xml @@ -16,9 +16,13 @@ android:key="osm_login_data" android:layout="@layout/preference_with_descr" android:persistent="false" - android:title="@string/login_and_pass" - tools:icon="@drawable/ic_action_openstreetmap_logo" - tools:summary="@string/open_street_map_login_descr" /> + android:title="@string/login_open_street_map" /> + + { private OsmandApplication app; + private final WeakReference fragmentRef; - public ValidateOsmLoginDetailsTask(OsmandApplication app) { + public ValidateOsmLoginDetailsTask(OsmandApplication app, OsmEditingFragment targetfragment) { this.app = app; + this.fragmentRef = new WeakReference<>(targetfragment); } @Override @@ -26,9 +30,15 @@ public class ValidateOsmLoginDetailsTask extends AsyncTask Date: Mon, 2 Nov 2020 21:32:27 +0200 Subject: [PATCH 02/16] Minor fixes, openstreet form --- OsmAnd/res/layout/bottom_sheet_login.xml | 6 +- OsmAnd/res/layout/osm_login_data.xml | 106 ++++++++---------- OsmAnd/res/layout/preference_login.xml | 2 +- OsmAnd/res/values/strings.xml | 3 +- OsmAnd/res/xml/osm_editing.xml | 2 +- .../plus/osmedit/OsmEditingFragment.java | 6 +- .../bottomsheets/OsmLoginDataBottomSheet.java | 18 ++- 7 files changed, 70 insertions(+), 73 deletions(-) diff --git a/OsmAnd/res/layout/bottom_sheet_login.xml b/OsmAnd/res/layout/bottom_sheet_login.xml index e8bf2a3ee5..b879800da9 100644 --- a/OsmAnd/res/layout/bottom_sheet_login.xml +++ b/OsmAnd/res/layout/bottom_sheet_login.xml @@ -16,8 +16,8 @@ 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_width="@dimen/bottom_sheet_list_item_height" + android:layout_height="@dimen/bottom_sheet_list_item_height" android:layout_gravity="center"/> + xmlns:osmand="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="wrap_content" + 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" + android:paddingBottom="@dimen/bottom_sheet_content_margin"> - + - + - + - + - + - + - + - + - \ No newline at end of file diff --git a/OsmAnd/res/layout/preference_login.xml b/OsmAnd/res/layout/preference_login.xml index 01c566a969..8754f1c76c 100644 --- a/OsmAnd/res/layout/preference_login.xml +++ b/OsmAnd/res/layout/preference_login.xml @@ -63,7 +63,7 @@ + Login + Password Account Use login and password 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. @@ -3201,7 +3203,6 @@ Global app settings Your OSM username Needed for openstreetmap.org submissions. - Your OSM password Background mode OsmAnd runs in the background with the screen off. There is not enough free space to download %1$s MB (free: %2$s). diff --git a/OsmAnd/res/xml/osm_editing.xml b/OsmAnd/res/xml/osm_editing.xml index 53f20cb7a0..469e841c36 100644 --- a/OsmAnd/res/xml/osm_editing.xml +++ b/OsmAnd/res/xml/osm_editing.xml @@ -19,7 +19,7 @@ android:title="@string/login_open_street_map" /> diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java index 3bf24170eb..37101874e8 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_EDITING_INFO = "osm_editing_info"; 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_EXIT = "osm_login_exit"; + private static final String OSM_LOGOUT = "osm_logout"; private static final String OSM_OAUTH_CLEAR = "osm_oauth_clear"; private static final String OSM_OAUTH_LOGIN = "osm_oauth_login"; @@ -95,7 +95,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer } private void setupExitPref() { - Preference nameAndPasswordPref = findPreference(OSM_LOGIN_EXIT); + Preference nameAndPasswordPref = findPreference(OSM_LOGOUT); nameAndPasswordPref.setSummary(settings.USER_NAME.get()); nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account)); @@ -157,7 +157,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer LoginBottomSheetFragment.showInstance(fragmentManager, this); return true; } - } else if (OSM_LOGIN_EXIT.equals(prefId)) { + } else if (OSM_LOGOUT.equals(prefId)) { if (client.isValidToken()) { settings.USER_ACCESS_TOKEN.set(""); settings.USER_ACCESS_TOKEN_SECRET.set(""); diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java index 4bc6262b53..8971fe8bcd 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java @@ -1,6 +1,7 @@ package net.osmand.plus.settings.bottomsheets; import android.content.Context; +import android.content.res.ColorStateList; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; @@ -10,7 +11,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; -import androidx.preference.Preference; + +import com.google.android.material.textfield.TextInputLayout; import net.osmand.plus.osmedit.OsmEditingFragment; import net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask; @@ -20,9 +22,6 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; -import net.osmand.plus.settings.fragments.OnPreferenceChanged; - -import java.lang.ref.WeakReference; public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet { @@ -33,6 +32,9 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet { private EditText userNameEditText; private EditText passwordEditText; + private TextInputLayout passwordBox; + private TextInputLayout loginBox; + @Override public void createMenuItems(Bundle savedInstanceState) { @@ -46,6 +48,8 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet { userNameEditText = view.findViewById(R.id.name_edit_text); passwordEditText = view.findViewById(R.id.password_edit_text); + passwordBox = view.findViewById(R.id.password_text_box); + loginBox = view.findViewById(R.id.name_text_box); String name = app.getSettings().USER_NAME.get(); String password = app.getSettings().USER_PASSWORD.get(); @@ -57,6 +61,10 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet { userNameEditText.setText(name); passwordEditText.setText(password); + passwordBox.setEndIconMode(TextInputLayout.END_ICON_PASSWORD_TOGGLE); + loginBox.setEndIconMode(TextInputLayout.END_ICON_CLEAR_TEXT); + passwordBox.setStartIconDrawable(R.drawable.ic_action_lock); + loginBox.setStartIconDrawable(R.drawable.ic_action_user_account); BaseBottomSheetItem titleItem = new SimpleBottomSheetItem.Builder() .setCustomView(view) @@ -78,7 +86,7 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet { @Override protected int getRightBottomButtonTextId() { - return R.string.shared_string_apply; + return R.string.user_login; } @Override From e14989f46420c521db1d3ea6c759d5a27ecb6e40 Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Tue, 3 Nov 2020 17:27:19 +0200 Subject: [PATCH 03/16] OAuth, refactor, fix icon --- .../oauth/OsmOAuthAuthorizationClient.java | 39 +++++++++++++ .../res/layout/bottom_sheet_dialog_button.xml | 7 ++- OsmAnd/res/values/strings.xml | 2 +- .../osmand/plus/activities/MapActivity.java | 5 +- .../net/osmand/plus/helpers/IntentHelper.java | 3 +- .../LoginBottomSheetFragment.java | 20 ++++++- .../plus/osmedit/OsmEditingFragment.java | 58 +++++++------------ .../osmedit/ValidateOsmLoginDetailsTask.java | 22 ++++--- .../oauth/OsmOAuthAuthorizationAdapter.java | 24 ++++++++ .../plus/settings/backend/OsmandSettings.java | 1 + .../bottomsheets/OsmLoginDataBottomSheet.java | 6 +- 11 files changed, 128 insertions(+), 59 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/oauth/OsmOAuthAuthorizationClient.java b/OsmAnd-java/src/main/java/net/osmand/osm/oauth/OsmOAuthAuthorizationClient.java index f1c718465e..f973e134a2 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/oauth/OsmOAuthAuthorizationClient.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/oauth/OsmOAuthAuthorizationClient.java @@ -9,8 +9,12 @@ import com.github.scribejava.core.model.*; import com.github.scribejava.core.oauth.OAuth10aService; import net.osmand.PlatformUtil; import org.apache.commons.logging.Log; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.ExecutionException; /** @@ -89,6 +93,39 @@ public class OsmOAuthAuthorizationClient { service.execute(req, callback); } + public String authorizeOsmUserDetails() throws InterruptedException, ExecutionException, IOException, XmlPullParserException { + OAuth1RequestToken requestToken = startOAuth(); + if (requestToken == null) { + throw new IllegalArgumentException("Illegal request token: "); + } + // save for reuse of request ( they usually don't match and should'nt be an issue) + String url = "https://api.openstreetmap.org/api/0.6/user/details"; + OAuthRequest req = new OAuthRequest(Verb.GET, url); + service.signRequest(accessToken, req); + req.addHeader("Content-Type", "application/xml"); + Response response = service.execute(req); + String user = ""; + String home = ""; + String lang = ""; + XmlPullParser parser = PlatformUtil.newXMLPullParser(); + parser.setInput(response.getStream(), "UTF-8"); + List languages = new ArrayList<>(); + int tok; + while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { + if (tok == XmlPullParser.START_TAG) { + String name = parser.getName(); + if ("user".equals(name)) { + user = parser.getAttributeValue("", "display_name"); + } else if ("home".equals(name)) { + } else if ("lang".equals(name)) { + languages.add(parser.nextText()); + } + } + } + return user; + } + + public Response performRequest(String url, String method, String body) throws InterruptedException, ExecutionException, IOException { service.getApi().getSignatureType(); @@ -103,6 +140,8 @@ public class OsmOAuthAuthorizationClient { return service.execute(req); } + + public OAuth1RequestToken startOAuth() { try { requestToken = service.getRequestToken(); diff --git a/OsmAnd/res/layout/bottom_sheet_dialog_button.xml b/OsmAnd/res/layout/bottom_sheet_dialog_button.xml index ee757eba8f..697075cba5 100644 --- a/OsmAnd/res/layout/bottom_sheet_dialog_button.xml +++ b/OsmAnd/res/layout/bottom_sheet_dialog_button.xml @@ -7,7 +7,7 @@ android:layout_height="@dimen/dialog_button_height" android:layout_weight="1"> - - + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index ab75bf8fc1..61b5aade88 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -17,7 +17,7 @@ Use login and password 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. You can view all your unloaded edits or OSM bugs in %1$s. Uploaded points don’t show in OsmAnd. - Sing in with OpenStreetMap + Sign in with OpenStreetMap Login to OpenStreetMap.org Login to OpenStreetMap These plugin setting are global, and apply to all profiles diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 8cb6e832c5..6d8c5ad4d5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -115,6 +115,7 @@ import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu; import net.osmand.plus.mapmarkers.PlanRouteFragment; import net.osmand.plus.measurementtool.GpxApproximationFragment; import net.osmand.plus.measurementtool.GpxData; +import net.osmand.plus.measurementtool.LoginBottomSheetFragment; import net.osmand.plus.measurementtool.MeasurementEditingContext; import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.measurementtool.SnapTrackWarningFragment; @@ -2217,8 +2218,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return getFragment(GpxApproximationFragment.TAG); } - public OsmEditingFragment getOsmEditingFragment() { - return getFragment(SettingsScreenType.OPEN_STREET_MAP_EDITING.fragmentName); + public LoginBottomSheetFragment getLoginBottomSheetFragment() { + return getFragment(LoginBottomSheetFragment.TAG); } public SnapTrackWarningFragment getSnapTrackWarningBottomSheet() { diff --git a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java index 19748b100c..3efb1f6aac 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java @@ -19,6 +19,7 @@ import net.osmand.plus.activities.PluginsFragment; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; import net.osmand.plus.mapsource.EditMapSourceDialogFragment; +import net.osmand.plus.measurementtool.LoginBottomSheetFragment; import net.osmand.plus.osmedit.OsmEditingFragment; import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.settings.backend.ApplicationMode; @@ -293,7 +294,7 @@ public class IntentHelper { if (intent != null && intent.getData() != null) { Uri uri = intent.getData(); if (uri.toString().startsWith("osmand-oauth")) { - OsmEditingFragment fragment = mapActivity.getOsmEditingFragment(); + LoginBottomSheetFragment fragment = mapActivity.getLoginBottomSheetFragment(); if (fragment != null) { String oauthVerifier = uri.getQueryParameter("oauth_verifier"); fragment.authorize(oauthVerifier); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java index a34de00fdf..bcdc7aa357 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java @@ -29,11 +29,10 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { private OsmOAuthAuthorizationAdapter client; private static final String OSM_LOGIN_DATA = "osm_login_data"; - public static final String TAG = ExitBottomSheetDialogFragment.class.getSimpleName(); + public static final String TAG = LoginBottomSheetFragment.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)) @@ -50,7 +49,6 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { return R.string.shared_string_cancel; } - @Override protected int getRightBottomButtonTextId() { return R.string.use_login_password; @@ -131,5 +129,21 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { fragment.show(fragmentManager, TAG); } } + + public interface LoginOsmAutorizationListener { + void informAutorizationPrefsUpdate(); + } + + public void authorize(String oauthVerifier) { + if (client != null) { + client.authorize(oauthVerifier); + } + Fragment target = getTargetFragment(); + if (target instanceof LoginOsmAutorizationListener) { + ((LoginOsmAutorizationListener) target).informAutorizationPrefsUpdate(); + } + dismiss(); + } } + diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java index 37101874e8..75f6c66d9c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java @@ -7,7 +7,6 @@ import android.os.Bundle; import android.text.SpannableString; import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import android.widget.TextView; import androidx.fragment.app.FragmentManager; @@ -33,7 +32,7 @@ import org.apache.commons.logging.Log; import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; import static net.osmand.plus.osmedit.OsmEditingPlugin.OSM_EDIT_TAB; -public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged { +public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginDetailsTask.ValidateOsmLoginListener, LoginBottomSheetFragment.LoginOsmAutorizationListener { private static final Log log = PlatformUtil.getLog(OsmEditingFragment.class); @@ -41,11 +40,14 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer 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_LOGOUT = "osm_logout"; - private static final String OSM_OAUTH_CLEAR = "osm_oauth_clear"; - private static final String OSM_OAUTH_LOGIN = "osm_oauth_login"; private OsmOAuthAuthorizationAdapter client; + @Override + public void loginValidationFinished(String error) { + updateAllSettings(); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -57,8 +59,8 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer Preference osmEditingInfo = findPreference(OSM_EDITING_INFO); osmEditingInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); - setupNameAndPasswordPref(); - setupExitPref(); + setupLoginPref(); + setupLogoutPref(); setupOfflineEditingPref(); setupOsmEditsDescrPref(); @@ -83,7 +85,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer } } - private void setupNameAndPasswordPref() { + private void setupLoginPref() { Preference nameAndPasswordPref = findPreference(OSM_LOGIN_DATA); nameAndPasswordPref.setTitle(R.string.login_open_street_map); nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account)); @@ -94,12 +96,17 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer nameAndPasswordPref.setVisible(visible); } - private void setupExitPref() { + private void setupLogoutPref() { Preference nameAndPasswordPref = findPreference(OSM_LOGOUT); - nameAndPasswordPref.setSummary(settings.USER_NAME.get()); + boolean validToken = client.isValidToken(); + if (validToken){ + nameAndPasswordPref.setSummary(settings.USER_DISPLAY_NAME.get()); + + } else { + nameAndPasswordPref.setSummary(settings.USER_NAME.get()); + } 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); @@ -171,23 +178,6 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer app.showShortToastMessage(R.string.osm_edit_logout_success); updateAllSettings(); return true; - } else if (OSM_OAUTH_CLEAR.equals(prefId)) { - settings.USER_ACCESS_TOKEN.set(""); - settings.USER_ACCESS_TOKEN_SECRET.set(""); - - client.resetToken(); - client = new OsmOAuthAuthorizationAdapter(app); - - app.showShortToastMessage(R.string.osm_edit_logout_success); - updateAllSettings(); - return true; - } else if (OSM_OAUTH_LOGIN.equals(prefId)) { - View view = getView(); - if (view != null) { - ViewGroup appBarLayout = view.findViewById(R.id.appbar); - client.startOAuth(appBarLayout); - } - return true; } return super.onPreferenceClick(preference); } @@ -197,17 +187,9 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer updateAllSettings(); } - public void authorize(String oauthVerifier) { - FragmentManager fragmentManager = getMapActivity().getSupportFragmentManager(); - 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); - } + @Override + public void informAutorizationPrefsUpdate() { + client = new OsmOAuthAuthorizationAdapter(app); updateAllSettings(); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/osmedit/ValidateOsmLoginDetailsTask.java b/OsmAnd/src/net/osmand/plus/osmedit/ValidateOsmLoginDetailsTask.java index dc6803c5bd..3fc06f1b8b 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/ValidateOsmLoginDetailsTask.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/ValidateOsmLoginDetailsTask.java @@ -2,6 +2,7 @@ package net.osmand.plus.osmedit; import android.os.AsyncTask; +import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -12,13 +13,21 @@ import java.lang.ref.WeakReference; public class ValidateOsmLoginDetailsTask extends AsyncTask { private OsmandApplication app; - private final WeakReference fragmentRef; + private ValidateOsmLoginListener validateOsmLoginListener; + + public interface ValidateOsmLoginListener { + + void loginValidationFinished(String error); - public ValidateOsmLoginDetailsTask(OsmandApplication app, OsmEditingFragment targetfragment) { - this.app = app; - this.fragmentRef = new WeakReference<>(targetfragment); } + public ValidateOsmLoginDetailsTask(OsmandApplication app, ValidateOsmLoginListener validateTargetOsmLoginDetailsTask ) { + this.app = app; + this.validateOsmLoginListener = validateTargetOsmLoginDetailsTask; + } + + + @Override protected OsmBugResult doInBackground(Void... params) { OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); @@ -36,9 +45,8 @@ public class ValidateOsmLoginDetailsTask extends AsyncTask USER_NAME = new StringPreference(this, "user_name", "").makeGlobal().makeShared(); + public final OsmandPreference USER_DISPLAY_NAME = new StringPreference(this, "user_display_name", "").makeGlobal().makeShared(); public static final String BILLING_USER_DONATION_WORLD_PARAMETER = ""; public static final String BILLING_USER_DONATION_NONE_PARAMETER = "none"; diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java index 8971fe8bcd..cca766bf9c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/OsmLoginDataBottomSheet.java @@ -32,8 +32,6 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet { private EditText userNameEditText; private EditText passwordEditText; - private TextInputLayout passwordBox; - private TextInputLayout loginBox; @Override @@ -48,8 +46,8 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet { userNameEditText = view.findViewById(R.id.name_edit_text); passwordEditText = view.findViewById(R.id.password_edit_text); - passwordBox = view.findViewById(R.id.password_text_box); - loginBox = view.findViewById(R.id.name_text_box); + TextInputLayout passwordBox = view.findViewById(R.id.password_text_box); + TextInputLayout loginBox = view.findViewById(R.id.name_text_box); String name = app.getSettings().USER_NAME.get(); String password = app.getSettings().USER_PASSWORD.get(); From 26ce1f9d7b40885d38c177b92a534a652d7305fb Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Thu, 5 Nov 2020 00:15:54 +0200 Subject: [PATCH 04/16] Send POI, Send GPX --- .../measurementtool/LoginBottomSheetFragment.java | 8 ++++---- .../osmand/plus/osmedit/EditPOIMenuController.java | 13 +++++++------ .../net/osmand/plus/osmedit/OsmEditingFragment.java | 4 ++-- .../net/osmand/plus/osmedit/OsmEditingPlugin.java | 5 ++++- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java index bcdc7aa357..a4f621592c 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java @@ -130,8 +130,8 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { } } - public interface LoginOsmAutorizationListener { - void informAutorizationPrefsUpdate(); + public interface LoginOsmAuthorizationListener { + void informAuthorizationPrefsUpdate(); } public void authorize(String oauthVerifier) { @@ -139,8 +139,8 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { client.authorize(oauthVerifier); } Fragment target = getTargetFragment(); - if (target instanceof LoginOsmAutorizationListener) { - ((LoginOsmAutorizationListener) target).informAutorizationPrefsUpdate(); + if (target instanceof LoginOsmAuthorizationListener) { + ((LoginOsmAuthorizationListener) target).informAuthorizationPrefsUpdate(); } dismiss(); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java index 8134e5a3be..e0aeb331b3 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java @@ -4,16 +4,19 @@ import android.content.DialogInterface; import android.graphics.drawable.Drawable; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; + import net.osmand.data.PointDescription; import net.osmand.osm.PoiType; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuController; +import net.osmand.plus.measurementtool.LoginBottomSheetFragment; import net.osmand.plus.osmedit.OsmPoint.Action; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.render.RenderingIcons; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.util.Algorithms; import java.util.Map; @@ -39,16 +42,14 @@ public class EditPOIMenuController extends MenuController { @Override public void buttonPressed() { MapActivity activity = getMapActivity(); + OsmandSettings settings = activity.getMyApplication().getSettings(); if (plugin != null && activity != null) { OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(activity.getMyApplication()); - if (client.isValidToken()){ + if (client.isValidToken() || !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get())){ new SendPoiDialogFragment.SimpleProgressDialogPoiUploader(activity). showProgressDialog(new OsmPoint[] { getOsmPoint() }, false, false); - } - else { - SendPoiDialogFragment sendPoiDialogFragment = - SendPoiDialogFragment.createInstance(new OsmPoint[]{getOsmPoint()}, SendPoiDialogFragment.PoiUploaderType.SIMPLE); - sendPoiDialogFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG); + } else { + LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), activity.getLoginBottomSheetFragment()); } } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java index 75f6c66d9c..4eb706eeaf 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java @@ -32,7 +32,7 @@ import org.apache.commons.logging.Log; import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; import static net.osmand.plus.osmedit.OsmEditingPlugin.OSM_EDIT_TAB; -public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginDetailsTask.ValidateOsmLoginListener, LoginBottomSheetFragment.LoginOsmAutorizationListener { +public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginDetailsTask.ValidateOsmLoginListener, LoginBottomSheetFragment.LoginOsmAuthorizationListener { private static final Log log = PlatformUtil.getLog(OsmEditingFragment.class); @@ -188,7 +188,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer } @Override - public void informAutorizationPrefsUpdate() { + public void informAuthorizationPrefsUpdate() { client = new OsmOAuthAuthorizationAdapter(app); updateAllSettings(); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 285e323867..fbb5c3e46f 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -21,6 +21,8 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; @@ -41,6 +43,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TabActivity; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.dashboard.tools.DashFragmentData; +import net.osmand.plus.measurementtool.LoginBottomSheetFragment; import net.osmand.plus.myplaces.AvailableGPXFragment; import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo; import net.osmand.plus.myplaces.FavoritesActivity; @@ -464,7 +467,7 @@ public class OsmEditingPlugin extends OsmandPlugin { String pwd = settings.USER_PASSWORD.get(); String authToken = settings.USER_ACCESS_TOKEN.get(); if ((Algorithms.isEmpty(name) || Algorithms.isEmpty(pwd)) && Algorithms.isEmpty(authToken)) { - Toast.makeText(la, R.string.validate_gpx_upload_name_pwd, Toast.LENGTH_LONG).show(); + LoginBottomSheetFragment.showInstance(f.getFragmentManager(), f.getTargetFragment()); return false; } AlertDialog.Builder bldr = new AlertDialog.Builder(la); From 47e8aa403b09952305a800c655db94a3bcdc678b Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Fri, 6 Nov 2020 10:16:03 +0200 Subject: [PATCH 05/16] minor fix --- OsmAnd/res/layout/bottom_sheet_login.xml | 84 ++++++++--------- OsmAnd/res/layout/osm_login_data.xml | 92 +++++++++---------- .../LoginBottomSheetFragment.java | 5 +- 3 files changed, 90 insertions(+), 91 deletions(-) diff --git a/OsmAnd/res/layout/bottom_sheet_login.xml b/OsmAnd/res/layout/bottom_sheet_login.xml index b879800da9..bcccec19bc 100644 --- a/OsmAnd/res/layout/bottom_sheet_login.xml +++ b/OsmAnd/res/layout/bottom_sheet_login.xml @@ -1,49 +1,49 @@ + 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"> - + - + - + \ No newline at end of file diff --git a/OsmAnd/res/layout/osm_login_data.xml b/OsmAnd/res/layout/osm_login_data.xml index c7a4617c97..88609e311d 100644 --- a/OsmAnd/res/layout/osm_login_data.xml +++ b/OsmAnd/res/layout/osm_login_data.xml @@ -1,58 +1,58 @@ + xmlns:osmand="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="wrap_content" + 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" + android:paddingBottom="@dimen/bottom_sheet_content_margin"> - + - + - + - + - + - + - + diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java index a4f621592c..8fad09f8dd 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java @@ -17,6 +17,7 @@ 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.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; @@ -33,9 +34,7 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { @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)) + items.add(new SimpleBottomSheetItem.Builder() .setLayoutId(R.layout.bottom_sheet_login) .create()); From 585534102aee1da48f6a078cb7fd5d217a5e2e7c Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Fri, 6 Nov 2020 11:27:36 +0200 Subject: [PATCH 06/16] Final refactor --- .../oauth/OsmOAuthAuthorizationClient.java | 39 ---- .../res/layout/bottom_sheet_dialog_button.xml | 1 + OsmAnd/res/layout/bottom_sheet_login.xml | 3 +- OsmAnd/res/layout/osm_login_data.xml | 3 +- OsmAnd/res/layout/preference_login.xml | 137 ++++++------ OsmAnd/res/values/strings.xml | 13 +- OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 9 +- .../osmand/plus/activities/MapActivity.java | 1 - .../net/osmand/plus/helpers/IntentHelper.java | 1 - .../LoginBottomSheetFragment.java | 209 +++++++++--------- .../plus/osmedit/EditPOIMenuController.java | 19 +- .../plus/osmedit/OsmEditingFragment.java | 76 ++++--- .../osmand/plus/osmedit/OsmEditingPlugin.java | 32 ++- .../osmedit/ValidateOsmLoginDetailsTask.java | 33 ++- .../oauth/OsmOAuthAuthorizationAdapter.java | 62 +++--- .../bottomsheets/OsmLoginDataBottomSheet.java | 27 ++- 16 files changed, 324 insertions(+), 341 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/oauth/OsmOAuthAuthorizationClient.java b/OsmAnd-java/src/main/java/net/osmand/osm/oauth/OsmOAuthAuthorizationClient.java index f973e134a2..f1c718465e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/oauth/OsmOAuthAuthorizationClient.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/oauth/OsmOAuthAuthorizationClient.java @@ -9,12 +9,8 @@ import com.github.scribejava.core.model.*; import com.github.scribejava.core.oauth.OAuth10aService; import net.osmand.PlatformUtil; import org.apache.commons.logging.Log; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.ExecutionException; /** @@ -93,39 +89,6 @@ public class OsmOAuthAuthorizationClient { service.execute(req, callback); } - public String authorizeOsmUserDetails() throws InterruptedException, ExecutionException, IOException, XmlPullParserException { - OAuth1RequestToken requestToken = startOAuth(); - if (requestToken == null) { - throw new IllegalArgumentException("Illegal request token: "); - } - // save for reuse of request ( they usually don't match and should'nt be an issue) - String url = "https://api.openstreetmap.org/api/0.6/user/details"; - OAuthRequest req = new OAuthRequest(Verb.GET, url); - service.signRequest(accessToken, req); - req.addHeader("Content-Type", "application/xml"); - Response response = service.execute(req); - String user = ""; - String home = ""; - String lang = ""; - XmlPullParser parser = PlatformUtil.newXMLPullParser(); - parser.setInput(response.getStream(), "UTF-8"); - List languages = new ArrayList<>(); - int tok; - while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { - if (tok == XmlPullParser.START_TAG) { - String name = parser.getName(); - if ("user".equals(name)) { - user = parser.getAttributeValue("", "display_name"); - } else if ("home".equals(name)) { - } else if ("lang".equals(name)) { - languages.add(parser.nextText()); - } - } - } - return user; - } - - public Response performRequest(String url, String method, String body) throws InterruptedException, ExecutionException, IOException { service.getApi().getSignatureType(); @@ -140,8 +103,6 @@ public class OsmOAuthAuthorizationClient { return service.execute(req); } - - public OAuth1RequestToken startOAuth() { try { requestToken = service.getRequestToken(); diff --git a/OsmAnd/res/layout/bottom_sheet_dialog_button.xml b/OsmAnd/res/layout/bottom_sheet_dialog_button.xml index 697075cba5..6ce7d34fc3 100644 --- a/OsmAnd/res/layout/bottom_sheet_dialog_button.xml +++ b/OsmAnd/res/layout/bottom_sheet_dialog_button.xml @@ -25,6 +25,7 @@ android:textSize="@dimen/default_desc_text_size" osmand:typeface="@string/font_roboto_medium" android:duplicateParentState="true" + android:drawablePadding="@dimen/content_padding_half" tools:text="Button" android:paddingStart="@dimen/content_padding_small" android:paddingEnd="@dimen/content_padding_small" /> diff --git a/OsmAnd/res/layout/bottom_sheet_login.xml b/OsmAnd/res/layout/bottom_sheet_login.xml index bcccec19bc..85915a72cc 100644 --- a/OsmAnd/res/layout/bottom_sheet_login.xml +++ b/OsmAnd/res/layout/bottom_sheet_login.xml @@ -10,7 +10,8 @@ android:paddingTop="@dimen/measurement_tool_menu_title_padding_top" android:orientation="vertical" android:paddingEnd="@dimen/content_padding" - android:paddingStart="@dimen/content_padding"> + android:paddingStart="@dimen/content_padding" + android:paddingBottom="@dimen/content_padding_half"> - - + \ No newline at end of file diff --git a/OsmAnd/res/layout/preference_login.xml b/OsmAnd/res/layout/preference_login.xml index 8754f1c76c..14ecba71af 100644 --- a/OsmAnd/res/layout/preference_login.xml +++ b/OsmAnd/res/layout/preference_login.xml @@ -1,81 +1,80 @@ + 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"> - + + - + - + - + - + - + - - - + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 91eec18222..fc7a48c5bc 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,16 @@ Thx - Hardy --> + Login + Password + Account + Use login and password + 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. + You can view all your unloaded edits or OSM bugs in %1$s. Uploaded points don’t show in OsmAnd. + Sing in with OpenStreetMap + Login to OpenStreetMap.org + Login to OpenStreetMap + These plugin setting are global, and apply to all profiles You must add at least two points. Travel Emergency @@ -482,9 +492,7 @@ Route recalculation Announce Username and password - These settings apply to all profiles. OSM editing - View your edits or OSM bugs not yet uploaded in %1$s. Uploaded points will not show any more. OSM Icon shown while navigating or moving. Icon shown at rest. @@ -3196,7 +3204,6 @@ Global app settings Your OSM username Needed for openstreetmap.org submissions. - Your OSM password Background mode OsmAnd runs in the background with the screen off. There is not enough free space to download %1$s MB (free: %2$s). diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 6d353713a0..54f45b7425 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -541,10 +541,10 @@ public abstract class OsmandPlugin { protected void addMyPlacesTab(FavoritesActivity favoritesActivity, List mTabs, Intent intent) { } - protected void contextMenuFragment(Activity activity, Fragment fragment, Object info, ContextMenuAdapter adapter) { + protected void contextMenuFragment(FragmentActivity activity, Fragment fragment, Object info, ContextMenuAdapter adapter) { } - protected void optionsMenuFragment(Activity activity, Fragment fragment, ContextMenuAdapter optionsMenuAdapter) { + protected void optionsMenuFragment(FragmentActivity activity, Fragment fragment, ContextMenuAdapter optionsMenuAdapter) { } protected boolean searchFinished(QuickSearchDialogFragment searchFragment, SearchPhrase phrase, boolean isResultEmpty) { @@ -815,14 +815,13 @@ public abstract class OsmandPlugin { } } - public static void onContextMenuActivity(Activity activity, Fragment fragment, Object info, ContextMenuAdapter adapter) { + public static void onContextMenuActivity(FragmentActivity activity, Fragment fragment, Object info, ContextMenuAdapter adapter) { for (OsmandPlugin plugin : getEnabledPlugins()) { plugin.contextMenuFragment(activity, fragment, info, adapter); } } - - public static void onOptionsMenuActivity(Activity activity, Fragment fragment, ContextMenuAdapter optionsMenuAdapter) { + public static void onOptionsMenuActivity(FragmentActivity activity, Fragment fragment, ContextMenuAdapter optionsMenuAdapter) { for (OsmandPlugin plugin : getEnabledPlugins()) { plugin.optionsMenuFragment(activity, fragment, optionsMenuAdapter); } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 6d8c5ad4d5..288f697470 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -119,7 +119,6 @@ import net.osmand.plus.measurementtool.LoginBottomSheetFragment; import net.osmand.plus.measurementtool.MeasurementEditingContext; import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.measurementtool.SnapTrackWarningFragment; -import net.osmand.plus.osmedit.OsmEditingFragment; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.routepreparationmenu.ChooseRouteFragment; diff --git a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java index 3efb1f6aac..9e5aaa5254 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java @@ -20,7 +20,6 @@ import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; import net.osmand.plus.mapsource.EditMapSourceDialogFragment; import net.osmand.plus.measurementtool.LoginBottomSheetFragment; -import net.osmand.plus.osmedit.OsmEditingFragment; import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java index 8fad09f8dd..e61813cd93 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java @@ -4,145 +4,144 @@ 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.PlatformUtil; +import net.osmand.plus.OsmandApplication; 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.simpleitems.DividerSpaceItem; -import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem; +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; +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + 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 = LoginBottomSheetFragment.class.getSimpleName(); + private static final Log log = PlatformUtil.getLog(LoginBottomSheetFragment.class); + private static final String OSM_LOGIN_DATA = "osm_login_data"; - public static final String TAG = LoginBottomSheetFragment.class.getSimpleName(); + private OsmOAuthAuthorizationAdapter authorizationAdapter; @Override public void createMenuItems(Bundle savedInstanceState) { - items.add(new SimpleBottomSheetItem.Builder() - .setLayoutId(R.layout.bottom_sheet_login) - .create()); - - items.add(new DividerSpaceItem(getContext(), - getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_margin))); - + OsmandApplication app = requiredMyApplication(); + authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); + items.add(new SimpleBottomSheetItem.Builder().setLayoutId(R.layout.bottom_sheet_login).create()); } - @Override - protected int getDismissButtonTextId() { - return R.string.shared_string_cancel; - } + @Override + protected int getDismissButtonTextId() { + return R.string.shared_string_cancel; + } - @Override - protected int getRightBottomButtonTextId() { - return R.string.use_login_password; - } + @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 void setupThirdButton() { + super.setupThirdButton(); + OsmandApplication app = getMyApplication(); + if (app != null) { + Drawable icon = app.getUIUtilities().getIcon(R.drawable.ic_action_openstreetmap_logo, R.color.popup_text_color); + TextView buttonText = thirdButton.findViewById(R.id.button_text); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(buttonText, icon, null, null, null); + } + } - @Override - protected int getThirdBottomButtonTextId() { - return R.string.sing_in_with_open_street_map; - } + @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 getFirstDividerHeight() { + return getResources().getDimensionPixelSize(R.dimen.card_content_padding_large); + } - @Override - public int getSecondDividerHeight() { - return getResources().getDimensionPixelSize(R.dimen.content_padding_small); - } + @Override + public int getSecondDividerHeight() { + return getResources().getDimensionPixelSize(R.dimen.content_padding_small); + } - public ApplicationMode getSelectedAppMode() { - return appMode; - } + @Override + protected void onRightBottomButtonClick() { + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + OsmLoginDataBottomSheet.showInstance(fragmentManager, OSM_LOGIN_DATA, getTargetFragment(), usedOnMap, null); + } + dismiss(); + } - @Override - protected void onRightBottomButtonClick() { - ApplicationMode appMode = getSelectedAppMode(); - FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager != null) { - OsmLoginDataBottomSheet.showInstance(fragmentManager, OSM_LOGIN_DATA, getTargetFragment(), false, appMode); - } - dismiss(); - } + @Override + protected void onThirdBottomButtonClick() { + View view = getView(); + if (view != null) { + authorizationAdapter.startOAuth((ViewGroup) view); + } + } - public OsmOAuthAuthorizationAdapter getClient() { - return client; - } + @Override + protected DialogButtonType getRightBottomButtonType() { + return (DialogButtonType.SECONDARY); + } - @Override - protected void onThirdBottomButtonClick() { - View view = getView(); - client = new OsmOAuthAuthorizationAdapter(getMyApplication()); - if (view != null) { - client.startOAuth((ViewGroup) view); - } - } + 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); + } + } - @Override - protected DialogButtonType getThirdBottomButtonType() { - return (DialogButtonType.PRIMARY); - } + public void authorize(String oauthVerifier) { + if (authorizationAdapter != null) { + authorizationAdapter.authorize(oauthVerifier); + updateUserName(); + } + Fragment target = getTargetFragment(); + if (target instanceof OsmAuthorizationListener) { + ((OsmAuthorizationListener) target).authorizationCompleted(); + } + dismiss(); + } - @Override - protected DialogButtonType getRightBottomButtonType() { - return (DialogButtonType.SECONDARY); - } + private void updateUserName() { + OsmandApplication app = getMyApplication(); + if (app != null) { + String userName = ""; + try { + userName = authorizationAdapter.getUserName(); + } catch (InterruptedException e) { + log.error(e); + } catch (ExecutionException e) { + log.error(e); + } catch (IOException e) { + log.error(e); + } catch (XmlPullParserException e) { + log.error(e); + } + app.getSettings().USER_DISPLAY_NAME.set(userName); + } + } - 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); - } - } - - public interface LoginOsmAuthorizationListener { - void informAuthorizationPrefsUpdate(); - } - - public void authorize(String oauthVerifier) { - if (client != null) { - client.authorize(oauthVerifier); - } - Fragment target = getTargetFragment(); - if (target instanceof LoginOsmAuthorizationListener) { - ((LoginOsmAuthorizationListener) target).informAuthorizationPrefsUpdate(); - } - dismiss(); - } + public interface OsmAuthorizationListener { + void authorizationCompleted(); + } } - - diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java index e0aeb331b3..60c2ed0b2b 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java @@ -2,18 +2,20 @@ package net.osmand.plus.osmedit; import android.content.DialogInterface; import android.graphics.drawable.Drawable; + import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import net.osmand.data.PointDescription; import net.osmand.osm.PoiType; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.measurementtool.LoginBottomSheetFragment; import net.osmand.plus.osmedit.OsmPoint.Action; -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; @@ -42,12 +44,15 @@ public class EditPOIMenuController extends MenuController { @Override public void buttonPressed() { MapActivity activity = getMapActivity(); - OsmandSettings settings = activity.getMyApplication().getSettings(); if (plugin != null && activity != null) { - OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(activity.getMyApplication()); - if (client.isValidToken() || !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get())){ - new SendPoiDialogFragment.SimpleProgressDialogPoiUploader(activity). - showProgressDialog(new OsmPoint[] { getOsmPoint() }, false, false); + OsmandApplication app = activity.getMyApplication(); + OsmandSettings settings = app.getSettings(); + OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app); + if (client.isValidToken() + || !Algorithms.isEmpty(settings.USER_NAME.get()) + && !Algorithms.isEmpty(settings.USER_PASSWORD.get())) { + SimpleProgressDialogPoiUploader poiDialogUploader = new SimpleProgressDialogPoiUploader(activity); + poiDialogUploader.showProgressDialog(new OsmPoint[] {getOsmPoint()}, false, false); } else { LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), activity.getLoginBottomSheetFragment()); } @@ -206,7 +211,7 @@ public class EditPOIMenuController extends MenuController { return null; } } - + @Override public int getAdditionalInfoIconRes() { if (osmPoint.getAction() == Action.DELETE) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java index 4eb706eeaf..3435ad1561 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java @@ -19,6 +19,8 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.measurementtool.LoginBottomSheetFragment; +import net.osmand.plus.measurementtool.LoginBottomSheetFragment.OsmAuthorizationListener; +import net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask.ValidateOsmLoginListener; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.plus.settings.fragments.BaseSettingsFragment; @@ -32,26 +34,21 @@ import org.apache.commons.logging.Log; import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; import static net.osmand.plus.osmedit.OsmEditingPlugin.OSM_EDIT_TAB; -public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginDetailsTask.ValidateOsmLoginListener, LoginBottomSheetFragment.LoginOsmAuthorizationListener { +public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginListener, OsmAuthorizationListener { private static final Log log = PlatformUtil.getLog(OsmEditingFragment.class); - private static final String OSM_EDITING_INFO = "osm_editing_info"; + 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"; - private static final String OSM_LOGOUT = "osm_logout"; + private static final String OSM_EDITING_INFO = "osm_editing_info"; - private OsmOAuthAuthorizationAdapter client; - - @Override - public void loginValidationFinished(String error) { - updateAllSettings(); - } + private OsmOAuthAuthorizationAdapter authorizationAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - client = new OsmOAuthAuthorizationAdapter(app); + authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); } @Override @@ -85,31 +82,40 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer } } + @Override + public void loginValidationFinished(String warning) { + updateAllSettings(); + } + private void setupLoginPref() { 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); + if (!isValidToken() && !isLoginExists()) { + nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account)); + nameAndPasswordPref.setVisible(true); + } else { + nameAndPasswordPref.setVisible(false); + } } private void setupLogoutPref() { + boolean validToken = isValidToken(); Preference nameAndPasswordPref = findPreference(OSM_LOGOUT); - boolean validToken = client.isValidToken(); - if (validToken){ - nameAndPasswordPref.setSummary(settings.USER_DISPLAY_NAME.get()); - + if (validToken || isLoginExists()) { + String userName = validToken ? settings.USER_DISPLAY_NAME.get() : settings.USER_NAME.get(); + nameAndPasswordPref.setVisible(true); + nameAndPasswordPref.setSummary(userName); + nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account)); } else { - nameAndPasswordPref.setSummary(settings.USER_NAME.get()); + nameAndPasswordPref.setVisible(false); } - nameAndPasswordPref.setIcon(getContentIcon(R.drawable.ic_action_user_account)); + } - boolean loginExists = !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get()); - boolean visible = validToken || loginExists; - nameAndPasswordPref.setVisible(visible); + private boolean isValidToken() { + return authorizationAdapter.isValidToken(); + } + + private boolean isLoginExists() { + return !Algorithms.isEmpty(settings.USER_NAME.get()) && !Algorithms.isEmpty(settings.USER_PASSWORD.get()); } private void setupOfflineEditingPref() { @@ -165,15 +171,15 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer return true; } } else if (OSM_LOGOUT.equals(prefId)) { - if (client.isValidToken()) { - settings.USER_ACCESS_TOKEN.set(""); - settings.USER_ACCESS_TOKEN_SECRET.set(""); + if (isValidToken()) { + settings.USER_ACCESS_TOKEN.resetToDefault(); + settings.USER_ACCESS_TOKEN_SECRET.resetToDefault(); - client.resetToken(); - client = new OsmOAuthAuthorizationAdapter(app); + authorizationAdapter.resetToken(); + authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); } else { - settings.USER_NAME.set(""); - settings.USER_PASSWORD.set(""); + settings.USER_NAME.resetToDefault(); + settings.USER_PASSWORD.resetToDefault(); } app.showShortToastMessage(R.string.osm_edit_logout_success); updateAllSettings(); @@ -188,8 +194,8 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer } @Override - public void informAuthorizationPrefsUpdate() { - client = new OsmOAuthAuthorizationAdapter(app); + public void authorizationCompleted() { + authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); updateAllSettings(); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index fbb5c3e46f..71da65bf20 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -1,6 +1,5 @@ package net.osmand.plus.osmedit; -import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; @@ -16,13 +15,11 @@ import android.view.View; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.Spinner; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; -import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; @@ -398,15 +395,15 @@ public class OsmEditingPlugin extends OsmandPlugin { } @Override - public void contextMenuFragment(final Activity la, final Fragment fragment, final Object info, ContextMenuAdapter adapter) { + public void contextMenuFragment(final FragmentActivity activity, final Fragment fragment, final Object info, ContextMenuAdapter adapter) { if (fragment instanceof AvailableGPXFragment) { - adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_upload_gpx, la) + adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_upload_gpx, activity) .setIcon(R.drawable.ic_action_export) .setListener(new ContextMenuAdapter.ItemClickListener() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) { - sendGPXFiles(la, (AvailableGPXFragment) fragment, (GpxInfo) info); + sendGPXFiles(activity, (AvailableGPXFragment) fragment, (GpxInfo) info); return true; } }).createItem()); @@ -414,7 +411,7 @@ public class OsmEditingPlugin extends OsmandPlugin { } @Override - public void optionsMenuFragment(final Activity activity, final Fragment fragment, ContextMenuAdapter optionsMenuAdapter) { + public void optionsMenuFragment(final FragmentActivity activity, final Fragment fragment, ContextMenuAdapter optionsMenuAdapter) { if (fragment instanceof AvailableGPXFragment) { final AvailableGPXFragment f = ((AvailableGPXFragment) fragment); optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_upload_gpx, activity) @@ -440,7 +437,6 @@ public class OsmEditingPlugin extends OsmandPlugin { } } - public enum UploadVisibility implements IEnumWithResource { Public(R.string.gpxup_public), Identifiable(R.string.gpxup_identifiable), @@ -462,16 +458,16 @@ public class OsmEditingPlugin extends OsmandPlugin { } } - public boolean sendGPXFiles(final Activity la, AvailableGPXFragment f, final GpxInfo... info) { + public boolean sendGPXFiles(final FragmentActivity activity, AvailableGPXFragment fragment, final GpxInfo... info) { String name = settings.USER_NAME.get(); String pwd = settings.USER_PASSWORD.get(); String authToken = settings.USER_ACCESS_TOKEN.get(); if ((Algorithms.isEmpty(name) || Algorithms.isEmpty(pwd)) && Algorithms.isEmpty(authToken)) { - LoginBottomSheetFragment.showInstance(f.getFragmentManager(), f.getTargetFragment()); + LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment.getTargetFragment()); return false; } - AlertDialog.Builder bldr = new AlertDialog.Builder(la); - LayoutInflater inflater = (LayoutInflater) la.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View view = inflater.inflate(R.layout.send_gpx_osm, null); final EditText descr = (EditText) view.findViewById(R.id.memory_size); if (info.length > 0 && info[0].getFileName() != null) { @@ -480,23 +476,23 @@ public class OsmEditingPlugin extends OsmandPlugin { } final EditText tags = (EditText) view.findViewById(R.id.TagsText); final Spinner visibility = ((Spinner) view.findViewById(R.id.Visibility)); - EnumAdapter adapter = new EnumAdapter<>(la, android.R.layout.simple_spinner_item, UploadVisibility.values()); + EnumAdapter adapter = new EnumAdapter<>(activity, android.R.layout.simple_spinner_item, UploadVisibility.values()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); visibility.setAdapter(adapter); visibility.setSelection(0); - bldr.setView(view); - bldr.setNegativeButton(R.string.shared_string_no, null); - bldr.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { + builder.setView(view); + builder.setNegativeButton(R.string.shared_string_no, null); + builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - new UploadGPXFilesTask(la, descr.getText().toString(), tags.getText().toString(), + new UploadGPXFilesTask(activity, descr.getText().toString(), tags.getText().toString(), (UploadVisibility) visibility.getItemAtPosition(visibility.getSelectedItemPosition()) ).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, info); } }); - bldr.show(); + builder.show(); return true; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/ValidateOsmLoginDetailsTask.java b/OsmAnd/src/net/osmand/plus/osmedit/ValidateOsmLoginDetailsTask.java index 3fc06f1b8b..5dabe123b4 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/ValidateOsmLoginDetailsTask.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/ValidateOsmLoginDetailsTask.java @@ -2,32 +2,23 @@ package net.osmand.plus.osmedit; import android.os.AsyncTask; -import net.osmand.plus.GpxSelectionHelper; +import androidx.annotation.NonNull; + import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.osmedit.OsmBugsUtil.OsmBugResult; -import java.lang.ref.WeakReference; - public class ValidateOsmLoginDetailsTask extends AsyncTask { private OsmandApplication app; - private ValidateOsmLoginListener validateOsmLoginListener; + private ValidateOsmLoginListener validateListener; - public interface ValidateOsmLoginListener { - - void loginValidationFinished(String error); - - } - - public ValidateOsmLoginDetailsTask(OsmandApplication app, ValidateOsmLoginListener validateTargetOsmLoginDetailsTask ) { + public ValidateOsmLoginDetailsTask(@NonNull OsmandApplication app, ValidateOsmLoginListener validateListener) { this.app = app; - this.validateOsmLoginListener = validateTargetOsmLoginDetailsTask; + this.validateListener = validateListener; } - - @Override protected OsmBugResult doInBackground(Void... params) { OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); @@ -39,14 +30,20 @@ public class ValidateOsmLoginDetailsTask extends AsyncTask Date: Fri, 6 Nov 2020 13:16:16 +0200 Subject: [PATCH 07/16] My places --- .../LoginBottomSheetFragment.java | 5 ----- .../plus/osmedit/EditPOIMenuController.java | 2 +- .../osmand/plus/osmedit/OsmEditsFragment.java | 21 +++++++++++++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java index e61813cd93..44547815ce 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java @@ -75,11 +75,6 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { return getResources().getDimensionPixelSize(R.dimen.card_content_padding_large); } - @Override - public int getSecondDividerHeight() { - return getResources().getDimensionPixelSize(R.dimen.content_padding_small); - } - @Override protected void onRightBottomButtonClick() { FragmentManager fragmentManager = getFragmentManager(); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java index 60c2ed0b2b..1d8a4e4aa6 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java @@ -54,7 +54,7 @@ public class EditPOIMenuController extends MenuController { SimpleProgressDialogPoiUploader poiDialogUploader = new SimpleProgressDialogPoiUploader(activity); poiDialogUploader.showProgressDialog(new OsmPoint[] {getOsmPoint()}, false, false); } else { - LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), activity.getLoginBottomSheetFragment()); + LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null); } } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 40f62e55b6..0a4cc5d7ff 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -29,6 +29,7 @@ import androidx.appcompat.app.AlertDialog; import androidx.appcompat.view.ActionMode; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; @@ -41,6 +42,8 @@ import net.osmand.osm.edit.Entity; 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.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.Version; @@ -624,10 +627,20 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo } private void uploadItems(final OsmPoint[] items) { - SendPoiDialogFragment.createInstance(items, PoiUploaderType.FRAGMENT) - .show(getChildFragmentManager(), SendPoiDialogFragment.TAG); -// UploadOsmEditsConfirmDialogFragment.createInstancee(items).show(getChildFragmentManager(), -// UploadOsmEditsConfirmDialogFragment.TAG); + FragmentActivity activity = getActivity(); + if (activity != null) { + OsmandApplication app = getMyApplication(); + OsmandSettings settings = app.getSettings(); + OsmOAuthAuthorizationAdapter authorizationAdapter = new OsmOAuthAuthorizationAdapter(app); + if (authorizationAdapter.isValidToken() + || !Algorithms.isEmpty(settings.USER_NAME.get()) + && !Algorithms.isEmpty(settings.USER_PASSWORD.get())) { + SendPoiDialogFragment.createInstance(items, PoiUploaderType.FRAGMENT) + .show(getChildFragmentManager(), SendPoiDialogFragment.TAG); + } else { + LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this); + } + } } public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) { From 7843aede9d5edfa6d8e6851a0359a317bc06b467 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 9 Nov 2020 10:06:54 +0200 Subject: [PATCH 08/16] Fix #9069 Polygons become visible after underlay change --- OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java | 7 ------- .../net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java | 3 --- 2 files changed, 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java index 8219cc5a23..54cb7ba447 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java @@ -79,13 +79,6 @@ public class RasterMapMenu { new OnMapSelectedCallback() { @Override public void onMapSelected(boolean canceled) { - if (type == RasterMapType.UNDERLAY && !canceled && !selected) { - hidePolygonsPref.set(true); - refreshMapComplete(mapActivity); - } else if (type == RasterMapType.UNDERLAY && !canceled && mapTypePreference.get() == null) { - hidePolygonsPref.set(false); - refreshMapComplete(mapActivity); - } mapActivity.getDashboard().refreshContent(true); } }; diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index 942a34cbf1..e96edba607 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -339,9 +339,6 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { adapter.notifyDataSetChanged(); - final CommonPreference hidePolygonsPref = - mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons"); - hidePolygonsPref.set(hasUnderlayDescription); RasterMapMenu.refreshMapComplete(mapActivity); } } From e3e780a434332545914d6f3166247b56e5e02eb4 Mon Sep 17 00:00:00 2001 From: Hardy Date: Mon, 9 Nov 2020 09:58:59 +0100 Subject: [PATCH 09/16] Some refineent to gpx.md --- GPX.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/GPX.md b/GPX.md index 8ab3640620..b3f1e441e4 100644 --- a/GPX.md +++ b/GPX.md @@ -1,11 +1,11 @@ -The OsmAnd's GPX file format conforms to GPX 1.1 specification with additional data written as extensions. There are few sections of such data: +The OsmAnd's GPX file format conforms to the GPX 1.1 specification with additional data written as extensions. There are several sections of such data: ## Track appearance -These parameters are used to customize the appearance of a track on the map. Used inside "gpx" tag and applies to all tracks inside gpx. +The following parameters are used to customize the appearance of a track on the map. They are used inside the "gpx" tag and apply to all tracks contained in the gpx. #### Parameters * **show_arrows** [*true, false*] - show / hide arrows along the path line. -* **width** [*thin, medium, bold, 1-24*] - width of a track line on the map. The thin, medium and bold are style depended values (should be defined as currentTrackWidth attribute). -* **color** [*#AARRGGBB, #RRGGBB*] - color of a track line on the map. Hex values. +* **width** [*thin, medium, bold, 1-24*] - width of the track line on the map. The thin, medium, and bold are style depended values (should be defined as currentTrackWidth attribute). +* **color** [*#AARRGGBB, #RRGGBB*] - color of a track line on the map. Hex value. * **split_type** [*no_split, distance, time*] - split type for a track. * **split_interval** [*double*] - split interval for a track. Distance (meters), time (seconds). @@ -41,11 +41,10 @@ Written to a gpx file while recording a track. ``` ## Calculated route(s) -This data contains information about a route built with **OsmAnd** (route segments, turns, road names and types, restrictions, etc.). With their help, route can be restored completely as if it had just been built even without the currently installed offline maps. - -There can be several routes in one gpx file. Each of them is contained in a specific segment (**trkseg** / **extensions**). In this form, a gpx file is saved when exporting a constructed route or when saving a track that consists of several separate segments via the **Plan route**. -When using the **Plan route** tool, route key points (**rtept**) are additionally written to the gpx file. There can also be several **rte** blocks (according to a number of separate segments / tracks in a gpx file). +This data contains all details of a route built with **OsmAnd** (route segments, turns, road names, road types, restrictions, etc.). The route can be completely restored as if just built, even in the absence of the respective offline maps. +A gpx file may contain several routes. Each of them is contained in a specific segment under **trkseg** / **extensions**. A gpx file is saved in this form when exporting a constructed route or when saving a track that consists of several separate segments via the **Plan a route** functionality. +**Plan a route** also adds one (or several, in accordance with the number of contained separate segments / tracks) **rte** blocks to the gpx file, containing route key points (**rtept**). #### Gpx structure: ```xml From 7159bd12c98579e3e2fa60c5785b681b5e145f16 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 9 Nov 2020 11:22:22 +0200 Subject: [PATCH 10/16] Fix strings resources --- OsmAnd/res/values/strings.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 005967cb54..dc262a8b1b 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -497,9 +497,7 @@ Route recalculation Announce Username and password - These settings apply to all profiles. OSM editing - View your edits or OSM bugs not yet uploaded in %1$s. Uploaded points will not show any more. OSM Icon shown while navigating or moving. Icon shown at rest. @@ -3211,7 +3209,6 @@ Global app settings Your OSM username Needed for openstreetmap.org submissions. - Your OSM password Background mode OsmAnd runs in the background with the screen off. There is not enough free space to download %1$s MB (free: %2$s). From c87afb05aa6f4f7f713aa63e625ba93f3c860e30 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Mon, 9 Nov 2020 13:19:15 +0300 Subject: [PATCH 11/16] Revert dev build ignoring --- OsmAnd/src/net/osmand/plus/Version.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/Version.java b/OsmAnd/src/net/osmand/plus/Version.java index 8e23518613..48dd9b1feb 100644 --- a/OsmAnd/src/net/osmand/plus/Version.java +++ b/OsmAnd/src/net/osmand/plus/Version.java @@ -134,11 +134,11 @@ public class Version { } public static boolean isDeveloperVersion(OsmandApplication ctx){ - return false;//getAppName(ctx).contains("~") || ctx.getPackageName().equals(FREE_DEV_VERSION_NAME); + return getAppName(ctx).contains("~") || ctx.getPackageName().equals(FREE_DEV_VERSION_NAME); } public static boolean isDeveloperBuild(OsmandApplication ctx){ - return false;//getAppName(ctx).contains("~"); + return getAppName(ctx).contains("~"); } public static String getVersionForTracker(OsmandApplication ctx) { From c706955daec1553051c3a47a7ce3187305f2c6a1 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Mon, 9 Nov 2020 16:00:06 +0300 Subject: [PATCH 12/16] Fix #10113 --- .../osmand/plus/measurementtool/MeasurementEditingContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index 5d18f52669..e1f1b2d314 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -1069,7 +1069,7 @@ public class MeasurementEditingContext { return new RouteExporter("", route, locations, null).generateRouteSegment(); } else if (endPointIndex - startPointIndex >= 0) { TrkSegment segment = new TrkSegment(); - segment.points = before.points.subList(startPointIndex, endPointIndex + 1); + segment.points = new ArrayList<>(before.points.subList(startPointIndex, endPointIndex + 1)); return segment; } return null; From 17b7386514528d4ac1ca6fd729278d6321ec95a8 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Mon, 9 Nov 2020 17:37:09 +0300 Subject: [PATCH 13/16] Fix #9869 --- .../MeasurementEditingContext.java | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index e1f1b2d314..3563ab77a6 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -92,7 +92,7 @@ public class MeasurementEditingContext { private final WptPt end; private final List points; private final List segments; - private double distance; + private final double distance; public RoadSegmentData(@NonNull ApplicationMode appMode, @NonNull WptPt start, @NonNull WptPt end, @Nullable List points, @Nullable List segments) { @@ -101,20 +101,18 @@ public class MeasurementEditingContext { this.end = end; this.points = points; this.segments = segments; - if (segments != null) { - double distance = 0; - for (RouteSegmentResult segment : segments) { - distance += segment.getDistance(); - } - this.distance = distance; - } else if (points != null && points.size() > 1) { - double distance = 0; + double distance = 0; + if (points != null && points.size() > 1) { for (int i = 1; i < points.size(); i++) { distance += MapUtils.getDistance(points.get(i - 1).lat, points.get(i - 1).lon, points.get(i).lat, points.get(i).lon); } - this.distance = distance; + } else if (segments != null) { + for (RouteSegmentResult segment : segments) { + distance += segment.getDistance(); + } } + this.distance = distance; } public ApplicationMode getAppMode() { @@ -259,14 +257,8 @@ public class MeasurementEditingContext { RoadSegmentData data = this.roadSegmentData.get(pair); if (data == null) { if (appMode != MeasurementEditingContext.DEFAULT_APP_MODE || !pair.first.lastPoint || !pair.second.firstPoint) { - double localDist = MapUtils.getDistance(pair.first.getLatitude(), pair.first.getLongitude(), + distance += MapUtils.getDistance(pair.first.getLatitude(), pair.first.getLongitude(), pair.second.getLatitude(), pair.second.getLongitude()); - if (!Double.isNaN(pair.first.ele) && !Double.isNaN(pair.second.ele) && - pair.first.ele != 0 && pair.second.ele != 0) { - double h = Math.abs(pair.first.ele - pair.second.ele); - localDist = Math.sqrt(localDist * localDist + h * h); - } - distance += localDist; } } else { distance += data.getDistance(); From 924d15616d04cb1b7509eaa590c0dff6e0585c57 Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Mon, 9 Nov 2020 17:16:49 +0200 Subject: [PATCH 14/16] Resend map, after map editing error --- .../net/osmand/telegram/TelegramService.kt | 6 ++-- .../net/osmand/telegram/TelegramSettings.kt | 34 +++++++++++++------ .../telegram/helpers/ShareLocationHelper.kt | 16 +++++---- .../osmand/telegram/helpers/TelegramHelper.kt | 2 +- .../osmand/telegram/ui/LiveNowTabFragment.kt | 3 +- .../telegram/ui/SharingStatusBottomSheet.kt | 2 +- 6 files changed, 40 insertions(+), 23 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt index 4ff84ca542..ee05034cb7 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt @@ -18,7 +18,6 @@ import net.osmand.telegram.helpers.TelegramHelper import net.osmand.telegram.helpers.TelegramHelper.* import net.osmand.telegram.notifications.TelegramNotification.NotificationType import net.osmand.telegram.utils.AndroidUtils -import net.osmand.telegram.utils.OsmandLocationUtils import org.drinkless.td.libcore.telegram.TdApi import java.util.* @@ -377,7 +376,10 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis Log.d(PlatformUtil.TAG, "Send live location error: $code - $message") when (messageType) { TelegramHelper.MESSAGE_TYPE_TEXT -> shareInfo.pendingTdLibText-- - TelegramHelper.MESSAGE_TYPE_MAP -> shareInfo.pendingTdLibMap-- + TelegramHelper.MESSAGE_TYPE_MAP -> { + shareInfo.pendingTdLibMap-- + shareInfo.currentMapMessageId = -1L + } } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index d9ec335a0e..a6a2377118 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -304,27 +304,18 @@ class TelegramSettings(private val app: TelegramApplication) { fun prepareForSharingNewMessages() { shareChatsInfo.forEach { (_, shareInfo) -> - prepareForSharingNewMessages(shareInfo) + shareInfo.resetMessagesInfo() } } fun prepareForSharingNewMessages(chatsIds: List) { chatsIds.forEach { shareChatsInfo[it]?.also { shareInfo -> - prepareForSharingNewMessages(shareInfo) + shareInfo.resetMessagesInfo() } } } - fun prepareForSharingNewMessages(shareInfo: ShareChatInfo) { - shareInfo.pendingTdLibText = 0 - shareInfo.pendingTdLibMap = 0 - shareInfo.currentTextMessageId = -1L - shareInfo.currentMapMessageId = -1L - shareInfo.pendingTextMessage = false - shareInfo.pendingMapMessage = false - } - fun getChatLivePeriod(chatId: Long) = shareChatsInfo[chatId]?.livePeriod fun getChatsShareInfo() = shareChatsInfo @@ -1497,6 +1488,27 @@ class TelegramSettings(private val app: TelegramApplication) { fun isPendingMapMessagesLimitReached() = pendingTdLibMap >= MAX_MESSAGES_IN_TDLIB_PER_CHAT + fun resetMessagesInfo() { + resetTextMessageInfo() + resetMapMessageInfo() + } + + fun resetTextMessageInfo() { + pendingTdLibText = 0 + currentTextMessageId = -1L + pendingTextMessage = false + } + + fun resetMapMessageInfo() { + pendingTdLibMap = 0 + currentMapMessageId = -1L + pendingMapMessage = false + } + + fun isTextMessageIdPresent() = currentTextMessageId != -1L + + fun isMapMessageIdPresent() = currentMapMessageId != -1L + companion object { internal const val CHAT_ID_KEY = "chatId" diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt index 8aa7d29856..35a397f4f5 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt @@ -138,7 +138,7 @@ class ShareLocationHelper(private val app: TelegramApplication) { } } if (pendingMessagesLimitReached && checkNetworkTypeAllowed) { - checkNetworkType() + updateNetworkType() } } @@ -167,7 +167,7 @@ class ShareLocationHelper(private val app: TelegramApplication) { app.locationMessages.getBufferedTextMessagesForChat(chatId).take(MAX_MESSAGES_IN_TDLIB_PER_CHAT).forEach { if (!shareInfo.isPendingTextMessagesLimitReached()) { if (it.deviceName.isEmpty()) { - if (!shareInfo.pendingTextMessage && shareInfo.currentTextMessageId != -1L) { + if (!shareInfo.pendingTextMessage && shareInfo.isTextMessageIdPresent()) { val content = OsmandLocationUtils.getTextMessageContent(shareInfo.updateTextMessageId, it, app) app.telegramHelper.editTextLocation(shareInfo, content) app.locationMessages.removeBufferedMessage(it) @@ -180,8 +180,12 @@ class ShareLocationHelper(private val app: TelegramApplication) { app.locationMessages.getBufferedMapMessagesForChat(chatId).take(MAX_MESSAGES_IN_TDLIB_PER_CHAT).forEach { if (!shareInfo.isPendingMapMessagesLimitReached()) { if (it.deviceName.isEmpty()) { - if (!shareInfo.pendingMapMessage && shareInfo.currentMapMessageId != -1L) { - app.telegramHelper.editMapLocation(shareInfo, it) + if (!shareInfo.pendingMapMessage) { + if (shareInfo.isMapMessageIdPresent()) { + app.telegramHelper.editMapLocation(shareInfo, it) + } else { + app.telegramHelper.sendNewMapLocation(shareInfo, it) + } app.locationMessages.removeBufferedMessage(it) } } else { @@ -279,7 +283,7 @@ class ShareLocationHelper(private val app: TelegramApplication) { } } if (pendingMessagesLimitReached) { - checkNetworkType() + updateNetworkType() } } @@ -347,7 +351,7 @@ class ShareLocationHelper(private val app: TelegramApplication) { } } - fun checkNetworkType(){ + fun updateNetworkType(){ if (app.isInternetConnectionAvailable) { val networkType = when { app.isWifiConnected -> TdApi.NetworkTypeWiFi() diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index 704a797af2..941e4a8aa4 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -840,7 +840,7 @@ class TelegramHelper private constructor() { } fun stopSendingLiveLocationToChat(shareInfo: ShareChatInfo) { - if (shareInfo.currentMapMessageId != -1L && shareInfo.chatId != -1L) { + if (!shareInfo.isMapMessageIdPresent() && shareInfo.chatId != -1L) { shareInfo.lastSendMapMessageTime = (System.currentTimeMillis() / 1000).toInt() client?.send( TdApi.EditMessageLiveLocation(shareInfo.chatId, shareInfo.currentMapMessageId, null, null)) { obj -> diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt index f3391246b4..fbc3725ec1 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt @@ -15,7 +15,6 @@ import android.widget.TextView import androidx.appcompat.widget.ListPopupWindow import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView import net.osmand.Location import net.osmand.data.LatLon import net.osmand.telegram.R @@ -99,7 +98,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage mainView.findViewById(R.id.swipe_refresh).apply { setOnRefreshListener { - app.shareLocationHelper.checkNetworkType() + app.shareLocationHelper.updateNetworkType() app.telegramHelper.scanChatsHistory() updateList() isRefreshing = false diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SharingStatusBottomSheet.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SharingStatusBottomSheet.kt index ef080fe40d..3dd9968f1c 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SharingStatusBottomSheet.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SharingStatusBottomSheet.kt @@ -72,7 +72,7 @@ class SharingStatusBottomSheet : DialogFragment() { if (sharingStatusType.canResendLocation) { if (i == 0) { setOnClickListener { - app.shareLocationHelper.checkNetworkType() + app.shareLocationHelper.updateNetworkType() app.settings.prepareForSharingNewMessages(sharingStatus.chatsIds) app.shareLocationHelper.checkAndSendBufferMessages() app.forceUpdateMyLocation() From 31f9895bb4b7e40fb834b80601df45a5b8db9dc0 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Mon, 9 Nov 2020 18:27:25 +0300 Subject: [PATCH 15/16] Fix #10112 --- OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 18ebc9b688..c2b961646e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -71,6 +71,7 @@ public class GPXUtilities { WHITE(0xFFFFFFFF), RED(0xFFFF0000), GREEN(0xFF00FF00), + DARKGREEN(0xFF006400), BLUE(0xFF0000FF), YELLOW(0xFFFFFF00), CYAN(0xFF00FFFF), From a9c797ebd769d95e45248352a96d8aa01120c6d5 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Mon, 9 Nov 2020 19:02:19 +0300 Subject: [PATCH 16/16] Fix #5310 --- .../net/osmand/plus/views/AnimateDraggingMapThread.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java b/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java index 0323498479..3df649ea2b 100644 --- a/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java +++ b/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java @@ -225,6 +225,13 @@ public class AnimateDraggingMapThread { if (!stopped) { animatingMoveInThread(mMoveX, mMoveY, animationTime, notifyListener, finishAnimationCallback); + } else if (finishAnimationCallback != null) { + tileView.getApplication().runInUIThread(new Runnable() { + @Override + public void run() { + finishAnimationCallback.run(); + } + }); } if (!stopped) { tileView.setLatLonAnimate(finalLat, finalLon, notifyListener);