add a rating library

This commit is contained in:
geeksville
2020-04-11 09:39:34 -07:00
parent 0300895494
commit aa79d55a66
4 changed files with 43 additions and 0 deletions

View File

@@ -91,6 +91,9 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// rate this app
implementation "com.vorlonsoft:androidrate:1.2.1"
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

View File

@@ -43,6 +43,7 @@
android:required="true" />
<application
tools:replace="android:icon"
android:name="com.geeksville.mesh.MeshUtilApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher_new"

View File

@@ -34,9 +34,13 @@ import com.geeksville.util.Exceptions
import com.geeksville.util.exceptionReporter
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import com.google.android.gms.tasks.Task
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.tabs.TabLayoutMediator
import com.vorlonsoft.android.rate.AppRate
import com.vorlonsoft.android.rate.StoreType
import kotlinx.android.synthetic.main.activity_main.*
import java.nio.charset.Charset
@@ -234,6 +238,30 @@ class MainActivity : AppCompatActivity(), Logging,
}
/// Ask user to rate in play store
private fun askToRate() {
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
// 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
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -300,6 +328,8 @@ class MainActivity : AppCompatActivity(), Logging,
connectStatusImage.setImageDrawable(getDrawable(image))
})
askToRate()
}

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- strings for the 'please rate on appstore dialog -->
<string name="rate_dialog_title_en" tools:override="true">Rate Meshtastic</string>
<string name="rate_dialog_message_en" tools:override="true">This is an application made by hobbyists, would you mind taking a moment to rate it? If you find bugs, please post in our forum. Thanks for your support!</string>
<string name="rate_dialog_ok_en" tools:override="true">Rate It Now</string>
<string name="rate_dialog_cancel_en" tools:override="true">Remind Me Later</string>
<string name="rate_dialog_no_en" tools:override="true">No, Thanks</string>
</resources>