Support cases when there is no files to import or export.

This commit is contained in:
Jimmy Shih
2013-06-21 17:22:37 -07:00
parent 9609010906
commit 8bb55ad5db
3 changed files with 63 additions and 25 deletions
+23
View File
@@ -637,6 +637,16 @@ limitations under the License.
%2$s the directory. E.g., '/MyTracks/kml'."> %2$s the directory. E.g., '/MyTracks/kml'.">
Exported %1$d of %2$s to %3$s. Exported %1$d of %2$s to %3$s.
</string> </string>
<string name="export_external_storage_no_track"
translation_description="When exporting tracks to the external storage, the messsage in the
result dialog when there is no tracks to export.">
There is no tracks to export.
</string>
<string name="export_external_storage_no_track_title"
translation_description="When exporting tracks to the external storage, the title in the result
dialog when there is no tracks to export.">
Export tracks
</string>
<string name="export_external_storage_option" <string name="export_external_storage_option"
translation_description="When exporting a track to the external storage, the option to export as translation_description="When exporting a track to the external storage, the option to export as
a certain file format. a certain file format.
@@ -929,6 +939,19 @@ limitations under the License.
%1$s: the directory. E.g., '/MyTracks/kml'."> %1$s: the directory. E.g., '/MyTracks/kml'.">
%1$s does not exist. %1$s does not exist.
</string> </string>
<string name="import_no_file"
translation_description="When importing from the external storage, the message in the result
dialog when there is no files to import.
%1$s: the directory. E.g., '/MyTracks/kml'.">
There were no files to import. Connect your device to your computer and place the files to
import in %1$s.
</string>
<string name="import_no_file_title"
translation_description="When importing from the external storage, the title in the result
dialog when there is no files to import.">
Import files
</string>
<string name="import_progress_message" <string name="import_progress_message"
translation_description="When importing from the external storage, the progress message. translation_description="When importing from the external storage, the progress message.
@@ -147,20 +147,28 @@ public class ImportActivity extends Activity {
}, directoryDisplayName); }, directoryDisplayName);
return progressDialog; return progressDialog;
case DIALOG_RESULT_ID: case DIALOG_RESULT_ID:
final boolean success; int iconId;
int titleId;
String message; String message;
String totalFiles = getResources() String totalFiles = getResources()
.getQuantityString(R.plurals.files, totalCount, totalCount); .getQuantityString(R.plurals.files, totalCount, totalCount);
if (successCount == totalCount && totalCount > 0) { if (successCount == totalCount) {
success = true; iconId = android.R.drawable.ic_dialog_info;
message = getString(R.string.import_success, totalFiles, directoryDisplayName); if (totalCount == 0) {
titleId = R.string.import_no_file_title;
message = getString(R.string.import_no_file, directoryDisplayName);
} else {
titleId = R.string.generic_success_title;
message = getString(R.string.import_success, totalFiles, directoryDisplayName);
}
} else { } else {
success = false; iconId = android.R.drawable.ic_dialog_alert;
message = getString(R.string.import_error, successCount, totalFiles, directoryDisplayName); titleId = R.string.generic_error_title;
message = getString(
R.string.import_error, successCount, totalFiles, directoryDisplayName);
} }
return new AlertDialog.Builder(this).setCancelable(true).setIcon( return new AlertDialog.Builder(this).setCancelable(true).setIcon(iconId).setMessage(message)
success ? android.R.drawable.ic_dialog_info : android.R.drawable.ic_dialog_alert) .setOnCancelListener(new DialogInterface.OnCancelListener() {
.setMessage(message).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override @Override
public void onCancel(DialogInterface dialog) { public void onCancel(DialogInterface dialog) {
dialog.dismiss(); dialog.dismiss();
@@ -169,7 +177,7 @@ 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 dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (success && !importAll && trackId != -1L) { if (successCount == totalCount && !importAll && trackId != -1L) {
Intent intent = IntentUtils.newIntent( Intent intent = IntentUtils.newIntent(
ImportActivity.this, TrackDetailActivity.class) ImportActivity.this, TrackDetailActivity.class)
.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId); .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId);
@@ -180,8 +188,7 @@ public class ImportActivity extends Activity {
dialog.dismiss(); dialog.dismiss();
finish(); finish();
} }
}).setTitle(success ? R.string.generic_success_title : R.string.generic_error_title) }).setTitle(titleId).create();
.create();
default: default:
return null; return null;
} }
@@ -126,21 +126,30 @@ public class SaveActivity extends Activity {
}, directoryDisplayName); }, directoryDisplayName);
return progressDialog; return progressDialog;
case DIALOG_RESULT_ID: case DIALOG_RESULT_ID:
boolean success; int iconId;
int titleId;
String message; String message;
String totalTracks = getResources() String totalTracks = getResources()
.getQuantityString(R.plurals.tracks, totalCount, totalCount); .getQuantityString(R.plurals.tracks, totalCount, totalCount);
if (successCount == totalCount && totalCount > 0) { if (successCount == totalCount) {
success = true; iconId = android.R.drawable.ic_dialog_info;
message = getString(R.string.export_external_storage_success, totalTracks, directoryDisplayName); if (totalCount == 0) {
titleId = R.string.export_external_storage_no_track_title;
message = getString(R.string.export_external_storage_no_track);
} else {
titleId = R.string.generic_success_title;
message = getString(
R.string.export_external_storage_success, totalTracks, directoryDisplayName);
}
} else { } else {
success = false; iconId = android.R.drawable.ic_dialog_alert;
message = getString( titleId = R.string.generic_error_title;
R.string.export_external_storage_error, successCount, totalTracks, directoryDisplayName); message = getString(R.string.export_external_storage_error, successCount, totalTracks,
directoryDisplayName);
} }
AlertDialog.Builder builder = new AlertDialog.Builder(this).setCancelable(true).setIcon( AlertDialog.Builder builder = new AlertDialog.Builder(this).setCancelable(true)
success ? android.R.drawable.ic_dialog_info : android.R.drawable.ic_dialog_alert) .setIcon(iconId).setMessage(message)
.setMessage(message).setOnCancelListener(new DialogInterface.OnCancelListener() { .setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override @Override
public void onCancel(DialogInterface dialog) { public void onCancel(DialogInterface dialog) {
dialog.dismiss(); dialog.dismiss();
@@ -152,8 +161,8 @@ public class SaveActivity extends Activity {
dialog.dismiss(); dialog.dismiss();
finish(); finish();
} }
}).setTitle(success ? R.string.generic_success_title : R.string.generic_error_title); }).setTitle(titleId);
if (!playTrack && trackIds.length == 1 && trackIds[0] != -1L && success if (!playTrack && trackIds.length == 1 && trackIds[0] != -1L && successCount == totalCount
&& savedPath != null) { && savedPath != null) {
builder.setNegativeButton( builder.setNegativeButton(
R.string.share_track_share_file, new DialogInterface.OnClickListener() { R.string.share_track_share_file, new DialogInterface.OnClickListener() {
@@ -167,7 +176,6 @@ public class SaveActivity extends Activity {
} }
}); });
} }
return builder.create(); return builder.create();
default: default:
return null; return null;