From cac842f61301b585296dceda12c1ad58218c1f72 Mon Sep 17 00:00:00 2001 From: ArtursK Date: Thu, 5 Oct 2017 05:47:39 +0300 Subject: [PATCH] Adding additional calls for star rating. Preparing things for release. --- CHANGELOG.md | 4 + app-messaging/build.gradle | 2 +- app/build.gradle | 2 +- sdk-messaging/build.gradle | 6 +- sdk/build.gradle | 4 +- .../java/ly/count/android/sdk/Countly.java | 60 ++++++++- .../count/android/sdk/CountlyStarRating.java | 124 ++++++++++++++++-- 7 files changed, 183 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16e320bfd..7e07b1595 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app-messaging/build.gradle b/app-messaging/build.gradle index 1cced1b51..fb3acbdca 100644 --- a/app-messaging/build.gradle +++ b/app-messaging/build.gradle @@ -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' } diff --git a/app/build.gradle b/app/build.gradle index 061a7e769..0ffed5f60 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' } diff --git a/sdk-messaging/build.gradle b/sdk-messaging/build.gradle index d573c2c8c..47fdec486 100644 --- a/sdk-messaging/build.gradle +++ b/sdk-messaging/build.gradle @@ -18,7 +18,7 @@ android { minSdkVersion 9 targetSdkVersion 25 versionCode 1 - versionName "17.09" + versionName "17.09.1" } buildTypes { release { @@ -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' } diff --git a/sdk/build.gradle b/sdk/build.gradle index 8e7c545c3..8abe73381 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -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 @@ -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' } diff --git a/sdk/src/main/java/ly/count/android/sdk/Countly.java b/sdk/src/main/java/ly/count/android/sdk/Countly.java index 4fa25e504..d02653f7f 100644 --- a/sdk/src/main/java/ly/count/android/sdk/Countly.java +++ b/sdk/src/main/java/ly/count/android/sdk/Countly.java @@ -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 */ @@ -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) { @@ -1228,7 +1228,7 @@ public void setStarRatingDisableAskingForEachAppVersion(boolean disableAsking) { return; } } - CountlyStarRating.setShowDialogAutomatically(context_, disableAsking); + CountlyStarRating.setStarRatingDisableAskingForEachAppVersion(context_, disableAsking); } /** @@ -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 diff --git a/sdk/src/main/java/ly/count/android/sdk/CountlyStarRating.java b/sdk/src/main/java/ly/count/android/sdk/CountlyStarRating.java index 444cb1bbf..1cbc85cfc 100644 --- a/sdk/src/main/java/ly/count/android/sdk/CountlyStarRating.java +++ b/sdk/src/main/java/ly/count/android/sdk/CountlyStarRating.java @@ -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)) { @@ -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 @@ -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"; @@ -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(); @@ -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); @@ -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(); @@ -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); @@ -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); @@ -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(); @@ -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); @@ -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); + } }