Skip to content

Commit

Permalink
Adding additional calls for star rating. Preparing things for release.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtursKadikis committed Oct 5, 2017
1 parent b0e371b commit cac842f
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
17.09.1
* Adding additional calls for manipulating the star rating dialog

17.09
* Fixed app crawler filtering & ANR if substantially changing device date back in time

17.05
* Added Rich Push Notifications support (attachments and custom action buttons)
* Added functionality to ignore app crawlers
Expand Down
2 changes: 1 addition & 1 deletion app-messaging/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':sdk-messaging')
compile "me.leolin:ShortcutBadger:1.1.10@aar"
//compile 'ly.count.android:sdk-messaging:17.09'
//compile 'ly.count.android:sdk-messaging:17.09.1'
}
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':sdk')
//compile 'ly.count.android:sdk:17.09'
//compile 'ly.count.android:sdk:17.09.1'
}
6 changes: 3 additions & 3 deletions sdk-messaging/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionName "17.09"
versionName "17.09.1"
}
buildTypes {
release {
Expand All @@ -36,14 +36,14 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-gcm:10.0.1'
compile project(':sdk')
// compile 'ly.count:sdk-android:17.09'
// compile 'ly.count:sdk-android:17.09.1'
}

publish {
userOrg = 'countly'
groupId = 'ly.count.android'
artifactId = 'sdk-messaging'
version = '17.09'
version = '17.09.1'
description = 'Countly Android SDK with GCM Support'
website = 'https://github.com/Countly/countly-sdk-android'
}
4 changes: 2 additions & 2 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionName "17.09"
versionName "17.09.1"

testInstrumentationRunner 'ly.count.android.sdk.test.InstrumentationTestRunner'
testHandleProfiling true
Expand Down Expand Up @@ -55,7 +55,7 @@ publish {
userOrg = 'countly'
groupId = 'ly.count.android'
artifactId = 'sdk'
version = '17.09'
version = '17.09.1'
description = 'Android SDK for Countly mobile analytics'
website = 'https://github.com/Countly/countly-sdk-android'
}
60 changes: 57 additions & 3 deletions sdk/src/main/java/ly/count/android/sdk/Countly.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class Countly {
/**
* Current version of the Count.ly Android SDK as a displayable string.
*/
public static final String COUNTLY_SDK_VERSION_STRING = "17.09";
public static final String COUNTLY_SDK_VERSION_STRING = "17.09.1";
/**
* Used as request meta data on every request
*/
Expand Down Expand Up @@ -1204,7 +1204,7 @@ public void setStarRatingDialogTexts(String starRatingTextTitle, String starRati
}

/**
* Set if the star rating
* Set if the star rating should be shown automatically
* @param IsShownAutomatically set it true if you want to show the app star rating dialog automatically for each new version after the specified session amount
*/
public void setIfStarRatingShownAutomatically(boolean IsShownAutomatically) {
Expand All @@ -1228,7 +1228,7 @@ public void setStarRatingDisableAskingForEachAppVersion(boolean disableAsking) {
return;
}
}
CountlyStarRating.setShowDialogAutomatically(context_, disableAsking);
CountlyStarRating.setStarRatingDisableAskingForEachAppVersion(context_, disableAsking);
}

/**
Expand All @@ -1245,6 +1245,60 @@ public void setAutomaticStarRatingSessionLimit(int limit) {
CountlyStarRating.setStarRatingInitConfig(context_, limit, null, null, null);
}

/**
* Returns the session limit set for automatic star rating
*/
public int getAutomaticStarRatingSessionLimit(){
if(context_ == null) {
if (Countly.sharedInstance().isLoggingEnabled()) {
Log.e(Countly.TAG, "Can't call this function before init has been called");
return -1;
}
}
return CountlyStarRating.getAutomaticStarRatingSessionLimit(context_);
}

/**
* Returns how many sessions has star rating counted internally for the current apps version
* @return
*/
public int getStarRatingsCurrentVersionsSessionCount(){
if(context_ == null) {
if (Countly.sharedInstance().isLoggingEnabled()) {
Log.e(Countly.TAG, "Can't call this function before init has been called");
return -1;
}
}
return CountlyStarRating.getCurrentVersionsSessionCount(context_);
}

/**
* Set the automatic star rating session count back to 0
*/
public void clearAutomaticStarRatingSessionCount(){
if(context_ == null) {
if (Countly.sharedInstance().isLoggingEnabled()) {
Log.e(Countly.TAG, "Can't call this function before init has been called");
return;
}
}
CountlyStarRating.clearAutomaticStarRatingSessionCount(context_);
}

/**
* Set if the star rating dialog is cancellable
* @param isCancellable
*/
public void setIfStarRatingDialogIsCancellable(boolean isCancellable){
if(context_ == null) {
if (Countly.sharedInstance().isLoggingEnabled()) {
Log.e(Countly.TAG, "Can't call this function before init has been called");
return;
}
}
CountlyStarRating.setIfRatingDialogIsCancellable(context_, isCancellable);
}

/**
* Set the override for forcing to use HTTP POST for all connections to the server
* @param isItForced the flag for the new status, set "true" if you want it to be forced
Expand Down
124 changes: 115 additions & 9 deletions sdk/src/main/java/ly/count/android/sdk/CountlyStarRating.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,41 @@
import java.util.HashMap;
import java.util.Map;

/**
* Created by Arturs on 29.11.2016..
*/
public class CountlyStarRating {

/**
* Callbacks for star rating dialog
*/
public interface RatingCallback {
void onRate(int rating);
void onDismiss();
}

/**
* Call to manually show star rating dialog
* @param context
* @param callback
*/
public static void showStarRating(Context context, final CountlyStarRating.RatingCallback callback){
StarRatingPreferences srp = loadStarRatingPreferences(context);
showStarRatingCustom(context, srp.dialogTextTitle, srp.dialogTextMessage, srp.dialogTextDismiss, callback);
showStarRatingCustom(context, srp.dialogTextTitle, srp.dialogTextMessage, srp.dialogTextDismiss, srp.isDialogCancellable, callback);
}

/**
* Method that created the star rating dialog
* @param context
* @param title
* @param message
* @param cancelText
* @param isCancellable
* @param callback
*/
public static void showStarRatingCustom(
final Context context,
final String title,
final String message,
final String cancelText,
final boolean isCancellable,
final CountlyStarRating.RatingCallback callback) {

if(!(context instanceof Activity)) {
Expand All @@ -51,6 +66,7 @@ public static void showStarRatingCustom(
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setTitle(title)
.setMessage(message)
.setCancelable(isCancellable)
.setView(dialogLayout)
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
Expand Down Expand Up @@ -92,14 +108,18 @@ public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
});
}

/**
* Class that handles star rating internal state
*/
static class StarRatingPreferences {
String appVersion = ""; //the name of the current version that we keep track of
int sessionLimit = 5;
int sessionLimit = 5; //session limit for the automatic star rating
int sessionAmount = 0; //session amount for the current version
boolean isShownForCurrentVersion = false;
boolean automaticRatingShouldBeShown = false;
boolean disabledAutomaticForNewVersions = false;
boolean automaticHasBeenShown = false;
boolean isShownForCurrentVersion = false; //if automatic star rating has been shown for the current version
boolean automaticRatingShouldBeShown = false; //if the automatic star rating should be shown
boolean disabledAutomaticForNewVersions = false; //if the automatic star star should not be shown for every new apps version
boolean automaticHasBeenShown = false; //if automatic star rating has been shown for any app's version
boolean isDialogCancellable = true; //if star rating dialog is cancellable
String dialogTextTitle = "App rating";
String dialogTextMessage = "Please rate this app";
String dialogTextDismiss = "Cancel";
Expand All @@ -111,10 +131,15 @@ static class StarRatingPreferences {
private static String KEY_AUTOMATIC_RATING_IS_SHOWN = "sr_is_automatic_shown";
private static String KEY_DISABLE_AUTOMATIC_NEW_VERSIONS = "sr_is_disable_automatic_new";
private static String KEY_AUTOMATIC_HAS_BEEN_SHOWN = "sr_automatic_has_been_shown";
private static String KEY_DIALOG_IS_CANCELLABLE = "sr_automatic_dialog_is_cancellable";
private static String KEY_DIALOG_TEXT_TITLE = "sr_text_title";
private static String KEY_DIALOG_TEXT_MESSAGE = "sr_text_message";
private static String KEY_DIALOG_TEXT_DISMISS = "sr_text_dismiss";

/**
* Create a JSONObject from the current state
* @return
*/
JSONObject toJSON() {
final JSONObject json = new JSONObject();

Expand All @@ -126,6 +151,7 @@ JSONObject toJSON() {
json.put(KEY_AUTOMATIC_RATING_IS_SHOWN, automaticRatingShouldBeShown);
json.put(KEY_DISABLE_AUTOMATIC_NEW_VERSIONS, disabledAutomaticForNewVersions);
json.put(KEY_AUTOMATIC_HAS_BEEN_SHOWN, automaticHasBeenShown);
json.put(KEY_DIALOG_IS_CANCELLABLE, isDialogCancellable);
json.put(KEY_DIALOG_TEXT_TITLE, dialogTextTitle);
json.put(KEY_DIALOG_TEXT_MESSAGE, dialogTextMessage);
json.put(KEY_DIALOG_TEXT_DISMISS, dialogTextDismiss);
Expand All @@ -140,6 +166,11 @@ JSONObject toJSON() {
return json;
}

/**
* Load the preference state from a JSONObject
* @param json
* @return
*/
static StarRatingPreferences fromJSON(final JSONObject json) {

StarRatingPreferences srp = new StarRatingPreferences();
Expand All @@ -153,6 +184,7 @@ static StarRatingPreferences fromJSON(final JSONObject json) {
srp.automaticRatingShouldBeShown = json.optBoolean(KEY_AUTOMATIC_RATING_IS_SHOWN, true);
srp.disabledAutomaticForNewVersions = json.optBoolean(KEY_DISABLE_AUTOMATIC_NEW_VERSIONS, false);
srp.automaticHasBeenShown = json.optBoolean(KEY_AUTOMATIC_HAS_BEEN_SHOWN, false);
srp.isDialogCancellable = json.optBoolean(KEY_DIALOG_IS_CANCELLABLE, true);

if(!json.isNull(KEY_DIALOG_TEXT_TITLE)) {
srp.dialogTextTitle = json.getString(KEY_DIALOG_TEXT_TITLE);
Expand All @@ -177,6 +209,14 @@ static StarRatingPreferences fromJSON(final JSONObject json) {
}
}

/**
* Setting things that would be provided during initial config
* @param context
* @param limit limit for automatic rating
* @param starRatingTextTitle provided title
* @param starRatingTextMessage provided message
* @param starRatingTextDismiss provided dismiss text
*/
public static void setStarRatingInitConfig(Context context, int limit, String starRatingTextTitle, String starRatingTextMessage, String starRatingTextDismiss) {
StarRatingPreferences srp = loadStarRatingPreferences(context);

Expand All @@ -199,6 +239,11 @@ public static void setStarRatingInitConfig(Context context, int limit, String st
saveStarRatingPreferences(context, srp);
}

/**
* Returns a object with the loaded preferences
* @param context
* @return
*/
private static StarRatingPreferences loadStarRatingPreferences(Context context) {
CountlyStore cs = new CountlyStore(context);
String srpString = cs.getStarRatingPreferences();
Expand All @@ -219,23 +264,45 @@ private static StarRatingPreferences loadStarRatingPreferences(Context context)
return srp;
}

/**
* Save the star rating preferences object
* @param context
* @param srp
*/
private static void saveStarRatingPreferences(Context context, StarRatingPreferences srp) {
CountlyStore cs = new CountlyStore(context);
cs.setStarRatingPreferences(srp.toJSON().toString());
}

/**
* Set if the star rating dialog should be shown automatically
* @param context
* @param shouldShow
*/
public static void setShowDialogAutomatically(Context context, boolean shouldShow) {
StarRatingPreferences srp = loadStarRatingPreferences(context);
srp.automaticRatingShouldBeShown = shouldShow;
saveStarRatingPreferences(context, srp);
}

/**
* Set if automatic star rating should be disabled for each new version.
* By default automatic star rating will be shown for every new app version.
* If this is set to true, star rating will be shown only once over apps lifetime
* @param context
* @param disableAsking if set true, will not show star rating for every new app version
*/
public static void setStarRatingDisableAskingForEachAppVersion(Context context, boolean disableAsking) {
StarRatingPreferences srp = loadStarRatingPreferences(context);
srp.disabledAutomaticForNewVersions = disableAsking;
saveStarRatingPreferences(context, srp);
}

/**
* Register that a apps session has transpired. Will increase session counter and show automatic star rating if needed.
* @param context
* @param starRatingCallback
*/
public static void registerAppSession(Context context, RatingCallback starRatingCallback) {
StarRatingPreferences srp = loadStarRatingPreferences(context);

Expand All @@ -258,4 +325,43 @@ public static void registerAppSession(Context context, RatingCallback starRating

saveStarRatingPreferences(context, srp);
}

/**
* Returns the session limit set for automatic star rating
*/
public static int getAutomaticStarRatingSessionLimit(Context context){
StarRatingPreferences srp = loadStarRatingPreferences(context);
return srp.sessionLimit;
}

/**
* Returns how many sessions has star rating counted internally
* @param context
* @return
*/
public static int getCurrentVersionsSessionCount(Context context){
StarRatingPreferences srp = loadStarRatingPreferences(context);
return srp.sessionAmount;
}

/**
* Set the automatic star rating session count back to 0
* @param context
*/
public static void clearAutomaticStarRatingSessionCount(Context context){
StarRatingPreferences srp = loadStarRatingPreferences(context);
srp.sessionAmount = 0;
saveStarRatingPreferences(context, srp);
}

/**
* Set if the star rating dialog is cancellable
* @param context
* @param isCancellable
*/
public static void setIfRatingDialogIsCancellable(Context context, boolean isCancellable){
StarRatingPreferences srp = loadStarRatingPreferences(context);
srp.isDialogCancellable = isCancellable;
saveStarRatingPreferences(context, srp);
}
}

0 comments on commit cac842f

Please sign in to comment.