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

@ -2,29 +2,41 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="22dp"
android:padding="24dp">
android:orientation="vertical">
<ImageView
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_christmas_illustration"/>
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:textSize="@dimen/default_desc_text_size"
android:textColor="@color/color_white"
android:text="@string/christmas_desc"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="24dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:textSize="@dimen/default_desc_text_size"
android:textColor="@color/color_white"
android:text="@string/christmas_desc_q"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_christmas_illustration"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/christmas_desc"
android:textColor="@color/color_white"
android:textSize="@dimen/default_desc_text_size"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:text="@string/christmas_desc_q"
android:textColor="@color/color_white"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

View file

@ -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() {

View file

@ -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;
}
}