saving state
This commit is contained in:
parent
cc107157fc
commit
6d0e76095f
6 changed files with 90 additions and 18 deletions
|
@ -14,6 +14,7 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||
import net.osmand.plus.osmedit.OsmPoint.Action;
|
||||
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment;
|
||||
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationClient;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
|
@ -39,9 +40,16 @@ public class EditPOIMenuController extends MenuController {
|
|||
public void buttonPressed() {
|
||||
MapActivity activity = getMapActivity();
|
||||
if (plugin != null && activity != null) {
|
||||
SendPoiDialogFragment sendPoiDialogFragment =
|
||||
SendPoiDialogFragment.createInstance(new OsmPoint[]{getOsmPoint()}, SendPoiDialogFragment.PoiUploaderType.SIMPLE);
|
||||
sendPoiDialogFragment.show(activity.getSupportFragmentManager(), SendPoiDialogFragment.TAG);
|
||||
OsmOAuthAuthorizationClient client = new OsmOAuthAuthorizationClient(activity.getMyApplication());
|
||||
if (client.isValidToken()){
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.osmand.osm.io.Base64;
|
|||
import net.osmand.osm.io.NetworkUtils;
|
||||
import net.osmand.osm.io.OsmBaseStorage;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationClient;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
|
@ -119,8 +120,14 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
|
|||
connection.setRequestProperty("User-Agent", Version.getFullVersion(ctx)); //$NON-NLS-1$
|
||||
StringBuilder responseBody = new StringBuilder();
|
||||
if (doAuthenticate) {
|
||||
String token = settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(); //$NON-NLS-1$
|
||||
connection.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
OsmOAuthAuthorizationClient client = new OsmOAuthAuthorizationClient(ctx);
|
||||
if (client.isValidToken()){
|
||||
connection.addRequestProperty("Authorization", "OAuth " + client.getAccessToken());
|
||||
}
|
||||
else {
|
||||
String token = settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(); //$NON-NLS-1$
|
||||
connection.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
}
|
||||
connection.setDoInput(true);
|
||||
if (requestMethod.equals("PUT") || requestMethod.equals("POST") || requestMethod.equals("DELETE")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
|
|
@ -5,6 +5,7 @@ import net.osmand.PlatformUtil;
|
|||
import net.osmand.osm.io.Base64;
|
||||
import net.osmand.osm.io.NetworkUtils;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationClient;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
|
@ -109,6 +110,7 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
|
|||
|
||||
private OsmBugResult editingPOI(String url, String requestMethod, String userOperation,
|
||||
boolean anonymous) {
|
||||
OsmOAuthAuthorizationClient client = new OsmOAuthAuthorizationClient(this.app);
|
||||
OsmBugResult r = new OsmBugResult();
|
||||
try {
|
||||
HttpURLConnection connection = NetworkUtils.getHttpURLConnection(url);
|
||||
|
@ -118,8 +120,13 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
|
|||
connection.setRequestProperty("User-Agent", Version.getFullVersion(app)); //$NON-NLS-1$
|
||||
|
||||
if (!anonymous) {
|
||||
String token = settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(); //$NON-NLS-1$
|
||||
connection.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
if (client.isValidToken()){
|
||||
connection.addRequestProperty("Authorization", "OAuth " + client.getAccessToken());
|
||||
}
|
||||
else {
|
||||
String token = settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(); //$NON-NLS-1$
|
||||
connection.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
}
|
||||
|
||||
connection.setDoInput(true);
|
||||
|
|
|
@ -18,6 +18,8 @@ import android.view.ViewGroup;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.github.scribejava.core.model.OAuthAsyncRequestCallback;
|
||||
import com.github.scribejava.core.model.Response;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationClient;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -25,6 +27,8 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.SettingsBaseActivity;
|
||||
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SettingsOsmEditingActivity extends SettingsBaseActivity {
|
||||
OsmOAuthAuthorizationClient client;
|
||||
|
||||
|
@ -72,17 +76,54 @@ public class SettingsOsmEditingActivity extends SettingsBaseActivity {
|
|||
grp.addPreference(pref);
|
||||
|
||||
final Preference prefOAuth = new Preference(this);
|
||||
prefOAuth.setTitle(R.string.osb_author_dialog_password);
|
||||
prefOAuth.setSummary(R.string.osb_author_dialog_password);
|
||||
prefOAuth.setKey("local_openstreetmap_points");
|
||||
prefOAuth.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
ViewGroup preferenceView = (ViewGroup)getListView().getChildAt(preference.getOrder());
|
||||
client.startOAuth(preferenceView);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (client.isValidToken()){
|
||||
prefOAuth.setTitle(R.string.osm_authorization_success);
|
||||
prefOAuth.setSummary(R.string.osm_authorization_success);
|
||||
prefOAuth.setKey("local_openstreetmap_token");
|
||||
|
||||
final Preference prefTestUser = new Preference(this);
|
||||
prefTestUser.setTitle("Test user request");
|
||||
prefTestUser.setSummary("Test user request");
|
||||
prefTestUser.setKey("local_openstreetmap_token");
|
||||
prefTestUser.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
String url = "https://api.openstreetmap.org/api/0.6/user/details";
|
||||
client.performGetRequest(url, new OAuthAsyncRequestCallback<Response>() {
|
||||
@Override
|
||||
public void onCompleted(Response response) {
|
||||
try {
|
||||
Toast.makeText(SettingsOsmEditingActivity.this,
|
||||
"DATA RETRIEVED: " + response.getBody().toString(),Toast.LENGTH_SHORT).show();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onThrowable(Throwable t) {
|
||||
Toast.makeText(SettingsOsmEditingActivity.this,
|
||||
"ERROR happened",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
});
|
||||
grp.addPreference(prefTestUser);
|
||||
}
|
||||
else {
|
||||
prefOAuth.setTitle(R.string.osb_author_dialog_password);
|
||||
prefOAuth.setSummary(R.string.osb_author_dialog_password);
|
||||
prefOAuth.setKey("local_openstreetmap_token");
|
||||
prefOAuth.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
ViewGroup preferenceView = (ViewGroup)getListView().getChildAt(preference.getOrder());
|
||||
client.startOAuth(preferenceView);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
grp.addPreference(prefOAuth);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.plus.osmedit;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.net.TrafficStats;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import net.osmand.osm.edit.Entity;
|
||||
|
@ -43,6 +44,9 @@ public class UploadOpenstreetmapPointAsyncTask
|
|||
|
||||
@Override
|
||||
protected Map<OsmPoint, String> doInBackground(OsmPoint... points) {
|
||||
final int THREAD_ID = 10102;
|
||||
TrafficStats.setThreadStatsTag(THREAD_ID);
|
||||
|
||||
Map<OsmPoint, String> loadErrorsMap = new HashMap<>();
|
||||
|
||||
boolean uploaded = false;
|
||||
|
|
|
@ -53,6 +53,11 @@ public class OsmOAuthAuthorizationClient {
|
|||
final int THREAD_ID = 10101;
|
||||
TrafficStats.setThreadStatsTag(THREAD_ID);
|
||||
this.application = application;
|
||||
restoreToken();
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return this.accessToken.getToken();
|
||||
}
|
||||
|
||||
public void performGetRequest(String url,OAuthAsyncRequestCallback<Response> callback) {
|
||||
|
|
Loading…
Reference in a new issue