forked from organicmaps/organicmaps
Added facebook app invites.
This commit is contained in:
parent
6c02385e75
commit
b629a59454
6 changed files with 203 additions and 31 deletions
44
android/res/layout/fragment_app_invites_dialog.xml
Normal file
44
android/res/layout/fragment_app_invites_dialog.xml
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/base_green"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/margin_medium_and_half"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/img_smile"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="@dimen/margin_medium"
|
||||
android:layout_marginLeft="@dimen/margin_medium_and_half"
|
||||
android:layout_marginRight="@dimen/margin_medium_and_half"
|
||||
android:text="@string/rating_do_like_maps"
|
||||
android:textAppearance="@style/MwmTextAppearance.Title.Light"
|
||||
android:textStyle="bold"/>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/margin_medium_and_half"
|
||||
android:layout_marginLeft="@dimen/margin_medium_and_half"
|
||||
android:layout_marginRight="@dimen/margin_medium_and_half"
|
||||
android:layout_marginTop="@dimen/margin_medium"
|
||||
android:text="@string/rating_tap_star"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body2"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -196,6 +196,11 @@
|
|||
<item name="android:textColor">@color/text_dark</item>
|
||||
</style>
|
||||
|
||||
<style name="MwmTextAppearance.Title.Light">
|
||||
<item name="android:textSize">@dimen/text_size_title</item>
|
||||
<item name="android:textColor">@color/text_light</item>
|
||||
</style>
|
||||
|
||||
<style name="MwmTextAppearance.Body1">
|
||||
<item name="android:textSize">@dimen/text_size_body_1</item>
|
||||
<item name="android:textColor">@color/text_dark</item>
|
||||
|
|
|
@ -1002,7 +1002,7 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
|
||||
SearchController.getInstance().onResume();
|
||||
mPlacePage.onResume();
|
||||
mLikesManager.showLikeDialogs();
|
||||
mLikesManager.showLikeDialogForCurrentSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1012,7 +1012,7 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
stopWatchingExternalStorage();
|
||||
stopWatchingCompassStatusUpdate();
|
||||
super.onPause();
|
||||
mLikesManager.cancelLikeDialogs();
|
||||
mLikesManager.cancelLikeDialog();
|
||||
}
|
||||
|
||||
private void updateExternalStorageState()
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package com.mapswithme.maps.ads;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import com.facebook.share.model.AppInviteContent;
|
||||
import com.facebook.share.widget.AppInviteDialog;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
public class FacebookInvitesDialogFragment extends BaseMwmDialogFragment
|
||||
{
|
||||
private static final String INVITE_APP_URL = "https://fb.me/958251974218933";
|
||||
private static final String INVITE_IMAGE = "http://maps.me/images/fb_app_invite_banner.png";
|
||||
|
||||
private static final String TAG = FacebookInvitesDialogFragment.class.getSimpleName();
|
||||
private boolean mHasInvited;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState)
|
||||
{
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
|
||||
final View root = inflater.inflate(R.layout.fragment_app_invites_dialog, null);
|
||||
builder.
|
||||
setView(root).
|
||||
setNegativeButton(R.string.remind_me_later, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
Statistics.INSTANCE.trackSimpleNamedEvent(Statistics.EventName.FACEBOOK_INVITE_LATER);
|
||||
}
|
||||
}).
|
||||
setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
mHasInvited = true;
|
||||
showAppInviteDialog();
|
||||
Statistics.INSTANCE.trackSimpleNamedEvent(Statistics.EventName.FACEBOOK_INVITE_INVITED);
|
||||
}
|
||||
});
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (mHasInvited)
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog)
|
||||
{
|
||||
super.onCancel(dialog);
|
||||
Statistics.INSTANCE.trackSimpleNamedEvent(Statistics.EventName.FACEBOOK_INVITE_LATER);
|
||||
}
|
||||
|
||||
private void showAppInviteDialog()
|
||||
{
|
||||
AppInviteContent content = new AppInviteContent.Builder()
|
||||
.setApplinkUrl(INVITE_APP_URL)
|
||||
.setPreviewImageUrl(INVITE_IMAGE)
|
||||
.build();
|
||||
if (AppInviteDialog.canShow())
|
||||
AppInviteDialog.show(this, content);
|
||||
else
|
||||
{
|
||||
UiUtils.showAlertDialog(getActivity(), R.string.email_error_title);
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,22 +4,68 @@ import android.os.Handler;
|
|||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
import com.mapswithme.maps.BuildConfig;
|
||||
import com.mapswithme.maps.MWMApplication;
|
||||
import com.mapswithme.util.ConnectionState;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class LikesManager
|
||||
{
|
||||
public static final Integer[] GPLAY_NEW_USERS = new Integer[]{3, 10, 21};
|
||||
public static final Integer[] GPLUS_NEW_USERS = new Integer[]{11, 30, 50};
|
||||
public static final Integer[] GPLAY_OLD_USERS = new Integer[]{1, 10, 21};
|
||||
public static final Integer[] GPLUS_OLD_USERS = new Integer[]{4, 24, 44};
|
||||
/*
|
||||
Maps type of like dialog to the dialog, performing like.
|
||||
*/
|
||||
private enum LikeType
|
||||
{
|
||||
GPLAY_NEW_USERS(RateStoreDialogFragment.class),
|
||||
GPLAY_OLD_USERS(RateStoreDialogFragment.class),
|
||||
GPLUS_NEW_USERS(GooglePlusDialogFragment.class),
|
||||
GPLUS_OLD_USERS(GooglePlusDialogFragment.class),
|
||||
FACEBOOK_INVITE_NEW_USERS(FacebookInvitesDialogFragment.class),
|
||||
FACEBOOK_INVITES_OLD_USERS(FacebookInvitesDialogFragment.class);
|
||||
|
||||
public final Class<? extends DialogFragment> clazz;
|
||||
|
||||
LikeType(Class<? extends DialogFragment> clazz)
|
||||
{
|
||||
this.clazz = clazz;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Maps number of session to LikeType
|
||||
*/
|
||||
private static Map<Integer, LikeType> mOldUsersMapping = new HashMap<>();
|
||||
private static Map<Integer, LikeType> mNewUsersMapping = new HashMap<>();
|
||||
|
||||
static
|
||||
{
|
||||
mOldUsersMapping.put(1, LikeType.GPLAY_OLD_USERS);
|
||||
mOldUsersMapping.put(4, LikeType.GPLUS_OLD_USERS);
|
||||
mOldUsersMapping.put(6, LikeType.FACEBOOK_INVITES_OLD_USERS);
|
||||
mOldUsersMapping.put(10, LikeType.GPLAY_OLD_USERS);
|
||||
mOldUsersMapping.put(21, LikeType.GPLAY_OLD_USERS);
|
||||
mOldUsersMapping.put(24, LikeType.GPLUS_OLD_USERS);
|
||||
mOldUsersMapping.put(30, LikeType.FACEBOOK_INVITES_OLD_USERS);
|
||||
mOldUsersMapping.put(44, LikeType.GPLUS_OLD_USERS);
|
||||
mOldUsersMapping.put(50, LikeType.FACEBOOK_INVITES_OLD_USERS);
|
||||
|
||||
mNewUsersMapping.put(3, LikeType.GPLAY_NEW_USERS);
|
||||
mNewUsersMapping.put(9, LikeType.FACEBOOK_INVITE_NEW_USERS);
|
||||
mNewUsersMapping.put(10, LikeType.GPLAY_NEW_USERS);
|
||||
mNewUsersMapping.put(11, LikeType.GPLUS_NEW_USERS);
|
||||
mNewUsersMapping.put(21, LikeType.GPLAY_NEW_USERS);
|
||||
mNewUsersMapping.put(30, LikeType.GPLUS_NEW_USERS);
|
||||
mNewUsersMapping.put(35, LikeType.FACEBOOK_INVITE_NEW_USERS);
|
||||
mNewUsersMapping.put(50, LikeType.GPLUS_NEW_USERS);
|
||||
mNewUsersMapping.put(55, LikeType.FACEBOOK_INVITE_NEW_USERS);
|
||||
}
|
||||
|
||||
private static final long DIALOG_DELAY_MILLIS = 30000;
|
||||
|
||||
private final boolean mIsNewUser;
|
||||
private final boolean mIsNewUser = MWMApplication.get().getFirstInstallVersion() == BuildConfig.VERSION_CODE;
|
||||
private final int mSessionNum;
|
||||
|
||||
private Handler mHandler;
|
||||
|
@ -34,40 +80,29 @@ public class LikesManager
|
|||
mHandler = new Handler(activity.getMainLooper());
|
||||
mActivityRef = new WeakReference<>(activity);
|
||||
|
||||
mIsNewUser = MWMApplication.get().getFirstInstallVersion() >= 422;
|
||||
mSessionNum = MWMApplication.get().getSessionsNumber();
|
||||
}
|
||||
|
||||
public void showLikeDialogs()
|
||||
public void showLikeDialogForCurrentSession()
|
||||
{
|
||||
if (!ConnectionState.isConnected())
|
||||
return;
|
||||
|
||||
if (mIsNewUser)
|
||||
{
|
||||
if (Arrays.asList(GPLAY_NEW_USERS).contains(mSessionNum))
|
||||
displayLikeDialog(RateStoreDialogFragment.class);
|
||||
else if (Arrays.asList(GPLUS_NEW_USERS).contains(mSessionNum))
|
||||
displayLikeDialog(GooglePlusDialogFragment.class);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Arrays.asList(GPLAY_OLD_USERS).contains(mSessionNum))
|
||||
displayLikeDialog(RateStoreDialogFragment.class);
|
||||
else if (Arrays.asList(GPLUS_OLD_USERS).contains(mSessionNum))
|
||||
displayLikeDialog(GooglePlusDialogFragment.class);
|
||||
}
|
||||
final LikeType type = mIsNewUser ? mNewUsersMapping.get(mSessionNum) : mOldUsersMapping.get(mSessionNum);
|
||||
if (type != null)
|
||||
displayLikeDialog(type.clazz);
|
||||
}
|
||||
|
||||
private void displayLikeDialog(final Class<? extends DialogFragment> dialogFragmentClass)
|
||||
{
|
||||
if (isSessionRated() || isRatingApplied(dialogFragmentClass))
|
||||
if (isSessionRated(mSessionNum) || isRatingApplied(dialogFragmentClass))
|
||||
return;
|
||||
setSessionRated();
|
||||
setSessionRated(mSessionNum);
|
||||
|
||||
mHandler.removeCallbacks(mLikeRunnable);
|
||||
mLikeRunnable = new Runnable()
|
||||
{
|
||||
@SuppressWarnings("TryWithIdenticalCatches")
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
|
@ -92,19 +127,19 @@ public class LikesManager
|
|||
mHandler.postDelayed(mLikeRunnable, DIALOG_DELAY_MILLIS);
|
||||
}
|
||||
|
||||
public void cancelLikeDialogs()
|
||||
public void cancelLikeDialog()
|
||||
{
|
||||
mHandler.removeCallbacks(mLikeRunnable);
|
||||
}
|
||||
|
||||
public boolean isSessionRated()
|
||||
public static boolean isSessionRated(int sessionNum)
|
||||
{
|
||||
return MWMApplication.get().nativeGetInt(LAST_RATED_SESSION, 0) >= mSessionNum;
|
||||
return MWMApplication.get().nativeGetInt(LAST_RATED_SESSION, 0) >= sessionNum;
|
||||
}
|
||||
|
||||
public void setSessionRated()
|
||||
public static void setSessionRated(int sessionNum)
|
||||
{
|
||||
MWMApplication.get().nativeSetInt(LAST_RATED_SESSION, mSessionNum);
|
||||
MWMApplication.get().nativeSetInt(LAST_RATED_SESSION, sessionNum);
|
||||
}
|
||||
|
||||
public static boolean isRatingApplied(final Class<? extends DialogFragment> dialogFragmentClass)
|
||||
|
|
|
@ -73,6 +73,8 @@ public enum Statistics
|
|||
public static final String APP_ACTIVATED = "Application activated.";
|
||||
public static final String PLUS_DIALOG_LATER = "GPlus dialog cancelled.";
|
||||
public static final String RATE_DIALOG_LATER = "GPlay dialog cancelled.";
|
||||
public static final String FACEBOOK_INVITE_LATER = "Facebook invites dialog cancelled.";
|
||||
public static final String FACEBOOK_INVITE_INVITED = "GPlay dialog cancelled.";
|
||||
public static final String RATE_DIALOG_RATED = "GPlay dialog. Rating set";
|
||||
public static final String PREINSTALL_ACTIVATED = "Preinstalled application activated.";
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue