Clear history confirmation dialog

This commit is contained in:
serso 2015-01-28 10:09:29 +01:00
parent ac07d546c1
commit e57e84a0e8
3 changed files with 34 additions and 10 deletions

View File

@ -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;

View File

@ -5,4 +5,7 @@
<string name="acl_wizard_back">Назад</string>
<string name="acl_wizard_finish">Завершить</string>
<string name="acl_wizard_start">Начать визард</string>
<string name="cpp_clear_history">Отчистить</string>
<string name="cpp_clear_history_message">Вся история будет отчищена</string>
<string name="cpp_clear_history_title">Отчистить историю?</string>
</resources>

View File

@ -5,4 +5,7 @@
<string name="acl_wizard_back">Back</string>
<string name="acl_wizard_finish">Finish</string>
<string name="acl_wizard_start">Start wizard</string>
<string name="cpp_clear_history_title">Clear history?</string>
<string name="cpp_clear_history_message">All history will be cleared.</string>
<string name="cpp_clear_history">Clear</string>
</resources>