From e57e84a0e8885089cb7a1f93f78724b9dd765192 Mon Sep 17 00:00:00 2001 From: serso Date: Wed, 28 Jan 2015 10:09:29 +0100 Subject: [PATCH] Clear history confirmation dialog --- .../history/BaseHistoryFragment.java | 38 ++++++++++++++----- .../src/main/res/values-ru/strings.xml | 3 ++ android-app/src/main/res/values/strings.xml | 3 ++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java index f234a43a..96f3fea2 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java @@ -22,29 +22,25 @@ package org.solovyev.android.calculator.history; +import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.app.FragmentActivity; +import android.support.v4.app.ListFragment; import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; +import android.view.*; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; -import android.support.v4.app.ListFragment; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import com.melnykov.fab.FloatingActionButton; import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.menu.*; -import org.solovyev.android.menu.AndroidMenuHelper; import org.solovyev.common.JPredicate; import org.solovyev.common.collections.Collections; import org.solovyev.common.equals.Equalizer; @@ -108,6 +104,20 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul @Nonnull private final SharedPreferences.OnSharedPreferenceChangeListener preferencesListener = new HistoryOnPreferenceChangeListener(); + @Nonnull + private final DialogInterface.OnClickListener clearDialogListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: + clearHistory(); + break; + } + } + }; + @Nullable + private AlertDialog clearDialog; + protected BaseHistoryFragment(@Nonnull CalculatorFragmentType fragmentType) { fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId(), false); } @@ -221,7 +231,10 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul @Override public void onDestroy() { logDebug("onDestroy"); - + if (clearDialog != null) { + clearDialog.dismiss(); + clearDialog = null; + } fragmentHelper.onDestroy(this); super.onDestroy(); @@ -335,7 +348,12 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul getActivity().runOnUiThread(new Runnable() { @Override public void run() { - clearHistory(); + clearDialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.cpp_clear_history_title) + .setMessage(R.string.cpp_clear_history_message) + .setPositiveButton(R.string.cpp_clear_history, clearDialogListener) + .setNegativeButton(R.string.c_cancel, clearDialogListener) + .create(); + clearDialog.show(); } }); break; diff --git a/android-app/src/main/res/values-ru/strings.xml b/android-app/src/main/res/values-ru/strings.xml index 0acb3ee4..ba8cd1ea 100644 --- a/android-app/src/main/res/values-ru/strings.xml +++ b/android-app/src/main/res/values-ru/strings.xml @@ -5,4 +5,7 @@ Назад Завершить Начать визард + Отчистить + Вся история будет отчищена + Отчистить историю? \ No newline at end of file diff --git a/android-app/src/main/res/values/strings.xml b/android-app/src/main/res/values/strings.xml index 86a94f0c..d9baad14 100644 --- a/android-app/src/main/res/values/strings.xml +++ b/android-app/src/main/res/values/strings.xml @@ -5,4 +5,7 @@ Back Finish Start wizard + Clear history? + All history will be cleared. + Clear \ No newline at end of file