Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d206c7ed authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix strings in DocumentsUI to use plurals."

parents 34c0f921 56aeb491
Loading
Loading
Loading
Loading
+25 −7
Original line number Diff line number Diff line
@@ -223,17 +223,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>
+7 −45
Original line number Diff line number Diff line
@@ -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>");
        final String message = new MessageBuilder(getContext()).generateListMessage(
                dialogType, operationType, docList, uriList);

        builder.setMessage(Html.fromHtml(String.format(messageFormat, list.toString())));
        builder.setMessage(Html.fromHtml(message));
        builder.setPositiveButton(
                R.string.close,
                new DialogInterface.OnClickListener() {
+62 −0
Original line number Diff line number Diff line
@@ -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.
     */