Wizard exit confirmation dialog
This commit is contained in:
parent
eafafcdea8
commit
450b63b7a7
@ -23,12 +23,10 @@
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -41,7 +39,7 @@ import static org.solovyev.android.calculator.wizard.CalculatorMode.*;
|
||||
* Date: 6/16/13
|
||||
* Time: 9:59 PM
|
||||
*/
|
||||
public class ChooseModeWizardStep extends Fragment {
|
||||
public class ChooseModeWizardStep extends WizardFragment {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
@ -84,7 +82,15 @@ public class ChooseModeWizardStep extends Fragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.cpp_wizard_step_choose_mode, null);
|
||||
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
setupNextButton(R.string.acl_wizard_next);
|
||||
setupPrevButton(R.string.acl_wizard_back);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getViewResId() {
|
||||
return R.layout.cpp_wizard_step_choose_mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
@ -13,10 +15,11 @@ import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.wizard.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
@Nonnull
|
||||
private final WizardUi<WizardActivity> wizardUi = new WizardUi<WizardActivity>(this, this, 0);
|
||||
private final WizardUi<WizardActivity> wizardUi = new WizardUi<>(this, this, 0);
|
||||
|
||||
@Nonnull
|
||||
private ViewPager pager;
|
||||
@ -31,6 +34,12 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
super(R.layout.cpp_activity_wizard);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private AlertDialog dialog;
|
||||
|
||||
@Nonnull
|
||||
private final DialogListener dialogListener = new DialogListener();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -46,7 +55,9 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
titleIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
wizardUi.setStep(flow.getStepAt(position));
|
||||
final WizardStep step = flow.getStepAt(position);
|
||||
wizardUi.setStep(step);
|
||||
wizardUi.getWizard().saveLastStep(step);
|
||||
}
|
||||
});
|
||||
|
||||
@ -54,12 +65,16 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
final int position = flow.getPositionFor(wizardUi.getStep());
|
||||
pager.setCurrentItem(position);
|
||||
}
|
||||
|
||||
if (wizardUi.getWizard().getLastSavedStepName() == null) {
|
||||
wizardUi.getWizard().saveLastStep(wizardUi.getStep());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (pager.getCurrentItem() == 0) {
|
||||
super.onBackPressed();
|
||||
finishWizardAbruptly();
|
||||
} else {
|
||||
pager.setCurrentItem(pager.getCurrentItem() - 1);
|
||||
}
|
||||
@ -88,6 +103,28 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
}
|
||||
|
||||
public void finishWizardAbruptly() {
|
||||
finishWizardAbruptly(false);
|
||||
}
|
||||
|
||||
public void finishWizardAbruptly(boolean confirmed) {
|
||||
if (!confirmed) {
|
||||
if (dialog != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final AlertDialog.Builder b = new AlertDialog.Builder(this);
|
||||
b.setTitle(getString(R.string.wizard_finish_confirmation_title)).
|
||||
setMessage(R.string.acl_wizard_finish_confirmation).
|
||||
setNegativeButton(R.string.c_no, dialogListener).
|
||||
setPositiveButton(R.string.c_yes, dialogListener).
|
||||
setOnCancelListener(dialogListener);
|
||||
dialog = b.create();
|
||||
dialog.setOnDismissListener(dialogListener);
|
||||
dialog.show();
|
||||
return;
|
||||
}
|
||||
|
||||
dismissDialog();
|
||||
wizardUi.finishWizardAbruptly();
|
||||
finish();
|
||||
}
|
||||
@ -121,6 +158,19 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
dismissDialog();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void dismissDialog() {
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
dialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
private class WizardPagerAdapter extends FragmentStatePagerAdapter {
|
||||
@Nonnull
|
||||
private final ListWizardFlow flow;
|
||||
@ -143,4 +193,22 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
return flow.getCount();
|
||||
}
|
||||
}
|
||||
|
||||
private class DialogListener implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, DialogInterface.OnCancelListener {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
finishWizardAbruptly(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onDismiss(DialogInterface d) {
|
||||
dialog = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface d) {
|
||||
dialog = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class BaseWizard implements Wizard {
|
||||
|
||||
editor.putString(makeLastStepPreferenceKey(name), step.getName());
|
||||
|
||||
editor.commit();
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,7 +47,7 @@ public class BaseWizard implements Wizard {
|
||||
|
||||
editor.putBoolean(makeFinishedPreferenceKey(name), forceFinish || flow.getNextStep(step) == null);
|
||||
|
||||
editor.commit();
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@ -14,4 +14,5 @@
|
||||
<string name="wizard_next">Далее</string>
|
||||
<string name="wizard_prev">Назад</string>
|
||||
<string name="wizard_final">Приложение настроено и готово к использованию.</string>
|
||||
<string name="wizard_finish_confirmation_title">Закончить?</string>
|
||||
</resources>
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="acl_wizard_finish_confirmation">Do you really want to finish wizard?</string>
|
||||
<string name="wizard_finish_confirmation_title">Finish?</string>
|
||||
<string name="acl_wizard_next">Next</string>
|
||||
<string name="acl_wizard_back">Back</string>
|
||||
<string name="acl_wizard_finish">Finish</string>
|
||||
|
Loading…
Reference in New Issue
Block a user