diff options
author | Dmitry Yunitsky <yunik@mapswithme.com> | 2016-03-18 14:31:55 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-03-23 16:57:02 +0300 |
commit | bea40690676b834d469bec1c6631a6d3c29a5941 (patch) | |
tree | fce1af7b5a9236473d741b66a3e140b8125e887b | |
parent | 9ae07dd93b38513e40b5db175055f5906881ee24 (diff) |
[android] Congrats dialog.
-rw-r--r-- | android/res/layout/dialog_edit_text.xml | 2 | ||||
-rw-r--r-- | android/res/layout/fragment_editor_viral.xml | 63 | ||||
-rw-r--r-- | android/res/values/dimens.xml | 2 | ||||
-rw-r--r-- | android/src/com/mapswithme/maps/MwmActivity.java | 8 | ||||
-rw-r--r-- | android/src/com/mapswithme/maps/editor/ViralFragment.java | 98 |
5 files changed, 171 insertions, 2 deletions
diff --git a/android/res/layout/dialog_edit_text.xml b/android/res/layout/dialog_edit_text.xml index 0757140626..30a346dbaa 100644 --- a/android/res/layout/dialog_edit_text.xml +++ b/android/res/layout/dialog_edit_text.xml @@ -1,7 +1,7 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" - android:minWidth="300dp" + android:minWidth="@dimen/width_dialog_base" android:layout_height="wrap_content" android:orientation="vertical" android:padding="@dimen/margin_base_plus"> diff --git a/android/res/layout/fragment_editor_viral.xml b/android/res/layout/fragment_editor_viral.xml new file mode 100644 index 0000000000..677523f2cc --- /dev/null +++ b/android/res/layout/fragment_editor_viral.xml @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="utf-8"?> +<ScrollView + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_horizontal" + android:minWidth="@dimen/width_dialog_base" + android:orientation="vertical" + android:padding="@dimen/margin_base"> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/margin_half_plus" + android:fontFamily="@string/robotoMedium" + android:text="@string/thank_you" + android:textAppearance="@style/MwmTextAppearance.Body1" + tools:ignore="UnusedAttribute"/> + + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/margin_half_plus" + android:src="@drawable/img_editor_medal"/> + + <TextView + android:id="@+id/viral" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/margin_base_plus" + android:gravity="center" + android:textAppearance="@style/MwmTextAppearance.Body1"/> + + <TextView + android:id="@+id/tell_friend" + android:layout_width="wrap_content" + android:layout_height="@dimen/height_block_base" + android:layout_gravity="end" + android:background="?clickableBackground" + android:gravity="end|center_vertical" + android:padding="@dimen/margin_half" + android:text="@string/tell_friends" + android:textAppearance="@style/MwmTextAppearance.PlacePage.Accent"/> + + <TextView + android:id="@+id/close" + android:layout_width="wrap_content" + android:layout_height="@dimen/height_block_base" + android:layout_gravity="end" + android:background="?clickableBackground" + android:gravity="end|center_vertical" + android:padding="@dimen/margin_half" + android:text="@string/close" + android:textAppearance="@style/MwmTextAppearance.PlacePage.Accent"/> + + </LinearLayout> + +</ScrollView>
\ No newline at end of file diff --git a/android/res/values/dimens.xml b/android/res/values/dimens.xml index b847765891..af91cf023a 100644 --- a/android/res/values/dimens.xml +++ b/android/res/values/dimens.xml @@ -46,6 +46,8 @@ <dimen name="button_width">240dp</dimen> <dimen name="placeholder_size">200dp</dimen> + <dimen name="width_dialog_base">300dp</dimen> + <!-- direction fragment --> <dimen name="margin_direction_small">8dp</dimen> <dimen name="margin_direction_big">20dp</dimen> diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index b132431cb5..5e833903b8 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -43,6 +43,7 @@ import com.mapswithme.maps.downloader.MapManager; import com.mapswithme.maps.downloader.MigrationFragment; import com.mapswithme.maps.downloader.OnmapDownloader; import com.mapswithme.maps.editor.AuthFragment; +import com.mapswithme.maps.editor.ViralFragment; import com.mapswithme.maps.editor.Editor; import com.mapswithme.maps.editor.EditorActivity; import com.mapswithme.maps.editor.EditorHostFragment; @@ -894,7 +895,12 @@ public class MwmActivity extends BaseMwmFragmentActivity }); } if (!isFirstStart && !NewsFragment.showOn(this)) - LikesManager.INSTANCE.showDialogs(this); + { + if (ViralFragment.shouldDisplay()) + new ViralFragment().show(getSupportFragmentManager(), ""); + else + LikesManager.INSTANCE.showDialogs(this); + } } RoutingController.get().restore(); diff --git a/android/src/com/mapswithme/maps/editor/ViralFragment.java b/android/src/com/mapswithme/maps/editor/ViralFragment.java new file mode 100644 index 0000000000..662760432a --- /dev/null +++ b/android/src/com/mapswithme/maps/editor/ViralFragment.java @@ -0,0 +1,98 @@ +package com.mapswithme.maps.editor; + +import android.annotation.SuppressLint; +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.StringRes; +import android.support.v7.app.AlertDialog; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +import java.util.Random; + +import com.mapswithme.maps.MwmApplication; +import com.mapswithme.maps.R; +import com.mapswithme.maps.base.BaseMwmDialogFragment; +import com.mapswithme.util.ConnectionState; + +public class ViralFragment extends BaseMwmDialogFragment +{ + private static final String EXTRA_CONTRATS_SHOWN = "CongratsShown"; + private TextView mViral; + + @StringRes + private static int sViralText; + + public static boolean shouldDisplay() + { + return !MwmApplication.prefs().contains(EXTRA_CONTRATS_SHOWN) && + Editor.nativeGetStats()[0] >= 2 && + ConnectionState.isConnected(); + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) + { + MwmApplication.prefs().edit().putBoolean(EXTRA_CONTRATS_SHOWN, true).apply(); + + final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setCancelable(true); + final LayoutInflater inflater = LayoutInflater.from(getActivity()); + @SuppressLint("InflateParams") + final View root = inflater.inflate(R.layout.fragment_editor_viral, null); + mViral = (TextView) root.findViewById(R.id.viral); + initViralText(); + mViral.setText(sViralText); + // TODO set rank with correct text. + root.findViewById(R.id.tell_friend).setOnClickListener(new View.OnClickListener() + { + @Override + public void onClick(View v) + { + dismiss(); + // TODO send statistics + // TODO open some share link + } + }); + root.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() + { + @Override + public void onClick(View v) + { + dismiss(); + // TODO send statistics + } + }); + return builder.setView(root).create(); + } + + @Override + public void onDismiss(DialogInterface dialog) + { + super.onDismiss(dialog); + // TODO remove before merge + } + + private void initViralText() + { + if (sViralText != 0) + return; + + if (new Random().nextBoolean()) + // FIXME +// sViralText = R.string.editor_done_dialog_1; + sViralText = R.string.dialog_routing_change_start; + else +// sViralText = R.string.editor_done_dialog_2; + sViralText = R.string.dialog_routing_change_end; + } + + // Counts fake editor rank based on number of total edits made by user. + private int getUserEditorRank() + { + return (int) ((1000 + new Random().nextInt(1000)) / Editor.nativeGetStats()[0] / 10); + } +} |