Skip to content

Commit

Permalink
Release 1.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderLS committed Apr 25, 2018
1 parent 22f3ac9 commit 37ea65f
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 82 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CHANGELOG

## 1.1.6 (released 24.04.2018)
## 1.1.6 (released 25.04.2018)

- LIBff10424
- LIBcc20420
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,74 @@ public class UriHelperTest extends AndroidTestCase {

private static final String GOOGLE_PLAY_WEB = "https://play.google.com/store/apps/details?id=";

@SuppressWarnings("ConstantConditions")
@SuppressWarnings({"ConstantConditions", "UnnecessaryLocalVariable"})
public void testGetStoreUri() {
{
Uri uri = UriHelper.getStoreUri(CHINESESTORES,"");
final byte appStore = CHINESESTORES;
Uri uri = UriHelper.getStoreUri(appStore,"");
assertEquals(uri.toString(), CHINESE_STORES);
}
{
Uri uri = UriHelper.getStoreUri(GOOGLEPLAY,"");
final byte appStore = GOOGLEPLAY;
Uri uri = UriHelper.getStoreUri(appStore,"");
assertEquals(uri.toString(), GOOGLE_PLAY);
}
{
Uri uri = UriHelper.getStoreUri(CHINESESTORES,null);
final byte appStore = CHINESESTORES;
Uri uri = UriHelper.getStoreUri(appStore,null);
assertNull(uri);
}
{
Uri uri = UriHelper.getStoreUri(GOOGLEPLAY,null);
final byte appStore = GOOGLEPLAY;
Uri uri = UriHelper.getStoreUri(appStore,null);
assertNull(uri);
}
{
final byte appStore = CHINESESTORES;
final String paramName = "com.vorlonsoft.android.rate";
Uri uri = UriHelper.getStoreUri(CHINESESTORES, paramName);
Uri uri = UriHelper.getStoreUri(appStore, paramName);
assertEquals(uri.toString(), CHINESE_STORES + paramName);
}
{
final byte appStore = GOOGLEPLAY;
final String paramName = "com.vorlonsoft.android.rate";
Uri uri = UriHelper.getStoreUri(GOOGLEPLAY, paramName);
Uri uri = UriHelper.getStoreUri(appStore, paramName);
assertEquals(uri.toString(), GOOGLE_PLAY + paramName);
}
}

@SuppressWarnings("ConstantConditions")
@SuppressWarnings({"ConstantConditions", "UnnecessaryLocalVariable"})
public void testGetStoreWebUri() {
{
Uri uri = UriHelper.getStoreWebUri(CHINESESTORES,"");
final byte appStore = CHINESESTORES;
Uri uri = UriHelper.getStoreWebUri(appStore,"");
assertNull(uri);
}
{
Uri uri = UriHelper.getStoreWebUri(GOOGLEPLAY,"");
final byte appStore = GOOGLEPLAY;
Uri uri = UriHelper.getStoreWebUri(appStore,"");
assertEquals(uri.toString(), GOOGLE_PLAY_WEB);
}
{
Uri uri = UriHelper.getStoreWebUri(CHINESESTORES,null);
final byte appStore = CHINESESTORES;
Uri uri = UriHelper.getStoreWebUri(appStore,null);
assertNull(uri);
}
{
Uri uri = UriHelper.getStoreWebUri(GOOGLEPLAY,null);
final byte appStore = GOOGLEPLAY;
Uri uri = UriHelper.getStoreWebUri(appStore,null);
assertNull(uri);
}
{
final byte appStore = CHINESESTORES;
final String paramName = "com.vorlonsoft.android.rate";
Uri uri = UriHelper.getStoreWebUri(CHINESESTORES, paramName);
Uri uri = UriHelper.getStoreWebUri(appStore, paramName);
assertNull(uri);
}
{
final byte appStore = GOOGLEPLAY;
final String paramName = "com.vorlonsoft.android.rate";
Uri uri = UriHelper.getStoreWebUri(GOOGLEPLAY, paramName);
Uri uri = UriHelper.getStoreWebUri(appStore, paramName);
assertEquals(uri.toString(), GOOGLE_PLAY_WEB + paramName);
}
}
Expand Down
36 changes: 23 additions & 13 deletions library/src/main/java/com/vorlonsoft/android/rate/AppRate.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,42 @@
import java.util.HashMap;
import java.util.Map;

import static com.vorlonsoft.android.rate.PreferenceHelper.*;
import static com.vorlonsoft.android.rate.PreferenceHelper.getCustomEventCount;
import static com.vorlonsoft.android.rate.PreferenceHelper.getInstallDate;
import static com.vorlonsoft.android.rate.PreferenceHelper.getIsAgreeShowDialog;
import static com.vorlonsoft.android.rate.PreferenceHelper.getLaunchTimes;
import static com.vorlonsoft.android.rate.PreferenceHelper.getRemindInterval;
import static com.vorlonsoft.android.rate.PreferenceHelper.isFirstLaunch;
import static com.vorlonsoft.android.rate.PreferenceHelper.setCustomEventCount;
import static com.vorlonsoft.android.rate.PreferenceHelper.setInstallDate;
import static com.vorlonsoft.android.rate.StoreType.AMAZON;
import static com.vorlonsoft.android.rate.StoreType.APPLE;
import static com.vorlonsoft.android.rate.StoreType.BLACKBERRY;
import static com.vorlonsoft.android.rate.StoreType.INTENT;
import static com.vorlonsoft.android.rate.StoreType.OTHER;
import static com.vorlonsoft.android.rate.StoreType.YANDEX;
import static com.vorlonsoft.android.rate.Utils.DAY_IN_MILLIS;

public final class AppRate {

static final String TAG = "ANDROIDRATE";

@SuppressLint("StaticFieldLeak")
private static AppRate singleton;
private static volatile AppRate singleton = null;

private final Context context;

private final DialogOptions options = new DialogOptions();

private byte installDate = 10;
private byte installDate = (byte) 10;

private byte launchTimes = 10;
private byte launchTimes = (byte) 10;

private byte remindInterval = 1;
private byte remindInterval = (byte) 1;

private final HashMap<String, Short> customEventCounts = new HashMap<>();

private byte remindLaunchTimes = 1;
private byte remindLaunchTimes = (byte) 1;

private boolean isDebug = false;

Expand All @@ -69,15 +77,15 @@ public static AppRate with(Context context) {

@SuppressWarnings("UnusedReturnValue")
public static boolean showRateDialogIfMeetsConditions(Activity activity) {
boolean isMeetsConditions = singleton.isDebug || singleton.shouldShowRateDialog();
boolean isMeetsConditions = singleton.isDebug() || singleton.shouldShowRateDialog();
if (isMeetsConditions) {
singleton.showRateDialog(activity);
}
return isMeetsConditions;
}

private static boolean isOverDate(long targetDate, byte threshold) {
return new Date().getTime() - targetDate >= (long) (threshold) * 24 * 60 * 60 * 1000;
return new Date().getTime() - targetDate >= threshold * DAY_IN_MILLIS;
}

public AppRate setLaunchTimes(@SuppressWarnings("SameParameterValue") byte launchTimes) {
Expand Down Expand Up @@ -214,7 +222,7 @@ public AppRate setCancelable(@SuppressWarnings("SameParameterValue") boolean can
return this;
}

public AppRate setStoreType(@StoreType.Store final int storeType) {
public AppRate setStoreType(@StoreType.StoreWithoutApplicationId final int storeType) {
if ((storeType == APPLE) || (storeType == BLACKBERRY)) {
throw new IllegalArgumentException("For StoreType.APPLE/StoreType.BLACKBERRY you must use setStoreType(StoreType.APPLE/StoreType.BLACKBERRY, long applicationId)");
} else if ((storeType < AMAZON) || (storeType > YANDEX)) {
Expand All @@ -224,7 +232,7 @@ public AppRate setStoreType(@StoreType.Store final int storeType) {
}

@SuppressWarnings("unused")
public AppRate setStoreType(@StoreType.StoreWithId final int storeType, final long applicationId) {
public AppRate setStoreType(@StoreType.StoreWithApplicationId final int storeType, final long applicationId) {
if ((storeType < AMAZON) || (storeType > YANDEX)) {
throw new IllegalArgumentException("StoreType must be one of: AMAZON, APPLE, BAZAAR, BLACKBERRY, CHINESESTORES, GOOGLEPLAY, MI, SAMSUNG, SLIDEME, TENCENT, YANDEX");
}
Expand Down Expand Up @@ -252,7 +260,7 @@ private AppRate setStoreType(final byte storeType, final String stringParam, fin
return this;
}

@StoreType.Return
@StoreType.AnyStoreType
public int getStoreType() {
return options.getStoreType();
}
Expand Down Expand Up @@ -313,7 +321,9 @@ private boolean isOverLaunchTimes() {
return getLaunchTimes(context) >= launchTimes;
}

private boolean isOverRemindLaunchTimes() { return ((remindLaunchTimes != 0) && ((getLaunchTimes(context) % remindLaunchTimes) == 0)); }
private boolean isOverRemindLaunchTimes() {
return ((remindLaunchTimes != 0) && ((getLaunchTimes(context) % remindLaunchTimes) == 0));
}

private boolean isOverInstallDate() {
return isOverDate(getInstallDate(context), installDate);
Expand All @@ -333,7 +343,7 @@ private boolean isOverCustomEventRequirements() {
return true;
}

@SuppressWarnings("unused")
@SuppressWarnings({"unused", "WeakerAccess"})
public boolean isDebug() {
return isDebug;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;

Expand Down Expand Up @@ -39,7 +40,7 @@ public class DefaultDialogManager implements DialogManager {

static class Factory implements DialogManager.Factory {
@Override
public DialogManager createDialogManager(Context context, DialogOptions options) {
public DialogManager createDialogManager(final Context context, final DialogOptions options) {
return new DefaultDialogManager(context, options);
}
}
Expand Down Expand Up @@ -105,7 +106,7 @@ public void onClick(final DialogInterface dialog, final int which) {
try {
if (intentsToAppStores != null) {
if (intentsToAppStores.length == 0) {
Log.w(TAG, "Failed to rate app, no intent found for startActivity (intentsToAppStores.length == null)");
Log.w(TAG, "Failed to rate app, no intent found for startActivity (intentsToAppStores.length == 0)");
} else if (intentsToAppStores[0] == null) {
throw new ActivityNotFoundException("Failed to rate app, no intent found for startActivity (intentsToAppStores[0] == null)");
} else {
Expand All @@ -114,22 +115,23 @@ public void onClick(final DialogInterface dialog, final int which) {
}
} catch (ActivityNotFoundException e) {
Log.w(TAG, "Failed to rate app, no activity found for " + intentsToAppStores[0], e);
if (intentsToAppStores.length > 1) {
for (byte i = 1; i < intentsToAppStores.length; i++) { // intentsToAppStores[1] - second intent in the array
boolean isCatch = false;
byte intentsToAppStoresNumber = (byte) intentsToAppStores.length;
if (intentsToAppStoresNumber > 1) {
boolean isCatch;
for (byte b = 1; b < intentsToAppStoresNumber; b++) { // intentsToAppStores[1] - second intent in the array
try {
if (intentsToAppStores[i] == null) {
throw new ActivityNotFoundException("Failed to rate app, no intent found for startActivity (intentsToAppStores[" + i + "] == null)");
if (intentsToAppStores[b] == null) {
throw new ActivityNotFoundException("Failed to rate app, no intent found for startActivity (intentsToAppStores[" + b + "] == null)");
} else {
context.startActivity(intentsToAppStores[i]);
context.startActivity(intentsToAppStores[b]);
}
isCatch = false;
} catch (ActivityNotFoundException ex) {
Log.w(TAG, "Failed to rate app, no activity found for " + intentsToAppStores[i], ex);
Log.w(TAG, "Failed to rate app, no activity found for " + intentsToAppStores[b], ex);
isCatch = true;
} finally {
if (!isCatch) {
i = (byte) intentsToAppStores.length;
}
}
if (!isCatch) {
break;
}
}
}
Expand All @@ -144,9 +146,10 @@ public void onClick(final DialogInterface dialog, final int which) {
@Override
public void onClick(final DialogInterface dialog, final int which) {
setAgreeShowDialog(context, false);
if (DefaultDialogManager.this.listener != null) DefaultDialogManager.this.listener.onClickButton((byte) which);
if (listener != null) listener.onClickButton((byte) which);
}
};

@SuppressWarnings("WeakerAccess")
protected final DialogInterface.OnClickListener neutralListener = new DialogInterface.OnClickListener() {
@Override
Expand All @@ -163,6 +166,7 @@ public DefaultDialogManager(final Context context, final DialogOptions options)
this.listener = options.getListener();
}

@Nullable
@Override
public Dialog createDialog() {
AlertDialog.Builder builder = getDialogBuilder(context, options.getThemeResId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.Nullable;
import android.view.View;

import java.lang.ref.Reference;
Expand Down Expand Up @@ -64,6 +65,9 @@ final class DialogOptions {

private Reference<OnClickButtonListener> listener = null;

DialogOptions() {
}

boolean shouldShowNeutralButton() {
return showNeutralButton;
}
Expand Down Expand Up @@ -173,6 +177,7 @@ void setTextPositiveResId(int textPositiveResId) {
int getTextNeutralResId() {
return textNeutralResId;
}

void setTextNeutralResId(int textNeutralResId) {
this.textNeutralResId = textNeutralResId;
}
Expand All @@ -194,6 +199,7 @@ void setView(View view) {
this.view = view;
}

@Nullable
OnClickButtonListener getListener() {
return listener != null ? listener.get() : null;
}
Expand Down
23 changes: 11 additions & 12 deletions library/src/main/java/com/vorlonsoft/android/rate/IntentHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

import java.util.Arrays;
Expand Down Expand Up @@ -96,10 +97,12 @@ private static void setIntentForStore(final Intent intent) {
}

@SuppressWarnings("ConstantConditions")
@Nullable
static Intent[] createIntentsForOtherStores(@NonNull final Uri uri) {
return uri == null ? null : new Intent[]{new Intent(Intent.ACTION_VIEW, uri)};
}

@Nullable
static Intent[] createIntentsForStore(@NonNull final Context context, final byte appStore, @NonNull final String paramName) {

//noinspection ConstantConditions
Expand Down Expand Up @@ -158,15 +161,11 @@ static Intent[] createIntentsForStore(@NonNull final Context context, final byte
deviceStoresPackagesNumber = deviceStoresPackagesNames == null ? 0 : (byte) deviceStoresPackagesNames.length;

if (deviceStoresPackagesNumber > 0) {
if (hasWebUriIntent) {
intents = new Intent[deviceStoresPackagesNumber + 1];
} else {
intents = new Intent[deviceStoresPackagesNumber];
}
for (byte i = 0; i < deviceStoresPackagesNumber; i++) {
intents[i] = new Intent(Intent.ACTION_VIEW, getStoreUri(appStore, paramName));
setIntentForStore(intents[i]);
intents[i].setPackage(storesPackagesNames[i]);
intents = hasWebUriIntent ? new Intent[deviceStoresPackagesNumber + 1] : new Intent[deviceStoresPackagesNumber];
for (byte b = 0; b < deviceStoresPackagesNumber; b++) {
intents[b] = new Intent(Intent.ACTION_VIEW, getStoreUri(appStore, paramName));
setIntentForStore(intents[b]);
intents[b].setPackage(deviceStoresPackagesNames[b]);
}
if (hasWebUriIntent) {
intents[deviceStoresPackagesNumber] = new Intent(Intent.ACTION_VIEW, getStoreWebUri(appStore, paramName));
Expand All @@ -181,10 +180,10 @@ static Intent[] createIntentsForStore(@NonNull final Context context, final byte
}
}
} else {
if (!hasWebUriIntent) {
Log.w(TAG, "Failed to rate app, " + Arrays.toString(storesPackagesNames) + " not exist on device and app store (" + appStore + ") hasn't web (http/https) uri");
} else {
if (hasWebUriIntent) {
Log.w(TAG, "Failed to rate app, " + Arrays.toString(storesPackagesNames) + " not exist on device and device can't start app store web (http/https) uri activity without it");
} else {
Log.w(TAG, "Failed to rate app, " + Arrays.toString(storesPackagesNames) + " not exist on device and app store (" + appStore + ") hasn't web (http/https) uri");
}
return null;
}
Expand Down
Loading

0 comments on commit 37ea65f

Please sign in to comment.