forked from upstream-mirrors/OpenTracks
Adding state persistence for low-memory situations and handling the share action.
This commit is contained in:
@@ -64,7 +64,7 @@ import java.util.List;
|
|||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class SendActivity extends Activity implements ProgressIndicator {
|
public class SendActivity extends Activity implements ProgressIndicator {
|
||||||
public static final String EXTRA_SHARE_LINK = "share_link";
|
private static final String EXTRA_SHARE_LINK = "share_link";
|
||||||
|
|
||||||
/** States for the state machine that defines the upload process. */
|
/** States for the state machine that defines the upload process. */
|
||||||
private enum SendState {
|
private enum SendState {
|
||||||
@@ -93,10 +93,13 @@ public class SendActivity extends Activity implements ProgressIndicator {
|
|||||||
/* @VisibleForTesting */
|
/* @VisibleForTesting */
|
||||||
static final int DONE_DIALOG = 3;
|
static final int DONE_DIALOG = 3;
|
||||||
|
|
||||||
|
// UI
|
||||||
|
private SendDialog sendDialog;
|
||||||
|
private ProgressDialog progressDialog;
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
private MyTracksProviderUtils providerUtils;
|
private MyTracksProviderUtils providerUtils;
|
||||||
private SharedPreferences sharedPreferences;
|
private SharedPreferences sharedPreferences;
|
||||||
|
|
||||||
private GoogleAnalyticsTracker tracker;
|
private GoogleAnalyticsTracker tracker;
|
||||||
|
|
||||||
// Authentication
|
// Authentication
|
||||||
@@ -109,25 +112,21 @@ public class SendActivity extends Activity implements ProgressIndicator {
|
|||||||
private boolean shareRequested = false;
|
private boolean shareRequested = false;
|
||||||
private long sendTrackId;
|
private long sendTrackId;
|
||||||
|
|
||||||
// Send result information, used by SendToGoogleResultDialog.
|
// Send result information, used by results dialog.
|
||||||
private boolean sendToMyMapsSuccess = false;
|
private boolean sendToMyMapsSuccess = false;
|
||||||
private boolean sendToFusionTablesSuccess = false;
|
private boolean sendToFusionTablesSuccess = false;
|
||||||
private boolean sendToDocsSuccess = false;
|
private boolean sendToDocsSuccess = false;
|
||||||
|
// TODO: Make these be used for showing results
|
||||||
|
private String sendToMyMapsMessage;
|
||||||
|
private String sendToFusionTablesMessage;
|
||||||
|
private String sendToDocsMessage;
|
||||||
|
|
||||||
|
// Send result information, used to share a link.
|
||||||
private String sendToMyMapsMapId;
|
private String sendToMyMapsMapId;
|
||||||
private String sendToFusionTablesTableId;
|
private String sendToFusionTablesTableId;
|
||||||
|
|
||||||
// TODO: Make these be used for showing results
|
// Current sending state.
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private String sendToMyMapsMessage;
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private String sendToFusionTablesMessage;
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private String sendToDocsMessage;
|
|
||||||
|
|
||||||
// State used while sending.
|
|
||||||
private SendState currentState;
|
private SendState currentState;
|
||||||
private SendDialog sendDialog;
|
|
||||||
private ProgressDialog progressDialog;
|
|
||||||
|
|
||||||
private final OnCancelListener finishOnCancelListener = new OnCancelListener() {
|
private final OnCancelListener finishOnCancelListener = new OnCancelListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -151,6 +150,18 @@ public class SendActivity extends Activity implements ProgressIndicator {
|
|||||||
tracker.start(getString(R.string.google_analytics_id), getApplicationContext());
|
tracker.start(getString(R.string.google_analytics_id), getApplicationContext());
|
||||||
tracker.setProductVersion("android-mytracks", SystemUtils.getMyTracksVersion(this));
|
tracker.setProductVersion("android-mytracks", SystemUtils.getMyTracksVersion(this));
|
||||||
|
|
||||||
|
if (!handleIntent()) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
restoreInstanceState(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
executeStateMachine(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean handleIntent() {
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
String type = intent.getType();
|
String type = intent.getType();
|
||||||
@@ -159,13 +170,13 @@ public class SendActivity extends Activity implements ProgressIndicator {
|
|||||||
!TracksColumns.CONTENT_ITEMTYPE.equals(type) ||
|
!TracksColumns.CONTENT_ITEMTYPE.equals(type) ||
|
||||||
!UriUtils.matchesContentUri(data, TracksColumns.CONTENT_URI)) {
|
!UriUtils.matchesContentUri(data, TracksColumns.CONTENT_URI)) {
|
||||||
Log.e(TAG, "Got bad send intent: " + intent);
|
Log.e(TAG, "Got bad send intent: " + intent);
|
||||||
finish();
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendTrackId = ContentUris.parseId(data);
|
sendTrackId = ContentUris.parseId(data);
|
||||||
|
shareRequested = intent.getBooleanExtra(EXTRA_SHARE_LINK, false);
|
||||||
|
|
||||||
executeState(SendState.SEND_OPTIONS);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -201,6 +212,42 @@ public class SendActivity extends Activity implements ProgressIndicator {
|
|||||||
return sendDialog;
|
return sendDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void restoreInstanceState(Bundle savedInstanceState) {
|
||||||
|
currentState = SendState.values()[savedInstanceState.getInt("state")];
|
||||||
|
|
||||||
|
sendToMyMapsSuccess = savedInstanceState.getBoolean("mapsSuccess");
|
||||||
|
sendToFusionTablesSuccess = savedInstanceState.getBoolean("fusionSuccess");
|
||||||
|
sendToDocsSuccess = savedInstanceState.getBoolean("docsSuccess");
|
||||||
|
|
||||||
|
sendToMyMapsMessage = savedInstanceState.getString("mapsMsg");
|
||||||
|
sendToFusionTablesMessage = savedInstanceState.getString("fusionMsg");
|
||||||
|
sendToDocsMessage = savedInstanceState.getString("docsMsg");
|
||||||
|
|
||||||
|
sendToMyMapsMapId = savedInstanceState.getString("mapId");
|
||||||
|
sendToFusionTablesTableId = savedInstanceState.getString("tableId");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
|
outState.putInt("state", currentState.ordinal());
|
||||||
|
|
||||||
|
outState.putBoolean("mapsSuccess", sendToMyMapsSuccess);
|
||||||
|
outState.putBoolean("fusionSuccess", sendToFusionTablesSuccess);
|
||||||
|
outState.putBoolean("docsSuccess", sendToDocsSuccess);
|
||||||
|
|
||||||
|
outState.putString("mapsMsg", sendToMyMapsMessage);
|
||||||
|
outState.putString("fusionMsg", sendToFusionTablesMessage);
|
||||||
|
outState.putString("docsMsg", sendToDocsMessage);
|
||||||
|
|
||||||
|
outState.putString("mapId", sendToMyMapsMapId);
|
||||||
|
outState.putString("tableId", sendToFusionTablesTableId);
|
||||||
|
|
||||||
|
// TODO: Ideally we should serialize/restore the authenticator map and lastAuth somehow,
|
||||||
|
// but it's highly unlikely we'll get killed while an auth dialog is displayed.
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
Log.d(TAG, "SendActivity.onStop" + currentState);
|
Log.d(TAG, "SendActivity.onStop" + currentState);
|
||||||
|
|||||||
Reference in New Issue
Block a user