-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to re-prompt at intervals after user accept/ignore #21
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
|
||
/** | ||
* <p>Sets the minimal number of time units until the Rate Dialog appears after it has already | ||
* been actioned.</p> | ||
* <p>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.</p> | ||
* @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; | ||
} | ||
|
||
/** | ||
* <p>Sets the minimal number of time units until the Rate Dialog pops up for the first time.</p> | ||
* <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) { | |
*/ | ||
@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()) && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. '&&' should be on a new line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Matching existing style as much as possible while combining the tightly related |
||
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); | ||
sampengilly marked this conversation as resolved.
Show resolved
Hide resolved
sampengilly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
private boolean isOverLaunchTimes() { | ||
return ((appLaunchTimes == 0) || (getLaunchTimes(context) >= appLaunchTimes)); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is longer than 100 characters (found 111). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not the only one among these constants |
||
|
||
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); | ||
} | ||
|
||
/** | ||
* <p>Sets number of times the app has been launched.</p> | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong lexicographical order for 'com.vorlonsoft.android.rate.PreferenceHelper.getLastAgreeShowFalseDate' import. Should be before 'java.util.Map'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matching existing imports in alphabetical order