| 1 | /* |
| 2 | * Copyright (C) 2013 Keith Kildare |
| 3 | * |
| 4 | * This file is part of SimplyDo. |
| 5 | * |
| 6 | * SimplyDo is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * SimplyDo is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with SimplyDo. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | package kdk.android.simplydo; |
| 21 | |
| 22 | import android.app.Activity; |
| 23 | import android.app.AlertDialog; |
| 24 | import android.app.Dialog; |
| 25 | import android.content.DialogInterface; |
| 26 | import android.content.SharedPreferences; |
| 27 | import android.preference.PreferenceManager; |
| 28 | |
| 29 | public class DeleteInactiveAction |
| 30 | { |
| 31 | private Activity activity; |
| 32 | private DataViewer dataViewer; |
| 33 | private ListPropertiesAdapter listPropertiesAdapter; |
| 34 | private ItemPropertiesAdapter itemPropertiesAdapter; |
| 35 | |
| 36 | private AlertDialog.Builder dialogBuilder; |
| 37 | |
| 38 | public DeleteInactiveAction( |
| 39 | Activity activity, |
| 40 | DataViewer dataViewer, |
| 41 | ListPropertiesAdapter listPropertiesAdapter, |
| 42 | ItemPropertiesAdapter itemPropertiesAdapter) |
| 43 | { |
| 44 | this.activity = activity; |
| 45 | this.dataViewer = dataViewer; |
| 46 | this.listPropertiesAdapter = listPropertiesAdapter; |
| 47 | this.itemPropertiesAdapter = itemPropertiesAdapter; |
| 48 | |
| 49 | dialogBuilder = new AlertDialog.Builder(this.activity); |
| 50 | dialogBuilder.setMessage(R.string.deleteInactiveMessage) |
| 51 | .setCancelable(true) |
| 52 | .setTitle(R.string.deleteInactiveTitle) |
| 53 | .setPositiveButton(R.string.deleteInactivePositive, new DialogInterface.OnClickListener() { |
| 54 | @Override |
| 55 | public void onClick(DialogInterface dialog, int id) { |
| 56 | deleteInactive(); |
| 57 | } |
| 58 | }) |
| 59 | .setNegativeButton(R.string.deleteInactiveNegative, null); |
| 60 | } |
| 61 | |
| 62 | public void deleteInactive(int dialogId) |
| 63 | { |
| 64 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity.getBaseContext()); |
| 65 | boolean confirmDeleteInactive = prefs.getBoolean("confirmDeleteInactive", true); |
| 66 | |
| 67 | if(confirmDeleteInactive) |
| 68 | { |
| 69 | activity.showDialog(dialogId); |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | deleteInactive(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | public Dialog createDialog() |
| 78 | { |
| 79 | return dialogBuilder.create(); |
| 80 | } |
| 81 | |
| 82 | private void deleteInactive() |
| 83 | { |
| 84 | dataViewer.deleteInactive(); |
| 85 | itemPropertiesAdapter.notifyDataSetChanged(); |
| 86 | listPropertiesAdapter.notifyDataSetChanged(); |
| 87 | } |
| 88 | } |