Fix Cristmas dialog

This commit is contained in:
Alexey Kulish 2016-10-25 13:54:29 +03:00
parent 54eba4bbdd
commit fb7e8f99c0
3 changed files with 63 additions and 34 deletions

View file

@ -1,9 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:paddingBottom="22dp"
android:padding="24dp"> android:padding="24dp">
<ImageView <ImageView
@ -15,16 +23,20 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:textSize="@dimen/default_desc_text_size" android:text="@string/christmas_desc"
android:textColor="@color/color_white" android:textColor="@color/color_white"
android:text="@string/christmas_desc"/> android:textSize="@dimen/default_desc_text_size"/>
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="22dp" android:layout_marginTop="22dp"
android:textSize="@dimen/default_desc_text_size" android:text="@string/christmas_desc_q"
android:textColor="@color/color_white" android:textColor="@color/color_white"
android:text="@string/christmas_desc_q"/> android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
</ScrollView>
</LinearLayout> </LinearLayout>

View file

@ -72,7 +72,7 @@ import net.osmand.plus.base.FailSafeFuntions;
import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dialogs.ErrorBottomSheetDialog; 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.RateUsBottomSheetDialog;
import net.osmand.plus.dialogs.WhatsNewDialogFragment; import net.osmand.plus.dialogs.WhatsNewDialogFragment;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
@ -630,8 +630,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()
.add(R.id.fragmentContainer, new FirstUsageWelcomeFragment(), .add(R.id.fragmentContainer, new FirstUsageWelcomeFragment(),
FirstUsageWelcomeFragment.TAG).commitAllowingStateLoss(); FirstUsageWelcomeFragment.TAG).commitAllowingStateLoss();
} else { } else if (!isFirstScreenShowing() && XMasDialogFragment.shouldShowXmasDialog(app)) {
XMasDialog.showXMasDialog(this); new XMasDialogFragment().show(getSupportFragmentManager(), XMasDialogFragment.TAG);
} }
FirstUsageWelcomeFragment.SHOW = false; 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 // DownloadEvents
@Override @Override
public void newDownloadIndexes() { public void newDownloadIndexes() {

View file

@ -1,6 +1,10 @@
package net.osmand.plus.dialogs; package net.osmand.plus.dialogs;
import android.app.Dialog;
import android.content.DialogInterface; 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.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@ -12,18 +16,15 @@ import net.osmand.plus.activities.MapActivity;
import java.util.Date; import java.util.Date;
public class XMasDialog { public class XMasDialogFragment extends DialogFragment {
public static final String TAG = "XMasDialogFragment";
private static boolean XmasDialogWasProcessed = false; private static boolean XmasDialogWasProcessed = false;
public static void showXMasDialog(final MapActivity mapActivity) { public static boolean shouldShowXmasDialog(OsmandApplication app) {
if (XmasDialogWasProcessed) { if (XmasDialogWasProcessed) {
return; return false;
} }
XmasDialogWasProcessed = true;
OsmandApplication app = mapActivity.getMyApplication();
int numberOfStarts = app.getAppInitializer().getNumberOfStarts(); int numberOfStarts = app.getAppInitializer().getNumberOfStarts();
if (numberOfStarts > 2) { if (numberOfStarts > 2) {
Date now = new Date(); Date now = new Date();
@ -36,17 +37,26 @@ public class XMasDialog {
app.getSettings().NUMBER_OF_STARTS_FIRST_XMAS_SHOWN.set(numberOfStarts); app.getSettings().NUMBER_OF_STARTS_FIRST_XMAS_SHOWN.set(numberOfStarts);
} }
} else { } else {
return; return false;
} }
} else { } else {
if (firstShownX != 0) { if (firstShownX != 0) {
app.getSettings().NUMBER_OF_STARTS_FIRST_XMAS_SHOWN.set(0); app.getSettings().NUMBER_OF_STARTS_FIRST_XMAS_SHOWN.set(0);
} }
return; return false;
} }
} else { } 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); final AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity, R.style.XmasDialogTheme);
View titleView = mapActivity.getLayoutInflater().inflate(R.layout.xmas_dialog_title, null); View titleView = mapActivity.getLayoutInflater().inflate(R.layout.xmas_dialog_title, null);
@ -86,6 +96,6 @@ public class XMasDialog {
negativeButton.invalidate(); negativeButton.invalidate();
} }
}); });
dialog.show(); return dialog;
} }
} }