forked from upstream-mirrors/OpenTracks
Use external storage directory display name rather than the actual path.
This commit is contained in:
@@ -171,7 +171,7 @@ public class ExportDialogFragment extends DialogFragment {
|
||||
*/
|
||||
private void setExternalStorageOption(RadioButton radioButton, TrackFileFormat trackFileFormat) {
|
||||
radioButton.setText(getString(R.string.export_external_storage_option, trackFileFormat.name(),
|
||||
FileUtils.getDisplayDirectory(trackFileFormat.getExtension())));
|
||||
FileUtils.getDirectoryDisplayName(trackFileFormat.getExtension())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,7 +92,7 @@ public class FileTypeDialogFragment extends DialogFragment {
|
||||
for (int i = 0; i < choices.length; i++) {
|
||||
TrackFileFormat trackFileFormat = trackFileFormats[i];
|
||||
choices[i] = getString(optionId, trackFileFormat.name(),
|
||||
FileUtils.getDisplayDirectory(trackFileFormat.getExtension()));
|
||||
FileUtils.getDirectoryDisplayName(trackFileFormat.getExtension()));
|
||||
}
|
||||
return new AlertDialog.Builder(getActivity()).setNegativeButton(R.string.generic_cancel, null)
|
||||
.setPositiveButton(R.string.generic_ok, new OnClickListener() {
|
||||
|
||||
@@ -86,8 +86,8 @@ class ExternalFileBackup {
|
||||
* @param create whether to try creating the directory if it doesn't exist
|
||||
*/
|
||||
private File getBackupsDirectory(boolean create) {
|
||||
String dirName = FileUtils.buildExternalDirectoryPath(BACKUPS_SUBDIR);
|
||||
final File dir = new File(dirName);
|
||||
String directoryPath = FileUtils.getDirectoryPath(BACKUPS_SUBDIR);
|
||||
final File dir = new File(directoryPath);
|
||||
Log.d(Constants.TAG, "Dir: " + dir.getAbsolutePath());
|
||||
if (create) {
|
||||
// Try to create - if that fails, return null
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ImportActivity extends Activity {
|
||||
private TrackFileFormat trackFileFormat;
|
||||
|
||||
// the path on the external storage to import
|
||||
private String path;
|
||||
private String directoryDisplayName;
|
||||
|
||||
// the number of files successfully imported
|
||||
private int successCount;
|
||||
@@ -86,10 +86,14 @@ public class ImportActivity extends Activity {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
String directoryPath;
|
||||
if (importAll) {
|
||||
path = FileUtils.buildExternalDirectoryPath(trackFileFormat.getExtension());
|
||||
if (!FileUtils.isDirectory(new File(path))) {
|
||||
Toast.makeText(this, getString(R.string.import_no_directory, path), Toast.LENGTH_LONG)
|
||||
directoryDisplayName = FileUtils.getDirectoryDisplayName(
|
||||
trackFileFormat.getExtension());
|
||||
directoryPath = FileUtils.getDirectoryPath(trackFileFormat.getExtension());
|
||||
if (!FileUtils.isDirectory(new File(directoryPath))) {
|
||||
Toast.makeText(
|
||||
this, getString(R.string.import_no_directory, directoryDisplayName), Toast.LENGTH_LONG)
|
||||
.show();
|
||||
finish();
|
||||
return;
|
||||
@@ -108,7 +112,8 @@ public class ImportActivity extends Activity {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
path = data.getPath();
|
||||
directoryDisplayName = data.getPath();
|
||||
directoryPath = data.getPath();
|
||||
}
|
||||
|
||||
Object retained = getLastNonConfigurationInstance();
|
||||
@@ -116,7 +121,7 @@ public class ImportActivity extends Activity {
|
||||
importAsyncTask = (ImportAsyncTask) retained;
|
||||
importAsyncTask.setActivity(this);
|
||||
} else {
|
||||
importAsyncTask = new ImportAsyncTask(this, importAll, trackFileFormat, path);
|
||||
importAsyncTask = new ImportAsyncTask(this, importAll, trackFileFormat, directoryPath);
|
||||
importAsyncTask.execute();
|
||||
}
|
||||
}
|
||||
@@ -139,7 +144,7 @@ public class ImportActivity extends Activity {
|
||||
dialog.dismiss();
|
||||
finish();
|
||||
}
|
||||
}, path);
|
||||
}, directoryDisplayName);
|
||||
return progressDialog;
|
||||
case DIALOG_RESULT_ID:
|
||||
final boolean success;
|
||||
@@ -148,10 +153,10 @@ public class ImportActivity extends Activity {
|
||||
.getQuantityString(R.plurals.files, totalCount, totalCount);
|
||||
if (successCount == totalCount && totalCount > 0) {
|
||||
success = true;
|
||||
message = getString(R.string.import_success, totalFiles, path);
|
||||
message = getString(R.string.import_success, totalFiles, directoryDisplayName);
|
||||
} else {
|
||||
success = false;
|
||||
message = getString(R.string.import_error, successCount, totalFiles, path);
|
||||
message = getString(R.string.import_error, successCount, totalFiles, directoryDisplayName);
|
||||
}
|
||||
return new AlertDialog.Builder(this).setCancelable(true).setIcon(
|
||||
success ? android.R.drawable.ic_dialog_info : android.R.drawable.ic_dialog_alert)
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SaveActivity extends Activity {
|
||||
private TrackFileFormat trackFileFormat;
|
||||
private long[] trackIds;
|
||||
private boolean playTrack;
|
||||
private String directoryName;
|
||||
private String directoryDisplayName;
|
||||
|
||||
private SaveAsyncTask saveAsyncTask;
|
||||
private ProgressDialog progressDialog;
|
||||
@@ -80,11 +80,14 @@ public class SaveActivity extends Activity {
|
||||
return;
|
||||
}
|
||||
|
||||
directoryName = playTrack ? FileUtils.buildExternalDirectoryPath(
|
||||
directoryDisplayName = playTrack ? FileUtils.getDirectoryDisplayName(
|
||||
trackFileFormat.getExtension(), FileUtils.TEMP_DIR)
|
||||
: FileUtils.buildExternalDirectoryPath(trackFileFormat.getExtension());
|
||||
: FileUtils.getDirectoryDisplayName(trackFileFormat.getExtension());
|
||||
|
||||
File directory = new File(directoryName);
|
||||
String directoryPath = playTrack ? FileUtils.getDirectoryPath(
|
||||
trackFileFormat.getExtension(), FileUtils.TEMP_DIR)
|
||||
: FileUtils.getDirectoryPath(trackFileFormat.getExtension());
|
||||
File directory = new File(directoryPath);
|
||||
if (!FileUtils.ensureDirectoryExists(directory)) {
|
||||
Toast.makeText(this, R.string.external_storage_not_writable, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
@@ -120,7 +123,7 @@ public class SaveActivity extends Activity {
|
||||
dialog.dismiss();
|
||||
finish();
|
||||
}
|
||||
}, directoryName);
|
||||
}, directoryDisplayName);
|
||||
return progressDialog;
|
||||
case DIALOG_RESULT_ID:
|
||||
boolean success;
|
||||
@@ -129,11 +132,11 @@ public class SaveActivity extends Activity {
|
||||
.getQuantityString(R.plurals.tracks, totalCount, totalCount);
|
||||
if (successCount == totalCount && totalCount > 0) {
|
||||
success = true;
|
||||
message = getString(R.string.export_external_storage_success, totalTracks, directoryName);
|
||||
message = getString(R.string.export_external_storage_success, totalTracks, directoryDisplayName);
|
||||
} else {
|
||||
success = false;
|
||||
message = getString(
|
||||
R.string.export_external_storage_error, successCount, totalTracks, directoryName);
|
||||
R.string.export_external_storage_error, successCount, totalTracks, directoryDisplayName);
|
||||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this).setCancelable(true).setIcon(
|
||||
success ? android.R.drawable.ic_dialog_info : android.R.drawable.ic_dialog_alert)
|
||||
|
||||
@@ -91,7 +91,7 @@ public class RemoveTempFilesService extends Service {
|
||||
}
|
||||
|
||||
private void cleanTempDirectory(String name) {
|
||||
cleanTempDirectory(new File(FileUtils.buildExternalDirectoryPath(name, FileUtils.TEMP_DIR)));
|
||||
cleanTempDirectory(new File(FileUtils.getDirectoryPath(name, FileUtils.TEMP_DIR)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -87,10 +87,11 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display directory.
|
||||
* Gets the directory display name.
|
||||
*
|
||||
* @param components the components
|
||||
*/
|
||||
public static String getDisplayDirectory(String... components) {
|
||||
public static String getDirectoryDisplayName(String... components) {
|
||||
StringBuilder dirNameBuilder = new StringBuilder();
|
||||
dirNameBuilder.append(File.separatorChar);
|
||||
dirNameBuilder.append(SDCARD_TOP_DIR);
|
||||
@@ -101,20 +102,14 @@ public class FileUtils {
|
||||
return dirNameBuilder.toString();
|
||||
}
|
||||
/**
|
||||
* Builds a path inside the My Tracks directory in the SD card.
|
||||
* Gets the directory path.
|
||||
*
|
||||
* @param components the path components inside the mytracks directory
|
||||
* @return the full path to the destination
|
||||
* @param components the components
|
||||
*/
|
||||
public static String buildExternalDirectoryPath(String... components) {
|
||||
public static String getDirectoryPath(String... components) {
|
||||
StringBuilder dirNameBuilder = new StringBuilder();
|
||||
dirNameBuilder.append(Environment.getExternalStorageDirectory());
|
||||
dirNameBuilder.append(File.separatorChar);
|
||||
dirNameBuilder.append(SDCARD_TOP_DIR);
|
||||
for (String component : components) {
|
||||
dirNameBuilder.append(File.separatorChar);
|
||||
dirNameBuilder.append(component);
|
||||
}
|
||||
dirNameBuilder.append(getDirectoryDisplayName(components));
|
||||
return dirNameBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user