1d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/* 2d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Copyright (C) 2015 The Android Open Source Project 3d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 4d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Licensed under the Apache License, Version 2.0 (the "License"); 5d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * you may not use this file except in compliance with the License. 6d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * You may obtain a copy of the License at 7d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 8d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * http://www.apache.org/licenses/LICENSE-2.0 9d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 10d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Unless required by applicable law or agreed to in writing, software 11d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * distributed under the License is distributed on an "AS IS" BASIS, 12d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * See the License for the specific language governing permissions and 14d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * limitations under the License. 15d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 16d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpackage com.android.messaging.ui; 18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.app.AlertDialog; 20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.app.Dialog; 21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.app.DialogFragment; 22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.app.Fragment; 23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.app.FragmentTransaction; 24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Context; 25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.DialogInterface; 26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.res.Resources; 27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.os.Bundle; 28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.LayoutInflater; 29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.View; 30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.View.OnClickListener; 31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.ViewGroup; 32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.widget.ArrayAdapter; 33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.widget.ListView; 34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.widget.TextView; 35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.R; 37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.action.HandleLowStorageAction; 38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.sms.SmsReleaseStorage; 39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.sms.SmsReleaseStorage.Duration; 40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.sms.SmsStorageStatusManager; 41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.Assert; 42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.google.common.collect.Lists; 43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport java.util.List; 45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/** 47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Dialog to show the sms storage low warning 48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic class SmsStorageLowWarningFragment extends Fragment { 50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private SmsStorageLowWarningFragment() { 51d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 52d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 53d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static SmsStorageLowWarningFragment newInstance() { 54d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return new SmsStorageLowWarningFragment(); 55d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 56d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 57d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 58d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onCreate(final Bundle savedInstanceState) { 59d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd super.onCreate(savedInstanceState); 60d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final FragmentTransaction ft = getFragmentManager().beginTransaction(); 61d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ChooseActionDialogFragment dialog = ChooseActionDialogFragment.newInstance(); 62d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dialog.setTargetFragment(this, 0/*requestCode*/); 63d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dialog.show(ft, null/*tag*/); 64d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 65d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 66d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 67d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Perform confirm action for a specific action 68d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 69d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @param actionIndex 70d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 71d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private void confirm(final int actionIndex) { 72d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final FragmentTransaction ft = getFragmentManager().beginTransaction(); 73d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ConfirmationDialog dialog = ConfirmationDialog.newInstance(actionIndex); 74d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dialog.setTargetFragment(this, 0/*requestCode*/); 75d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dialog.show(ft, null/*tag*/); 76d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 77d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 78d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 79d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * The dialog is cancelled at any step 80d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 81d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private void cancel() { 82d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd getActivity().finish(); 83d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 84d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 85d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 86d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * The dialog to show for user to choose what delete actions to take when storage is low 87d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 88d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private static class ChooseActionDialogFragment extends DialogFragment { 89d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static ChooseActionDialogFragment newInstance() { 90d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return new ChooseActionDialogFragment(); 91d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 92d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 93d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 94d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public Dialog onCreateDialog(final Bundle savedInstanceState) { 95d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 96d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 97d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final LayoutInflater inflater = getActivity().getLayoutInflater(); 98d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final View dialogLayout = inflater.inflate( 99d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd R.layout.sms_storage_low_warning_dialog, null); 100d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ListView actionListView = (ListView) dialogLayout.findViewById( 101d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd R.id.free_storage_action_list); 102d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final List<String> actions = loadFreeStorageActions(getActivity().getResources()); 103d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ActionListAdapter listAdapter = new ActionListAdapter(getActivity(), actions); 104d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd actionListView.setAdapter(listAdapter); 105d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 106d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd builder.setTitle(R.string.sms_storage_low_title) 107d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .setView(dialogLayout) 108d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .setNegativeButton(R.string.ignore, new DialogInterface.OnClickListener() { 109d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 110d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onClick(DialogInterface dialog, int id) { 111d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dialog.cancel(); 112d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 113d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd }); 114d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 115d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final Dialog dialog = builder.create(); 116d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dialog.setCanceledOnTouchOutside(false); 117d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return dialog; 118d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 119d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 120d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 121d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onCancel(final DialogInterface dialog) { 122d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ((SmsStorageLowWarningFragment) getTargetFragment()).cancel(); 123d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 124d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 125d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private class ActionListAdapter extends ArrayAdapter<String> { 126d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public ActionListAdapter(final Context context, final List<String> actions) { 127d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd super(context, R.layout.sms_free_storage_action_item_view, actions); 128d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 129d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 130d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 131d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public View getView(final int position, final View view, final ViewGroup parent) { 132d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd TextView actionItemView; 133d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (view == null || !(view instanceof TextView)) { 134d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final LayoutInflater inflater = LayoutInflater.from(getContext()); 135d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd actionItemView = (TextView) inflater.inflate( 136d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd R.layout.sms_free_storage_action_item_view, parent, false); 137d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } else { 138d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd actionItemView = (TextView) view; 139d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 140d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 141d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final String action = getItem(position); 142d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd actionItemView.setText(action); 143d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd actionItemView.setOnClickListener(new OnClickListener() { 144d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 145d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onClick(final View view) { 146d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dismiss(); 147d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ((SmsStorageLowWarningFragment) getTargetFragment()).confirm(position); 148d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 149d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd }); 150d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return actionItemView; 151d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 152d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 153d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 154d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 155d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private static final String KEY_ACTION_INDEX = "action_index"; 156d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 157d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 158d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * The dialog to confirm user's delete action 159d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 160d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private static class ConfirmationDialog extends DialogFragment { 161d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private Duration mDuration; 162d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private String mDurationString; 163d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 164d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static ConfirmationDialog newInstance(final int actionIndex) { 165d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ConfirmationDialog dialog = new ConfirmationDialog(); 166d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final Bundle args = new Bundle(); 167d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd args.putInt(KEY_ACTION_INDEX, actionIndex); 168d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dialog.setArguments(args); 169d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return dialog; 170d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 171d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 172d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 173d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onCancel(final DialogInterface dialog) { 174d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ((SmsStorageLowWarningFragment) getTargetFragment()).cancel(); 175d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 176d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 177d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 178d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public Dialog onCreateDialog(final Bundle savedInstanceState) { 179d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mDuration = SmsReleaseStorage.parseMessageRetainingDuration(); 180d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mDurationString = SmsReleaseStorage.getMessageRetainingDurationString(mDuration); 181d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 182d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int actionIndex = getArguments().getInt(KEY_ACTION_INDEX); 183d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (actionIndex < 0 || actionIndex > 1) { 184d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return null; 185d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 186d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 187d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd builder.setTitle(R.string.sms_storage_low_title) 188d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .setMessage(getConfirmDialogMessage(actionIndex)) 189d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .setNegativeButton(android.R.string.cancel, 190d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd new DialogInterface.OnClickListener() { 191d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 192d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onClick(final DialogInterface dialog, 193d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int button) { 194d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dismiss(); 195d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ((SmsStorageLowWarningFragment) getTargetFragment()).cancel(); 196d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 197d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd }) 198d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .setPositiveButton(android.R.string.ok, 199d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd new DialogInterface.OnClickListener() { 200d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 201d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onClick(final DialogInterface dialog, 202d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int button) { 203d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dismiss(); 204d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd handleAction(actionIndex); 205d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd getActivity().finish(); 206d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd SmsStorageStatusManager.cancelStorageLowNotification(); 207d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 208d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd }); 209d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return builder.create(); 210d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 211d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 212d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private void handleAction(final int actionIndex) { 213d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final long durationInMillis = 214d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd SmsReleaseStorage.durationToTimeInMillis(mDuration); 215d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd switch (actionIndex) { 216d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd case 0: 217d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd HandleLowStorageAction.handleDeleteMediaMessages(durationInMillis); 218d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd break; 219d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 220d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd case 1: 221d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd HandleLowStorageAction.handleDeleteOldMessages(durationInMillis); 222d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd break; 223d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 224d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd default: 225d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd Assert.fail("Unsupported action"); 226d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd break; 227d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 228d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 229d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 230d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 231d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Get the confirm dialog text for a specific delete action 232d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @param index The action index 233d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @return 234d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 235d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private String getConfirmDialogMessage(final int index) { 236d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd switch (index) { 237d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd case 0: 238d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return getString(R.string.delete_all_media_confirmation, mDurationString); 239d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd case 1: 240d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return getString(R.string.delete_oldest_messages_confirmation, mDurationString); 241d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd case 2: 242d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return getString(R.string.auto_delete_oldest_messages_confirmation, 243d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mDurationString); 244d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 245d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd throw new IllegalArgumentException( 246d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd "SmsStorageLowWarningFragment: invalid action index " + index); 247d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 248d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 249d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 250d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 251d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Load the text of delete message actions 252d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 253d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @param resources 254d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @return 255d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 256d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private static List<String> loadFreeStorageActions(final Resources resources) { 257d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final Duration duration = SmsReleaseStorage.parseMessageRetainingDuration(); 258d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final String durationString = SmsReleaseStorage.getMessageRetainingDurationString(duration); 259d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final List<String> actions = Lists.newArrayList(); 260d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd actions.add(resources.getString(R.string.delete_all_media)); 261d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd actions.add(resources.getString(R.string.delete_oldest_messages, durationString)); 262d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 263d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // TODO: Auto-purging is disabled for Bugle V1. 264d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // actions.add(resources.getString(R.string.auto_delete_oldest_messages, durationString)); 265d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return actions; 266d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 267d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd} 268