Fix my places send gpx OAuth
This commit is contained in:
parent
99ad1f2aeb
commit
9405c7c898
8 changed files with 86 additions and 32 deletions
|
@ -297,7 +297,8 @@ public class IntentHelper {
|
|||
Uri uri = intent.getData();
|
||||
if (uri.toString().startsWith("osmand-oauth")) {
|
||||
String oauthVerifier = uri.getQueryParameter("oauth_verifier");
|
||||
app.getOsmOAuthHelper().authorize(oauthVerifier, getOnAuthorizeListener());
|
||||
app.getOsmOAuthHelper().addListener(getOnAuthorizeListener());
|
||||
app.getOsmOAuthHelper().authorize(oauthVerifier);
|
||||
mapActivity.setIntent(null);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet;
|
|||
import org.apache.commons.logging.Log;
|
||||
|
||||
import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA;
|
||||
import static net.osmand.plus.osmedit.oauth.OsmOAuthHelper.*;
|
||||
import static net.osmand.plus.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener;
|
||||
|
||||
public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment implements OsmAuthorizationListener {
|
||||
|
||||
|
@ -89,6 +89,10 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment impl
|
|||
protected void onThirdBottomButtonClick() {
|
||||
View view = getView();
|
||||
if (view != null) {
|
||||
Fragment fragment = getTargetFragment();
|
||||
if (fragment instanceof OsmAuthorizationListener) {
|
||||
osmOAuthHelper.addListener((OsmAuthorizationListener) fragment);
|
||||
}
|
||||
osmOAuthHelper.startOAuth((ViewGroup) view);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,11 +80,12 @@ import net.osmand.plus.activities.TrackActivity;
|
|||
import net.osmand.plus.base.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
|
||||
import net.osmand.plus.helpers.enums.TracksSortByMode;
|
||||
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
|
||||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.helpers.enums.TracksSortByMode;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
|
@ -112,7 +113,7 @@ import static net.osmand.util.Algorithms.objectEquals;
|
|||
import static net.osmand.util.Algorithms.removeAllFiles;
|
||||
|
||||
public class AvailableGPXFragment extends OsmandExpandableListFragment implements
|
||||
FavoritesFragmentStateHolder {
|
||||
FavoritesFragmentStateHolder, OsmAuthorizationListener {
|
||||
|
||||
public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]");
|
||||
public static final int SEARCH_ID = -1;
|
||||
|
@ -922,6 +923,18 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
|||
public void restoreState(Bundle bundle) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authorizationCompleted() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(TAB_ID, GPX_TAB);
|
||||
|
||||
Intent intent = new Intent(app, app.getAppCustomization().getFavoritesActivity());
|
||||
intent.putExtra(MapActivity.INTENT_PARAMS, bundle);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
app.startActivity(intent);
|
||||
}
|
||||
|
||||
public class LoadGpxTask extends AsyncTask<Activity, GpxInfo, List<GpxInfo>> {
|
||||
|
||||
private List<GpxInfo> result;
|
||||
|
|
|
@ -461,10 +461,10 @@ 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)) {
|
||||
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment.getTargetFragment());
|
||||
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment);
|
||||
return false;
|
||||
} else {
|
||||
SendGpxBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment.getTargetFragment(), info);
|
||||
SendGpxBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment, info);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,11 +42,6 @@ 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.dialogs.SendOsmNoteBottomSheetFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment;
|
||||
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.ActionBarProgressActivity;
|
||||
|
@ -55,13 +50,20 @@ import net.osmand.plus.activities.OsmandActionBarActivity;
|
|||
import net.osmand.plus.base.OsmAndListFragment;
|
||||
import net.osmand.plus.dialogs.ProgressDialogFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.measurementtool.LoginBottomSheetFragment;
|
||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
import net.osmand.plus.myplaces.FavoritesFragmentStateHolder;
|
||||
import net.osmand.plus.osmedit.ExportOptionsBottomSheetDialogFragment.ExportOptionsFragmentListener;
|
||||
import net.osmand.plus.osmedit.FileTypeBottomSheetDialogFragment.FileTypeFragmentListener;
|
||||
import net.osmand.plus.osmedit.OpenstreetmapLocalUtil.OnNodeCommittedListener;
|
||||
import net.osmand.plus.osmedit.OsmEditOptionsBottomSheetDialogFragment.OsmEditOptionsFragmentListener;
|
||||
import net.osmand.plus.osmedit.OsmPoint.Group;
|
||||
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.ProgressDialogPoiUploader;
|
||||
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.util.Algorithms;
|
||||
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
|
@ -79,8 +81,8 @@ import java.util.Map;
|
|||
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
|
||||
import static net.osmand.plus.osmedit.OsmEditingPlugin.OSM_EDIT_TAB;
|
||||
|
||||
public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialogFragment.ProgressDialogPoiUploader, OpenstreetmapLocalUtil.OnNodeCommittedListener,
|
||||
FavoritesFragmentStateHolder {
|
||||
public class OsmEditsFragment extends OsmAndListFragment implements ProgressDialogPoiUploader,
|
||||
OnNodeCommittedListener, FavoritesFragmentStateHolder, OsmAuthorizationListener {
|
||||
|
||||
public static final int EXPORT_TYPE_ALL = 0;
|
||||
public static final int EXPORT_TYPE_POI = 1;
|
||||
|
@ -104,6 +106,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
|||
private final static int MODE_DELETE = 100;
|
||||
private final static int MODE_UPLOAD = 101;
|
||||
|
||||
private OsmandApplication app;
|
||||
private OsmEditingPlugin plugin;
|
||||
|
||||
private View footerView;
|
||||
|
@ -144,6 +147,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
|||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
app = getMyApplication();
|
||||
if (savedInstanceState != null) {
|
||||
exportType = savedInstanceState.getInt(EXPORT_TYPE_KEY);
|
||||
}
|
||||
|
@ -647,6 +651,18 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authorizationCompleted() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(TAB_ID, OSM_EDIT_TAB);
|
||||
|
||||
Intent intent = new Intent(app, app.getAppCustomization().getFavoritesActivity());
|
||||
intent.putExtra(MapActivity.INTENT_PARAMS, bundle);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
app.startActivity(intent);
|
||||
}
|
||||
|
||||
boolean hasPoiGroup(OsmPoint[] points) {
|
||||
boolean hasPoiGroup = false;
|
||||
for (OsmPoint p : points) {
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.widget.TextView;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
@ -38,8 +39,10 @@ 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.*;
|
||||
import static net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask.ValidateOsmLoginListener;
|
||||
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.OPENSTREETMAP_POINT;
|
||||
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.ProgressDialogPoiUploader;
|
||||
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.SimpleProgressDialogPoiUploader;
|
||||
|
||||
public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment implements ValidateOsmLoginListener,
|
||||
OsmAuthorizationListener {
|
||||
|
@ -89,7 +92,10 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
|||
signInButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
OsmandApplication app = requiredMyApplication();
|
||||
Fragment fragment = getParentFragment();
|
||||
if (fragment instanceof OsmAuthorizationListener) {
|
||||
app.getOsmOAuthHelper().addListener((OsmAuthorizationListener) fragment);
|
||||
}
|
||||
app.getOsmOAuthHelper().startOAuth((ViewGroup) v);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -26,8 +26,6 @@ import org.xmlpull.v1.XmlPullParserException;
|
|||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static net.osmand.plus.osmedit.oauth.OsmOAuthHelper.*;
|
||||
|
||||
public class OsmOAuthAuthorizationAdapter {
|
||||
|
||||
private static final int THREAD_ID = 10101;
|
||||
|
@ -99,8 +97,8 @@ public class OsmOAuthAuthorizationAdapter {
|
|||
return client.performRequestWithoutAuth(url, method, body);
|
||||
}
|
||||
|
||||
public void authorize(String oauthVerifier, final OsmOAuthHelper helper, final OsmAuthorizationListener listener) {
|
||||
new AuthorizeAsyncTask(helper, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, oauthVerifier);
|
||||
public void authorize(String oauthVerifier, OsmOAuthHelper helper) {
|
||||
new AuthorizeAsyncTask(helper).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, oauthVerifier);
|
||||
}
|
||||
|
||||
private class StartOAuthAsyncTask extends AsyncTask<Void, Void, OAuth1RequestToken> {
|
||||
|
@ -120,17 +118,14 @@ public class OsmOAuthAuthorizationAdapter {
|
|||
protected void onPostExecute(@NonNull OAuth1RequestToken requestToken) {
|
||||
loadWebView(rootLayout, client.getService().getAuthorizationUrl(requestToken));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class AuthorizeAsyncTask extends AsyncTask<String, Void, Void> {
|
||||
|
||||
private final OsmOAuthHelper helper;
|
||||
private final OsmAuthorizationListener listener;
|
||||
|
||||
public AuthorizeAsyncTask(OsmOAuthHelper helper, OsmAuthorizationListener listener) {
|
||||
public AuthorizeAsyncTask(OsmOAuthHelper helper) {
|
||||
this.helper = helper;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -143,9 +138,7 @@ public class OsmOAuthAuthorizationAdapter {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
if (listener != null) {
|
||||
listener.authorizationCompleted();
|
||||
}
|
||||
helper.notifyAndRemoveListeners();
|
||||
}
|
||||
|
||||
public void updateUserName() {
|
||||
|
|
|
@ -6,26 +6,47 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class OsmOAuthHelper {
|
||||
|
||||
private final OsmandApplication app;
|
||||
private final OsmOAuthAuthorizationAdapter authorizationAdapter;
|
||||
private final Set<OsmAuthorizationListener> listeners = new HashSet<>();
|
||||
|
||||
public OsmOAuthHelper(@NonNull OsmandApplication app) {
|
||||
this.app = app;
|
||||
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||
}
|
||||
|
||||
public void startOAuth(ViewGroup view) {
|
||||
authorizationAdapter.startOAuth(view);
|
||||
public void addListener(OsmAuthorizationListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void authorize(String oauthVerifier, OsmAuthorizationListener listener) {
|
||||
authorizationAdapter.authorize(oauthVerifier, this, listener);
|
||||
public void removeListener(OsmAuthorizationListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
public OsmOAuthAuthorizationAdapter getAuthorizationAdapter() {
|
||||
return authorizationAdapter;
|
||||
}
|
||||
|
||||
public void startOAuth(@NonNull ViewGroup view) {
|
||||
authorizationAdapter.startOAuth(view);
|
||||
}
|
||||
|
||||
public void authorize(@NonNull String oauthVerifier) {
|
||||
authorizationAdapter.authorize(oauthVerifier, this);
|
||||
}
|
||||
|
||||
public void notifyAndRemoveListeners() {
|
||||
for (OsmAuthorizationListener listener : listeners) {
|
||||
listener.authorizationCompleted();
|
||||
}
|
||||
listeners.clear();
|
||||
}
|
||||
|
||||
public interface OsmAuthorizationListener {
|
||||
void authorizationCompleted();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue