diff --git a/CHANGELOG.md b/CHANGELOG.md index 6846441..5b62b73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## 1.1.6 (released 24.04.2018) +## 1.1.6 (released 25.04.2018) - LIBff10424 - LIBcc20420 diff --git a/library/src/androidTest/java/com/vorlonsoft/android/rate/UriHelperTest.java b/library/src/androidTest/java/com/vorlonsoft/android/rate/UriHelperTest.java index 76f6347..d7b221c 100644 --- a/library/src/androidTest/java/com/vorlonsoft/android/rate/UriHelperTest.java +++ b/library/src/androidTest/java/com/vorlonsoft/android/rate/UriHelperTest.java @@ -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); } } diff --git a/library/src/main/java/com/vorlonsoft/android/rate/AppRate.java b/library/src/main/java/com/vorlonsoft/android/rate/AppRate.java index 3ed35ea..3591018 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/AppRate.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/AppRate.java @@ -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 customEventCounts = new HashMap<>(); - private byte remindLaunchTimes = 1; + private byte remindLaunchTimes = (byte) 1; private boolean isDebug = false; @@ -69,7 +77,7 @@ 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); } @@ -77,7 +85,7 @@ public static boolean showRateDialogIfMeetsConditions(Activity activity) { } 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) { @@ -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)) { @@ -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"); } @@ -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(); } @@ -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); @@ -333,7 +343,7 @@ private boolean isOverCustomEventRequirements() { return true; } - @SuppressWarnings("unused") + @SuppressWarnings({"unused", "WeakerAccess"}) public boolean isDebug() { return isDebug; } diff --git a/library/src/main/java/com/vorlonsoft/android/rate/DefaultDialogManager.java b/library/src/main/java/com/vorlonsoft/android/rate/DefaultDialogManager.java index e0d7319..9a4566a 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/DefaultDialogManager.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/DefaultDialogManager.java @@ -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; @@ -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); } } @@ -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 { @@ -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; } } } @@ -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 @@ -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()); diff --git a/library/src/main/java/com/vorlonsoft/android/rate/DialogOptions.java b/library/src/main/java/com/vorlonsoft/android/rate/DialogOptions.java index 6746fe5..4cd005b 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/DialogOptions.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/DialogOptions.java @@ -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; @@ -64,6 +65,9 @@ final class DialogOptions { private Reference listener = null; + DialogOptions() { + } + boolean shouldShowNeutralButton() { return showNeutralButton; } @@ -173,6 +177,7 @@ void setTextPositiveResId(int textPositiveResId) { int getTextNeutralResId() { return textNeutralResId; } + void setTextNeutralResId(int textNeutralResId) { this.textNeutralResId = textNeutralResId; } @@ -194,6 +199,7 @@ void setView(View view) { this.view = view; } + @Nullable OnClickButtonListener getListener() { return listener != null ? listener.get() : null; } diff --git a/library/src/main/java/com/vorlonsoft/android/rate/IntentHelper.java b/library/src/main/java/com/vorlonsoft/android/rate/IntentHelper.java index 28e1f75..be575c3 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/IntentHelper.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/IntentHelper.java @@ -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; @@ -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 @@ -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)); @@ -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; } diff --git a/library/src/main/java/com/vorlonsoft/android/rate/PreferenceHelper.java b/library/src/main/java/com/vorlonsoft/android/rate/PreferenceHelper.java index a7391f9..a3a9a4b 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/PreferenceHelper.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/PreferenceHelper.java @@ -8,7 +8,6 @@ import android.content.Context; import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; import java.util.Date; @@ -37,7 +36,7 @@ private static SharedPreferences getPreferences(final Context context) { return context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE); } - private static Editor getPreferencesEditor(final Context context) { + private static SharedPreferences.Editor getPreferencesEditor(final Context context) { return getPreferences(context).edit(); } @@ -54,7 +53,7 @@ static void clearSharedPreferences(final Context context) { } /** - * Set agree flag about show dialog.
+ * Set agree flag about show dialog.
* If it is false, rate dialog will never shown unless data is cleared. * * @param context context @@ -77,7 +76,7 @@ static void setRemindInterval(final Context context) { } static long getRemindInterval(final Context context) { - return getPreferences(context).getLong(PREF_KEY_REMIND_INTERVAL, 0); + return getPreferences(context).getLong(PREF_KEY_REMIND_INTERVAL, 0L); } static void setInstallDate(final Context context) { @@ -87,7 +86,7 @@ static void setInstallDate(final Context context) { } static long getInstallDate(final Context context) { - return getPreferences(context).getLong(PREF_KEY_INSTALL_DATE, 0); + return getPreferences(context).getLong(PREF_KEY_INSTALL_DATE, 0L); } static void setLaunchTimes(final Context context, final short launchTimes) { @@ -101,7 +100,7 @@ static short getLaunchTimes(final Context context) { } static boolean isFirstLaunch(final Context context) { - return getPreferences(context).getLong(PREF_KEY_INSTALL_DATE, 0) == 0L; + return getPreferences(context).getLong(PREF_KEY_INSTALL_DATE, 0L) == 0L; } static short getCustomEventCount(final Context context, final String eventName) { diff --git a/library/src/main/java/com/vorlonsoft/android/rate/StoreType.java b/library/src/main/java/com/vorlonsoft/android/rate/StoreType.java index e402669..825ab9a 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/StoreType.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/StoreType.java @@ -15,31 +15,31 @@ public final class StoreType { @SuppressWarnings("WeakerAccess") - public static final byte AMAZON = 0; // Amazon Appstore + public static final byte AMAZON = (byte) 0; // Amazon Appstore @SuppressWarnings("WeakerAccess") - public static final byte APPLE = 1; // Apple App Store + public static final byte APPLE = (byte) 1; // Apple App Store @SuppressWarnings("WeakerAccess") - public static final byte BAZAAR = 2; // Cafe Bazaar + public static final byte BAZAAR = (byte) 2; // Cafe Bazaar @SuppressWarnings("WeakerAccess") - public static final byte BLACKBERRY = 3; // BlackBerry World + public static final byte BLACKBERRY = (byte) 3; // BlackBerry World @SuppressWarnings("WeakerAccess") - public static final byte CHINESESTORES = 4; // 19 chinese app stores + public static final byte CHINESESTORES = (byte) 4; // 19 chinese app stores @SuppressWarnings("WeakerAccess") - public static final byte GOOGLEPLAY = 5; // Google Play + public static final byte GOOGLEPLAY = (byte) 5; // Google Play @SuppressWarnings("WeakerAccess") - public static final byte MI = 6; // Mi Appstore (Xiaomi Market) + public static final byte MI = (byte) 6; // Mi Appstore (Xiaomi Market) @SuppressWarnings("WeakerAccess") - public static final byte SAMSUNG = 7; // Samsung Galaxy Apps + public static final byte SAMSUNG = (byte) 7; // Samsung Galaxy Apps @SuppressWarnings("WeakerAccess") - public static final byte SLIDEME = 8; // SlideME Marketplace + public static final byte SLIDEME = (byte) 8; // SlideME Marketplace @SuppressWarnings("WeakerAccess") - public static final byte TENCENT = 9; // Tencent App Store + public static final byte TENCENT = (byte) 9; // Tencent App Store @SuppressWarnings("WeakerAccess") - public static final byte YANDEX = 10; // Yandex.Store + public static final byte YANDEX = (byte) 10; // Yandex.Store @SuppressWarnings("WeakerAccess") - public static final byte INTENT = 11; // Any custom intents + public static final byte INTENT = (byte) 11; // Any custom intents @SuppressWarnings("WeakerAccess") - public static final byte OTHER = 12; // Any Other Store + public static final byte OTHER = (byte) 12; // Any Other Store private StoreType() { } @@ -47,15 +47,15 @@ private StoreType() { @SuppressWarnings("WeakerAccess") @Retention(RUNTIME) @IntDef({AMAZON, BAZAAR, CHINESESTORES, GOOGLEPLAY, MI, SAMSUNG, SLIDEME, TENCENT, YANDEX}) - public @interface Store {} + public @interface StoreWithoutApplicationId {} @SuppressWarnings("WeakerAccess") @Retention(RUNTIME) @IntDef({APPLE, BLACKBERRY}) - public @interface StoreWithId {} + public @interface StoreWithApplicationId {} @SuppressWarnings("WeakerAccess") @Retention(RUNTIME) - @IntDef({AMAZON, APPLE, BAZAAR, BLACKBERRY, CHINESESTORES, GOOGLEPLAY, MI, OTHER, SAMSUNG, SLIDEME, TENCENT, YANDEX}) - public @interface Return {} + @IntDef({AMAZON, APPLE, BAZAAR, BLACKBERRY, CHINESESTORES, GOOGLEPLAY, INTENT, MI, OTHER, SAMSUNG, SLIDEME, TENCENT, YANDEX}) + public @interface AnyStoreType {} } \ No newline at end of file diff --git a/library/src/main/java/com/vorlonsoft/android/rate/UriHelper.java b/library/src/main/java/com/vorlonsoft/android/rate/UriHelper.java index 89de28f..45d63fd 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/UriHelper.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/UriHelper.java @@ -8,6 +8,7 @@ import android.net.Uri; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import static com.vorlonsoft.android.rate.StoreType.AMAZON; import static com.vorlonsoft.android.rate.StoreType.APPLE; @@ -65,6 +66,7 @@ final class UriHelper { private UriHelper() { } + @Nullable private static Uri getStoreUri(final byte appStore, final String paramName, final boolean isWebUri) { final String baseStoreUri; if (isWebUri) { @@ -140,11 +142,13 @@ private static Uri getStoreUri(final byte appStore, final String paramName, fina } @SuppressWarnings("ConstantConditions") + @Nullable static Uri getStoreUri(final byte appStore, @NonNull final String paramName) { return paramName == null ? null : getStoreUri(appStore, paramName, false); } @SuppressWarnings("ConstantConditions") + @Nullable static Uri getStoreWebUri(final byte appStore, @NonNull final String paramName) { return paramName == null ? null : getStoreUri(appStore, paramName, true); } diff --git a/library/src/main/java/com/vorlonsoft/android/rate/Utils.java b/library/src/main/java/com/vorlonsoft/android/rate/Utils.java index 3c30081..ed6c314 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/Utils.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/Utils.java @@ -12,6 +12,7 @@ import android.content.pm.ApplicationInfo; import android.os.Build; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.util.Log; import java.util.ArrayList; @@ -21,6 +22,17 @@ final class Utils { + @SuppressWarnings("WeakerAccess") + static final long SECOND_IN_MILLIS = 1000; + + @SuppressWarnings("WeakerAccess") + static final long MINUTE_IN_MILLIS = SECOND_IN_MILLIS * 60; + + @SuppressWarnings("WeakerAccess") + static final long HOUR_IN_MILLIS = MINUTE_IN_MILLIS * 60; + + static final long DAY_IN_MILLIS = HOUR_IN_MILLIS * 24; + private Utils() { } @@ -34,6 +46,7 @@ private static int getDialogTheme() { @SuppressLint("ObsoleteSdkInt") @SuppressWarnings("ConstantConditions") + @Nullable static AlertDialog.Builder getDialogBuilder(@NonNull final Context context, final int themeResId) { if (context == null) { Log.i(TAG, "Failed to create AlertDialog.Builder"); @@ -41,11 +54,12 @@ static AlertDialog.Builder getDialogBuilder(@NonNull final Context context, fina } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { return new AlertDialog.Builder(context); } else { - return new AlertDialog.Builder(context, themeResId != 0 ? themeResId : getDialogTheme()); + return new AlertDialog.Builder(context, themeResId == 0 ? getDialogTheme() : themeResId); } } @SuppressWarnings("ConstantConditions") + @Nullable static String[] isPackagesExists(@NonNull final Context context, @NonNull final String[] targetPackages) { final String[] EMPTY_STRING_ARRAY = new String[0]; final String EMPTY_STRING = ""; @@ -71,7 +85,7 @@ static String[] isPackagesExists(@NonNull final Context context, @NonNull final } return EMPTY_STRING_ARRAY; } else { - ArrayList packageNames = new ArrayList<>(); + final ArrayList packageNames = new ArrayList<>(); for (String aTargetPackage : targetPackages) { if ((aTargetPackage != null) && (aTargetPackage.hashCode() != EMPTY_STRING.hashCode())) { for (ApplicationInfo anApplicationInfo : applicationInfo) { diff --git a/sample/src/main/java/com/vorlonsoft/android/rate/sample/MainActivity.java b/sample/src/main/java/com/vorlonsoft/android/rate/sample/MainActivity.java index c03f0d0..d7d3f4b 100644 --- a/sample/src/main/java/com/vorlonsoft/android/rate/sample/MainActivity.java +++ b/sample/src/main/java/com/vorlonsoft/android/rate/sample/MainActivity.java @@ -72,7 +72,7 @@ protected void onCreate(Bundle savedInstanceState) { .setShowLaterButton(true) // default true. .setDebug(true) // default false. .setCancelable(false) // default false. - .setOnClickButtonListener(which -> Log.d(TAG, "RateButton: " + Byte.toString(which) + "")) + .setOnClickButtonListener(which -> Log.d(TAG, "RateButton: " + Byte.toString(which))) // comment to use library strings instead app strings .setTitle(R.string.new_rate_dialog_title) .setTextLater(R.string.new_rate_dialog_later) @@ -83,7 +83,6 @@ protected void onCreate(Bundle savedInstanceState) { .setTextRateNow(R.string.new_rate_dialog_ok) .monitor(); - //noinspection ConstantConditions if (AppRate.with(this).getStoreType() == StoreType.GOOGLEPLAY) { //Check that Google Play is available if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) != ConnectionResult.SERVICE_MISSING) { diff --git a/sample/src/main/java/com/vorlonsoft/android/rate/sample/SampleApplication.java b/sample/src/main/java/com/vorlonsoft/android/rate/sample/SampleApplication.java index f753a5e..5464bb0 100644 --- a/sample/src/main/java/com/vorlonsoft/android/rate/sample/SampleApplication.java +++ b/sample/src/main/java/com/vorlonsoft/android/rate/sample/SampleApplication.java @@ -21,7 +21,6 @@ public SampleApplication() { @Override public void onCreate() { super.onCreate(); - //noinspection ConstantConditions if (LeakCanary.isInAnalyzerProcess(this)) { // This process is dedicated to LeakCanary for heap analysis. // You should not init your app in this process.