From 2126976eede8871df802b36a7eadea657cf7f865 Mon Sep 17 00:00:00 2001 From: Christian Grach Date: Fri, 4 Oct 2019 22:19:48 +0200 Subject: [PATCH 01/14] remove activity --- build.gradle.kts | 2 +- buildSrc/src/main/kotlin/Deps.kt | 6 +- gradle/wrapper/gradle-wrapper.properties | 2 +- library/src/main/AndroidManifest.xml | 10 +- .../cmgapps/android/apprater/AppRater.java | 45 ++++-- .../android/apprater/AppRaterActivity.java | 151 ------------------ library/src/main/res/values/styles.xml | 15 -- sample/build.gradle.kts | 5 + sample/src/main/res/values/colors.xml | 2 +- sample/src/main/res/values/styles.xml | 5 + 10 files changed, 45 insertions(+), 198 deletions(-) delete mode 100644 library/src/main/java/com/cmgapps/android/apprater/AppRaterActivity.java delete mode 100644 library/src/main/res/values/styles.xml diff --git a/build.gradle.kts b/build.gradle.kts index dd65817..6a4287e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ buildscript { } dependencies { - classpath("com.android.tools.build:gradle:3.4.0") + classpath("com.android.tools.build:gradle:3.5.1") classpath(kotlin("gradle-plugin", version = Deps.Versions.KOTLIN)) } } diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 0007368..5e4e02d 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -16,11 +16,11 @@ object Deps { object Versions { - const val COMPILE_SDK_VERSION = 28 - const val BUILD_TOOLS_VERSION = "28.0.3" + const val COMPILE_SDK_VERSION = 29 + const val BUILD_TOOLS_VERSION = "29.0.2" const val TARGET_SDK_VERSION = COMPILE_SDK_VERSION - const val KOTLIN = "1.3.31" + const val KOTLIN = "1.3.50" const val APP_COMPAT = "1.0.2" const val CORE_KTX = "1.0.1" const val LIFECYCLE_EXT = "2.0.0" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ee69dd6..ca9d628 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index e919bdd..daea32e 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -2,14 +2,6 @@ Copyright (c) 2016. Christian Grach --> - + - - - diff --git a/library/src/main/java/com/cmgapps/android/apprater/AppRater.java b/library/src/main/java/com/cmgapps/android/apprater/AppRater.java index f6b18a7..68ec7c2 100644 --- a/library/src/main/java/com/cmgapps/android/apprater/AppRater.java +++ b/library/src/main/java/com/cmgapps/android/apprater/AppRater.java @@ -5,33 +5,23 @@ package com.cmgapps.android.apprater; import android.app.Activity; -import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Build; -import android.os.Bundle; import android.text.format.DateUtils; import android.util.Log; import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; import com.cmgapps.android.apprater.store.GooglePlayStore; import com.cmgapps.android.apprater.store.Store; -/** - *

- * Class that utilizes usage count and time to open a rate dialog. - *

- *

- * Use {@link #incrementUseCount()} on your main activity - * {@link Activity#onCreate(Bundle)} implementation. - *

- * Then call {@link #checkForRating()} to check if the requirements are met to - * show the dialog and finally call {@link #show(Activity)} to show the rating dialog - */ public class AppRater { private static final String TAG = "AppRater"; @@ -122,10 +112,31 @@ public void incrementUseCount() { * @param activity An {@link Activity} to show the dialog from. */ public void show(@NonNull final Activity activity) { - Intent intent = new Intent(activity, AppRaterActivity.class); - intent.putExtra(AppRaterActivity.EXTRA_STORE_URI, mStore.getStoreUri(activity)); - activity.startActivity(intent); - activity.overridePendingTransition(0, 0); + final PackageManager pm = activity.getPackageManager(); + + String appName; + try { + ApplicationInfo ai = pm.getApplicationInfo(activity.getPackageName(), 0); + appName = (String) pm.getApplicationLabel(ai); + } catch (PackageManager.NameNotFoundException e) { + Log.e(TAG, "Application name can not be found"); + appName = "App"; + } + + new AlertDialog.Builder(activity) + .setTitle(R.string.dialog_cmgrate_title) + .setMessage(activity.getString(R.string.dialog_cmgrate_message_fmt, appName)) + .setPositiveButton(R.string.dialog_cmgrate_ok, (dialog, which) -> { + mPreferenceManager.setAppRated(true); + + Intent intent = new Intent(Intent.ACTION_VIEW, mStore.getStoreUri(activity)); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + activity.startActivity(intent); + }) + .setNeutralButton(R.string.dialog_cmgrate_later, (dialog, which) -> mPreferenceManager.setRemindLaterTimeStamp(System.currentTimeMillis())) + .setNegativeButton(R.string.dialog_cmgrate_no, (dialog, which) -> mPreferenceManager.setDeclinedToRate(true)) + .setOnCancelListener(dialog -> mPreferenceManager.setRemindLaterTimeStamp(System.currentTimeMillis())) + .show(); } /** diff --git a/library/src/main/java/com/cmgapps/android/apprater/AppRaterActivity.java b/library/src/main/java/com/cmgapps/android/apprater/AppRaterActivity.java deleted file mode 100644 index e4fecba..0000000 --- a/library/src/main/java/com/cmgapps/android/apprater/AppRaterActivity.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2016. Christian Grach - */ - -package com.cmgapps.android.apprater; - -import android.app.Activity; -import android.app.Dialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.net.Uri; -import android.os.Bundle; -import android.util.Log; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; -import androidx.fragment.app.DialogFragment; - -/** - * App Rater Dialog Activity - */ -public class AppRaterActivity extends AppCompatActivity { - - static final String EXTRA_STORE_URI = "com.cmgapps.android.apprater.extra.STORE_URI"; - - private static final String TAG = "AppRaterActivity"; - - boolean mButtonClicked; - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - if (savedInstanceState == null) { - RaterFragment.newInstance(getIntent().getExtras()) - .show(getSupportFragmentManager(), "CMGAppsRaterFragment"); - } - } - - @Override - public void finish() { - if (!mButtonClicked) { - new PreferenceManager(this).setRemindLaterTimeStamp(System.currentTimeMillis()); - } - super.finish(); - overridePendingTransition(0, 0); - } - - public static class RaterFragment extends DialogFragment { - - private PreferenceManager mPreferenceManager; - - static RaterFragment newInstance(Bundle extras) { - RaterFragment raterFragment = new RaterFragment(); - raterFragment.setArguments(extras); - return raterFragment; - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mPreferenceManager = new PreferenceManager(requireContext()); - } - - @NonNull - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - - final Context context = requireContext(); - final PackageManager pm = context.getPackageManager(); - - String appName; - try { - ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0); - appName = (String) pm.getApplicationLabel(ai); - } catch (PackageManager.NameNotFoundException e) { - Log.e(TAG, "Application name can not be found"); - appName = "App"; - } - - return new AlertDialog.Builder(context) - .setTitle(R.string.dialog_cmgrate_title) - .setMessage(getString(R.string.dialog_cmgrate_message_fmt, appName)) - .setPositiveButton(R.string.dialog_cmgrate_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - AppRaterActivity activity = (AppRaterActivity) getActivity(); - - if (activity == null) { - return; - } - - mPreferenceManager.setAppRated(true); - activity.mButtonClicked = true; - Uri storeUri = null; - - if (getArguments() != null) { - storeUri = getArguments().getParcelable(EXTRA_STORE_URI); - } - - Intent intent = new Intent(Intent.ACTION_VIEW, storeUri); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); - activity.finish(); - } - }) - .setNeutralButton(R.string.dialog_cmgrate_later, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - AppRaterActivity activity = (AppRaterActivity) getActivity(); - - if (activity == null) { - return; - } - mPreferenceManager.setRemindLaterTimeStamp(System.currentTimeMillis()); - activity.mButtonClicked = true; - activity.finish(); - } - }) - .setNegativeButton(R.string.dialog_cmgrate_no, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - AppRaterActivity activity = (AppRaterActivity) getActivity(); - - if (activity == null) { - return; - } - - mPreferenceManager.setDeclinedToRate(true); - activity.mButtonClicked = true; - activity.finish(); - } - }) - .create(); - } - - @Override - public void onCancel(DialogInterface dialog) { - Activity activity = getActivity(); - - if (activity != null) { - activity.finish(); - } - } - } -} diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/styles.xml deleted file mode 100644 index cf7fded..0000000 --- a/library/src/main/res/values/styles.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 90cfb40..4dfcd55 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -36,6 +36,11 @@ android { proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") } } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } } dependencies { diff --git a/sample/src/main/res/values/colors.xml b/sample/src/main/res/values/colors.xml index 0ea4096..bba6d16 100644 --- a/sample/src/main/res/values/colors.xml +++ b/sample/src/main/res/values/colors.xml @@ -6,5 +6,5 @@ #3F51B5 #303F9F - #FF4081 + #0000FF diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml index 37c6e0f..f2367fd 100644 --- a/sample/src/main/res/values/styles.xml +++ b/sample/src/main/res/values/styles.xml @@ -10,6 +10,11 @@ @color/colorPrimary @color/colorPrimaryDark @color/colorAccent + @style/RaterDialog + + + From 25c787ba4fe3a6665ce92eb53d4d4ded7324462f Mon Sep 17 00:00:00 2001 From: Christian Grach Date: Sat, 5 Oct 2019 13:17:01 +0200 Subject: [PATCH 02/14] update tests --- LICENSE | 2 +- README.md | 2 +- buildSrc/src/main/kotlin/Deps.kt | 14 ++++----- gradle.properties | 15 ++++++++-- library/build.gradle.kts | 2 +- ...rActivityShould.kt => AppRaterUiShould.kt} | 29 +++++++++++++++++-- library/src/debug/AndroidManifest.xml | 26 +++++++++++++++++ library/src/debug/java/TestActivity.kt | 21 ++++++++++++++ library/src/main/AndroidManifest.xml | 17 +++++++++-- .../cmgapps/android/apprater/AppRater.java | 12 ++++++++ .../android/apprater/PreferenceManager.kt | 12 ++++++++ .../android/apprater/store/AmazonStore.java | 12 ++++++++ .../apprater/store/GooglePlayStore.java | 12 ++++++++ .../cmgapps/android/apprater/store/Store.java | 12 ++++++++ library/src/main/res/values-de/strings.xml | 14 ++++++++- library/src/main/res/values-es/strings.xml | 14 ++++++++- library/src/main/res/values-fr/strings.xml | 14 ++++++++- library/src/main/res/values-it/strings.xml | 14 ++++++++- library/src/main/res/values/strings.xml | 14 ++++++++- .../android/apprater/AppRaterBuilderShould.kt | 16 ++++++++++ .../android/apprater/AppRaterShould.kt | 14 ++++++++- .../apprater/PreferenceManagerShould.kt | 14 ++++++++- 22 files changed, 277 insertions(+), 25 deletions(-) rename library/src/androidTest/java/{AppRaterActivityShould.kt => AppRaterUiShould.kt} (51%) create mode 100644 library/src/debug/AndroidManifest.xml create mode 100644 library/src/debug/java/TestActivity.kt diff --git a/LICENSE b/LICENSE index 5c304d1..8dada3e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Apache License + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ diff --git a/README.md b/README.md index a4fc3c3..7a0b2d6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Android™ App Rater Dialog [![License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg?style=for-the-badge&logo=apache)](http://www.apache.org/licenses/LICENSE-2.0) -[![Bintray](https://img.shields.io/bintray/v/chrimaeon/maven/com.cmgapps.android:app-rater.svg?style=for-the-badge)](https://jcenter.bintray.com/com/cmgapps/android/cmgUtilities/) +[![Bintray](https://www.cmgapps.com/badge/chrimaeon/maven/com.cmgapps.android:app-rater/badge.svg)](https://jcenter.bintray.com/com/cmgapps/android/cmgUtilities/) This is a App Rater Dialog to encourage user to rate the app on the Google Play Store™ diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 5e4e02d..de5a0a5 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -21,16 +21,16 @@ object Deps { const val TARGET_SDK_VERSION = COMPILE_SDK_VERSION const val KOTLIN = "1.3.50" - const val APP_COMPAT = "1.0.2" - const val CORE_KTX = "1.0.1" + const val APP_COMPAT = "1.1.0" + const val CORE_KTX = "1.1.0" const val LIFECYCLE_EXT = "2.0.0" const val JUNIT = "4.12" - const val TEST_CORE = "1.1.0" - const val MOCKITO_CORE = "2.27.0" + const val TEST_CORE = "1.2.0" + const val MOCKITO_CORE = "3.1.0" const val HAMCREST = "2.1" - const val TEST_RUNNER = "1.1.1" - const val JUNIT_KTX = "1.1.0" - const val ESPRESSO_CORE = "3.1.1" + const val TEST_RUNNER = "1.2.0" + const val JUNIT_KTX = "1.1.1" + const val ESPRESSO_CORE = "3.2.0" } } diff --git a/gradle.properties b/gradle.properties index cf24bf0..600e4bd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,17 @@ # -# Copyright (c) 2016. Christian Grach +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # versionName=1.0.0 group=com.cmgapps.android @@ -15,6 +27,5 @@ pomLicenseUrl=http://www.apache.org/licenses/LICENSE-2.0.txt pomLicenseDist=repo projectUrl=https://github.com/chrimaeon/app-rater issuesTrackerUrl=https://github.com/chrimaeon/app-rater/issues - android.useAndroidX=true android.enableJetifier=true diff --git a/library/build.gradle.kts b/library/build.gradle.kts index ebb701f..b7563f4 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -25,7 +25,7 @@ plugins { id("com.android.library") kotlin("android") id("digital.wup.android-maven-publish") version "3.6.2" - id("com.github.ben-manes.versions") version "0.20.0" + id("com.github.ben-manes.versions") version "0.25.0" id("com.jfrog.bintray") version "1.8.4" id("org.jetbrains.dokka-android") version "0.9.18" } diff --git a/library/src/androidTest/java/AppRaterActivityShould.kt b/library/src/androidTest/java/AppRaterUiShould.kt similarity index 51% rename from library/src/androidTest/java/AppRaterActivityShould.kt rename to library/src/androidTest/java/AppRaterUiShould.kt index d68322e..98cd59a 100644 --- a/library/src/androidTest/java/AppRaterActivityShould.kt +++ b/library/src/androidTest/java/AppRaterUiShould.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2019. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.cmgapps.android.apprater import androidx.test.espresso.Espresso.onView @@ -6,19 +22,25 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.activityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.cmgapps.android.apprater.testing.TestActivity import org.hamcrest.Matchers.containsString import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) -class AppRaterActivityShould { +class AppRaterUiShould { - @get:Rule - var activityScenarioRule = activityScenarioRule() + @Rule + @JvmField + var activityScenarioRule = activityScenarioRule() @Test fun showDialog() { + activityScenarioRule.scenario.onActivity { + AppRater.Builder(it).build().show(it) + } + onView(withText("Rate now!")) .check(matches(isDisplayed())) onView(withText(containsString("If you enjoy using"))) @@ -28,5 +50,6 @@ class AppRaterActivityShould { .check(matches(isDisplayed())) onView(withText("No, thanks")) .check(matches(isDisplayed())) + } } diff --git a/library/src/debug/AndroidManifest.xml b/library/src/debug/AndroidManifest.xml new file mode 100644 index 0000000..0d9ab18 --- /dev/null +++ b/library/src/debug/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + diff --git a/library/src/debug/java/TestActivity.kt b/library/src/debug/java/TestActivity.kt new file mode 100644 index 0000000..384ef32 --- /dev/null +++ b/library/src/debug/java/TestActivity.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2019. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cmgapps.android.apprater.testing + +import androidx.appcompat.app.AppCompatActivity + +class TestActivity : AppCompatActivity() diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index daea32e..3d229ab 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,7 +1,18 @@ + - + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + + diff --git a/library/src/main/java/com/cmgapps/android/apprater/AppRater.java b/library/src/main/java/com/cmgapps/android/apprater/AppRater.java index 68ec7c2..64e3cdd 100644 --- a/library/src/main/java/com/cmgapps/android/apprater/AppRater.java +++ b/library/src/main/java/com/cmgapps/android/apprater/AppRater.java @@ -1,5 +1,17 @@ /* * Copyright (c) 2016. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.cmgapps.android.apprater; diff --git a/library/src/main/java/com/cmgapps/android/apprater/PreferenceManager.kt b/library/src/main/java/com/cmgapps/android/apprater/PreferenceManager.kt index 310b1a8..345b5ba 100644 --- a/library/src/main/java/com/cmgapps/android/apprater/PreferenceManager.kt +++ b/library/src/main/java/com/cmgapps/android/apprater/PreferenceManager.kt @@ -1,5 +1,17 @@ /* * Copyright (c) 2019. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.cmgapps.android.apprater diff --git a/library/src/main/java/com/cmgapps/android/apprater/store/AmazonStore.java b/library/src/main/java/com/cmgapps/android/apprater/store/AmazonStore.java index e001228..43b676a 100644 --- a/library/src/main/java/com/cmgapps/android/apprater/store/AmazonStore.java +++ b/library/src/main/java/com/cmgapps/android/apprater/store/AmazonStore.java @@ -1,5 +1,17 @@ /* * Copyright (c) 2016. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.cmgapps.android.apprater.store; diff --git a/library/src/main/java/com/cmgapps/android/apprater/store/GooglePlayStore.java b/library/src/main/java/com/cmgapps/android/apprater/store/GooglePlayStore.java index 1a3b911..9e6109b 100644 --- a/library/src/main/java/com/cmgapps/android/apprater/store/GooglePlayStore.java +++ b/library/src/main/java/com/cmgapps/android/apprater/store/GooglePlayStore.java @@ -1,5 +1,17 @@ /* * Copyright (c) 2016. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.cmgapps.android.apprater.store; diff --git a/library/src/main/java/com/cmgapps/android/apprater/store/Store.java b/library/src/main/java/com/cmgapps/android/apprater/store/Store.java index 48c08d6..611cb56 100644 --- a/library/src/main/java/com/cmgapps/android/apprater/store/Store.java +++ b/library/src/main/java/com/cmgapps/android/apprater/store/Store.java @@ -1,5 +1,17 @@ /* * Copyright (c) 2016. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.cmgapps.android.apprater.store; diff --git a/library/src/main/res/values-de/strings.xml b/library/src/main/res/values-de/strings.xml index 78e5f1b..618893f 100644 --- a/library/src/main/res/values-de/strings.xml +++ b/library/src/main/res/values-de/strings.xml @@ -1,7 +1,19 @@ + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> diff --git a/library/src/main/res/values-es/strings.xml b/library/src/main/res/values-es/strings.xml index fcfd9c5..dfecb5f 100644 --- a/library/src/main/res/values-es/strings.xml +++ b/library/src/main/res/values-es/strings.xml @@ -1,7 +1,19 @@ + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> diff --git a/library/src/main/res/values-fr/strings.xml b/library/src/main/res/values-fr/strings.xml index e63a9c0..73ad07b 100644 --- a/library/src/main/res/values-fr/strings.xml +++ b/library/src/main/res/values-fr/strings.xml @@ -1,7 +1,19 @@ + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> diff --git a/library/src/main/res/values-it/strings.xml b/library/src/main/res/values-it/strings.xml index 58204d6..8d901b5 100644 --- a/library/src/main/res/values-it/strings.xml +++ b/library/src/main/res/values-it/strings.xml @@ -1,7 +1,19 @@ + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml index 9e8c111..291d600 100644 --- a/library/src/main/res/values/strings.xml +++ b/library/src/main/res/values/strings.xml @@ -1,7 +1,19 @@ + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> diff --git a/library/src/test/java/com/cmgapps/android/apprater/AppRaterBuilderShould.kt b/library/src/test/java/com/cmgapps/android/apprater/AppRaterBuilderShould.kt index a930101..9eeffa3 100644 --- a/library/src/test/java/com/cmgapps/android/apprater/AppRaterBuilderShould.kt +++ b/library/src/test/java/com/cmgapps/android/apprater/AppRaterBuilderShould.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2019. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.cmgapps.android.apprater import android.content.Context diff --git a/library/src/test/java/com/cmgapps/android/apprater/AppRaterShould.kt b/library/src/test/java/com/cmgapps/android/apprater/AppRaterShould.kt index 041a54f..5fc3b8b 100644 --- a/library/src/test/java/com/cmgapps/android/apprater/AppRaterShould.kt +++ b/library/src/test/java/com/cmgapps/android/apprater/AppRaterShould.kt @@ -1,5 +1,17 @@ /* - * Copyright (c) 2019. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.cmgapps.android.apprater diff --git a/library/src/test/java/com/cmgapps/android/apprater/PreferenceManagerShould.kt b/library/src/test/java/com/cmgapps/android/apprater/PreferenceManagerShould.kt index 6aa93b8..da0dc5d 100644 --- a/library/src/test/java/com/cmgapps/android/apprater/PreferenceManagerShould.kt +++ b/library/src/test/java/com/cmgapps/android/apprater/PreferenceManagerShould.kt @@ -1,5 +1,17 @@ /* - * Copyright (c) 2019. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.cmgapps.android.apprater From 0d699741aaeec2fb28eb35589141aa9f85a0870e Mon Sep 17 00:00:00 2001 From: Christian Grach Date: Sat, 5 Oct 2019 13:36:10 +0200 Subject: [PATCH 03/14] use DefaultLifecycleObserver --- buildSrc/build.gradle.kts | 2 +- buildSrc/src/main/kotlin/Deps.kt | 1 + sample/build.gradle.kts | 1 + .../src/main/java/com/cmgapps/android/SampleApp.kt | 14 ++++---------- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index cbc086a..9504d1e 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -23,5 +23,5 @@ repositories { } dependencies { - implementation(kotlin("stdlib-jdk8", "1.3.31")) + implementation(kotlin("stdlib-jdk8", "1.3.50")) } diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index de5a0a5..5867eaf 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -24,6 +24,7 @@ object Deps { const val APP_COMPAT = "1.1.0" const val CORE_KTX = "1.1.0" const val LIFECYCLE_EXT = "2.0.0" + const val LIFECYCLE_COMMON = "2.1.0" const val JUNIT = "4.12" const val TEST_CORE = "1.2.0" const val MOCKITO_CORE = "3.1.0" diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 4dfcd55..e6efb9e 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -48,5 +48,6 @@ dependencies { implementation("androidx.appcompat:appcompat:${Deps.Versions.APP_COMPAT}") implementation("androidx.core:core-ktx:${Deps.Versions.CORE_KTX}") implementation("androidx.lifecycle:lifecycle-extensions:${Deps.Versions.LIFECYCLE_EXT}") + implementation("androidx.lifecycle:lifecycle-common-java8:${Deps.Versions.LIFECYCLE_COMMON}") implementation(kotlin("stdlib-jdk7", Deps.Versions.KOTLIN)) } diff --git a/sample/src/main/java/com/cmgapps/android/SampleApp.kt b/sample/src/main/java/com/cmgapps/android/SampleApp.kt index 6b5b168..e0e9e37 100644 --- a/sample/src/main/java/com/cmgapps/android/SampleApp.kt +++ b/sample/src/main/java/com/cmgapps/android/SampleApp.kt @@ -5,16 +5,11 @@ package com.cmgapps.android import android.app.Application -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.LifecycleObserver -import androidx.lifecycle.OnLifecycleEvent +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.ProcessLifecycleOwner import com.cmgapps.android.apprater.AppRater -/* - * Copyright (c) 2019. Christian Grach - */ - class SampleApp : Application() { override fun onCreate() { @@ -25,10 +20,9 @@ class SampleApp : Application() { } } -class AppLifecycleListener(private val appRater: AppRater) : LifecycleObserver { +class AppLifecycleListener(private val appRater: AppRater) : DefaultLifecycleObserver { - @OnLifecycleEvent(Lifecycle.Event.ON_START) - fun onAppForeground() { + override fun onStart(owner: LifecycleOwner) { appRater.incrementUseCount() } } From 10423ecd0db26c77c746c02ad97230815c3c5104 Mon Sep 17 00:00:00 2001 From: Christian Grach Date: Sun, 6 Oct 2019 16:34:02 +0200 Subject: [PATCH 04/14] convert to kotlin --- build.gradle.kts | 21 +- buildSrc/build.gradle.kts | 4 + buildSrc/src/main/kotlin/Deps.kt | 14 +- .../main/kotlin/bintray-publish.gradle.kts | 111 +++++++++ gradle.properties | 4 - library-ktx/build.gradle.kts | 59 +++++ library-ktx/gradle.properties | 19 ++ library-ktx/src/main/AndroidManifest.xml | 17 ++ library-ktx/src/main/java/AppRaterDsl.kt | 29 +++ library/build.gradle.kts | 106 +------- library/gradle.properties | 19 ++ .../cmgapps/android/apprater/AppRater.java | 230 ------------------ .../com/cmgapps/android/apprater/AppRater.kt | 215 ++++++++++++++++ .../{AmazonStore.java => AmazonStore.kt} | 19 +- ...ooglePlayStore.java => GooglePlayStore.kt} | 19 +- .../apprater/store/{Store.java => Store.kt} | 12 +- .../android/apprater/AppRaterBuilderShould.kt | 20 +- sample/build.gradle.kts | 1 + .../com/cmgapps/android/MainActivity.java | 6 +- .../java/com/cmgapps/android/SampleApp.kt | 11 +- sample/src/main/res/layout/activity_main.xml | 4 +- sample/src/main/res/values/colors.xml | 2 +- sample/src/main/res/values/styles.xml | 5 - settings.gradle.kts | 2 +- 24 files changed, 547 insertions(+), 402 deletions(-) create mode 100644 buildSrc/src/main/kotlin/bintray-publish.gradle.kts create mode 100644 library-ktx/build.gradle.kts create mode 100644 library-ktx/gradle.properties create mode 100644 library-ktx/src/main/AndroidManifest.xml create mode 100644 library-ktx/src/main/java/AppRaterDsl.kt create mode 100644 library/gradle.properties delete mode 100644 library/src/main/java/com/cmgapps/android/apprater/AppRater.java create mode 100644 library/src/main/java/com/cmgapps/android/apprater/AppRater.kt rename library/src/main/java/com/cmgapps/android/apprater/store/{AmazonStore.java => AmazonStore.kt} (61%) rename library/src/main/java/com/cmgapps/android/apprater/store/{GooglePlayStore.java => GooglePlayStore.kt} (63%) rename library/src/main/java/com/cmgapps/android/apprater/store/{Store.java => Store.kt} (79%) diff --git a/build.gradle.kts b/build.gradle.kts index 6a4287e..3a52237 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,5 @@ +import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask + /* * Copyright (c) 2019. Christian Grach * @@ -27,6 +29,10 @@ buildscript { } } +plugins { + id("com.github.ben-manes.versions") version "0.25.0" +} + allprojects { repositories { jcenter() @@ -35,6 +41,17 @@ allprojects { } } -tasks.create("clean") { - delete(rootProject.buildDir) +tasks { + withType { + revision = "release" + rejectVersionIf { + listOf("alpha", "beta", "rc", "cr", "m", "preview", "b", "ea").any { qualifier -> + candidate.version.matches(Regex("(?i).*[.-]$qualifier[.\\d-+]*")) + } + } + } + + register("clean") { + delete(rootProject.buildDir) + } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 9504d1e..acb84b9 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -19,9 +19,13 @@ plugins { } repositories { + google() jcenter() } dependencies { implementation(kotlin("stdlib-jdk8", "1.3.50")) + implementation("com.android.tools.build:gradle:3.5.1") + implementation("digital.wup:android-maven-publish:3.6.2") + implementation("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4") } diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 5867eaf..aea948a 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -20,18 +20,18 @@ object Deps { const val BUILD_TOOLS_VERSION = "29.0.2" const val TARGET_SDK_VERSION = COMPILE_SDK_VERSION - const val KOTLIN = "1.3.50" const val APP_COMPAT = "1.1.0" const val CORE_KTX = "1.1.0" - const val LIFECYCLE_EXT = "2.0.0" - const val LIFECYCLE_COMMON = "2.1.0" + const val ESPRESSO_CORE = "3.2.0" + const val HAMCREST = "2.1" const val JUNIT = "4.12" - const val TEST_CORE = "1.2.0" + const val JUNIT_KTX = "1.1.1" + const val KOTLIN = "1.3.50" + const val LIFECYCLE_EXT = "2.1.0" + const val LIFECYCLE_COMMON = "2.1.0" const val MOCKITO_CORE = "3.1.0" - const val HAMCREST = "2.1" + const val TEST_CORE = "1.2.0" const val TEST_RUNNER = "1.2.0" - const val JUNIT_KTX = "1.1.1" - const val ESPRESSO_CORE = "3.2.0" } } diff --git a/buildSrc/src/main/kotlin/bintray-publish.gradle.kts b/buildSrc/src/main/kotlin/bintray-publish.gradle.kts new file mode 100644 index 0000000..37c3c3a --- /dev/null +++ b/buildSrc/src/main/kotlin/bintray-publish.gradle.kts @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2019. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.jfrog.bintray.gradle.BintrayExtension +import com.jfrog.bintray.gradle.BintrayPlugin +import digital.wup.android_maven_publish.AndroidMavenPublishPlugin +import java.util.Date +import java.util.Properties + +val pomName: String by project +val versionName: String by project +project.version = versionName + +val group: String by project +project.group = group + +val pomArtifactId: String by project +val pomDesc: String by project + +fun Project.bintrayPublishConvention() { + apply() + + configure { + publications { + register("pluginMaven") { + + from(components["android"]) + artifact(tasks["androidSourcesJar"]) + artifact(tasks["androidJavadocsJar"]) + + artifactId = pomArtifactId + + pom { + name.set(pomName) + description.set(pomDesc) + developers { + developer { + id.set("cgrach") + name.set("Christian Grach") + } + } + scm { + val pomScmConnection: String by project + connection.set(pomScmConnection) + val pomScmDevConnection: String by project + developerConnection.set(pomScmDevConnection) + val pomScmUrl: String by project + url.set(pomScmUrl) + } + licenses { + license { + val pomLicenseName: String by project + name.set(pomLicenseName) + val pomLicenseUrl: String by project + url.set(pomLicenseUrl) + distribution.set("repo") + } + } + } + } + } + } + + apply() + + configure { + val credentialProps = Properties() + credentialProps.load(rootProject.file("credentials.properties").inputStream()) + user = credentialProps.getProperty("user") + key = credentialProps.getProperty("key") + setPublications("pluginMaven") + + dryRun = true + + pkg(closureOf { + + val projectUrl: String by project + repo = "maven" + name = "${project.group}:$pomArtifactId" + userOrg = user + setLicenses("Apache-2.0") + vcsUrl = projectUrl + val issuesTrackerUrl: String by project + issueTrackerUrl = issuesTrackerUrl + githubRepo = projectUrl + version(closureOf { + name = versionName + vcsTag = versionName + released = Date().toString() + }) + }) + + } +} + +bintrayPublishConvention() + + diff --git a/gradle.properties b/gradle.properties index 600e4bd..4ed248c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,11 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -versionName=1.0.0 group=com.cmgapps.android -pomName=Android App Rater Dialog -pomArtifactId=app-rater -pomDesc=A App Rater Dialog pomUrl=https://github.com/chrimaeon/app-rater pomScmUrl=https://github.com/chrimaeon/app-rater.git pomScmConnection=scm:git:git@github.com:chrimaeon/app-rater.git diff --git a/library-ktx/build.gradle.kts b/library-ktx/build.gradle.kts new file mode 100644 index 0000000..0542858 --- /dev/null +++ b/library-ktx/build.gradle.kts @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2019. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.jetbrains.dokka.gradle.DokkaAndroidTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("com.android.library") + kotlin("android") + id("org.jetbrains.dokka-android") version "0.9.18" +} + +android { + compileSdkVersion(Deps.Versions.COMPILE_SDK_VERSION) + buildToolsVersion(Deps.Versions.BUILD_TOOLS_VERSION) +} + +tasks.withType(KotlinCompile::class).all { + kotlinOptions { + jvmTarget = "1.8" + } +} + +tasks.withType() { + moduleName = "app-rater" + outputFormat = "javadoc" + outputDirectory = "$buildDir/javadoc" +} + +tasks.register("androidJavadocsJar") { + archiveClassifier.set("javadoc") + from(tasks["dokka"]) +} + +tasks.register("androidSourcesJar") { + archiveClassifier.set("sources") + from(android.sourceSets["main"].java.srcDirs) +} + +apply(plugin = "bintray-publish") + +dependencies { + api(project(":library")) + implementation(kotlin("stdlib-jdk7", Deps.Versions.KOTLIN)) +} + diff --git a/library-ktx/gradle.properties b/library-ktx/gradle.properties new file mode 100644 index 0000000..837b3c7 --- /dev/null +++ b/library-ktx/gradle.properties @@ -0,0 +1,19 @@ +# +# Copyright (c) 2019. Christian Grach +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +versionName=1.0.0-SNAPSHOT +pomName=Android App Rater Dialog KTX +pomArtifactId=app-rater-ktx +pomDesc=A App Rater Dialog Kotlin Extension diff --git a/library-ktx/src/main/AndroidManifest.xml b/library-ktx/src/main/AndroidManifest.xml new file mode 100644 index 0000000..06452cb --- /dev/null +++ b/library-ktx/src/main/AndroidManifest.xml @@ -0,0 +1,17 @@ + + + diff --git a/library-ktx/src/main/java/AppRaterDsl.kt b/library-ktx/src/main/java/AppRaterDsl.kt new file mode 100644 index 0000000..b59a479 --- /dev/null +++ b/library-ktx/src/main/java/AppRaterDsl.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cmgapps.android.apprater + +import android.content.Context + + +@DslMarker +annotation class AppRaterDsl + +@AppRaterDsl +class AppRaterBuilder(context: Context) : AppRater.Builder(context) + +inline fun appRater(context: Context, buildAppRater: AppRaterBuilder.() -> Unit = {}) = + AppRaterBuilder(context).apply(buildAppRater).build() diff --git a/library/build.gradle.kts b/library/build.gradle.kts index b7563f4..6132030 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -14,19 +14,12 @@ * limitations under the License. */ -import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask -import com.jfrog.bintray.gradle.BintrayExtension import org.jetbrains.dokka.gradle.DokkaAndroidTask import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import java.util.Date -import java.util.Properties plugins { id("com.android.library") kotlin("android") - id("digital.wup.android-maven-publish") version "3.6.2" - id("com.github.ben-manes.versions") version "0.25.0" - id("com.jfrog.bintray") version "1.8.4" id("org.jetbrains.dokka-android") version "0.9.18" } @@ -60,11 +53,9 @@ tasks.withType(KotlinCompile::class).all { } } -val pomName: String by project -val versionName: String by project tasks.named("dokka") { - moduleName = "app-rater" + moduleName = "app-rater-ktx" outputFormat = "javadoc" outputDirectory = "$buildDir/javadoc" } @@ -79,101 +70,12 @@ tasks.register("androidSourcesJar") { from(android.sourceSets["main"].java.srcDirs) } -version = versionName - -val group: String by project -project.group = group - -val pomArtifactId: String by project -val pomDesc: String by project - -publishing { - publications { - register("pluginMaven") { - - from(components["android"]) - artifact(tasks["androidSourcesJar"]) - artifact(tasks["androidJavadocsJar"]) - - artifactId = pomArtifactId - - pom { - name.set(pomName) - description.set(pomDesc) - developers { - developer { - id.set("cgrach") - name.set("Christian Grach") - } - } - scm { - val pomScmConnection: String by project - connection.set(pomScmConnection) - val pomScmDevConnection: String by project - developerConnection.set(pomScmDevConnection) - val pomScmUrl: String by project - url.set(pomScmUrl) - } - licenses { - license { - val pomLicenseName: String by project - name.set(pomLicenseName) - val pomLicenseUrl: String by project - url.set(pomLicenseUrl) - distribution.set("repo") - } - } - } - } - } -} - -bintray { - val credentialProps = Properties() - credentialProps.load(file("${project.rootDir}/credentials.properties").inputStream()) - user = credentialProps.getProperty("user") - key = credentialProps.getProperty("key") - setPublications("pluginMaven") - - pkg(closureOf { - - val projectUrl: String by project - repo = "maven" - name = "${project.group}:$pomArtifactId" - userOrg = user - setLicenses("Apache-2.0") - vcsUrl = projectUrl - val issuesTrackerUrl: String by project - issueTrackerUrl = issuesTrackerUrl - githubRepo = projectUrl - version(closureOf { - name = versionName - vcsTag = versionName - released = Date().toString() - }) - }) -} - -tasks.named("dependencyUpdates") { - revision = "release" - resolutionStrategy { - componentSelection { - all { - val rejected = listOf("alpha", "beta", "rc", "cr", "m", "preview", "b", "ea").any { qualifier -> - candidate.version.matches(Regex("(?i).*[.-]$qualifier[.\\d-+]*")) - } - if (rejected) { - reject("Release candidate") - } - } - } - } -} +apply(plugin = "bintray-publish") dependencies { implementation("androidx.appcompat:appcompat:${Deps.Versions.APP_COMPAT}") - implementation("androidx.core:core-ktx:${Deps.Versions.CORE_KTX}") - implementation(kotlin("stdlib-jdk7", Deps.Versions.KOTLIN)) + api("androidx.core:core-ktx:${Deps.Versions.CORE_KTX}") + api(kotlin("stdlib-jdk7", Deps.Versions.KOTLIN)) testImplementation("junit:junit:${Deps.Versions.JUNIT}") testImplementation("androidx.test:core:${Deps.Versions.TEST_CORE}") diff --git a/library/gradle.properties b/library/gradle.properties new file mode 100644 index 0000000..7ecd64f --- /dev/null +++ b/library/gradle.properties @@ -0,0 +1,19 @@ +# +# Copyright (c) 2019. Christian Grach +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +versionName=2.0.0-SNAPSHOT +pomName=Android App Rater Dialog +pomArtifactId=app-rater +pomDesc=A App Rater Dialog diff --git a/library/src/main/java/com/cmgapps/android/apprater/AppRater.java b/library/src/main/java/com/cmgapps/android/apprater/AppRater.java deleted file mode 100644 index 64e3cdd..0000000 --- a/library/src/main/java/com/cmgapps/android/apprater/AppRater.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2016. Christian Grach - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.cmgapps.android.apprater; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.content.pm.PackageManager.NameNotFoundException; -import android.os.Build; -import android.text.format.DateUtils; -import android.util.Log; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; - -import com.cmgapps.android.apprater.store.GooglePlayStore; -import com.cmgapps.android.apprater.store.Store; - -public class AppRater { - - private static final String TAG = "AppRater"; - - private final boolean mDebug; - private final int mLaunchesUntilPrompt; - private final long mDaysUntilPrompt; - private final long mDaysUntilRemindAgain; - private final Store mStore; - private final PreferenceManager mPreferenceManager; - - private long mVersionCode; - - private AppRater(@NonNull Builder builder) { - - final Context context = builder.mContext; - - mPreferenceManager = new PreferenceManager(builder.mContext); - - try { - final PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { - mVersionCode = packageInfo.versionCode; - } else { - mVersionCode = packageInfo.getLongVersionCode(); - } - } catch (NameNotFoundException exc) { - mVersionCode = 0; - Log.e(TAG, "PackageName not found: " + context.getPackageName()); - } - - mStore = builder.mStore; - mLaunchesUntilPrompt = builder.mLaunchesUntilPrompt; - mDaysUntilPrompt = builder.mDaysUntilPrompt; - mDaysUntilRemindAgain = builder.mDaysUntilRemindAgain; - mDebug = builder.mDebug; - } - - /** - *

- * Call to check if the requirements to open the rating dialog are met - *

- * - * @return true if requirements are met. - */ - public boolean checkForRating() { - - if (mDebug) { - Log.i(TAG, "Rater Content:" + toString()); - } - - return !mPreferenceManager.getDeclinedToRate() && - !mPreferenceManager.getAppRated() && - System.currentTimeMillis() >= (mPreferenceManager.getFirstUsedTimestamp() + mDaysUntilPrompt) && - mPreferenceManager.getUseCount() > mLaunchesUntilPrompt && - System.currentTimeMillis() >= (mPreferenceManager.getRemindLaterTimeStamp() + mDaysUntilRemindAgain); - } - - /** - *

- * Increments the usage count. - *

- */ - public void incrementUseCount() { - - long trackingVersion = mPreferenceManager.getTrackingVersion(); - - if (trackingVersion == -1) { - trackingVersion = mVersionCode; - mPreferenceManager.setTrackingVersion(trackingVersion); - } - - if (trackingVersion == mVersionCode) { - - if (mPreferenceManager.getUseCount() == 0L) { - mPreferenceManager.setFirstUsedTimestamp(System.currentTimeMillis()); - } - - mPreferenceManager.incrementUseCount(); - } else { - mPreferenceManager.resetNewVersion(mVersionCode); - } - } - - /** - * Shows a default {@link AlertDialog}. - * - * @param activity An {@link Activity} to show the dialog from. - */ - public void show(@NonNull final Activity activity) { - final PackageManager pm = activity.getPackageManager(); - - String appName; - try { - ApplicationInfo ai = pm.getApplicationInfo(activity.getPackageName(), 0); - appName = (String) pm.getApplicationLabel(ai); - } catch (PackageManager.NameNotFoundException e) { - Log.e(TAG, "Application name can not be found"); - appName = "App"; - } - - new AlertDialog.Builder(activity) - .setTitle(R.string.dialog_cmgrate_title) - .setMessage(activity.getString(R.string.dialog_cmgrate_message_fmt, appName)) - .setPositiveButton(R.string.dialog_cmgrate_ok, (dialog, which) -> { - mPreferenceManager.setAppRated(true); - - Intent intent = new Intent(Intent.ACTION_VIEW, mStore.getStoreUri(activity)); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - activity.startActivity(intent); - }) - .setNeutralButton(R.string.dialog_cmgrate_later, (dialog, which) -> mPreferenceManager.setRemindLaterTimeStamp(System.currentTimeMillis())) - .setNegativeButton(R.string.dialog_cmgrate_no, (dialog, which) -> mPreferenceManager.setDeclinedToRate(true)) - .setOnCancelListener(dialog -> mPreferenceManager.setRemindLaterTimeStamp(System.currentTimeMillis())) - .show(); - } - - /** - * Get the {@link SharedPreferences} file contents - */ - @Override - @NonNull - public String toString() { - return mPreferenceManager.toString(); - } - - @SuppressWarnings("unused") - public static final class Builder { - - final Context mContext; - Store mStore = new GooglePlayStore(); - int mLaunchesUntilPrompt = 5; - long mDaysUntilPrompt = 10 * DateUtils.DAY_IN_MILLIS; - long mDaysUntilRemindAgain = 5 * DateUtils.DAY_IN_MILLIS; - boolean mDebug = false; - - public Builder(@NonNull Context context) { - mContext = context; - } - - /** - * Set the store to open for rating - */ - @NonNull - public Builder setStore(@NonNull Store store) { - mStore = store; - return this; - } - - /** - * Sets the minimun app lauched until the dialog is shown - */ - @NonNull - public Builder setLaunchesUntilPrompt(int launchesUntilPrompt) { - mLaunchesUntilPrompt = launchesUntilPrompt; - return this; - } - - /** - * Set the minimul days to pass until the dialig is shown - */ - @NonNull - public Builder setDaysUntilPrompt(int daysUntilPrompt) { - mDaysUntilPrompt = daysUntilPrompt * DateUtils.DAY_IN_MILLIS; - return this; - } - - /** - * Set the days until the dialog is shown again - */ - @NonNull - public Builder setDaysUntilRemindAgain(int daysUntilRemindAgain) { - mDaysUntilRemindAgain = daysUntilRemindAgain * DateUtils.DAY_IN_MILLIS; - return this; - } - - /** - * Enables debug mode with Logcat output id the current state - */ - @NonNull - public Builder setDebug(boolean debug) { - mDebug = debug; - return this; - } - - /** - * creates the App Rater instance - */ - @NonNull - public AppRater build() { - return new AppRater(this); - } - } -} diff --git a/library/src/main/java/com/cmgapps/android/apprater/AppRater.kt b/library/src/main/java/com/cmgapps/android/apprater/AppRater.kt new file mode 100644 index 0000000..ab4cf06 --- /dev/null +++ b/library/src/main/java/com/cmgapps/android/apprater/AppRater.kt @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2016. Christian Grach + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cmgapps.android.apprater + +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import android.content.pm.PackageManager.NameNotFoundException +import android.os.Build +import android.text.format.DateUtils +import android.util.Log +import androidx.appcompat.app.AlertDialog +import com.cmgapps.android.apprater.store.GooglePlayStore +import com.cmgapps.android.apprater.store.Store + +class AppRater private constructor(builder: Builder) { + + private val debug = builder._debug + private val launchesUntilPrompt = builder._launchesUntilPrompt + private val daysUntilPrompt = builder._daysUntilPrompt + private val daysUntilRemindAgain = builder._daysUntilRemindAgain + private val store = builder._store + private val preferenceManager = PreferenceManager(builder.mContext) + + private val versionCode: Long + + init { + val context = builder.mContext + + versionCode = try { + val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { + @Suppress("DEPRECATION") + packageInfo.versionCode.toLong() + } else { + packageInfo.longVersionCode + } + } catch (exc: NameNotFoundException) { + Log.e(TAG, "PackageName not found: " + context.packageName) + 0 + } + } + + /** + * + * + * Call to check if the requirements to open the rating dialog are met + * + * + * @return true if requirements are met. + */ + fun checkForRating(): Boolean { + + if (debug) { + Log.i(TAG, "Rater Content:" + toString()) + } + + return !preferenceManager.declinedToRate && + !preferenceManager.appRated && + System.currentTimeMillis() >= preferenceManager.firstUsedTimestamp + daysUntilPrompt && + preferenceManager.useCount > launchesUntilPrompt && + System.currentTimeMillis() >= preferenceManager.remindLaterTimeStamp + daysUntilRemindAgain + } + + /** + * + * + * Increments the usage count. + * + */ + fun incrementUseCount() { + + var trackingVersion = preferenceManager.trackingVersion + + if (trackingVersion == -1L) { + trackingVersion = versionCode + preferenceManager.trackingVersion = trackingVersion + } + + if (trackingVersion == versionCode) { + + if (preferenceManager.useCount.toLong() == 0L) { + preferenceManager.firstUsedTimestamp = System.currentTimeMillis() + } + + preferenceManager.incrementUseCount() + } else { + preferenceManager.resetNewVersion(versionCode) + } + } + + /** + * Shows a default [AlertDialog]. + * + * @param activity An [Activity] to show the dialog from. + */ + fun show(activity: Activity) { + val pm = activity.packageManager + + val appName = try { + val ai = pm.getApplicationInfo(activity.packageName, 0) + pm.getApplicationLabel(ai) as String + } catch (e: NameNotFoundException) { + Log.e(TAG, "Application name can not be found") + "App" + } + + AlertDialog.Builder(activity) + .setTitle(R.string.dialog_cmgrate_title) + .setMessage(activity.getString(R.string.dialog_cmgrate_message_fmt, appName)) + .setPositiveButton(R.string.dialog_cmgrate_ok) { _, _ -> + preferenceManager.appRated = true + + val intent = Intent(Intent.ACTION_VIEW, store.getStoreUri(activity)) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + activity.startActivity(intent) + } + .setNeutralButton(R.string.dialog_cmgrate_later) { _, _ -> + preferenceManager.remindLaterTimeStamp = System.currentTimeMillis() + } + .setNegativeButton(R.string.dialog_cmgrate_no) { _, _ -> + preferenceManager.declinedToRate = true + } + .setOnCancelListener { + preferenceManager.remindLaterTimeStamp = System.currentTimeMillis() + } + .show() + } + + /** + * Get the [SharedPreferences] file contents + */ + override fun toString(): String { + return preferenceManager.toString() + } + + @Suppress("PropertyName") + open class Builder(internal val mContext: Context) { + internal var _store: Store = GooglePlayStore() + private set + + internal var _launchesUntilPrompt = 5 + private set + + internal var _daysUntilPrompt = 10 * DateUtils.DAY_IN_MILLIS + private set + + internal var _daysUntilRemindAgain = 5 * DateUtils.DAY_IN_MILLIS + private set + + internal var _debug = false + private set + + /** + * Set the store to open for rating + */ + fun store(store: Store) = apply { + _store = store + } + + /** + * Sets the minimun app lauched until the dialog is shown + */ + fun launchesUntilPrompt(launchesUntilPrompt: Int) = apply { + _launchesUntilPrompt = launchesUntilPrompt + } + + /** + * Set the minimul days to pass until the dialig is shown + */ + fun daysUntilPrompt(daysUntilPrompt: Int) = apply { + _daysUntilPrompt = daysUntilPrompt * DateUtils.DAY_IN_MILLIS + } + + /** + * Set the days until the dialog is shown again + */ + fun daysUntilRemindAgain(daysUntilRemindAgain: Int) = apply { + _daysUntilRemindAgain = daysUntilRemindAgain * DateUtils.DAY_IN_MILLIS + } + + /** + * Enables debug mode with Logcat output id the current state + */ + fun debug(debug: Boolean) = apply { + _debug = debug + } + + /** + * creates the App Rater instance + */ + fun build(): AppRater { + return AppRater(this) + } + } + + companion object { + private const val TAG = "AppRater" + } +} diff --git a/library/src/main/java/com/cmgapps/android/apprater/store/AmazonStore.java b/library/src/main/java/com/cmgapps/android/apprater/store/AmazonStore.kt similarity index 61% rename from library/src/main/java/com/cmgapps/android/apprater/store/AmazonStore.java rename to library/src/main/java/com/cmgapps/android/apprater/store/AmazonStore.kt index 43b676a..3df7192 100644 --- a/library/src/main/java/com/cmgapps/android/apprater/store/AmazonStore.java +++ b/library/src/main/java/com/cmgapps/android/apprater/store/AmazonStore.kt @@ -14,23 +14,16 @@ * limitations under the License. */ -package com.cmgapps.android.apprater.store; +package com.cmgapps.android.apprater.store -import android.content.Context; -import android.net.Uri; - -import androidx.annotation.NonNull; +import android.content.Context +import android.net.Uri /** * The Amazon Store */ -public class AmazonStore implements Store { - - private static final String STORE_URL = "http://www.amazon.com/gp/mas/dl/android?p="; - +class AmazonStore : Store { - @Override - public Uri getStoreUri(@NonNull Context context) { - return Uri.parse(STORE_URL + context.getPackageName()); - } + override fun getStoreUri(context: Context): Uri = + Uri.parse("http://www.amazon.com/gp/mas/dl/android?p=" + context.packageName) } diff --git a/library/src/main/java/com/cmgapps/android/apprater/store/GooglePlayStore.java b/library/src/main/java/com/cmgapps/android/apprater/store/GooglePlayStore.kt similarity index 63% rename from library/src/main/java/com/cmgapps/android/apprater/store/GooglePlayStore.java rename to library/src/main/java/com/cmgapps/android/apprater/store/GooglePlayStore.kt index 9e6109b..e0bac91 100644 --- a/library/src/main/java/com/cmgapps/android/apprater/store/GooglePlayStore.java +++ b/library/src/main/java/com/cmgapps/android/apprater/store/GooglePlayStore.kt @@ -14,22 +14,15 @@ * limitations under the License. */ -package com.cmgapps.android.apprater.store; +package com.cmgapps.android.apprater.store -import android.content.Context; -import android.net.Uri; - -import androidx.annotation.NonNull; +import android.content.Context +import android.net.Uri /** * The Google Play Store */ -public class GooglePlayStore implements Store { - - private static final String STORE_URI = "market://details?id="; - - @Override - public Uri getStoreUri(@NonNull Context context) { - return Uri.parse(STORE_URI + context.getPackageName()); - } +class GooglePlayStore : Store { + override fun getStoreUri(context: Context): Uri = + Uri.parse("market://details?id=" + context.packageName) } diff --git a/library/src/main/java/com/cmgapps/android/apprater/store/Store.java b/library/src/main/java/com/cmgapps/android/apprater/store/Store.kt similarity index 79% rename from library/src/main/java/com/cmgapps/android/apprater/store/Store.java rename to library/src/main/java/com/cmgapps/android/apprater/store/Store.kt index 611cb56..3458a59 100644 --- a/library/src/main/java/com/cmgapps/android/apprater/store/Store.java +++ b/library/src/main/java/com/cmgapps/android/apprater/store/Store.kt @@ -14,21 +14,19 @@ * limitations under the License. */ -package com.cmgapps.android.apprater.store; +package com.cmgapps.android.apprater.store -import android.content.Context; -import android.net.Uri; - -import androidx.annotation.NonNull; +import android.content.Context +import android.net.Uri /** * A Store to open for rating */ -public interface Store { +interface Store { /** * @param context the application context * @return the store uri to open for rating */ - Uri getStoreUri(@NonNull Context context); + fun getStoreUri(context: Context): Uri } diff --git a/library/src/test/java/com/cmgapps/android/apprater/AppRaterBuilderShould.kt b/library/src/test/java/com/cmgapps/android/apprater/AppRaterBuilderShould.kt index 9eeffa3..4cd8581 100644 --- a/library/src/test/java/com/cmgapps/android/apprater/AppRaterBuilderShould.kt +++ b/library/src/test/java/com/cmgapps/android/apprater/AppRaterBuilderShould.kt @@ -44,33 +44,33 @@ class AppRaterBuilderShould { @Test fun `set store`() { val store = mock(Store::class.java) - builder.setStore(store) + builder.store(store) - assertThat(builder.mStore, `is`(store)) + assertThat(builder._store, `is`(store)) } @Test fun `set launches until prompt`() { - builder.setLaunchesUntilPrompt(200) - assertThat(builder.mLaunchesUntilPrompt, `is`(200)) + builder.launchesUntilPrompt(200) + assertThat(builder._launchesUntilPrompt, `is`(200)) } @Test fun `set days until prompt`() { - builder.setDaysUntilPrompt(50) - assertThat(builder.mDaysUntilPrompt, `is`(50 * DateUtils.DAY_IN_MILLIS)) + builder.daysUntilPrompt(50) + assertThat(builder._daysUntilPrompt, `is`(50 * DateUtils.DAY_IN_MILLIS)) } @Test fun `set days until remind again`() { - builder.setDaysUntilRemindAgain(20) - assertThat(builder.mDaysUntilRemindAgain, `is`(20 * DateUtils.DAY_IN_MILLIS)) + builder.daysUntilRemindAgain(20) + assertThat(builder._daysUntilRemindAgain, `is`(20 * DateUtils.DAY_IN_MILLIS)) } @Test fun `set debug mode`() { - builder.setDebug(true) - assertThat(builder.mDebug, `is`(true)) + builder.debug(true) + assertThat(builder._debug, `is`(true)) } } diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index e6efb9e..aaccc03 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -45,6 +45,7 @@ android { dependencies { implementation(project(":library")) + implementation(project(":library-ktx")) implementation("androidx.appcompat:appcompat:${Deps.Versions.APP_COMPAT}") implementation("androidx.core:core-ktx:${Deps.Versions.CORE_KTX}") implementation("androidx.lifecycle:lifecycle-extensions:${Deps.Versions.LIFECYCLE_EXT}") diff --git a/sample/src/main/java/com/cmgapps/android/MainActivity.java b/sample/src/main/java/com/cmgapps/android/MainActivity.java index cc297d6..1cf4532 100644 --- a/sample/src/main/java/com/cmgapps/android/MainActivity.java +++ b/sample/src/main/java/com/cmgapps/android/MainActivity.java @@ -7,10 +7,10 @@ import android.os.Bundle; import android.view.View; -import com.cmgapps.android.apprater.AppRater; - import androidx.appcompat.app.AppCompatActivity; +import com.cmgapps.android.apprater.AppRater; + public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private AppRater mAppRater; @@ -19,7 +19,7 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - mAppRater = new AppRater.Builder(this).build(); + mAppRater = ((SampleApp) getApplication()).getAppRater(); if (mAppRater.checkForRating()) { mAppRater.show(this); diff --git a/sample/src/main/java/com/cmgapps/android/SampleApp.kt b/sample/src/main/java/com/cmgapps/android/SampleApp.kt index e0e9e37..51bf181 100644 --- a/sample/src/main/java/com/cmgapps/android/SampleApp.kt +++ b/sample/src/main/java/com/cmgapps/android/SampleApp.kt @@ -9,13 +9,20 @@ import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.ProcessLifecycleOwner import com.cmgapps.android.apprater.AppRater +import com.cmgapps.android.apprater.appRater class SampleApp : Application() { + lateinit var appRater: AppRater + private set + override fun onCreate() { + appRater = appRater(this) { + debug(true) + daysUntilPrompt(5) + } super.onCreate() - val apprater = AppRater.Builder(this).build() - ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifecycleListener(apprater)) + ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifecycleListener(appRater)) } } diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 04f730f..7183ebb 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -3,7 +3,7 @@ Copyright (c) 2016. Christian Grach - - + diff --git a/sample/src/main/res/values/colors.xml b/sample/src/main/res/values/colors.xml index bba6d16..f626edd 100644 --- a/sample/src/main/res/values/colors.xml +++ b/sample/src/main/res/values/colors.xml @@ -6,5 +6,5 @@ #3F51B5 #303F9F - #0000FF + #FF9800 diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml index f2367fd..37c6e0f 100644 --- a/sample/src/main/res/values/styles.xml +++ b/sample/src/main/res/values/styles.xml @@ -10,11 +10,6 @@ @color/colorPrimary @color/colorPrimaryDark @color/colorAccent - @style/RaterDialog - - -
diff --git a/settings.gradle.kts b/settings.gradle.kts index 427b384..957c7c5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,4 +15,4 @@ */ rootProject.name = "app-rater" -include(":sample", ":library") +include(":sample", ":library", ":library-ktx") From 3f7e65260f629f66519b59455f2510f2f49c17f0 Mon Sep 17 00:00:00 2001 From: Christian Grach Date: Sun, 6 Oct 2019 16:58:02 +0200 Subject: [PATCH 05/14] use afterEvaluate --- buildSrc/src/main/kotlin/bintray-publish.gradle.kts | 5 +++-- library-ktx/build.gradle.kts | 3 +-- library/build.gradle.kts | 3 +-- sample/build.gradle.kts | 8 ++++++++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/buildSrc/src/main/kotlin/bintray-publish.gradle.kts b/buildSrc/src/main/kotlin/bintray-publish.gradle.kts index 37c3c3a..dec4989 100644 --- a/buildSrc/src/main/kotlin/bintray-publish.gradle.kts +++ b/buildSrc/src/main/kotlin/bintray-publish.gradle.kts @@ -106,6 +106,7 @@ fun Project.bintrayPublishConvention() { } } -bintrayPublishConvention() - +afterEvaluate { + bintrayPublishConvention() +} diff --git a/library-ktx/build.gradle.kts b/library-ktx/build.gradle.kts index 0542858..e035fa1 100644 --- a/library-ktx/build.gradle.kts +++ b/library-ktx/build.gradle.kts @@ -21,6 +21,7 @@ plugins { id("com.android.library") kotlin("android") id("org.jetbrains.dokka-android") version "0.9.18" + id("bintray-publish") } android { @@ -50,8 +51,6 @@ tasks.register("androidSourcesJar") { from(android.sourceSets["main"].java.srcDirs) } -apply(plugin = "bintray-publish") - dependencies { api(project(":library")) implementation(kotlin("stdlib-jdk7", Deps.Versions.KOTLIN)) diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 6132030..b993f86 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -21,6 +21,7 @@ plugins { id("com.android.library") kotlin("android") id("org.jetbrains.dokka-android") version "0.9.18" + id("bintray-publish") } android { @@ -70,8 +71,6 @@ tasks.register("androidSourcesJar") { from(android.sourceSets["main"].java.srcDirs) } -apply(plugin = "bintray-publish") - dependencies { implementation("androidx.appcompat:appcompat:${Deps.Versions.APP_COMPAT}") api("androidx.core:core-ktx:${Deps.Versions.CORE_KTX}") diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index aaccc03..ac44a3d 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + /* * Copyright (c) 2019. Christian Grach * @@ -43,6 +45,12 @@ android { } } +tasks.withType { + kotlinOptions { + jvmTarget = "1.8" + } +} + dependencies { implementation(project(":library")) implementation(project(":library-ktx")) From 2c8aa8c2b4d8f372a63fc5c82b9830fee7d6afa4 Mon Sep 17 00:00:00 2001 From: Christian Grach Date: Sun, 6 Oct 2019 16:58:26 +0200 Subject: [PATCH 06/14] show rater output --- .../android/apprater/PreferenceManager.kt | 2 +- .../com/cmgapps/android/MainActivity.java | 33 --------------- .../java/com/cmgapps/android/MainActivity.kt | 40 +++++++++++++++++++ .../java/com/cmgapps/android/SampleApp.kt | 11 +++-- sample/src/main/res/layout/activity_main.xml | 18 +++++---- 5 files changed, 59 insertions(+), 45 deletions(-) delete mode 100644 sample/src/main/java/com/cmgapps/android/MainActivity.java create mode 100644 sample/src/main/java/com/cmgapps/android/MainActivity.kt diff --git a/library/src/main/java/com/cmgapps/android/apprater/PreferenceManager.kt b/library/src/main/java/com/cmgapps/android/apprater/PreferenceManager.kt index 345b5ba..1c6cb3f 100644 --- a/library/src/main/java/com/cmgapps/android/apprater/PreferenceManager.kt +++ b/library/src/main/java/com/cmgapps/android/apprater/PreferenceManager.kt @@ -78,7 +78,7 @@ internal class PreferenceManager(context: Context) { } catch (exc: JSONException) { Log.e("PreferenceManager", "Error creating JSON Object ", exc) } - }.toString() + }.toString(2) } diff --git a/sample/src/main/java/com/cmgapps/android/MainActivity.java b/sample/src/main/java/com/cmgapps/android/MainActivity.java deleted file mode 100644 index 1cf4532..0000000 --- a/sample/src/main/java/com/cmgapps/android/MainActivity.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2016. Christian Grach (R.id.output)?.apply { + text = appRater.toString() + } + } + + + fun showDialogClicked(v: View) { + appRater.show(this) + } + + companion object { + private val TAG = "MainActivity" + } + + +} diff --git a/sample/src/main/java/com/cmgapps/android/SampleApp.kt b/sample/src/main/java/com/cmgapps/android/SampleApp.kt index 51bf181..15bf1e4 100644 --- a/sample/src/main/java/com/cmgapps/android/SampleApp.kt +++ b/sample/src/main/java/com/cmgapps/android/SampleApp.kt @@ -17,13 +17,16 @@ class SampleApp : Application() { private set override fun onCreate() { + super.onCreate() appRater = appRater(this) { - debug(true) - daysUntilPrompt(5) + if (BuildConfig.DEBUG) { + debug(true) + } + daysUntilPrompt(0) + launchesUntilPrompt(0) + } - super.onCreate() ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifecycleListener(appRater)) - } } diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 7183ebb..dca54ff 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -1,17 +1,16 @@ - - -