forked from upstream-mirrors/OpenTracks
Moved Import all/Export all functionality to Settings.
This commit is contained in:
@@ -128,7 +128,7 @@ limitations under the License.
|
|||||||
android:name="android.app.default_searchable"
|
android:name="android.app.default_searchable"
|
||||||
android:value=".SearchListActivity" />
|
android:value=".SearchListActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".io.file.exporter.SaveActivity" />
|
<activity android:name=".io.file.exporter.ExportActivity" />
|
||||||
<activity android:name=".settings.RecordingSettingsActivity" />
|
<activity android:name=".settings.RecordingSettingsActivity" />
|
||||||
<activity android:name=".settings.SettingsActivity" />
|
<activity android:name=".settings.SettingsActivity" />
|
||||||
<activity android:name=".settings.StatsSettingsActivity" />
|
<activity android:name=".settings.StatsSettingsActivity" />
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import android.content.pm.PackageManager;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -58,11 +57,6 @@ import java.util.Locale;
|
|||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.TracksColumns;
|
import de.dennisguse.opentracks.content.TracksColumns;
|
||||||
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment;
|
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment;
|
||||||
import de.dennisguse.opentracks.fragments.FileTypeDialogFragment;
|
|
||||||
import de.dennisguse.opentracks.fragments.FileTypeDialogFragment.FileTypeCaller;
|
|
||||||
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
|
||||||
import de.dennisguse.opentracks.io.file.exporter.SaveActivity;
|
|
||||||
import de.dennisguse.opentracks.io.file.importer.ImportActivity;
|
|
||||||
import de.dennisguse.opentracks.services.ITrackRecordingService;
|
import de.dennisguse.opentracks.services.ITrackRecordingService;
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||||
import de.dennisguse.opentracks.settings.SettingsActivity;
|
import de.dennisguse.opentracks.settings.SettingsActivity;
|
||||||
@@ -79,7 +73,7 @@ import de.dennisguse.opentracks.util.TrackUtils;
|
|||||||
*
|
*
|
||||||
* @author Leif Hendrik Wilden
|
* @author Leif Hendrik Wilden
|
||||||
*/
|
*/
|
||||||
public class TrackListActivity extends AbstractTrackActivity implements FileTypeCaller, ConfirmDeleteDialogFragment.ConfirmDeleteCaller {
|
public class TrackListActivity extends AbstractTrackActivity implements ConfirmDeleteDialogFragment.ConfirmDeleteCaller {
|
||||||
|
|
||||||
private static final String TAG = TrackListActivity.class.getSimpleName();
|
private static final String TAG = TrackListActivity.class.getSimpleName();
|
||||||
private static final String[] PROJECTION = new String[]{TracksColumns._ID, TracksColumns.NAME,
|
private static final String[] PROJECTION = new String[]{TracksColumns._ID, TracksColumns.NAME,
|
||||||
@@ -175,8 +169,6 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
private MenuItem searchMenuItem;
|
private MenuItem searchMenuItem;
|
||||||
private MenuItem startGpsMenuItem;
|
private MenuItem startGpsMenuItem;
|
||||||
private MenuItem aggregatedStatisticsMenuItem;
|
private MenuItem aggregatedStatisticsMenuItem;
|
||||||
private MenuItem exportAllMenuItem;
|
|
||||||
private MenuItem importAllMenuItem;
|
|
||||||
private MenuItem deleteAllMenuItem;
|
private MenuItem deleteAllMenuItem;
|
||||||
private final OnClickListener stopListener = new OnClickListener() {
|
private final OnClickListener stopListener = new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -391,8 +383,6 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
|
|
||||||
startGpsMenuItem = menu.findItem(R.id.track_list_start_gps);
|
startGpsMenuItem = menu.findItem(R.id.track_list_start_gps);
|
||||||
aggregatedStatisticsMenuItem = menu.findItem(R.id.track_list_aggregated_statistics);
|
aggregatedStatisticsMenuItem = menu.findItem(R.id.track_list_aggregated_statistics);
|
||||||
exportAllMenuItem = menu.findItem(R.id.track_list_export_all);
|
|
||||||
importAllMenuItem = menu.findItem(R.id.track_list_import_all);
|
|
||||||
deleteAllMenuItem = menu.findItem(R.id.track_list_delete_all);
|
deleteAllMenuItem = menu.findItem(R.id.track_list_delete_all);
|
||||||
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
@@ -452,16 +442,6 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
intent = IntentUtils.newIntent(this, AggregatedStatsActivity.class);
|
intent = IntentUtils.newIntent(this, AggregatedStatsActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_list_export_all:
|
|
||||||
FileTypeDialogFragment.newInstance(R.id.track_list_export_all,
|
|
||||||
R.string.export_all_title, R.string.export_all_option)
|
|
||||||
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
|
|
||||||
return true;
|
|
||||||
case R.id.track_list_import_all:
|
|
||||||
FileTypeDialogFragment.newInstance(R.id.track_list_import_all,
|
|
||||||
R.string.import_selection_title, R.string.import_selection_option)
|
|
||||||
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
|
|
||||||
return true;
|
|
||||||
case R.id.track_list_delete_all:
|
case R.id.track_list_delete_all:
|
||||||
deleteTracks(new long[]{-1L});
|
deleteTracks(new long[]{-1L});
|
||||||
return true;
|
return true;
|
||||||
@@ -517,26 +497,6 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFileTypeDone(int menuId, TrackFileFormat trackFileFormat) {
|
|
||||||
Intent intent;
|
|
||||||
switch (menuId) {
|
|
||||||
case R.id.track_list_export_all:
|
|
||||||
intent = IntentUtils.newIntent(this, SaveActivity.class)
|
|
||||||
.putExtra(SaveActivity.EXTRA_TRACK_IDS, new long[]{-1L})
|
|
||||||
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
|
|
||||||
startActivity(intent);
|
|
||||||
break;
|
|
||||||
case R.id.track_list_import_all:
|
|
||||||
intent = IntentUtils.newIntent(this, ImportActivity.class)
|
|
||||||
.putExtra(ImportActivity.EXTRA_IMPORT_ALL, true)
|
|
||||||
.putExtra(ImportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
|
|
||||||
startActivity(intent);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows start up dialogs.
|
* Shows start up dialogs.
|
||||||
*/
|
*/
|
||||||
@@ -575,12 +535,6 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
if (aggregatedStatisticsMenuItem != null) {
|
if (aggregatedStatisticsMenuItem != null) {
|
||||||
aggregatedStatisticsMenuItem.setVisible(hasTrack);
|
aggregatedStatisticsMenuItem.setVisible(hasTrack);
|
||||||
}
|
}
|
||||||
if (exportAllMenuItem != null) {
|
|
||||||
exportAllMenuItem.setVisible(hasTrack && !isRecording);
|
|
||||||
}
|
|
||||||
if (importAllMenuItem != null) {
|
|
||||||
importAllMenuItem.setVisible(!isRecording);
|
|
||||||
}
|
|
||||||
if (deleteAllMenuItem != null) {
|
if (deleteAllMenuItem != null) {
|
||||||
deleteAllMenuItem.setVisible(hasTrack && !isRecording);
|
deleteAllMenuItem.setVisible(hasTrack && !isRecording);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ import android.content.DialogInterface;
|
|||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
||||||
import de.dennisguse.opentracks.util.FileUtils;
|
import de.dennisguse.opentracks.util.FileUtils;
|
||||||
import de.dennisguse.opentracks.R;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A DialogFragment to select a file type, gpx, kml, etc.
|
* A DialogFragment to select a file type, gpx, kml, etc.
|
||||||
@@ -35,14 +35,12 @@ import de.dennisguse.opentracks.R;
|
|||||||
public class FileTypeDialogFragment extends AbstractDialogFragment {
|
public class FileTypeDialogFragment extends AbstractDialogFragment {
|
||||||
|
|
||||||
public static final String FILE_TYPE_DIALOG_TAG = "fileType";
|
public static final String FILE_TYPE_DIALOG_TAG = "fileType";
|
||||||
private static final String KEY_MENU_ID = "menuId";
|
|
||||||
private static final String KEY_TITLE_ID = "titleId";
|
private static final String KEY_TITLE_ID = "titleId";
|
||||||
private static final String KEY_OPTION_ID = "optionId";
|
private static final String KEY_OPTION_ID = "optionId";
|
||||||
private FileTypeCaller caller;
|
private FileTypeCaller caller;
|
||||||
|
|
||||||
public static FileTypeDialogFragment newInstance(int menuId, int titleId, int optionId) {
|
public static FileTypeDialogFragment newInstance(int titleId, int optionId) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putInt(KEY_MENU_ID, menuId);
|
|
||||||
bundle.putInt(KEY_TITLE_ID, titleId);
|
bundle.putInt(KEY_TITLE_ID, titleId);
|
||||||
bundle.putInt(KEY_OPTION_ID, optionId);
|
bundle.putInt(KEY_OPTION_ID, optionId);
|
||||||
|
|
||||||
@@ -65,7 +63,6 @@ public class FileTypeDialogFragment extends AbstractDialogFragment {
|
|||||||
protected Dialog createDialog() {
|
protected Dialog createDialog() {
|
||||||
int optionId = getArguments().getInt(KEY_OPTION_ID);
|
int optionId = getArguments().getInt(KEY_OPTION_ID);
|
||||||
final int titleId = getArguments().getInt(KEY_TITLE_ID);
|
final int titleId = getArguments().getInt(KEY_TITLE_ID);
|
||||||
final int menuId = getArguments().getInt(KEY_MENU_ID);
|
|
||||||
TrackFileFormat[] trackFileFormats = TrackFileFormat.values();
|
TrackFileFormat[] trackFileFormats = TrackFileFormat.values();
|
||||||
String[] choices = new String[trackFileFormats.length];
|
String[] choices = new String[trackFileFormats.length];
|
||||||
for (int i = 0; i < choices.length; i++) {
|
for (int i = 0; i < choices.length; i++) {
|
||||||
@@ -78,7 +75,7 @@ public class FileTypeDialogFragment extends AbstractDialogFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
||||||
caller.onFileTypeDone(menuId, TrackFileFormat.values()[position]);
|
caller.onFileTypeDone(TrackFileFormat.values()[position]);
|
||||||
}
|
}
|
||||||
}).setSingleChoiceItems(choices, 0, null).setTitle(titleId).create();
|
}).setSingleChoiceItems(choices, 0, null).setTitle(titleId).create();
|
||||||
}
|
}
|
||||||
@@ -93,6 +90,6 @@ public class FileTypeDialogFragment extends AbstractDialogFragment {
|
|||||||
/**
|
/**
|
||||||
* Called when file type selection is done.
|
* Called when file type selection is done.
|
||||||
*/
|
*/
|
||||||
void onFileTypeDone(int menuId, TrackFileFormat trackFileFormat);
|
void onFileTypeDone(TrackFileFormat trackFileFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+23
-60
@@ -16,22 +16,22 @@
|
|||||||
|
|
||||||
package de.dennisguse.opentracks.io.file.exporter;
|
package de.dennisguse.opentracks.io.file.exporter;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
|
import de.dennisguse.opentracks.fragments.FileTypeDialogFragment;
|
||||||
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
||||||
import de.dennisguse.opentracks.util.DialogUtils;
|
import de.dennisguse.opentracks.util.DialogUtils;
|
||||||
import de.dennisguse.opentracks.util.FileUtils;
|
import de.dennisguse.opentracks.util.FileUtils;
|
||||||
import de.dennisguse.opentracks.util.IntentUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An activity for saving tracks to the external storage. If saving a specific
|
* An activity for saving tracks to the external storage. If saving a specific
|
||||||
@@ -39,20 +39,11 @@ import de.dennisguse.opentracks.util.IntentUtils;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class SaveActivity extends Activity {
|
public class ExportActivity extends FragmentActivity implements FileTypeDialogFragment.FileTypeCaller {
|
||||||
|
|
||||||
public static final String EXTRA_TRACK_FILE_FORMAT = "track_file_format";
|
|
||||||
public static final String EXTRA_TRACK_IDS = "track_ids";
|
|
||||||
|
|
||||||
@Deprecated //TODO Seems to be a left over from Google Earth integration and can be removed.
|
|
||||||
public static final String EXTRA_PLAY_TRACK = "play_track";
|
|
||||||
|
|
||||||
private static final int DIALOG_PROGRESS_ID = 0;
|
private static final int DIALOG_PROGRESS_ID = 0;
|
||||||
private static final int DIALOG_RESULT_ID = 1;
|
private static final int DIALOG_RESULT_ID = 1;
|
||||||
|
|
||||||
private TrackFileFormat trackFileFormat;
|
|
||||||
private long[] trackIds;
|
|
||||||
private boolean playTrack;
|
|
||||||
private String directoryDisplayName;
|
private String directoryDisplayName;
|
||||||
|
|
||||||
private SaveAsyncTask saveAsyncTask;
|
private SaveAsyncTask saveAsyncTask;
|
||||||
@@ -64,53 +55,41 @@ public class SaveActivity extends Activity {
|
|||||||
// the number of tracks to save
|
// the number of tracks to save
|
||||||
private int totalCount;
|
private int totalCount;
|
||||||
|
|
||||||
// the last successfully saved path
|
|
||||||
private String savedPath;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Intent intent = getIntent();
|
FileTypeDialogFragment
|
||||||
trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT);
|
.newInstance(R.string.export_all_title, R.string.export_all_option)
|
||||||
trackIds = intent.getLongArrayExtra(EXTRA_TRACK_IDS);
|
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
|
||||||
playTrack = intent.getBooleanExtra(EXTRA_PLAY_TRACK, false);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFileTypeDone(TrackFileFormat trackFileFormat) {
|
||||||
if (!FileUtils.isExternalStorageWriteable()) {
|
if (!FileUtils.isExternalStorageWriteable()) {
|
||||||
Toast.makeText(this, R.string.external_storage_not_writable, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.external_storage_not_writable, Toast.LENGTH_LONG).show();
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File directory = playTrack ? new File(getCacheDir(), FileUtils.PLAY_TRACKS_DIR) : new File(FileUtils.getPath(trackFileFormat.getExtension()));
|
File directory = new File(FileUtils.getPath(trackFileFormat.getExtension()));
|
||||||
if (!FileUtils.ensureDirectoryExists(directory)) {
|
if (!FileUtils.ensureDirectoryExists(directory)) {
|
||||||
Toast.makeText(this, R.string.external_storage_not_writable, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.external_storage_not_writable, Toast.LENGTH_LONG).show();
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playTrack) {
|
directoryDisplayName = FileUtils.getPathDisplayName(trackFileFormat.getExtension());
|
||||||
for (File file : directory.listFiles()) {
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
directoryDisplayName = playTrack ? directory.getName() : FileUtils.getPathDisplayName(trackFileFormat.getExtension());
|
//TODO (still needed?): getLastNonConfiguration instance returned SaveAsyncTask before
|
||||||
|
// Object retained = getLastNonConfigurationInstance();
|
||||||
Object retained = getLastNonConfigurationInstance();
|
// if (retained instanceof SaveAsyncTask) {
|
||||||
if (retained instanceof SaveAsyncTask) {
|
// saveAsyncTask = (SaveAsyncTask) retained;
|
||||||
saveAsyncTask = (SaveAsyncTask) retained;
|
// saveAsyncTask.setActivity(this);
|
||||||
saveAsyncTask.setActivity(this);
|
// } else {
|
||||||
} else {
|
saveAsyncTask = new SaveAsyncTask(this, trackFileFormat, directory);
|
||||||
saveAsyncTask = new SaveAsyncTask(this, trackIds, trackFileFormat, directory);
|
saveAsyncTask.execute();
|
||||||
saveAsyncTask.execute();
|
// }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object onRetainNonConfigurationInstance() {
|
|
||||||
saveAsyncTask.setActivity(null);
|
|
||||||
return saveAsyncTask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -159,26 +138,12 @@ public class SaveActivity extends Activity {
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}).setTitle(titleId);
|
}).setTitle(titleId);
|
||||||
if (!playTrack && trackIds.length == 1 && trackIds[0] != -1L && successCount == totalCount
|
|
||||||
&& 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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
final Dialog dialog = builder.create();
|
final Dialog dialog = builder.create();
|
||||||
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onShow(DialogInterface dialogInterface) {
|
public void onShow(DialogInterface dialogInterface) {
|
||||||
DialogUtils.setDialogTitleDivider(SaveActivity.this, dialog);
|
DialogUtils.setDialogTitleDivider(ExportActivity.this, dialog);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return dialog;
|
return dialog;
|
||||||
@@ -192,12 +157,10 @@ public class SaveActivity extends Activity {
|
|||||||
*
|
*
|
||||||
* @param aSuccessCount the number of tracks successfully saved
|
* @param aSuccessCount the number of tracks successfully saved
|
||||||
* @param aTotalCount the number of tracks to save
|
* @param aTotalCount the number of tracks to save
|
||||||
* @param aSavedPath the last successfully saved path
|
|
||||||
*/
|
*/
|
||||||
public void onAsyncTaskCompleted(int aSuccessCount, int aTotalCount, String aSavedPath) {
|
public void onAsyncTaskCompleted(int aSuccessCount, int aTotalCount) {
|
||||||
successCount = aSuccessCount;
|
successCount = aSuccessCount;
|
||||||
totalCount = aTotalCount;
|
totalCount = aTotalCount;
|
||||||
savedPath = aSavedPath;
|
|
||||||
removeDialog(DIALOG_PROGRESS_ID);
|
removeDialog(DIALOG_PROGRESS_ID);
|
||||||
showDialog(DIALOG_RESULT_ID);
|
showDialog(DIALOG_RESULT_ID);
|
||||||
}
|
}
|
||||||
@@ -44,12 +44,11 @@ import de.dennisguse.opentracks.util.SystemUtils;
|
|||||||
public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||||
|
|
||||||
private static final String TAG = SaveAsyncTask.class.getSimpleName();
|
private static final String TAG = SaveAsyncTask.class.getSimpleName();
|
||||||
private final long[] trackIds;
|
|
||||||
private final TrackFileFormat trackFileFormat;
|
private final TrackFileFormat trackFileFormat;
|
||||||
private final File directory;
|
private final File directory;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final ContentProviderUtils contentProviderUtils;
|
private final ContentProviderUtils contentProviderUtils;
|
||||||
private SaveActivity saveActivity;
|
private ExportActivity exportActivity;
|
||||||
private WakeLock wakeLock;
|
private WakeLock wakeLock;
|
||||||
|
|
||||||
// true if the AsyncTask has completed
|
// true if the AsyncTask has completed
|
||||||
@@ -67,18 +66,15 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
/**
|
/**
|
||||||
* Creates an AsyncTask.
|
* Creates an AsyncTask.
|
||||||
*
|
*
|
||||||
* @param saveActivity the activity currently associated with this task
|
* @param exportActivity the activity currently associated with this task
|
||||||
* @param trackIds the track ids to save. To save all, set to size 1 with
|
|
||||||
* trackIds[0] == -1L
|
|
||||||
* @param trackFileFormat the track file format
|
* @param trackFileFormat the track file format
|
||||||
* @param directory the directory to write the file
|
* @param directory the directory to write the file
|
||||||
*/
|
*/
|
||||||
public SaveAsyncTask(SaveActivity saveActivity, long[] trackIds, TrackFileFormat trackFileFormat, File directory) {
|
public SaveAsyncTask(ExportActivity exportActivity, TrackFileFormat trackFileFormat, File directory) {
|
||||||
this.saveActivity = saveActivity;
|
this.exportActivity = exportActivity;
|
||||||
this.trackIds = trackIds;
|
|
||||||
this.trackFileFormat = trackFileFormat;
|
this.trackFileFormat = trackFileFormat;
|
||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
context = saveActivity.getApplicationContext();
|
context = exportActivity.getApplicationContext();
|
||||||
contentProviderUtils = ContentProviderUtils.Factory.get(context);
|
contentProviderUtils = ContentProviderUtils.Factory.get(context);
|
||||||
|
|
||||||
completed = false;
|
completed = false;
|
||||||
@@ -90,19 +86,19 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
/**
|
/**
|
||||||
* Sets the current activity associated with this AsyncTask.
|
* Sets the current activity associated with this AsyncTask.
|
||||||
*
|
*
|
||||||
* @param saveActivity the current activity, can be null
|
* @param exportActivity the current activity, can be null
|
||||||
*/
|
*/
|
||||||
public void setActivity(SaveActivity saveActivity) {
|
public void setActivity(ExportActivity exportActivity) {
|
||||||
this.saveActivity = saveActivity;
|
this.exportActivity = exportActivity;
|
||||||
if (completed && saveActivity != null) {
|
if (completed && exportActivity != null) {
|
||||||
saveActivity.onAsyncTaskCompleted(successCount, totalCount, savedPath);
|
exportActivity.onAsyncTaskCompleted(successCount, totalCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
if (saveActivity != null) {
|
if (exportActivity != null) {
|
||||||
saveActivity.showProgressDialog();
|
exportActivity.showProgressDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,31 +106,13 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
protected Boolean doInBackground(Void... params) {
|
protected Boolean doInBackground(Void... params) {
|
||||||
try {
|
try {
|
||||||
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
|
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
|
||||||
boolean isRecording = PreferencesUtils.getLong(saveActivity, R.string.recording_track_id_key) != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
boolean isRecording = PreferencesUtils.getLong(exportActivity, R.string.recording_track_id_key) != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||||
boolean isPaused = PreferencesUtils.getBoolean(saveActivity, R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
boolean isPaused = PreferencesUtils.getBoolean(exportActivity, R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
||||||
// Get the wake lock if not recording or paused
|
// Get the wake lock if not recording or paused
|
||||||
if (!isRecording || isPaused) {
|
if (!isRecording || isPaused) {
|
||||||
wakeLock = SystemUtils.acquireWakeLock(saveActivity, wakeLock);
|
wakeLock = SystemUtils.acquireWakeLock(exportActivity, wakeLock);
|
||||||
}
|
|
||||||
if (trackIds.length == 1 && trackIds[0] == -1L) {
|
|
||||||
return saveAllTracks();
|
|
||||||
} else {
|
|
||||||
totalCount = 1;
|
|
||||||
Track[] tracks = new Track[trackIds.length];
|
|
||||||
for (int i = 0; i < trackIds.length; i++) {
|
|
||||||
tracks[i] = contentProviderUtils.getTrack(trackIds[i]);
|
|
||||||
if (tracks[i] == null) {
|
|
||||||
Log.d(TAG, "No track for " + trackIds[i]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (saveTracks(tracks)) {
|
|
||||||
successCount = 1;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return saveAllTracks();
|
||||||
} finally {
|
} finally {
|
||||||
if (wakeLock != null && wakeLock.isHeld()) {
|
if (wakeLock != null && wakeLock.isHeld()) {
|
||||||
wakeLock.release();
|
wakeLock.release();
|
||||||
@@ -144,24 +122,24 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onProgressUpdate(Integer... values) {
|
protected void onProgressUpdate(Integer... values) {
|
||||||
if (saveActivity != null) {
|
if (exportActivity != null) {
|
||||||
saveActivity.setProgressDialogValue(values[0], values[1]);
|
exportActivity.setProgressDialogValue(values[0], values[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Boolean result) {
|
protected void onPostExecute(Boolean result) {
|
||||||
completed = true;
|
completed = true;
|
||||||
if (saveActivity != null) {
|
if (exportActivity != null) {
|
||||||
saveActivity.onAsyncTaskCompleted(successCount, totalCount, savedPath);
|
exportActivity.onAsyncTaskCompleted(successCount, totalCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCancelled() {
|
protected void onCancelled() {
|
||||||
completed = true;
|
completed = true;
|
||||||
if (saveActivity != null) {
|
if (exportActivity != null) {
|
||||||
saveActivity.onAsyncTaskCompleted(successCount, totalCount, null);
|
exportActivity.onAsyncTaskCompleted(successCount, totalCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,14 +157,10 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
FileTrackExporter fileTrackExporter = new FileTrackExporter(contentProviderUtils, tracks,
|
FileTrackExporter fileTrackExporter = new FileTrackExporter(contentProviderUtils, tracks,
|
||||||
trackFileFormat.newTrackWriter(context, tracks.length > 1),
|
trackFileFormat.newTrackWriter(context, tracks.length > 1),
|
||||||
new TrackExporterListener() {
|
new TrackExporterListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgressUpdate(int number, int max) {
|
public void onProgressUpdate(int number, int max) {
|
||||||
/*
|
//Update the progress dialog once every 500 points.
|
||||||
* If only saving one track, update the progress dialog once every
|
if (number % 500 == 0) {
|
||||||
* 500 points
|
|
||||||
*/
|
|
||||||
if (trackIds.length == 1 && trackIds[0] != -1L && number % 500 == 0) {
|
|
||||||
publishProgress(number, max);
|
publishProgress(number, max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,27 +16,23 @@
|
|||||||
|
|
||||||
package de.dennisguse.opentracks.io.file.importer;
|
package de.dennisguse.opentracks.io.file.importer;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.core.app.TaskStackBuilder;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.TrackDetailActivity;
|
import java.io.File;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.R;
|
||||||
|
import de.dennisguse.opentracks.fragments.FileTypeDialogFragment;
|
||||||
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
||||||
import de.dennisguse.opentracks.util.DialogUtils;
|
import de.dennisguse.opentracks.util.DialogUtils;
|
||||||
import de.dennisguse.opentracks.util.FileUtils;
|
import de.dennisguse.opentracks.util.FileUtils;
|
||||||
import de.dennisguse.opentracks.util.IntentUtils;
|
|
||||||
import de.dennisguse.opentracks.R;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An activity to import files from the external storage. Optionally to import
|
* An activity to import files from the external storage. Optionally to import
|
||||||
@@ -44,10 +40,7 @@ import java.io.File;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class ImportActivity extends Activity {
|
public class ImportActivity extends FragmentActivity implements FileTypeDialogFragment.FileTypeCaller {
|
||||||
|
|
||||||
public static final String EXTRA_IMPORT_ALL = "import_all";
|
|
||||||
public static final String EXTRA_TRACK_FILE_FORMAT = "track_file_format";
|
|
||||||
|
|
||||||
private static final String TAG = ImportActivity.class.getSimpleName();
|
private static final String TAG = ImportActivity.class.getSimpleName();
|
||||||
private static final int DIALOG_PROGRESS_ID = 0;
|
private static final int DIALOG_PROGRESS_ID = 0;
|
||||||
@@ -56,8 +49,6 @@ public class ImportActivity extends Activity {
|
|||||||
private ImportAsyncTask importAsyncTask;
|
private ImportAsyncTask importAsyncTask;
|
||||||
private ProgressDialog progressDialog;
|
private ProgressDialog progressDialog;
|
||||||
|
|
||||||
private boolean importAll;
|
|
||||||
|
|
||||||
// the path on the external storage to import
|
// the path on the external storage to import
|
||||||
private String directoryDisplayName;
|
private String directoryDisplayName;
|
||||||
|
|
||||||
@@ -67,16 +58,19 @@ public class ImportActivity extends Activity {
|
|||||||
// the number of files to import
|
// the number of files to import
|
||||||
private int totalCount;
|
private int totalCount;
|
||||||
|
|
||||||
// the last successfully imported track id
|
|
||||||
private long trackId;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
FileTypeDialogFragment
|
||||||
|
.newInstance(R.string.import_selection_title, R.string.import_selection_option)
|
||||||
|
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFileTypeDone(TrackFileFormat trackFileFormat) {
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
importAll = intent.getBooleanExtra(EXTRA_IMPORT_ALL, false);
|
|
||||||
TrackFileFormat trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT);
|
|
||||||
if (trackFileFormat == null) {
|
if (trackFileFormat == null) {
|
||||||
trackFileFormat = TrackFileFormat.GPX;
|
trackFileFormat = TrackFileFormat.GPX;
|
||||||
}
|
}
|
||||||
@@ -86,49 +80,26 @@ public class ImportActivity extends Activity {
|
|||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String directoryPath;
|
|
||||||
if (importAll) {
|
|
||||||
directoryDisplayName = FileUtils.getPathDisplayName(trackFileFormat.getExtension());
|
|
||||||
directoryPath = FileUtils.getPath(trackFileFormat.getExtension());
|
|
||||||
if (!FileUtils.isDirectory(new File(directoryPath))) {
|
|
||||||
Toast.makeText(
|
|
||||||
this, getString(R.string.import_no_directory, directoryDisplayName), Toast.LENGTH_LONG)
|
|
||||||
.show();
|
|
||||||
finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String action = intent.getAction();
|
|
||||||
if (!(Intent.ACTION_ATTACH_DATA.equals(action) || Intent.ACTION_VIEW.equals(action))) {
|
|
||||||
Log.d(TAG, "Invalid action: " + intent);
|
|
||||||
finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uri data = intent.getData();
|
directoryDisplayName = FileUtils.getPathDisplayName(trackFileFormat.getExtension());
|
||||||
if ("file".equals(data.getScheme())) {
|
String directoryPath = FileUtils.getPath(trackFileFormat.getExtension());
|
||||||
Log.d(TAG, "Invalid data: " + intent);
|
if (!FileUtils.isDirectory(new File(directoryPath))) {
|
||||||
finish();
|
Toast.makeText(
|
||||||
return;
|
this, getString(R.string.import_no_directory, directoryDisplayName), Toast.LENGTH_LONG)
|
||||||
}
|
.show();
|
||||||
directoryDisplayName = data.getPath();
|
finish();
|
||||||
directoryPath = data.getPath();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object retained = getLastNonConfigurationInstance();
|
//TODO (still needed?): getLastNonConfiguration instance returned SaveAsyncTask before
|
||||||
if (retained instanceof ImportAsyncTask) {
|
// Object retained = getLastNonConfigurationInstance();
|
||||||
importAsyncTask = (ImportAsyncTask) retained;
|
// if (retained instanceof ImportAsyncTask) {
|
||||||
importAsyncTask.setActivity(this);
|
// importAsyncTask = (ImportAsyncTask) retained;
|
||||||
} else {
|
// importAsyncTask.setActivity(this);
|
||||||
importAsyncTask = new ImportAsyncTask(this, importAll, trackFileFormat, directoryPath);
|
// } else {
|
||||||
importAsyncTask.execute();
|
importAsyncTask = new ImportAsyncTask(this, trackFileFormat, directoryPath);
|
||||||
}
|
importAsyncTask.execute();
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object onRetainNonConfigurationInstance() {
|
|
||||||
importAsyncTask.setActivity(null);
|
|
||||||
return importAsyncTask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -176,14 +147,6 @@ public class ImportActivity extends Activity {
|
|||||||
}).setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
}).setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialogInterface, int which) {
|
public void onClick(DialogInterface dialogInterface, int which) {
|
||||||
if (successCount == totalCount && !importAll && trackId != -1L) {
|
|
||||||
Intent intent = IntentUtils.newIntent(
|
|
||||||
ImportActivity.this, TrackDetailActivity.class)
|
|
||||||
.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId);
|
|
||||||
TaskStackBuilder.create(ImportActivity.this)
|
|
||||||
.addParentStack(TrackDetailActivity.class).addNextIntent(intent)
|
|
||||||
.startActivities();
|
|
||||||
}
|
|
||||||
dialogInterface.dismiss();
|
dialogInterface.dismiss();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
@@ -206,12 +169,10 @@ public class ImportActivity extends Activity {
|
|||||||
*
|
*
|
||||||
* @param aSuccessCount the number of files successfully imported
|
* @param aSuccessCount the number of files successfully imported
|
||||||
* @param aTotalCount the number of files to import
|
* @param aTotalCount the number of files to import
|
||||||
* @param aTrackId the last successfully imported track id
|
|
||||||
*/
|
*/
|
||||||
public void onAsyncTaskCompleted(int aSuccessCount, int aTotalCount, long aTrackId) {
|
public void onAsyncTaskCompleted(int aSuccessCount, int aTotalCount) {
|
||||||
successCount = aSuccessCount;
|
successCount = aSuccessCount;
|
||||||
totalCount = aTotalCount;
|
totalCount = aTotalCount;
|
||||||
trackId = aTrackId;
|
|
||||||
removeDialog(DIALOG_PROGRESS_ID);
|
removeDialog(DIALOG_PROGRESS_ID);
|
||||||
showDialog(DIALOG_RESULT_ID);
|
showDialog(DIALOG_RESULT_ID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,14 @@ import android.os.AsyncTask;
|
|||||||
import android.os.PowerManager.WakeLock;
|
import android.os.PowerManager.WakeLock;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
import de.dennisguse.opentracks.content.Track;
|
||||||
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
||||||
@@ -29,14 +37,6 @@ import de.dennisguse.opentracks.io.file.exporter.KmzTrackExporter;
|
|||||||
import de.dennisguse.opentracks.util.FileUtils;
|
import de.dennisguse.opentracks.util.FileUtils;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
import de.dennisguse.opentracks.util.SystemUtils;
|
import de.dennisguse.opentracks.util.SystemUtils;
|
||||||
import de.dennisguse.opentracks.R;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AsyncTask to import files from the external storage.
|
* AsyncTask to import files from the external storage.
|
||||||
@@ -46,7 +46,6 @@ import java.util.List;
|
|||||||
public class ImportAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
public class ImportAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||||
|
|
||||||
private static final String TAG = ImportAsyncTask.class.getSimpleName();
|
private static final String TAG = ImportAsyncTask.class.getSimpleName();
|
||||||
private final boolean importAll;
|
|
||||||
private final TrackFileFormat trackFileFormat;
|
private final TrackFileFormat trackFileFormat;
|
||||||
private final String path;
|
private final String path;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
@@ -69,14 +68,11 @@ public class ImportAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
* Creates an AsyncTask.
|
* Creates an AsyncTask.
|
||||||
*
|
*
|
||||||
* @param importActivity the activity currently associated with this AsyncTask
|
* @param importActivity the activity currently associated with this AsyncTask
|
||||||
* @param importAll true to import all GPX files
|
|
||||||
* @param trackFileFormat the track file format
|
* @param trackFileFormat the track file format
|
||||||
* @param path path to import GPX files
|
* @param path path to import GPX files
|
||||||
*/
|
*/
|
||||||
public ImportAsyncTask(ImportActivity importActivity, boolean importAll,
|
public ImportAsyncTask(ImportActivity importActivity, TrackFileFormat trackFileFormat, String path) {
|
||||||
TrackFileFormat trackFileFormat, String path) {
|
|
||||||
this.importActivity = importActivity;
|
this.importActivity = importActivity;
|
||||||
this.importAll = importAll;
|
|
||||||
this.trackFileFormat = trackFileFormat;
|
this.trackFileFormat = trackFileFormat;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
context = importActivity.getApplicationContext();
|
context = importActivity.getApplicationContext();
|
||||||
@@ -95,7 +91,7 @@ public class ImportAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
public void setActivity(ImportActivity importActivity) {
|
public void setActivity(ImportActivity importActivity) {
|
||||||
this.importActivity = importActivity;
|
this.importActivity = importActivity;
|
||||||
if (completed && importActivity != null) {
|
if (completed && importActivity != null) {
|
||||||
importActivity.onAsyncTaskCompleted(successCount, totalCount, trackId);
|
importActivity.onAsyncTaskCompleted(successCount, totalCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +151,7 @@ public class ImportAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
protected void onPostExecute(Boolean result) {
|
protected void onPostExecute(Boolean result) {
|
||||||
completed = true;
|
completed = true;
|
||||||
if (importActivity != null) {
|
if (importActivity != null) {
|
||||||
importActivity.onAsyncTaskCompleted(successCount, totalCount, trackId);
|
importActivity.onAsyncTaskCompleted(successCount, totalCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +159,7 @@ public class ImportAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
protected void onCancelled() {
|
protected void onCancelled() {
|
||||||
completed = true;
|
completed = true;
|
||||||
if (importActivity != null) {
|
if (importActivity != null) {
|
||||||
importActivity.onAsyncTaskCompleted(successCount, totalCount, trackId);
|
importActivity.onAsyncTaskCompleted(successCount, totalCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,26 +211,24 @@ public class ImportAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
private List<File> getFiles() {
|
private List<File> getFiles() {
|
||||||
List<File> files = new ArrayList<>();
|
List<File> files = new ArrayList<>();
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
if (importAll) {
|
|
||||||
File[] candidates = file.listFiles();
|
File[] candidates = file.listFiles();
|
||||||
if (candidates != null) {
|
if (candidates != null) {
|
||||||
for (File candidate : candidates) {
|
for (File candidate : candidates) {
|
||||||
if (!FileUtils.isDirectory(candidate)) {
|
if (!FileUtils.isDirectory(candidate)) {
|
||||||
String extension = FileUtils.getExtension(candidate.getName());
|
String extension = FileUtils.getExtension(candidate.getName());
|
||||||
if (trackFileFormat == TrackFileFormat.KML && (
|
if (trackFileFormat == TrackFileFormat.KML
|
||||||
TrackFileFormat.KML.getExtension().equals(extension)
|
&& (TrackFileFormat.KML.getExtension().equals(extension)
|
||||||
|| KmzTrackExporter.KMZ_EXTENSION.equals(extension))) {
|
|| KmzTrackExporter.KMZ_EXTENSION.equals(extension))) {
|
||||||
files.add(candidate);
|
files.add(candidate);
|
||||||
} else if (trackFileFormat == TrackFileFormat.GPX
|
} else if (trackFileFormat == TrackFileFormat.GPX && TrackFileFormat.GPX.getExtension().equals(extension)) {
|
||||||
&& TrackFileFormat.GPX.getExtension().equals(extension)) {
|
files.add(candidate);
|
||||||
files.add(candidate);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
files.add(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,14 +34,6 @@ limitations under the License.
|
|||||||
android:id="@+id/track_list_aggregated_statistics"
|
android:id="@+id/track_list_aggregated_statistics"
|
||||||
android:icon="@drawable/ic_menu_aggregated_statistics"
|
android:icon="@drawable/ic_menu_aggregated_statistics"
|
||||||
android:title="@string/menu_aggregated_statistics" />
|
android:title="@string/menu_aggregated_statistics" />
|
||||||
<item
|
|
||||||
android:id="@+id/track_list_export_all"
|
|
||||||
android:icon="@drawable/ic_menu_export"
|
|
||||||
android:title="@string/menu_export_all" />
|
|
||||||
<item
|
|
||||||
android:id="@+id/track_list_import_all"
|
|
||||||
android:icon="@drawable/ic_menu_import"
|
|
||||||
android:title="@string/menu_import_all" />
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/track_list_delete_all"
|
android:id="@+id/track_list_delete_all"
|
||||||
android:icon="@drawable/ic_menu_delete"
|
android:icon="@drawable/ic_menu_delete"
|
||||||
|
|||||||
@@ -77,6 +77,19 @@ limitations under the License.
|
|||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
|
<PreferenceCategory android:title="@string/menu_import_all">
|
||||||
|
<Preference android:title="@string/menu_import_all">
|
||||||
|
<intent
|
||||||
|
android:targetClass="de.dennisguse.opentracks.io.file.importer.ImportActivity"
|
||||||
|
android:targetPackage="@string/applicationId" />
|
||||||
|
</Preference>
|
||||||
|
<Preference android:title="@string/menu_export_all">
|
||||||
|
<intent
|
||||||
|
android:targetClass="de.dennisguse.opentracks.io.file.exporter.ExportActivity"
|
||||||
|
android:targetPackage="@string/applicationId" />
|
||||||
|
</Preference>
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/settings_reset">
|
<PreferenceCategory android:title="@string/settings_reset">
|
||||||
<de.dennisguse.opentracks.settings.ResetDialogPreference
|
<de.dennisguse.opentracks.settings.ResetDialogPreference
|
||||||
android:dialogMessage="@string/settings_reset_confirm_message"
|
android:dialogMessage="@string/settings_reset_confirm_message"
|
||||||
|
|||||||
Reference in New Issue
Block a user