From 28a18ca314500762fcf09b0c6aa5b0c1aa8f61c5 Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 14 Jul 2020 22:21:54 -0700 Subject: [PATCH] Let user rate the app through google play or through amazon --- .../java/com/geeksville/mesh/MainActivity.kt | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt index a2d36be9..dbc81456 100644 --- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt +++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt @@ -334,26 +334,20 @@ class MainActivity : AppCompatActivity(), Logging, private fun askToRate() { exceptionReporter { // Got one IllegalArgumentException from inside this lib, but we don't want to crash our app because of bugs in this optional feature - AppRate.with(this) + val hasGooglePlay = GoogleApiAvailability.getInstance() + .isGooglePlayServicesAvailable(this) != ConnectionResult.SERVICE_MISSING + + val rater = AppRate.with(this) .setInstallDays(10.toByte()) // default is 10, 0 means install day, 10 means app is launched 10 or more days later than installation .setLaunchTimes(10.toByte()) // default is 10, 3 means app is launched 3 or more times .setRemindInterval(1.toByte()) // default is 1, 1 means app is launched 1 or more days after neutral button clicked .setRemindLaunchesNumber(1.toByte()) // default is 0, 1 means app is launched 1 or more times after neutral button clicked - .monitor() // Monitors the app launch times + .setStoreType(if (hasGooglePlay) StoreType.GOOGLEPLAY else StoreType.AMAZON) + + rater.monitor() // Monitors the app launch times // Only ask to rate if the user has a suitable store - if (AppRate.with(this).storeType == StoreType.GOOGLEPLAY) { // Checks that current app store type from library options is StoreType.GOOGLEPLAY - if (GoogleApiAvailability.getInstance() - .isGooglePlayServicesAvailable(this) != ConnectionResult.SERVICE_MISSING - ) { // Checks that Google Play is available - AppRate.showRateDialogIfMeetsConditions(this) // Shows the Rate Dialog when conditions are met - - // Force the dialog - for testing - // AppRate.with(this).showRateDialog(this) - } - } else { - AppRate.showRateDialogIfMeetsConditions(this); // Shows the Rate Dialog when conditions are met - } + AppRate.showRateDialogIfMeetsConditions(this); // Shows the Rate Dialog when conditions are met } }