summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tomasz Mikolajewski <mtomasz@google.com> 2017-01-31 16:50:57 +0900
committer Tomasz Mikolajewski <mtomasz@google.com> 2017-02-08 17:52:18 +0900
commit56aeb4918fdd6419f71f48ac5927c4709de42d4f (patch)
treeae70f88c78ab0c1d3feac7d5248040922392492a
parente731da6d7dc46611e232ddee9a0f9b87d604ea44 (diff)
Fix strings in DocumentsUI to use plurals.
Test: Tested manually conversion and moving dialogs. Bug: 34824654 Change-Id: Ib4c75333d80ee024d7905675d02a1238a2b38ca5
-rw-r--r--res/values/strings.xml32
-rw-r--r--src/com/android/documentsui/OperationDialogFragment.java52
-rw-r--r--src/com/android/documentsui/ui/MessageBuilder.java62
3 files changed, 94 insertions, 52 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 471e6c674..d10705c07 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -218,17 +218,35 @@
<!-- Label of the close dialog button.[CHAR LIMIT=24] -->
<string name="close">Close</string>
<!-- Contents of the copying failure alert dialog. [CHAR LIMIT=48] -->
- <string name="copy_failure_alert_content">These files weren\u2019t copied: <xliff:g id="list">%1$s</xliff:g></string>
+ <plurals name="copy_failure_alert_content">
+ <item quantity="one">This file wasn\u2019t copied: <xliff:g id="list" example="Document.pdf">%1$s</xliff:g></item>
+ <item quantity="other">These files weren\u2019t copied: <xliff:g id="list" example="Document.pdf, Photo.jpg, Song.ogg">%1$s</xliff:g></item>
+ </plurals>
<!-- Contents of the compressing failure alert dialog. [CHAR LIMIT=48] -->
- <string name="compress_failure_alert_content">These files weren\u2019t compressed: <xliff:g id="list">%1$s</xliff:g></string>
+ <plurals name="compress_failure_alert_content">
+ <item quantity="one">This file wasn\u2019t compressed: <xliff:g id="list" example="Document.pdf">%1$s</xliff:g></item>
+ <item quantity="other">These files weren\u2019t compressed: <xliff:g id="list" example="Document.pdf, Photo.jpg, Song.ogg">%1$s</xliff:g></item>
+ </plurals>
<!-- Contents of the extracting failure alert dialog. [CHAR LIMIT=48] -->
- <string name="extract_failure_alert_content">These files weren\u2019t extracted: <xliff:g id="list">%1$s</xliff:g></string>
+ <plurals name="extract_failure_alert_content">
+ <item quantity="one">This file wasn\u2019t extracted: <xliff:g id="list" example="Document.pdf">%1$s</xliff:g></item>
+ <item quantity="other">These files weren\u2019t extracted: <xliff:g id="list" example="Document.pdf, Photo.jpg, Song.ogg">%1$s</xliff:g></item>
+ </plurals>
<!-- Contents of the moving failure alert dialog. [CHAR LIMIT=48] -->
- <string name="move_failure_alert_content">These files weren\u2019t moved: <xliff:g id="list">%1$s</xliff:g></string>
- <!-- Message shown to users when an operation to delete one or more files has failed. Presented in a dialog. [CHAR LIMIT=48] -->
- <string name="delete_failure_alert_content">These files weren\u2019t deleted: <xliff:g id="list">%1$s</xliff:g></string>
+ <plurals name="move_failure_alert_content">
+ <item quantity="one">This file wasn\u2019t moved: <xliff:g id="list" example="Document.pdf">%1$s</xliff:g></item>
+ <item quantity="other">These files weren\u2019t moved: <xliff:g id="list" example="Document.pdf, Photo.jpg, Song.ogg">%1$s</xliff:g></item>
+ </plurals>
+ <!-- Contents of the deleting failure alert dialog. [CHAR LIMIT=48] -->
+ <plurals name="delete_failure_alert_content">
+ <item quantity="one">This file wasn\u2019t deleted: <xliff:g id="list" example="Document.pdf">%1$s</xliff:g></item>
+ <item quantity="other">These files weren\u2019t deleted: <xliff:g id="list" example="Document.pdf, Photo.jpg, Song.ogg">%1$s</xliff:g></item>
+ </plurals>
<!-- Contents of the copying warning dialog due to converted files. [CHAR LIMIT=64] -->
- <string name="copy_converted_warning_content">These files were converted to another format: <xliff:g id="list" example="Document.pdf, Photo.jpg, Song.ogg">%1$s</xliff:g></string>
+ <plurals name="copy_converted_warning_content">
+ <item quantity="one">This file was converted to another format: <xliff:g id="list" example="Document.pdf">%1$s</xliff:g></item>
+ <item quantity="other">These files were converted to another format: <xliff:g id="list" example="Document.pdf, Photo.jpg, Song.ogg">%1$s</xliff:g></item>
+ </plurals>
<!-- Toast shown when a user copies files to clipboard. -->
<plurals name="clipboard_files_clipped">
<item quantity="one">Copied <xliff:g id="count" example="1">%1$d</xliff:g> item to clipboard.</item>
diff --git a/src/com/android/documentsui/OperationDialogFragment.java b/src/com/android/documentsui/OperationDialogFragment.java
index 8b0b70eb5..c13fea0f5 100644
--- a/src/com/android/documentsui/OperationDialogFragment.java
+++ b/src/com/android/documentsui/OperationDialogFragment.java
@@ -31,10 +31,12 @@ import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.DocumentStack;
import com.android.documentsui.services.FileOperationService;
import com.android.documentsui.services.FileOperationService.OpType;
+import com.android.documentsui.ui.MessageBuilder;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
+
/**
* Alert dialog for operation dialogs.
*/
@@ -67,6 +69,7 @@ public class OperationDialogFragment extends DialogFragment {
args.putInt(FileOperationService.EXTRA_DIALOG_TYPE, dialogType);
args.putInt(FileOperationService.EXTRA_OPERATION_TYPE, operationType);
args.putParcelableArrayList(FileOperationService.EXTRA_FAILED_DOCS, failedSrcList);
+ args.putParcelableArrayList(FileOperationService.EXTRA_FAILED_URIS, uriList);
final FragmentTransaction ft = fm.beginTransaction();
final OperationDialogFragment fragment = new OperationDialogFragment();
@@ -90,51 +93,10 @@ public class OperationDialogFragment extends DialogFragment {
FileOperationService.EXTRA_FAILED_DOCS);
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- String messageFormat;
-
- switch (dialogType) {
- case DIALOG_TYPE_CONVERTED:
- messageFormat = getString(R.string.copy_converted_warning_content);
- break;
-
- case DIALOG_TYPE_FAILURE:
- switch (operationType) {
- case FileOperationService.OPERATION_COPY:
- messageFormat = getString(R.string.copy_failure_alert_content);
- break;
- case FileOperationService.OPERATION_COMPRESS:
- messageFormat = getString(R.string.compress_failure_alert_content);
- break;
- case FileOperationService.OPERATION_EXTRACT:
- messageFormat = getString(R.string.extract_failure_alert_content);
- break;
- case FileOperationService.OPERATION_DELETE:
- messageFormat = getString(R.string.delete_failure_alert_content);
- break;
- case FileOperationService.OPERATION_MOVE:
- messageFormat = getString(R.string.move_failure_alert_content);
- break;
- default:
- throw new UnsupportedOperationException();
- }
- break;
-
- default:
- throw new UnsupportedOperationException();
- }
-
- final StringBuilder list = new StringBuilder("<p>");
- for (DocumentInfo documentInfo : docList) {
- list.append("&#8226; " + Html.escapeHtml(documentInfo.displayName) + "<br>");
- }
- if (uriList != null) {
- for (Uri uri : uriList) {
- list.append("&#8226; " + uri.toSafeString() + "<br>");
- }
- }
- list.append("</p>");
-
- builder.setMessage(Html.fromHtml(String.format(messageFormat, list.toString())));
+ final String message = new MessageBuilder(getContext()).generateListMessage(
+ dialogType, operationType, docList, uriList);
+
+ builder.setMessage(Html.fromHtml(message));
builder.setPositiveButton(
R.string.close,
new DialogInterface.OnClickListener() {
diff --git a/src/com/android/documentsui/ui/MessageBuilder.java b/src/com/android/documentsui/ui/MessageBuilder.java
index dc3a6385d..4a4af2977 100644
--- a/src/com/android/documentsui/ui/MessageBuilder.java
+++ b/src/com/android/documentsui/ui/MessageBuilder.java
@@ -18,10 +18,19 @@ package com.android.documentsui.ui;
import android.annotation.PluralsRes;
import android.content.Context;
import android.text.BidiFormatter;
+import android.net.Uri;
+import android.text.Html;
+import com.android.documentsui.OperationDialogFragment.DialogType;
import com.android.documentsui.R;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.Shared;
+import com.android.documentsui.services.FileOperationService;
+import com.android.documentsui.services.FileOperationService.OpType;
+import com.android.documentsui.OperationDialogFragment.DialogType;
+
+import static com.android.documentsui.OperationDialogFragment.DIALOG_TYPE_FAILURE;
+import static com.android.documentsui.OperationDialogFragment.DIALOG_TYPE_CONVERTED;
import java.util.List;
@@ -70,6 +79,59 @@ public class MessageBuilder {
return message;
}
+ public String generateListMessage(
+ @DialogType int dialogType, @OpType int operationType, List<DocumentInfo> docs,
+ List<Uri> uris) {
+ int resourceId;
+
+ switch (dialogType) {
+ case DIALOG_TYPE_CONVERTED:
+ resourceId = R.plurals.copy_converted_warning_content;
+ break;
+
+ case DIALOG_TYPE_FAILURE:
+ switch (operationType) {
+ case FileOperationService.OPERATION_COPY:
+ resourceId = R.plurals.copy_failure_alert_content;
+ break;
+ case FileOperationService.OPERATION_COMPRESS:
+ resourceId = R.plurals.compress_failure_alert_content;
+ break;
+ case FileOperationService.OPERATION_EXTRACT:
+ resourceId = R.plurals.extract_failure_alert_content;
+ break;
+ case FileOperationService.OPERATION_DELETE:
+ resourceId = R.plurals.delete_failure_alert_content;
+ break;
+ case FileOperationService.OPERATION_MOVE:
+ resourceId = R.plurals.move_failure_alert_content;
+ break;
+ default:
+ throw new UnsupportedOperationException();
+ }
+ break;
+
+ default:
+ throw new UnsupportedOperationException();
+ }
+
+ final StringBuilder list = new StringBuilder("<p>");
+ for (DocumentInfo documentInfo : docs) {
+ list.append("&#8226; " + Html.escapeHtml(BidiFormatter.getInstance().unicodeWrap(
+ documentInfo.displayName)) + "<br>");
+ }
+ if (uris != null) {
+ for (Uri uri : uris) {
+ list.append("&#8226; " + BidiFormatter.getInstance().unicodeWrap(uri.toSafeString()) +
+ "<br>");
+ }
+ }
+ list.append("</p>");
+
+ final int totalItems = docs.size() + (uris != null ? uris.size() : 0);
+ return mContext.getResources().getQuantityString(resourceId, totalItems, list.toString());
+ }
+
/**
* Generates a formatted quantity string.
*/