This commit is contained in:
Sergey Solovyev
2013-06-25 16:17:17 +04:00
parent c906e572f7
commit 2fb20dc2b5
7 changed files with 52 additions and 37 deletions

View File

@@ -41,6 +41,9 @@ import javax.annotation.Nullable;
import static android.os.Build.VERSION_CODES.GINGERBREAD_MR1;
import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
import static org.solovyev.android.calculator.wizard.Wizard.FIRST_TIME_WIZARD;
import static org.solovyev.android.calculator.wizard.Wizard.isWizardFinished;
import static org.solovyev.android.calculator.wizard.Wizard.isWizardStarted;
public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEventListener {
@@ -130,27 +133,31 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
if (!CalculatorApplication.isMonkeyRunner(context)) {
boolean dialogShown = false;
if (Objects.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
// new start
context.startActivity(new Intent(context, CalculatorWizardActivity.class));
if(isWizardStarted(FIRST_TIME_WIZARD) && !isWizardFinished(FIRST_TIME_WIZARD)) {
CalculatorWizardActivity.continueWizard(FIRST_TIME_WIZARD, context);
dialogShown = true;
} else {
if (savedVersion < appVersion) {
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
if (showReleaseNotes) {
final String releaseNotes = CalculatorReleaseNotesFragment.getReleaseNotes(context, savedVersion + 1);
if (!Strings.isEmpty(releaseNotes)) {
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
builder.setPositiveButton(android.R.string.ok, null);
builder.setTitle(R.string.c_release_notes);
builder.create().show();
dialogShown = true;
if (Objects.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
// new start
context.startActivity(new Intent(context, CalculatorWizardActivity.class));
dialogShown = true;
} else {
if (savedVersion < appVersion) {
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
if (showReleaseNotes) {
final String releaseNotes = CalculatorReleaseNotesFragment.getReleaseNotes(context, savedVersion + 1);
if (!Strings.isEmpty(releaseNotes)) {
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
builder.setPositiveButton(android.R.string.ok, null);
builder.setTitle(R.string.c_release_notes);
builder.create().show();
dialogShown = true;
}
}
}
}
}
//Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
if (!dialogShown) {
if (appOpenedCounter != null && appOpenedCounter > 100) {

View File

@@ -268,16 +268,22 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
*/
public static void startWizard(@Nonnull String name, @Nonnull Context context) {
final Intent intent = createLaunchIntent(name, context);
context.startActivity(intent);
}
@Nonnull
private static Intent createLaunchIntent(@Nonnull String name, @Nonnull Context context) {
final Intent intent = new Intent(context, CalculatorWizardActivity.class);
intent.putExtra(FLOW, name);
context.startActivity(intent);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
return intent;
}
public static void continueWizard(@Nonnull String name, @Nonnull Context context) {
final String step = Wizard.getLastSavedWizardStepName(name);
final Intent intent = new Intent(context, CalculatorWizardActivity.class);
intent.putExtra(FLOW, name);
final Intent intent = createLaunchIntent(name, context);
if (step != null) {
intent.putExtra(STEP, step);
}

View File

@@ -1,6 +1,5 @@
package org.solovyev.android.calculator.wizard;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.solovyev.android.calculator.CalculatorApplication;
@@ -41,14 +40,18 @@ public final class Wizard {
public static boolean isWizardFinished(@Nonnull String name) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
return preferences.getBoolean(makeFlowFinishedPreferenceKey(name), false);
return preferences.getBoolean(makeFinishedPreferenceKey(name), false);
}
public static boolean isWizardStarted(@Nonnull String name) {
return getLastSavedWizardStepName(name) != null;
}
static void saveLastWizardStep(@Nonnull WizardFlow flow, @Nonnull WizardStep step) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
final SharedPreferences.Editor editor = preferences.edit();
editor.putString(makeFlowStepPreferenceKey(flow), step.name());
editor.putString(makeLastStepPreferenceKey(flow), step.name());
editor.commit();
}
@@ -57,35 +60,35 @@ public final class Wizard {
static String getLastSavedWizardStepName(@Nonnull String name) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
return preferences.getString(makeFlowStepPreferenceKey(name), null);
return preferences.getString(makeLastStepPreferenceKey(name), null);
}
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), forceFinish || flow.getNextStep(step) == null);
editor.putBoolean(makeFinishedPreferenceKey(flow), forceFinish || flow.getNextStep(step) == null);
editor.commit();
}
@Nonnull
private static String makeFlowFinishedPreferenceKey(@Nonnull String flowName) {
private static String makeFinishedPreferenceKey(@Nonnull WizardFlow flow) {
return makeFinishedPreferenceKey(flow.getName());
}
@Nonnull
private static String makeFinishedPreferenceKey(@Nonnull String flowName) {
return FLOW_FINISHED + ":" + flowName;
}
@Nonnull
private static String makeFlowStepPreferenceKey(@Nonnull WizardFlow flow) {
return makeFlowStepPreferenceKey(flow.getName());
private static String makeLastStepPreferenceKey(@Nonnull WizardFlow flow) {
return makeLastStepPreferenceKey(flow.getName());
}
@Nonnull
private static String makeFlowStepPreferenceKey(@Nonnull String flowName) {
private static String makeLastStepPreferenceKey(@Nonnull String flowName) {
return FLOW + ":" + flowName;
}
@Nonnull
private static String makeFlowFinishedPreferenceKey(@Nonnull WizardFlow flow) {
return makeFlowFinishedPreferenceKey(flow.getName());
}
}