| /* |
| * Copyright (C) 2016 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| package com.android.documentsui.ui; |
| |
| import android.annotation.PluralsRes; |
| import android.content.Context; |
| import android.text.BidiFormatter; |
| |
| import com.android.documentsui.R; |
| import com.android.documentsui.base.DocumentInfo; |
| import com.android.documentsui.base.Shared; |
| |
| import java.util.List; |
| |
| public class MessageBuilder { |
| |
| private Context mContext; |
| |
| public MessageBuilder(Context context) { |
| mContext = context; |
| } |
| |
| public String generateDeleteMessage(List<DocumentInfo> docs) { |
| String message; |
| int dirsCount = 0; |
| |
| for (DocumentInfo doc : docs) { |
| if (doc.isDirectory()) { |
| ++dirsCount; |
| } |
| } |
| |
| if (docs.size() == 1) { |
| // Deleteing 1 file xor 1 folder in cwd |
| |
| // Address b/28772371, where including user strings in message can result in |
| // broken bidirectional support. |
| String displayName = BidiFormatter.getInstance().unicodeWrap(docs.get(0).displayName); |
| message = dirsCount == 0 |
| ? mContext.getString(R.string.delete_filename_confirmation_message, |
| displayName) |
| : mContext.getString(R.string.delete_foldername_confirmation_message, |
| displayName); |
| } else if (dirsCount == 0) { |
| // Deleting only files in cwd |
| message = Shared.getQuantityString(mContext, |
| R.plurals.delete_files_confirmation_message, docs.size()); |
| } else if (dirsCount == docs.size()) { |
| // Deleting only folders in cwd |
| message = Shared.getQuantityString(mContext, |
| R.plurals.delete_folders_confirmation_message, docs.size()); |
| } else { |
| // Deleting mixed items (files and folders) in cwd |
| message = Shared.getQuantityString(mContext, |
| R.plurals.delete_items_confirmation_message, docs.size()); |
| } |
| return message; |
| } |
| |
| /** |
| * Generates a formatted quantity string. |
| */ |
| public String getQuantityString(@PluralsRes int stringId, int quantity) { |
| return Shared.getQuantityString(mContext, stringId, quantity); |
| } |
| } |