mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
After exporting to external storage, add option to share the file.
This commit is contained in:
@@ -44,7 +44,6 @@ public class SaveActivity extends Activity {
|
||||
public static final String EXTRA_TRACK_FILE_FORMAT = "track_file_format";
|
||||
public static final String EXTRA_TRACK_IDS = "track_ids";
|
||||
public static final String EXTRA_PLAY_TRACK = "play_track";
|
||||
public static final String EXTRA_SHARE_TRACK = "share_track";
|
||||
|
||||
private static final int DIALOG_PROGRESS_ID = 0;
|
||||
private static final int DIALOG_RESULT_ID = 1;
|
||||
@@ -52,7 +51,6 @@ public class SaveActivity extends Activity {
|
||||
private TrackFileFormat trackFileFormat;
|
||||
private long[] trackIds;
|
||||
private boolean playTrack;
|
||||
private boolean shareTrack;
|
||||
private String directoryName;
|
||||
|
||||
private SaveAsyncTask saveAsyncTask;
|
||||
@@ -64,6 +62,9 @@ public class SaveActivity extends Activity {
|
||||
// the number of tracks to save
|
||||
private int totalCount;
|
||||
|
||||
// the last successfully saved path
|
||||
private String savedPath;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -72,7 +73,6 @@ public class SaveActivity extends Activity {
|
||||
trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT);
|
||||
trackIds = intent.getLongArrayExtra(EXTRA_TRACK_IDS);
|
||||
playTrack = intent.getBooleanExtra(EXTRA_PLAY_TRACK, false);
|
||||
shareTrack = intent.getBooleanExtra(EXTRA_SHARE_TRACK, false);
|
||||
|
||||
if (!FileUtils.isExternalStorageWriteable()) {
|
||||
Toast.makeText(this, R.string.external_storage_not_writable, Toast.LENGTH_LONG).show();
|
||||
@@ -80,7 +80,7 @@ public class SaveActivity extends Activity {
|
||||
return;
|
||||
}
|
||||
|
||||
directoryName = playTrack || shareTrack ? FileUtils.buildExternalDirectoryPath(
|
||||
directoryName = playTrack ? FileUtils.buildExternalDirectoryPath(
|
||||
trackFileFormat.getExtension(), "tmp")
|
||||
: FileUtils.buildExternalDirectoryPath(trackFileFormat.getExtension());
|
||||
|
||||
@@ -133,7 +133,7 @@ public class SaveActivity extends Activity {
|
||||
success = false;
|
||||
message = getString(R.string.save_error, successCount, totalTracks, directoryName);
|
||||
}
|
||||
return new AlertDialog.Builder(this).setCancelable(true).setIcon(
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this).setCancelable(true).setIcon(
|
||||
success ? android.R.drawable.ic_dialog_info : android.R.drawable.ic_dialog_alert)
|
||||
.setMessage(message).setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
@@ -147,8 +147,23 @@ public class SaveActivity extends Activity {
|
||||
dialog.dismiss();
|
||||
finish();
|
||||
}
|
||||
}).setTitle(success ? R.string.generic_success_title : R.string.generic_error_title)
|
||||
.create();
|
||||
}).setTitle(success ? R.string.generic_success_title : R.string.generic_error_title);
|
||||
if (!playTrack && trackIds.length == 1 && trackIds[0] != -1L && success
|
||||
&& savedPath != null) {
|
||||
builder.setNegativeButton(
|
||||
R.string.share_track_share_file, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = IntentUtils.newShareFileIntent(
|
||||
SaveActivity.this, trackIds[0], savedPath, trackFileFormat);
|
||||
startActivity(
|
||||
Intent.createChooser(intent, getString(R.string.share_track_picker_title)));
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return builder.create();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -159,25 +174,19 @@ public class SaveActivity extends Activity {
|
||||
*
|
||||
* @param aSuccessCount the number of tracks successfully saved
|
||||
* @param aTotalCount the number of tracks to save
|
||||
* @param savedPath the last successfully saved path
|
||||
* @param aSavedPath the last successfully saved path
|
||||
*/
|
||||
public void onAsyncTaskCompleted(int aSuccessCount, int aTotalCount, String savedPath) {
|
||||
public void onAsyncTaskCompleted(int aSuccessCount, int aTotalCount, String aSavedPath) {
|
||||
successCount = aSuccessCount;
|
||||
totalCount = aTotalCount;
|
||||
savedPath = aSavedPath;
|
||||
removeDialog(DIALOG_PROGRESS_ID);
|
||||
if (successCount == 1 && totalCount == 1 && savedPath != null) {
|
||||
if (playTrack) {
|
||||
startActivity(GoogleEarthUtils.getPlayInEarthIntent(savedPath));
|
||||
finish();
|
||||
return;
|
||||
} else if (shareTrack) {
|
||||
Intent intent = IntentUtils.newShareFileIntent(this, trackIds[0], savedPath, trackFileFormat);
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.share_track_picker_title)));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
if (playTrack && successCount == 1 && totalCount == 1 && savedPath != null) {
|
||||
startActivity(GoogleEarthUtils.getPlayInEarthIntent(savedPath));
|
||||
finish();
|
||||
} else {
|
||||
showDialog(DIALOG_RESULT_ID);
|
||||
}
|
||||
showDialog(DIALOG_RESULT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user