Skip to content
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

Ability to choose between AND and OR for the shouldShowDialog method #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions ratethisapp/src/main/java/com/kobakei/ratethisapp/RateThisApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import android.support.v7.app.AlertDialog;
import android.util.Log;

import com.kobakei.ratethisapp.enums.RateConditionsEnum;

/**
* RateThisApp<br>
* A library to show the app rate dialog
Expand Down Expand Up @@ -140,14 +142,16 @@ public static boolean shouldShowRateDialog() {
if (mOptOut) {
return false;
} else {
if (mLaunchTimes >= sConfig.mCriteriaLaunchTimes) {
return true;
}
boolean launchTimesFulfilled = (mLaunchTimes >= sConfig.mCriteriaLaunchTimes);

long threshold = sConfig.mCriteriaInstallDays * 24 * 60 * 60 * 1000L; // msec
if (new Date().getTime() - mInstallDate.getTime() >= threshold) {
return true;
boolean installThresholdFulfilled = new Date().getTime() - mInstallDate.getTime() >= threshold;

if (sConfig.mAndCondition){
return launchTimesFulfilled && installThresholdFulfilled;
} else {
return launchTimesFulfilled || installThresholdFulfilled;
}
return false;
}
}

Expand Down Expand Up @@ -284,6 +288,7 @@ public static class Config {
private int mRateButton = 0;
private int mThanksButton = 0;
private int mCancelButton = 0;
private boolean mAndCondition = false;

/**
* Constructor with default criteria.
Expand All @@ -292,6 +297,11 @@ public Config() {
this(7, 10);
}

public Config(RateConditionsEnum rateConditionsJoin) {
this();
this.mAndCondition = rateConditionsJoin == RateConditionsEnum.AND;
}

/**
* Constructor.
* @param criteriaInstallDays
Expand All @@ -302,6 +312,18 @@ public Config(int criteriaInstallDays, int criteriaLaunchTimes) {
this.mCriteriaLaunchTimes = criteriaLaunchTimes;
}

/**
* Constructor.
* @param criteriaInstallDays
* @param criteriaLaunchTimes
* @param rateConditionsJoin
*/
public Config(int criteriaInstallDays, int criteriaLaunchTimes, RateConditionsEnum rateConditionsJoin) {
this.mCriteriaInstallDays = criteriaInstallDays;
this.mCriteriaLaunchTimes = criteriaLaunchTimes;
this.mAndCondition = rateConditionsJoin == RateConditionsEnum.AND;
}

/**
* Set title string ID.
* @param stringId
Expand All @@ -317,30 +339,40 @@ public void setTitle(int stringId) {
public void setMessage(int stringId) {
this.mMessageId = stringId;
}

/**
* Set rate now string ID.
* @param stringId
*/
public void setRateButton(int stringId) {
this.mRateButton = stringId;
}

/**
* Set no thanks string ID.
* @param stringId
*/
public void setThanksButton(int stringId) {
this.mThanksButton = stringId;
}

/**
* Set cancel string ID.
* @param stringId
*/
public void setCancelButton(int stringId) {
this.mCancelButton = stringId;
}

/**
* Set condition to And
*/
public void setOrCondition() { this.mAndCondition = false; }

/**
* Set condition to Or
*/
public void setAndCondition(){ this.mAndCondition = true; }
}

public interface Callback {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.kobakei.ratethisapp.enums;

/**
* Created by eylen
* Enum to choose the join condition to decide if the dialog should be shown
*/
public enum RateConditionsEnum {
AND, OR
}