diff --git a/OsmAnd/res/layout/xmas_dialog.xml b/OsmAnd/res/layout/xmas_dialog.xml index 4e8d4b0859..e8123fc437 100644 --- a/OsmAnd/res/layout/xmas_dialog.xml +++ b/OsmAnd/res/layout/xmas_dialog.xml @@ -2,29 +2,41 @@ + android:orientation="vertical"> - + android:layout_height="wrap_content"> - + - + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index e715a76092..e8bbc71a34 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -72,7 +72,7 @@ import net.osmand.plus.base.FailSafeFuntions; import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dialogs.ErrorBottomSheetDialog; -import net.osmand.plus.dialogs.XMasDialog; +import net.osmand.plus.dialogs.XMasDialogFragment; import net.osmand.plus.dialogs.RateUsBottomSheetDialog; import net.osmand.plus.dialogs.WhatsNewDialogFragment; import net.osmand.plus.download.DownloadActivity; @@ -630,8 +630,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven getSupportFragmentManager().beginTransaction() .add(R.id.fragmentContainer, new FirstUsageWelcomeFragment(), FirstUsageWelcomeFragment.TAG).commitAllowingStateLoss(); - } else { - XMasDialog.showXMasDialog(this); + } else if (!isFirstScreenShowing() && XMasDialogFragment.shouldShowXmasDialog(app)) { + new XMasDialogFragment().show(getSupportFragmentManager(), XMasDialogFragment.TAG); } FirstUsageWelcomeFragment.SHOW = false; } @@ -1278,6 +1278,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } } + public boolean isFirstScreenShowing() { + FirstUsageWelcomeFragment welcomeFragment = (FirstUsageWelcomeFragment) getSupportFragmentManager().findFragmentByTag(FirstUsageWelcomeFragment.TAG); + FirstUsageWizardFragment wizardFragment = (FirstUsageWizardFragment) getSupportFragmentManager().findFragmentByTag(FirstUsageWizardFragment.TAG); + return welcomeFragment != null && !welcomeFragment.isDetached() + || wizardFragment != null && !wizardFragment.isDetached(); + } + // DownloadEvents @Override public void newDownloadIndexes() { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/XMasDialog.java b/OsmAnd/src/net/osmand/plus/dialogs/XMasDialogFragment.java similarity index 83% rename from OsmAnd/src/net/osmand/plus/dialogs/XMasDialog.java rename to OsmAnd/src/net/osmand/plus/dialogs/XMasDialogFragment.java index 3c5b388e20..57d2695d95 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/XMasDialog.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/XMasDialogFragment.java @@ -1,6 +1,10 @@ package net.osmand.plus.dialogs; +import android.app.Dialog; import android.content.DialogInterface; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.view.View; import android.widget.Button; @@ -12,18 +16,15 @@ import net.osmand.plus.activities.MapActivity; import java.util.Date; -public class XMasDialog { +public class XMasDialogFragment extends DialogFragment { + public static final String TAG = "XMasDialogFragment"; private static boolean XmasDialogWasProcessed = false; - public static void showXMasDialog(final MapActivity mapActivity) { - + public static boolean shouldShowXmasDialog(OsmandApplication app) { if (XmasDialogWasProcessed) { - return; + return false; } - XmasDialogWasProcessed = true; - - OsmandApplication app = mapActivity.getMyApplication(); int numberOfStarts = app.getAppInitializer().getNumberOfStarts(); if (numberOfStarts > 2) { Date now = new Date(); @@ -36,17 +37,26 @@ public class XMasDialog { app.getSettings().NUMBER_OF_STARTS_FIRST_XMAS_SHOWN.set(numberOfStarts); } } else { - return; + return false; } } else { if (firstShownX != 0) { app.getSettings().NUMBER_OF_STARTS_FIRST_XMAS_SHOWN.set(0); } - return; + return false; } } else { - return; + return false; } + return true; + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + + XmasDialogWasProcessed = true; + final MapActivity mapActivity = (MapActivity) getActivity(); final AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity, R.style.XmasDialogTheme); View titleView = mapActivity.getLayoutInflater().inflate(R.layout.xmas_dialog_title, null); @@ -86,6 +96,6 @@ public class XMasDialog { negativeButton.invalidate(); } }); - dialog.show(); + return dialog; } }