Add OsmOAuthHelper
This commit is contained in:
parent
f4edc8dc83
commit
291bed500b
7 changed files with 167 additions and 93 deletions
|
@ -43,6 +43,7 @@ import net.osmand.plus.liveupdates.LiveUpdatesHelper;
|
|||
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
|
||||
import net.osmand.plus.monitoring.LiveMonitoringHelper;
|
||||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper;
|
||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
import net.osmand.plus.quickaction.QuickActionRegistry;
|
||||
import net.osmand.plus.render.MapRenderRepositories;
|
||||
|
@ -466,7 +467,7 @@ public class AppInitializer implements IProgress {
|
|||
app.lockHelper = startupInit(new LockHelper(app), LockHelper.class);
|
||||
app.settingsHelper = startupInit(new SettingsHelper(app), SettingsHelper.class);
|
||||
app.quickActionRegistry = startupInit(new QuickActionRegistry(app.getSettings()), QuickActionRegistry.class);
|
||||
|
||||
app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.class);
|
||||
|
||||
initOpeningHoursParser();
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ import net.osmand.osm.MapPoiTypes;
|
|||
import net.osmand.osm.io.NetworkUtils;
|
||||
import net.osmand.plus.AppInitializer.AppInitializeListener;
|
||||
import net.osmand.plus.access.AccessibilityMode;
|
||||
import net.osmand.plus.helpers.DayNightHelper;
|
||||
import net.osmand.plus.activities.ExitActivity;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
|
@ -57,13 +56,15 @@ import net.osmand.plus.download.DownloadIndexesThread;
|
|||
import net.osmand.plus.download.DownloadService;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.helpers.AvoidSpecificRoads;
|
||||
import net.osmand.plus.helpers.enums.DrivingRegion;
|
||||
import net.osmand.plus.helpers.DayNightHelper;
|
||||
import net.osmand.plus.helpers.LockHelper;
|
||||
import net.osmand.plus.helpers.enums.MetricsConstants;
|
||||
import net.osmand.plus.helpers.WaypointHelper;
|
||||
import net.osmand.plus.helpers.enums.DrivingRegion;
|
||||
import net.osmand.plus.helpers.enums.MetricsConstants;
|
||||
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
|
||||
import net.osmand.plus.monitoring.LiveMonitoringHelper;
|
||||
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper;
|
||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
import net.osmand.plus.quickaction.QuickActionRegistry;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
|
@ -154,6 +155,7 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
SettingsHelper settingsHelper;
|
||||
GpxDbHelper gpxDbHelper;
|
||||
QuickActionRegistry quickActionRegistry;
|
||||
OsmOAuthHelper osmOAuthHelper;
|
||||
|
||||
private Resources localizedResources;
|
||||
|
||||
|
@ -368,8 +370,12 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
return settingsHelper;
|
||||
}
|
||||
|
||||
public OsmOAuthHelper getOsmOAuthHelper() {
|
||||
return osmOAuthHelper;
|
||||
}
|
||||
|
||||
public synchronized DownloadIndexesThread getDownloadThread() {
|
||||
if(downloadIndexesThread == null) {
|
||||
if (downloadIndexesThread == null) {
|
||||
downloadIndexesThread = new DownloadIndexesThread(this);
|
||||
}
|
||||
return downloadIndexesThread;
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import net.osmand.AndroidNetworkUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.IndexConstants;
|
||||
|
@ -19,7 +21,6 @@ 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.search.QuickSearchDialogFragment;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
|
@ -35,6 +36,8 @@ import java.util.Map;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static net.osmand.plus.osmedit.oauth.OsmOAuthHelper.*;
|
||||
|
||||
public class IntentHelper {
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(IntentHelper.class);
|
||||
|
@ -293,13 +296,15 @@ public class IntentHelper {
|
|||
if (intent != null && intent.getData() != null) {
|
||||
Uri uri = intent.getData();
|
||||
if (uri.toString().startsWith("osmand-oauth")) {
|
||||
LoginBottomSheetFragment fragment = mapActivity.getLoginBottomSheetFragment();
|
||||
if (fragment != null) {
|
||||
String oauthVerifier = uri.getQueryParameter("oauth_verifier");
|
||||
fragment.authorize(oauthVerifier);
|
||||
mapActivity.setIntent(null);
|
||||
return true;
|
||||
String oauthVerifier = uri.getQueryParameter("oauth_verifier");
|
||||
app.getOsmOAuthHelper().authorize(oauthVerifier);
|
||||
for (Fragment fragment : mapActivity.getSupportFragmentManager().getFragments()) {
|
||||
if (fragment instanceof OsmAuthorizationListener) {
|
||||
((OsmAuthorizationListener) fragment).authorizationCompleted();
|
||||
}
|
||||
}
|
||||
mapActivity.setIntent(null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -18,30 +18,32 @@ 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.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
||||
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper;
|
||||
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;
|
||||
|
||||
import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA;
|
||||
import static net.osmand.plus.osmedit.oauth.OsmOAuthHelper.*;
|
||||
|
||||
public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||
public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment implements OsmAuthorizationListener {
|
||||
|
||||
public static final String TAG = LoginBottomSheetFragment.class.getSimpleName();
|
||||
private static final Log log = PlatformUtil.getLog(LoginBottomSheetFragment.class);
|
||||
private static final Log LOG = PlatformUtil.getLog(LoginBottomSheetFragment.class);
|
||||
|
||||
private OsmOAuthAuthorizationAdapter authorizationAdapter;
|
||||
private OsmOAuthHelper osmOAuthHelper;
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
OsmandApplication app = requiredMyApplication();
|
||||
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||
items.add(new SimpleBottomSheetItem.Builder().setLayoutId(R.layout.bottom_sheet_login).create());
|
||||
}
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
OsmandApplication app = requiredMyApplication();
|
||||
osmOAuthHelper = app.getOsmOAuthHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
items.add(new SimpleBottomSheetItem.Builder().setLayoutId(R.layout.bottom_sheet_login).create());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDismissButtonTextId() {
|
||||
|
@ -87,59 +89,29 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
|||
protected void onThirdBottomButtonClick() {
|
||||
View view = getView();
|
||||
if (view != null) {
|
||||
authorizationAdapter.startOAuth((ViewGroup) view);
|
||||
osmOAuthHelper.startOAuth((ViewGroup) view);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidToken() {
|
||||
return authorizationAdapter.isValidToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DialogButtonType getRightBottomButtonType() {
|
||||
return (DialogButtonType.SECONDARY);
|
||||
}
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment) {
|
||||
if (!fragmentManager.isStateSaved()) {
|
||||
LoginBottomSheetFragment fragment = new LoginBottomSheetFragment();
|
||||
fragment.setTargetFragment(targetFragment, 0);
|
||||
fragment.show(fragmentManager, TAG);
|
||||
try {
|
||||
if (!fragmentManager.isStateSaved()) {
|
||||
LoginBottomSheetFragment fragment = new LoginBottomSheetFragment();
|
||||
fragment.setTargetFragment(targetFragment, 0);
|
||||
fragment.show(fragmentManager, TAG);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("showInstance", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void authorize(String oauthVerifier) {
|
||||
if (authorizationAdapter != null) {
|
||||
authorizationAdapter.authorize(oauthVerifier);
|
||||
updateUserName();
|
||||
}
|
||||
Fragment target = getTargetFragment();
|
||||
if (target instanceof OsmAuthorizationListener) {
|
||||
((OsmAuthorizationListener) target).authorizationCompleted();
|
||||
}
|
||||
@Override
|
||||
public void authorizationCompleted() {
|
||||
dismiss();
|
||||
}
|
||||
|
||||
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 interface OsmAuthorizationListener {
|
||||
void authorizationCompleted();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ 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.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener;
|
||||
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
|
||||
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
|
||||
import net.osmand.plus.settings.fragments.OnPreferenceChanged;
|
||||
|
@ -34,7 +34,8 @@ 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, ValidateOsmLoginListener, OsmAuthorizationListener {
|
||||
public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginListener,
|
||||
OsmAuthorizationListener {
|
||||
|
||||
private static final Log log = PlatformUtil.getLog(OsmEditingFragment.class);
|
||||
|
||||
|
@ -48,7 +49,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||
authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -176,7 +177,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
settings.USER_ACCESS_TOKEN_SECRET.resetToDefault();
|
||||
|
||||
authorizationAdapter.resetToken();
|
||||
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||
authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
|
||||
} else {
|
||||
settings.USER_NAME.resetToDefault();
|
||||
settings.USER_PASSWORD.resetToDefault();
|
||||
|
@ -195,7 +196,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
|
||||
@Override
|
||||
public void authorizationCompleted() {
|
||||
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||
authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
|
||||
updateAllSettings();
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import android.graphics.drawable.Drawable;
|
|||
import android.os.Bundle;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
@ -28,6 +29,7 @@ import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
|||
import net.osmand.plus.osmedit.OsmNotesPoint;
|
||||
import net.osmand.plus.osmedit.OsmPoint;
|
||||
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
||||
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -36,18 +38,23 @@ import org.apache.commons.logging.Log;
|
|||
|
||||
import static net.osmand.plus.UiUtilities.setupDialogButton;
|
||||
import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA;
|
||||
import static net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask.*;
|
||||
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.*;
|
||||
|
||||
public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||
public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment implements ValidateOsmLoginListener,
|
||||
OsmAuthorizationListener {
|
||||
|
||||
public static final String TAG = SendOsmNoteBottomSheetFragment.class.getSimpleName();
|
||||
private static final Log LOG = PlatformUtil.getLog(SendOsmNoteBottomSheetFragment.class);
|
||||
public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
|
||||
public static final String POI_UPLOADER_TYPE = "poi_uploader_type";
|
||||
private OsmPoint[] poi;
|
||||
private boolean isLogin;
|
||||
|
||||
protected OsmandSettings settings;
|
||||
private TextView accountName;
|
||||
private LinearLayout accountBlockView;
|
||||
private LinearLayout signInView;
|
||||
private SwitchCompat uploadAnonymously;
|
||||
|
||||
public enum PoiUploaderType {
|
||||
SIMPLE,
|
||||
|
@ -64,7 +71,6 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
|||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
isLogin = isLogin();
|
||||
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
|
||||
OsmandApplication app = getMyApplication();
|
||||
|
||||
|
@ -77,23 +83,21 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
|||
noteText.setText(((OsmNotesPoint) poi[0]).getText());
|
||||
TextInputLayout noteHint = sendOsmNoteView.findViewById(R.id.note_hint);
|
||||
noteHint.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name));
|
||||
final LinearLayout accountBlockView = sendOsmNoteView.findViewById(R.id.account_container);
|
||||
final LinearLayout signInView = sendOsmNoteView.findViewById(R.id.sign_in_container);
|
||||
final SwitchCompat uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch);
|
||||
final TextView accountName = sendOsmNoteView.findViewById(R.id.user_name);
|
||||
accountBlockView = sendOsmNoteView.findViewById(R.id.account_container);
|
||||
signInView = sendOsmNoteView.findViewById(R.id.sign_in_container);
|
||||
uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch);
|
||||
accountName = sendOsmNoteView.findViewById(R.id.user_name);
|
||||
|
||||
settings = app.getSettings();
|
||||
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
|
||||
String userNameOpenID = settings.USER_NAME.get();
|
||||
String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID;
|
||||
accountName.setText(userName);
|
||||
updateAccountName();
|
||||
View signInButton = sendOsmNoteView.findViewById(R.id.sign_in_button);
|
||||
setupButton(signInButton, R.string.sing_in_with_open_street_map, DialogButtonType.PRIMARY,
|
||||
R.drawable.ic_action_openstreetmap_logo);
|
||||
signInButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
OsmandApplication app = requiredMyApplication();
|
||||
app.getOsmOAuthHelper().startOAuth((ViewGroup) v);
|
||||
}
|
||||
});
|
||||
View loginButton = sendOsmNoteView.findViewById(R.id.login_button);
|
||||
|
@ -101,20 +105,18 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
|||
loginButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
OsmLoginDataBottomSheet.showInstance(getFragmentManager(), OSM_LOGIN_DATA, getTargetFragment(),
|
||||
usedOnMap, null);
|
||||
OsmLoginDataBottomSheet.showInstance(getFragmentManager(), OSM_LOGIN_DATA,
|
||||
SendOsmNoteBottomSheetFragment.this, usedOnMap, null);
|
||||
}
|
||||
});
|
||||
accountBlockView.setVisibility(!isLogin ? View.GONE : View.VISIBLE);
|
||||
signInView.setVisibility(isLogin ? View.GONE : View.VISIBLE);
|
||||
updateSignIn(uploadAnonymously.isChecked());
|
||||
uploadAnonymously.setBackgroundResource(nightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg);
|
||||
final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
|
||||
uploadAnonymously.setPadding(paddingSmall, 0, paddingSmall, 0);
|
||||
uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
accountBlockView.setVisibility(isChecked || !isLogin ? View.GONE : View.VISIBLE);
|
||||
signInView.setVisibility(isChecked || isLogin ? View.GONE : View.VISIBLE);
|
||||
updateSignIn(isChecked);
|
||||
if (nightMode) {
|
||||
uploadAnonymously.setBackgroundResource(
|
||||
isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark);
|
||||
|
@ -131,6 +133,20 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
|||
items.add(bottomSheetItem);
|
||||
}
|
||||
|
||||
private void updateAccountName() {
|
||||
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
|
||||
String userNameOpenID = settings.USER_NAME.get();
|
||||
String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID;
|
||||
accountName.setText(userName);
|
||||
updateSignIn(uploadAnonymously.isChecked());
|
||||
}
|
||||
|
||||
private void updateSignIn(boolean isChecked) {
|
||||
boolean isLogin = isLogin();
|
||||
accountBlockView.setVisibility(isChecked || !isLogin ? View.GONE : View.VISIBLE);
|
||||
signInView.setVisibility(isChecked || isLogin ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
private void setupButton(View buttonView, int buttonTextId, DialogButtonType buttonType, int drawableId) {
|
||||
Drawable icon = null;
|
||||
if (drawableId != -1) {
|
||||
|
@ -205,11 +221,21 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
|||
return R.string.shared_string_upload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authorizationCompleted() {
|
||||
updateAccountName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loginValidationFinished(String warning) {
|
||||
updateAccountName();
|
||||
}
|
||||
|
||||
private boolean isLogin() {
|
||||
OsmandApplication app = getMyApplication();
|
||||
OsmandSettings settings = app.getSettings();
|
||||
OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app);
|
||||
return client.isValidToken()
|
||||
OsmOAuthAuthorizationAdapter adapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
|
||||
return adapter.isValidToken()
|
||||
|| !Algorithms.isEmpty(settings.USER_NAME.get())
|
||||
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get());
|
||||
}
|
||||
|
|
63
OsmAnd/src/net/osmand/plus/osmedit/oauth/OsmOAuthHelper.java
Normal file
63
OsmAnd/src/net/osmand/plus/osmedit/oauth/OsmOAuthHelper.java
Normal file
|
@ -0,0 +1,63 @@
|
|||
package net.osmand.plus.osmedit.oauth;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class OsmOAuthHelper {
|
||||
|
||||
private static final Log log = PlatformUtil.getLog(OsmOAuthHelper.class);
|
||||
|
||||
private final OsmandApplication app;
|
||||
|
||||
private final OsmOAuthAuthorizationAdapter authorizationAdapter;
|
||||
|
||||
public OsmOAuthHelper(@NonNull OsmandApplication app) {
|
||||
this.app = app;
|
||||
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||
}
|
||||
|
||||
public void startOAuth(ViewGroup view) {
|
||||
authorizationAdapter.startOAuth(view);
|
||||
}
|
||||
|
||||
public void authorize(String oauthVerifier) {
|
||||
authorizationAdapter.authorize(oauthVerifier);
|
||||
updateUserName();
|
||||
}
|
||||
|
||||
public OsmOAuthAuthorizationAdapter getAuthorizationAdapter() {
|
||||
return authorizationAdapter;
|
||||
}
|
||||
|
||||
private void updateUserName() {
|
||||
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 interface OsmAuthorizationListener {
|
||||
void authorizationCompleted();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue