implement in app review

This commit is contained in:
2020-09-21 08:52:15 +02:00
parent 2cb496ea8f
commit 92bb0dc86f
2 changed files with 36 additions and 3 deletions

View File

@@ -10,7 +10,7 @@ android {
applicationId "me.zobrist.tichucounter" applicationId "me.zobrist.tichucounter"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 30 targetSdkVersion 30
versionCode 5 versionCode 6
versionName "1.0.0" versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@@ -12,6 +12,10 @@ import android.widget.ScrollView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.core.widget.doOnTextChanged import androidx.core.widget.doOnTextChanged
import com.google.android.play.core.review.ReviewInfo
import com.google.android.play.core.review.ReviewManager
import com.google.android.play.core.review.ReviewManagerFactory
import com.google.android.play.core.review.testing.FakeReviewManager
import com.google.gson.Gson import com.google.gson.Gson
import kotlinx.android.synthetic.main.content_main.* import kotlinx.android.synthetic.main.content_main.*
@@ -22,6 +26,9 @@ class MainActivity : AppCompatActivity() {
private lateinit var history: History private lateinit var history: History
private var currentRound = Round() private var currentRound = Round()
lateinit var manager: ReviewManager
lateinit var reviewInfo: ReviewInfo
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
@@ -42,6 +49,8 @@ class MainActivity : AppCompatActivity() {
nameTeamB.setText(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("nameTeamB", "TeamB")) nameTeamB.setText(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("nameTeamB", "TeamB"))
updateView() updateView()
initReviews()
inputTeamA.setOnFocusChangeListener { view, b -> inputTeamA.setOnFocusChangeListener { view, b ->
if (b) { if (b) {
@@ -62,7 +71,7 @@ class MainActivity : AppCompatActivity() {
currentRound = try { currentRound = try {
Round(text.toString().toInt(), true) Round(text.toString().toInt(), true)
} catch (e: java.lang.Exception) { } catch (e: Exception) {
Round(1, 1) Round(1, 1)
} }
inputTeamB.setText(currentRound.scoreB.toString()) inputTeamB.setText(currentRound.scoreB.toString())
@@ -91,7 +100,7 @@ class MainActivity : AppCompatActivity() {
currentRound = try { currentRound = try {
Round(text.toString().toInt(), false) Round(text.toString().toInt(), false)
} catch (e: java.lang.Exception) { } catch (e: Exception) {
Round(1, 1) Round(1, 1)
} }
inputTeamA.setText(currentRound.scoreA.toString()) inputTeamA.setText(currentRound.scoreA.toString())
@@ -385,6 +394,30 @@ class MainActivity : AppCompatActivity() {
scoreB.text = "0" scoreB.text = "0"
history.clearAll() history.clearAll()
askForReview()
}
private fun initReviews() {
manager = ReviewManagerFactory.create(this)
manager.requestReviewFlow().addOnCompleteListener { request ->
if (request.isSuccessful) {
reviewInfo = request.result
}
}
}
// Call this when you want to show the dialog
private fun askForReview() {
try{
manager.launchReviewFlow(this, reviewInfo).addOnFailureListener {
// Log error and continue with the flow
}.addOnCompleteListener { _ ->
// Log success and continue with the flow
}
} catch (e: Exception){
}
} }
private fun appendToFocusedInput(toAppend: Char) { private fun appendToFocusedInput(toAppend: Char) {