1 /* 2 * Copyright (C) 2014 Google Inc. 3 * Licensed to The Android Open Source Project. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.mail.utils; 19 20 import android.content.res.Resources; 21 import androidx.core.text.BidiFormatter; 22 import android.widget.ImageView; 23 import android.widget.TextView; 24 25 import com.android.mail.R; 26 import com.android.mail.providers.Folder; 27 28 /** 29 * Utility class for handling logic related to empty states throughout the app. 30 */ 31 public class EmptyStateUtils { 32 33 /** 34 * Given an empty folder, set the corresponding empty state icon for that folder. 35 */ bindEmptyFolderIcon(ImageView view, Folder folder)36 public static void bindEmptyFolderIcon(ImageView view, Folder folder) { 37 if (folder == null) { 38 view.setImageResource(R.drawable.ic_empty_default); 39 } else if (folder.isInbox()) { 40 view.setImageResource(R.drawable.ic_empty_inbox); 41 } else if (folder.isSearch()) { 42 view.setImageResource(R.drawable.ic_empty_search); 43 } else if (folder.isSpam()) { 44 view.setImageResource(R.drawable.ic_empty_spam); 45 } else if (folder.isTrash()) { 46 view.setImageResource(R.drawable.ic_empty_trash); 47 } else { 48 view.setImageResource(R.drawable.ic_empty_default); 49 } 50 } 51 52 /** 53 * Given an empty folder, set the corresponding text for indicating the empty state. 54 */ bindEmptyFolderText(TextView view, Folder folder, Resources res, String searchQuery, BidiFormatter bidiFormatter)55 public static void bindEmptyFolderText(TextView view, Folder folder, Resources res, 56 String searchQuery, BidiFormatter bidiFormatter) { 57 if (folder == null) { 58 view.setText(R.string.empty_folder); 59 } else if (folder.isInbox()) { 60 view.setText(R.string.empty_inbox); 61 } else if (folder.isSearch()) { 62 final String text = res.getString(R.string.empty_search, 63 bidiFormatter.unicodeWrap(searchQuery)); 64 view.setText(text); 65 } else if (folder.isSpam()) { 66 view.setText(R.string.empty_spam_folder); 67 } else if (folder.isTrash()) { 68 view.setText(R.string.empty_trash_folder); 69 } else { 70 view.setText(R.string.empty_folder); 71 } 72 } 73 } 74