Skip to content

Commit 2d6a106

Browse files
committed
Add option to re-prompt at intervals after user accept/ignore
1 parent 803361f commit 2d6a106

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ protected void onCreate(Bundle savedInstanceState) {
130130
* setStoreType(Intent...) (Any custom intent/intents, Intent... - an intent or array of intents) */
131131
.setTimeToWait(Time.DAY, (short) 0) // default is 10 days, 0 means install millisecond, 10 means app is launched 10 or more time units later than installation
132132
.setLaunchTimes((byte) 3) // default is 10, 3 means app is launched 3 or more times
133+
.setTimeToReprompt(Time.MONTH, (short) 3) // default is off, 3 means prompt is shown again 3 months after last user accept/ignore action. Setting this value enables the check.
133134
.setRemindTimeToWait(Time.DAY, (short) 2) // default is 1 day, 1 means app is launched 1 or more time units after neutral button clicked
134135
.setRemindLaunchesNumber((byte) 1) // default is 0, 1 means app is launched 1 or more times after neutral button clicked
135136
.setSelectedAppLaunches((byte) 1) // default is 1, 1 means each launch, 2 means every 2nd launch, 3 means every 3rd launch, etc
@@ -165,6 +166,7 @@ Default options of the Rate Dialog are as below:
165166
10. Don't re-enable the Rate Dialog if a new version of app with different version name is installed. Change via `AppRate#setVersionNameCheck(boolean)`.
166167
11. Setting `AppRate#setDebug(boolean)` to `true` ensures that the Rate Dialog will be shown each time the app is launched. **This feature is for development only!**.
167168
12. There is no default callback when the button of Rate Dialog is pressed. Change via `AppRate.with(this).setOnClickButtonListener(OnClickButtonListener)`.
169+
13. Prompt is not shown again after user action (accept/ignore).
168170

169171
### OnClickButtonListener interface
170172

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import android.content.Context;
1313
import android.content.Intent;
1414
import android.graphics.drawable.Drawable;
15-
import android.os.Build;
1615
import android.util.ArrayMap;
1716
import android.util.Log;
1817
import android.view.View;
@@ -36,6 +35,7 @@
3635
import static com.vorlonsoft.android.rate.PreferenceHelper.getCustomEventCount;
3736
import static com.vorlonsoft.android.rate.PreferenceHelper.getInstallDate;
3837
import static com.vorlonsoft.android.rate.PreferenceHelper.getIsAgreeShowDialog;
38+
import static com.vorlonsoft.android.rate.PreferenceHelper.getLastAgreeShowFalseDate;
3939
import static com.vorlonsoft.android.rate.PreferenceHelper.getLaunchTimes;
4040
import static com.vorlonsoft.android.rate.PreferenceHelper.getRemindInterval;
4141
import static com.vorlonsoft.android.rate.PreferenceHelper.getRemindLaunchesNumber;
@@ -76,6 +76,8 @@ public final class AppRate {
7676
private boolean isVersionCodeCheck = false;
7777
private boolean isVersionNameCheck = false;
7878
private long installDate = Time.DAY * 10L;
79+
private long repromptDate = Time.MONTH * 6L;
80+
private boolean repromptCheck = false;
7981
private byte appLaunchTimes = (byte) 10;
8082
private long remindInterval = Time.DAY;
8183
private byte remindLaunchesNumber = (byte) 0;
@@ -215,6 +217,24 @@ public AppRate setInstallDays(byte installDate) {
215217
return setTimeToWait(Time.DAY, installDate);
216218
}
217219

220+
/**
221+
* <p>Sets the minimal number of time units until the Rate Dialog appears after it has already
222+
* been actioned.</p>
223+
* <p>Default is off (no check), calling this method enables the check, 0 means user
224+
* accept/ignore millisecond, 10 means prompt is re-shown 10 or more time units later than the
225+
* last accept/ignore.</p>
226+
* @param timeUnit one of the values defined by {@link Time.TimeUnits}
227+
* @param timeUnitsNumber time units number
228+
* @return the {@link AppRate} singleton object
229+
* @see Time.TimeUnits
230+
*/
231+
@SuppressWarnings("unused")
232+
public AppRate setTimeToReprompt(@Time.TimeUnits long timeUnit, short timeUnitsNumber) {
233+
this.repromptDate = timeUnit * timeUnitsNumber;
234+
this.repromptCheck = true;
235+
return this;
236+
}
237+
218238
/**
219239
* <p>Sets the minimal number of time units until the Rate Dialog pops up for the first time.</p>
220240
* <p>Default is 10 {@link Time#DAY days}, 0 means install millisecond, 10 means app is launched
@@ -952,7 +972,9 @@ public void rateNow(Activity activity) {
952972
*/
953973
@SuppressWarnings("WeakerAccess")
954974
public boolean shouldShowRateDialog() {
955-
return getAgreeShowDialog() &&
975+
// If Agree show is false (user has ignored/accepted) then return false unless it has
976+
// been `repromptDate` time since the time when the user accepted/ignored the prompt
977+
return (getAgreeShowDialog() || isOverLastAgreeShowFalseDate()) &&
956978
isOverLaunchTimes() &&
957979
isSelectedAppLaunch() &&
958980
isOverInstallDate() &&
@@ -962,6 +984,14 @@ public boolean shouldShowRateDialog() {
962984
isBelow365DayPeriodMaxNumberDialogLaunchTimes();
963985
}
964986

987+
private boolean isOverLastAgreeShowFalseDate() {
988+
if (!repromptCheck) {
989+
return false;
990+
}
991+
992+
return ((repromptDate == 0L)) || isOverDate(getLastAgreeShowFalseDate(context), repromptDate);
993+
}
994+
965995
private boolean isOverLaunchTimes() {
966996
return ((appLaunchTimes == 0) || (getLaunchTimes(context) >= appLaunchTimes));
967997
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ final class PreferenceHelper {
4040

4141
private static final String PREF_KEY_IS_AGREE_SHOW_DIALOG = "androidrate_is_agree_show_dialog";
4242

43+
private static final String PREF_KEY_LAST_AGREE_SHOW_FALSE_DATE = "androidrate_last_agree_show_false_date";
44+
4345
private static final String PREF_KEY_LAUNCH_TIMES = "androidrate_launch_times";
4446

4547
private static final String PREF_KEY_REMIND_INTERVAL = "androidrate_remind_interval";
@@ -216,12 +218,22 @@ static void setIsAgreeShowDialog(final Context context, final boolean isAgree) {
216218
getPreferencesEditor(context)
217219
.putBoolean(PREF_KEY_IS_AGREE_SHOW_DIALOG, isAgree)
218220
.apply();
221+
222+
if (!isAgree) {
223+
getPreferencesEditor(context)
224+
.putLong(PREF_KEY_LAST_AGREE_SHOW_FALSE_DATE, new Date().getTime())
225+
.apply();
226+
}
219227
}
220228

221229
static boolean getIsAgreeShowDialog(final Context context) {
222230
return getPreferences(context).getBoolean(PREF_KEY_IS_AGREE_SHOW_DIALOG, true);
223231
}
224232

233+
static long getLastAgreeShowFalseDate(final Context context) {
234+
return getPreferences(context).getLong(PREF_KEY_LAST_AGREE_SHOW_FALSE_DATE, 0L);
235+
}
236+
225237
/**
226238
* <p>Sets number of times the app has been launched.</p>
227239
*

sample/src/main/java/com/vorlonsoft/android/rate/sample/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ protected void onCreate(Bundle savedInstanceState) {
7272
* setStoreType(Intent...) (Any custom intent/intents, Intent... - an intent or array of intents) */
7373
.setTimeToWait(Time.DAY, (short) 3) // default is 10 days, 0 means install millisecond, 10 means app is launched 10 or more time units later than installation
7474
.setLaunchTimes((byte) 10) // default is 10, 3 means app is launched 3 or more times
75+
.setTimeToReprompt(Time.MONTH, (short) 3) // default is off, 3 means prompt is shown again 3 months after last user accept/ignore action. Setting this value enables the check.
7576
.setRemindTimeToWait(Time.DAY, (short) 2) // default is 1 day, 1 means app is launched 1 or more time units after neutral button clicked
7677
.setRemindLaunchesNumber((byte) 1) // default is 0, 1 means app is launched 1 or more times after neutral button clicked
7778
.setSelectedAppLaunches((byte) 4) // default is 1, 1 means each launch, 2 means every 2nd launch, 3 means every 3rd launch, etc

0 commit comments

Comments
 (0)