refactor: move askToRate() to GeeksvilleApplication

This commit is contained in:
andrekir
2023-01-26 11:32:46 -03:00
committed by Andre K
parent 023d4d767d
commit 9ea6dff385
4 changed files with 34 additions and 24 deletions

View File

@@ -6,11 +6,13 @@ import android.content.Context
import android.content.SharedPreferences
import android.os.Bundle
import android.provider.Settings
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.edit
import com.geeksville.mesh.analytics.AnalyticsProvider
import com.geeksville.mesh.util.exceptionReporter
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailabilityLight
import com.suddenh4x.ratingdialog.AppRating
fun isGooglePlayAvailable(context: Context): Boolean {
val a = GoogleApiAvailabilityLight.getInstance()
@@ -82,6 +84,19 @@ open class GeeksvilleApplication : Application(), Logging {
analytics.setEnabled(value && !isInTestLab) // Never do analytics in the test lab
}
/** Ask user to rate in play store */
fun askToRate(activity: AppCompatActivity) {
if (!isGooglePlayAvailable(this)) return
exceptionReporter { // we don't want to crash our app because of bugs in this optional feature
AppRating.Builder(activity)
.setMinimumLaunchTimes(10) // default is 5, 3 means app is launched 3 or more times
.setMinimumDays(10) // default is 5, 0 means install day, 10 means app is launched 10 or more days later than installation
.setMinimumLaunchTimesToShowAgain(5) // default is 5, 1 means app is launched 1 or more times after neutral button clicked
.setMinimumDaysToShowAgain(14) // default is 14, 1 means app is launched 1 or more days after neutral button clicked
.showIfMeetsConditions()
}
}
override fun onCreate() {
super.onCreate()