Skip to content

Commit 37ea65f

Browse files
committed
Release 1.1.6
1 parent 22f3ac9 commit 37ea65f

File tree

12 files changed

+128
-82
lines changed

12 files changed

+128
-82
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CHANGELOG
22

3-
## 1.1.6 (released 24.04.2018)
3+
## 1.1.6 (released 25.04.2018)
44

55
- LIBff10424
66
- LIBcc20420

library/src/androidTest/java/com/vorlonsoft/android/rate/UriHelperTest.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,62 +23,74 @@ public class UriHelperTest extends AndroidTestCase {
2323

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

26-
@SuppressWarnings("ConstantConditions")
26+
@SuppressWarnings({"ConstantConditions", "UnnecessaryLocalVariable"})
2727
public void testGetStoreUri() {
2828
{
29-
Uri uri = UriHelper.getStoreUri(CHINESESTORES,"");
29+
final byte appStore = CHINESESTORES;
30+
Uri uri = UriHelper.getStoreUri(appStore,"");
3031
assertEquals(uri.toString(), CHINESE_STORES);
3132
}
3233
{
33-
Uri uri = UriHelper.getStoreUri(GOOGLEPLAY,"");
34+
final byte appStore = GOOGLEPLAY;
35+
Uri uri = UriHelper.getStoreUri(appStore,"");
3436
assertEquals(uri.toString(), GOOGLE_PLAY);
3537
}
3638
{
37-
Uri uri = UriHelper.getStoreUri(CHINESESTORES,null);
39+
final byte appStore = CHINESESTORES;
40+
Uri uri = UriHelper.getStoreUri(appStore,null);
3841
assertNull(uri);
3942
}
4043
{
41-
Uri uri = UriHelper.getStoreUri(GOOGLEPLAY,null);
44+
final byte appStore = GOOGLEPLAY;
45+
Uri uri = UriHelper.getStoreUri(appStore,null);
4246
assertNull(uri);
4347
}
4448
{
49+
final byte appStore = CHINESESTORES;
4550
final String paramName = "com.vorlonsoft.android.rate";
46-
Uri uri = UriHelper.getStoreUri(CHINESESTORES, paramName);
51+
Uri uri = UriHelper.getStoreUri(appStore, paramName);
4752
assertEquals(uri.toString(), CHINESE_STORES + paramName);
4853
}
4954
{
55+
final byte appStore = GOOGLEPLAY;
5056
final String paramName = "com.vorlonsoft.android.rate";
51-
Uri uri = UriHelper.getStoreUri(GOOGLEPLAY, paramName);
57+
Uri uri = UriHelper.getStoreUri(appStore, paramName);
5258
assertEquals(uri.toString(), GOOGLE_PLAY + paramName);
5359
}
5460
}
5561

56-
@SuppressWarnings("ConstantConditions")
62+
@SuppressWarnings({"ConstantConditions", "UnnecessaryLocalVariable"})
5763
public void testGetStoreWebUri() {
5864
{
59-
Uri uri = UriHelper.getStoreWebUri(CHINESESTORES,"");
65+
final byte appStore = CHINESESTORES;
66+
Uri uri = UriHelper.getStoreWebUri(appStore,"");
6067
assertNull(uri);
6168
}
6269
{
63-
Uri uri = UriHelper.getStoreWebUri(GOOGLEPLAY,"");
70+
final byte appStore = GOOGLEPLAY;
71+
Uri uri = UriHelper.getStoreWebUri(appStore,"");
6472
assertEquals(uri.toString(), GOOGLE_PLAY_WEB);
6573
}
6674
{
67-
Uri uri = UriHelper.getStoreWebUri(CHINESESTORES,null);
75+
final byte appStore = CHINESESTORES;
76+
Uri uri = UriHelper.getStoreWebUri(appStore,null);
6877
assertNull(uri);
6978
}
7079
{
71-
Uri uri = UriHelper.getStoreWebUri(GOOGLEPLAY,null);
80+
final byte appStore = GOOGLEPLAY;
81+
Uri uri = UriHelper.getStoreWebUri(appStore,null);
7282
assertNull(uri);
7383
}
7484
{
85+
final byte appStore = CHINESESTORES;
7586
final String paramName = "com.vorlonsoft.android.rate";
76-
Uri uri = UriHelper.getStoreWebUri(CHINESESTORES, paramName);
87+
Uri uri = UriHelper.getStoreWebUri(appStore, paramName);
7788
assertNull(uri);
7889
}
7990
{
91+
final byte appStore = GOOGLEPLAY;
8092
final String paramName = "com.vorlonsoft.android.rate";
81-
Uri uri = UriHelper.getStoreWebUri(GOOGLEPLAY, paramName);
93+
Uri uri = UriHelper.getStoreWebUri(appStore, paramName);
8294
assertEquals(uri.toString(), GOOGLE_PLAY_WEB + paramName);
8395
}
8496
}

library/src/main/java/com/vorlonsoft/android/rate/AppRate.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,42 @@
1919
import java.util.HashMap;
2020
import java.util.Map;
2121

22-
import static com.vorlonsoft.android.rate.PreferenceHelper.*;
22+
import static com.vorlonsoft.android.rate.PreferenceHelper.getCustomEventCount;
23+
import static com.vorlonsoft.android.rate.PreferenceHelper.getInstallDate;
24+
import static com.vorlonsoft.android.rate.PreferenceHelper.getIsAgreeShowDialog;
25+
import static com.vorlonsoft.android.rate.PreferenceHelper.getLaunchTimes;
26+
import static com.vorlonsoft.android.rate.PreferenceHelper.getRemindInterval;
27+
import static com.vorlonsoft.android.rate.PreferenceHelper.isFirstLaunch;
28+
import static com.vorlonsoft.android.rate.PreferenceHelper.setCustomEventCount;
29+
import static com.vorlonsoft.android.rate.PreferenceHelper.setInstallDate;
2330
import static com.vorlonsoft.android.rate.StoreType.AMAZON;
2431
import static com.vorlonsoft.android.rate.StoreType.APPLE;
2532
import static com.vorlonsoft.android.rate.StoreType.BLACKBERRY;
2633
import static com.vorlonsoft.android.rate.StoreType.INTENT;
2734
import static com.vorlonsoft.android.rate.StoreType.OTHER;
2835
import static com.vorlonsoft.android.rate.StoreType.YANDEX;
36+
import static com.vorlonsoft.android.rate.Utils.DAY_IN_MILLIS;
2937

3038
public final class AppRate {
3139

3240
static final String TAG = "ANDROIDRATE";
3341

3442
@SuppressLint("StaticFieldLeak")
35-
private static AppRate singleton;
43+
private static volatile AppRate singleton = null;
3644

3745
private final Context context;
3846

3947
private final DialogOptions options = new DialogOptions();
4048

41-
private byte installDate = 10;
49+
private byte installDate = (byte) 10;
4250

43-
private byte launchTimes = 10;
51+
private byte launchTimes = (byte) 10;
4452

45-
private byte remindInterval = 1;
53+
private byte remindInterval = (byte) 1;
4654

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

49-
private byte remindLaunchTimes = 1;
57+
private byte remindLaunchTimes = (byte) 1;
5058

5159
private boolean isDebug = false;
5260

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

7078
@SuppressWarnings("UnusedReturnValue")
7179
public static boolean showRateDialogIfMeetsConditions(Activity activity) {
72-
boolean isMeetsConditions = singleton.isDebug || singleton.shouldShowRateDialog();
80+
boolean isMeetsConditions = singleton.isDebug() || singleton.shouldShowRateDialog();
7381
if (isMeetsConditions) {
7482
singleton.showRateDialog(activity);
7583
}
7684
return isMeetsConditions;
7785
}
7886

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

8391
public AppRate setLaunchTimes(@SuppressWarnings("SameParameterValue") byte launchTimes) {
@@ -214,7 +222,7 @@ public AppRate setCancelable(@SuppressWarnings("SameParameterValue") boolean can
214222
return this;
215223
}
216224

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

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

255-
@StoreType.Return
263+
@StoreType.AnyStoreType
256264
public int getStoreType() {
257265
return options.getStoreType();
258266
}
@@ -313,7 +321,9 @@ private boolean isOverLaunchTimes() {
313321
return getLaunchTimes(context) >= launchTimes;
314322
}
315323

316-
private boolean isOverRemindLaunchTimes() { return ((remindLaunchTimes != 0) && ((getLaunchTimes(context) % remindLaunchTimes) == 0)); }
324+
private boolean isOverRemindLaunchTimes() {
325+
return ((remindLaunchTimes != 0) && ((getLaunchTimes(context) % remindLaunchTimes) == 0));
326+
}
317327

318328
private boolean isOverInstallDate() {
319329
return isOverDate(getInstallDate(context), installDate);
@@ -333,7 +343,7 @@ private boolean isOverCustomEventRequirements() {
333343
return true;
334344
}
335345

336-
@SuppressWarnings("unused")
346+
@SuppressWarnings({"unused", "WeakerAccess"})
337347
public boolean isDebug() {
338348
return isDebug;
339349
}

library/src/main/java/com/vorlonsoft/android/rate/DefaultDialogManager.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.content.Context;
1313
import android.content.DialogInterface;
1414
import android.content.Intent;
15+
import android.support.annotation.Nullable;
1516
import android.util.Log;
1617
import android.view.View;
1718

@@ -39,7 +40,7 @@ public class DefaultDialogManager implements DialogManager {
3940

4041
static class Factory implements DialogManager.Factory {
4142
@Override
42-
public DialogManager createDialogManager(Context context, DialogOptions options) {
43+
public DialogManager createDialogManager(final Context context, final DialogOptions options) {
4344
return new DefaultDialogManager(context, options);
4445
}
4546
}
@@ -105,7 +106,7 @@ public void onClick(final DialogInterface dialog, final int which) {
105106
try {
106107
if (intentsToAppStores != null) {
107108
if (intentsToAppStores.length == 0) {
108-
Log.w(TAG, "Failed to rate app, no intent found for startActivity (intentsToAppStores.length == null)");
109+
Log.w(TAG, "Failed to rate app, no intent found for startActivity (intentsToAppStores.length == 0)");
109110
} else if (intentsToAppStores[0] == null) {
110111
throw new ActivityNotFoundException("Failed to rate app, no intent found for startActivity (intentsToAppStores[0] == null)");
111112
} else {
@@ -114,22 +115,23 @@ public void onClick(final DialogInterface dialog, final int which) {
114115
}
115116
} catch (ActivityNotFoundException e) {
116117
Log.w(TAG, "Failed to rate app, no activity found for " + intentsToAppStores[0], e);
117-
if (intentsToAppStores.length > 1) {
118-
for (byte i = 1; i < intentsToAppStores.length; i++) { // intentsToAppStores[1] - second intent in the array
119-
boolean isCatch = false;
118+
byte intentsToAppStoresNumber = (byte) intentsToAppStores.length;
119+
if (intentsToAppStoresNumber > 1) {
120+
boolean isCatch;
121+
for (byte b = 1; b < intentsToAppStoresNumber; b++) { // intentsToAppStores[1] - second intent in the array
120122
try {
121-
if (intentsToAppStores[i] == null) {
122-
throw new ActivityNotFoundException("Failed to rate app, no intent found for startActivity (intentsToAppStores[" + i + "] == null)");
123+
if (intentsToAppStores[b] == null) {
124+
throw new ActivityNotFoundException("Failed to rate app, no intent found for startActivity (intentsToAppStores[" + b + "] == null)");
123125
} else {
124-
context.startActivity(intentsToAppStores[i]);
126+
context.startActivity(intentsToAppStores[b]);
125127
}
128+
isCatch = false;
126129
} catch (ActivityNotFoundException ex) {
127-
Log.w(TAG, "Failed to rate app, no activity found for " + intentsToAppStores[i], ex);
130+
Log.w(TAG, "Failed to rate app, no activity found for " + intentsToAppStores[b], ex);
128131
isCatch = true;
129-
} finally {
130-
if (!isCatch) {
131-
i = (byte) intentsToAppStores.length;
132-
}
132+
}
133+
if (!isCatch) {
134+
break;
133135
}
134136
}
135137
}
@@ -144,9 +146,10 @@ public void onClick(final DialogInterface dialog, final int which) {
144146
@Override
145147
public void onClick(final DialogInterface dialog, final int which) {
146148
setAgreeShowDialog(context, false);
147-
if (DefaultDialogManager.this.listener != null) DefaultDialogManager.this.listener.onClickButton((byte) which);
149+
if (listener != null) listener.onClickButton((byte) which);
148150
}
149151
};
152+
150153
@SuppressWarnings("WeakerAccess")
151154
protected final DialogInterface.OnClickListener neutralListener = new DialogInterface.OnClickListener() {
152155
@Override
@@ -163,6 +166,7 @@ public DefaultDialogManager(final Context context, final DialogOptions options)
163166
this.listener = options.getListener();
164167
}
165168

169+
@Nullable
166170
@Override
167171
public Dialog createDialog() {
168172
AlertDialog.Builder builder = getDialogBuilder(context, options.getThemeResId());

library/src/main/java/com/vorlonsoft/android/rate/DialogOptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.content.Context;
1010
import android.content.Intent;
1111
import android.net.Uri;
12+
import android.support.annotation.Nullable;
1213
import android.view.View;
1314

1415
import java.lang.ref.Reference;
@@ -64,6 +65,9 @@ final class DialogOptions {
6465

6566
private Reference<OnClickButtonListener> listener = null;
6667

68+
DialogOptions() {
69+
}
70+
6771
boolean shouldShowNeutralButton() {
6872
return showNeutralButton;
6973
}
@@ -173,6 +177,7 @@ void setTextPositiveResId(int textPositiveResId) {
173177
int getTextNeutralResId() {
174178
return textNeutralResId;
175179
}
180+
176181
void setTextNeutralResId(int textNeutralResId) {
177182
this.textNeutralResId = textNeutralResId;
178183
}
@@ -194,6 +199,7 @@ void setView(View view) {
194199
this.view = view;
195200
}
196201

202+
@Nullable
197203
OnClickButtonListener getListener() {
198204
return listener != null ? listener.get() : null;
199205
}

library/src/main/java/com/vorlonsoft/android/rate/IntentHelper.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.content.Intent;
1111
import android.net.Uri;
1212
import android.support.annotation.NonNull;
13+
import android.support.annotation.Nullable;
1314
import android.util.Log;
1415

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

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

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

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

160163
if (deviceStoresPackagesNumber > 0) {
161-
if (hasWebUriIntent) {
162-
intents = new Intent[deviceStoresPackagesNumber + 1];
163-
} else {
164-
intents = new Intent[deviceStoresPackagesNumber];
165-
}
166-
for (byte i = 0; i < deviceStoresPackagesNumber; i++) {
167-
intents[i] = new Intent(Intent.ACTION_VIEW, getStoreUri(appStore, paramName));
168-
setIntentForStore(intents[i]);
169-
intents[i].setPackage(storesPackagesNames[i]);
164+
intents = hasWebUriIntent ? new Intent[deviceStoresPackagesNumber + 1] : new Intent[deviceStoresPackagesNumber];
165+
for (byte b = 0; b < deviceStoresPackagesNumber; b++) {
166+
intents[b] = new Intent(Intent.ACTION_VIEW, getStoreUri(appStore, paramName));
167+
setIntentForStore(intents[b]);
168+
intents[b].setPackage(deviceStoresPackagesNames[b]);
170169
}
171170
if (hasWebUriIntent) {
172171
intents[deviceStoresPackagesNumber] = new Intent(Intent.ACTION_VIEW, getStoreWebUri(appStore, paramName));
@@ -181,10 +180,10 @@ static Intent[] createIntentsForStore(@NonNull final Context context, final byte
181180
}
182181
}
183182
} else {
184-
if (!hasWebUriIntent) {
185-
Log.w(TAG, "Failed to rate app, " + Arrays.toString(storesPackagesNames) + " not exist on device and app store (" + appStore + ") hasn't web (http/https) uri");
186-
} else {
183+
if (hasWebUriIntent) {
187184
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");
185+
} else {
186+
Log.w(TAG, "Failed to rate app, " + Arrays.toString(storesPackagesNames) + " not exist on device and app store (" + appStore + ") hasn't web (http/https) uri");
188187
}
189188
return null;
190189
}

0 commit comments

Comments
 (0)