finish wizard dialog
This commit is contained in:
parent
e267e314ab
commit
c906e572f7
@ -158,6 +158,7 @@
|
||||
</style>
|
||||
|
||||
<style name="cpp_gray_dialog_theme" parent="Theme.Sherlock.Dialog">
|
||||
<item name="android:windowCloseOnTouchOutside">false</item>
|
||||
<!-- buttons -->
|
||||
<item name="cpp_digit_button_style">@style/cpp_default_digit_button_style</item>
|
||||
<item name="cpp_control_button_style">@style/cpp_default_control_button_style</item>
|
||||
|
@ -53,7 +53,11 @@ abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider implem
|
||||
protected AbstractCalculatorWidgetProvider() {
|
||||
final Class<? extends AppWidgetProvider> componentClass = this.getComponentClass();
|
||||
|
||||
Locator.getInstance().getExternalListenersContainer().addExternalListener(componentClass);
|
||||
final CalculatorExternalListenersContainer externalListenersContainer = Locator.getInstance().getExternalListenersContainer();
|
||||
// NOTE: null might be in tests, now robolectric creates widget provider before application
|
||||
if (externalListenersContainer != null) {
|
||||
externalListenersContainer.addExternalListener(componentClass);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -52,6 +52,7 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.cpp_wizard);
|
||||
|
||||
prevButton = findViewById(R.id.wizard_prev_button);
|
||||
nextButton = findViewById(R.id.wizard_next_button);
|
||||
finishButton = findViewById(R.id.wizard_finish_button);
|
||||
@ -143,8 +144,12 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
|
||||
}
|
||||
|
||||
void finishFlow() {
|
||||
finishFlow(false);
|
||||
}
|
||||
|
||||
void finishFlow(boolean forceFinish) {
|
||||
if (flow != null && step != null) {
|
||||
Wizard.saveWizardFinished(flow, step);
|
||||
Wizard.saveWizardFinished(flow, step, forceFinish);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
@ -229,6 +234,11 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
FinishWizardConfirmationDialog.show(this);
|
||||
}
|
||||
|
||||
WizardStep getStep() {
|
||||
return step;
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.solovyev.android.sherlock.AndroidSherlockUtils;
|
||||
|
||||
public class FinishWizardConfirmationDialog extends DialogFragment {
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
|
||||
b.setMessage("Do you really want to finish wizard?");
|
||||
b.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
((CalculatorWizardActivity) getActivity()).finishFlow(true);
|
||||
}
|
||||
});
|
||||
b.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
return b.create();
|
||||
}
|
||||
|
||||
public static void show(@Nonnull CalculatorWizardActivity activity){
|
||||
AndroidSherlockUtils.showDialog(new FinishWizardConfirmationDialog(), FinishWizardConfirmationDialog.class.getSimpleName(), activity.getSupportFragmentManager());
|
||||
}
|
||||
}
|
@ -60,11 +60,11 @@ public final class Wizard {
|
||||
return preferences.getString(makeFlowStepPreferenceKey(name), null);
|
||||
}
|
||||
|
||||
static void saveWizardFinished(@Nonnull WizardFlow flow, @Nonnull WizardStep step) {
|
||||
static void saveWizardFinished(@Nonnull WizardFlow flow, @Nonnull WizardStep step, boolean forceFinish) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
||||
final SharedPreferences.Editor editor = preferences.edit();
|
||||
|
||||
editor.putBoolean(makeFlowFinishedPreferenceKey(flow), flow.getNextStep(step) == null);
|
||||
editor.putBoolean(makeFlowFinishedPreferenceKey(flow), forceFinish || flow.getNextStep(step) == null);
|
||||
|
||||
editor.commit();
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ public interface CalculatorLocator {
|
||||
@Nonnull
|
||||
CalculatorPreferenceService getPreferenceService();
|
||||
|
||||
@Nonnull
|
||||
// for robolectric
|
||||
/*@Nonnull*/
|
||||
CalculatorExternalListenersContainer getExternalListenersContainer();
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class Locator implements CalculatorLocator {
|
||||
@Nonnull
|
||||
private CalculatorPreferenceService calculatorPreferenceService;
|
||||
|
||||
@Nonnull
|
||||
/*@Nonnull*/
|
||||
private CalculatorExternalListenersContainer calculatorExternalListenersContainer;
|
||||
|
||||
@Nonnull
|
||||
@ -154,7 +154,7 @@ public class Locator implements CalculatorLocator {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
/*@Nonnull*/
|
||||
public CalculatorExternalListenersContainer getExternalListenersContainer() {
|
||||
return calculatorExternalListenersContainer;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user