diff --git a/README.md b/README.md index 07aa30c..e2d9b68 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,7 @@ protected void onCreate(Bundle savedInstanceState) { * setStoreType(Intent...) (Any custom intent/intents, Intent... - an intent or array of intents) */ .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 .setLaunchTimes((byte) 3) // default is 10, 3 means app is launched 3 or more times + .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. .setRemindTimeToWait(Time.DAY, (short) 2) // default is 1 day, 1 means app is launched 1 or more time units after neutral button clicked .setRemindLaunchesNumber((byte) 1) // default is 0, 1 means app is launched 1 or more times after neutral button clicked .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: 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)`. 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!**. 12. There is no default callback when the button of Rate Dialog is pressed. Change via `AppRate.with(this).setOnClickButtonListener(OnClickButtonListener)`. +13. Prompt is not shown again after user action (accept/ignore). ### OnClickButtonListener interface 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 36f0d56..47ac3ad 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/AppRate.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/AppRate.java @@ -12,7 +12,6 @@ import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; -import android.os.Build; import android.util.ArrayMap; import android.util.Log; import android.view.View; @@ -36,6 +35,7 @@ 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.getLastAgreeShowFalseDate; import static com.vorlonsoft.android.rate.PreferenceHelper.getLaunchTimes; import static com.vorlonsoft.android.rate.PreferenceHelper.getRemindInterval; import static com.vorlonsoft.android.rate.PreferenceHelper.getRemindLaunchesNumber; @@ -76,6 +76,8 @@ public final class AppRate { private boolean isVersionCodeCheck = false; private boolean isVersionNameCheck = false; private long installDate = Time.DAY * 10L; + private long repromptDate = Time.MONTH * 6L; + private boolean repromptCheck = false; private byte appLaunchTimes = (byte) 10; private long remindInterval = Time.DAY; private byte remindLaunchesNumber = (byte) 0; @@ -215,6 +217,24 @@ public AppRate setInstallDays(byte installDate) { return setTimeToWait(Time.DAY, installDate); } + /** + *
Sets the minimal number of time units until the Rate Dialog appears after it has already + * been actioned.
+ *Default is off (no check), calling this method enables the check, 0 means user + * accept/ignore millisecond, 10 means prompt is re-shown 10 or more time units later than the + * last accept/ignore.
+ * @param timeUnit one of the values defined by {@link Time.TimeUnits} + * @param timeUnitsNumber time units number + * @return the {@link AppRate} singleton object + * @see Time.TimeUnits + */ + @SuppressWarnings("unused") + public AppRate setTimeToReprompt(@Time.TimeUnits long timeUnit, short timeUnitsNumber) { + this.repromptDate = timeUnit * timeUnitsNumber; + this.repromptCheck = true; + return this; + } + /** *Sets the minimal number of time units until the Rate Dialog pops up for the first time.
*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) { */ @SuppressWarnings("WeakerAccess") public boolean shouldShowRateDialog() { - return getAgreeShowDialog() && + // If Agree show is false (user has ignored/accepted) then return false unless it has + // been `repromptDate` time since the time when the user accepted/ignored the prompt + return (getAgreeShowDialog() || isOverLastAgreeShowFalseDate()) && isOverLaunchTimes() && isSelectedAppLaunch() && isOverInstallDate() && @@ -962,6 +984,14 @@ public boolean shouldShowRateDialog() { isBelow365DayPeriodMaxNumberDialogLaunchTimes(); } + private boolean isOverLastAgreeShowFalseDate() { + if (!repromptCheck) { + return false; + } + + return (repromptDate == 0L) || isOverDate(getLastAgreeShowFalseDate(context), repromptDate); + } + private boolean isOverLaunchTimes() { return ((appLaunchTimes == 0) || (getLaunchTimes(context) >= appLaunchTimes)); } 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 16b67e1..5406266 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/PreferenceHelper.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/PreferenceHelper.java @@ -40,6 +40,8 @@ final class PreferenceHelper { private static final String PREF_KEY_IS_AGREE_SHOW_DIALOG = "androidrate_is_agree_show_dialog"; + private static final String PREF_KEY_LAST_AGREE_SHOW_FALSE_DATE = "androidrate_last_agree_show_false_date"; + private static final String PREF_KEY_LAUNCH_TIMES = "androidrate_launch_times"; private static final String PREF_KEY_REMIND_INTERVAL = "androidrate_remind_interval"; @@ -216,12 +218,22 @@ static void setIsAgreeShowDialog(final Context context, final boolean isAgree) { getPreferencesEditor(context) .putBoolean(PREF_KEY_IS_AGREE_SHOW_DIALOG, isAgree) .apply(); + + if (!isAgree) { + getPreferencesEditor(context) + .putLong(PREF_KEY_LAST_AGREE_SHOW_FALSE_DATE, new Date().getTime()) + .apply(); + } } static boolean getIsAgreeShowDialog(final Context context) { return getPreferences(context).getBoolean(PREF_KEY_IS_AGREE_SHOW_DIALOG, true); } + static long getLastAgreeShowFalseDate(final Context context) { + return getPreferences(context).getLong(PREF_KEY_LAST_AGREE_SHOW_FALSE_DATE, 0L); + } + /** *
Sets number of times the app has been launched.
* 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 1a56f96..71aedcf 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,6 +72,7 @@ protected void onCreate(Bundle savedInstanceState) { * setStoreType(Intent...) (Any custom intent/intents, Intent... - an intent or array of intents) */ .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 .setLaunchTimes((byte) 10) // default is 10, 3 means app is launched 3 or more times + .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. .setRemindTimeToWait(Time.DAY, (short) 2) // default is 1 day, 1 means app is launched 1 or more time units after neutral button clicked .setRemindLaunchesNumber((byte) 1) // default is 0, 1 means app is launched 1 or more times after neutral button clicked .setSelectedAppLaunches((byte) 4) // default is 1, 1 means each launch, 2 means every 2nd launch, 3 means every 3rd launch, etc