Should request a review every new game.
All checks were successful
Build Android / build (push) Successful in 8m24s
All checks were successful
Build Android / build (push) Successful in 8m24s
This commit is contained in:
@@ -40,6 +40,7 @@ import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
import com.google.android.play.core.review.ReviewManager
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -47,6 +48,7 @@ import me.zobrist.tichucounter.domain.DrawerItem
|
||||
import me.zobrist.tichucounter.domain.ISettingsChangeListener
|
||||
import me.zobrist.tichucounter.domain.KeepScreenOn
|
||||
import me.zobrist.tichucounter.domain.Language
|
||||
import me.zobrist.tichucounter.domain.ReviewService
|
||||
import me.zobrist.tichucounter.domain.Route
|
||||
import me.zobrist.tichucounter.domain.SettingsAdapter
|
||||
import me.zobrist.tichucounter.domain.Theme
|
||||
@@ -73,6 +75,9 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
||||
@Inject
|
||||
lateinit var settingsAdapter: SettingsAdapter
|
||||
|
||||
@Inject
|
||||
lateinit var reviewService: ReviewService
|
||||
|
||||
private val counterViewModel: CounterViewModel by viewModels()
|
||||
private val historyViewModel: HistoryViewModel by viewModels()
|
||||
private val settingsViewModel: SettingsViewModel by viewModels()
|
||||
@@ -84,6 +89,10 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
||||
|
||||
settingsAdapter.registerOnChangeListener(this)
|
||||
|
||||
mainViewModel.onNewGame = {
|
||||
reviewService.request()
|
||||
}
|
||||
|
||||
setContent {
|
||||
AppTheme {
|
||||
val systemUiController = rememberSystemUiController()
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.google.android.play.core.review.ReviewManagerFactory
|
||||
import com.google.android.play.core.review.testing.FakeReviewManager
|
||||
import dagger.hilt.android.internal.Contexts
|
||||
import dagger.hilt.android.qualifiers.ActivityContext
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.android.scopes.ActivityScoped
|
||||
import dagger.hilt.android.scopes.FragmentScoped
|
||||
import dagger.hilt.android.scopes.ViewScoped
|
||||
import java.time.Duration
|
||||
import java.time.Period
|
||||
import java.util.Date
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class ReviewService @Inject constructor(@ActivityContext private val appContext: Context) {
|
||||
|
||||
private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext)
|
||||
|
||||
private val THREE_MONTHS : Long = 3 * 30 * 24 * 60 * 60
|
||||
|
||||
private var lastReviewedDate: Date
|
||||
get() = Date(sharedPreferences.getLong("lastReviewedDate", 0))
|
||||
set(value) {
|
||||
val editor = sharedPreferences.edit()
|
||||
editor.putLong("lastReviewedDate", value.time)
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
fun request() {
|
||||
|
||||
val diff = Date().time - lastReviewedDate.time
|
||||
|
||||
if(diff > 0)
|
||||
{
|
||||
lastReviewedDate = Date()
|
||||
|
||||
val manager = ReviewManagerFactory.create(appContext)
|
||||
|
||||
val request = manager.requestReviewFlow()
|
||||
request.addOnCompleteListener { task ->
|
||||
if (task.isSuccessful) {
|
||||
// We got the ReviewInfo object
|
||||
val reviewInfo = task.result
|
||||
manager.launchReviewFlow(appContext as Activity, reviewInfo)
|
||||
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import android.content.Context
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import java.util.Date
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -36,6 +37,9 @@ class SettingsAdapter @Inject constructor(@ApplicationContext private val contex
|
||||
|
||||
var keepScreenOn: KeepScreenOn
|
||||
private set
|
||||
var reviewDialogShownDate: Date
|
||||
get() = Date(sharedPreferences.getLong("reviewDialogShownDate", 0))
|
||||
set(value) = updatePreference("reviewDialogShownDate", value.time)
|
||||
|
||||
init {
|
||||
language = try {
|
||||
@@ -95,6 +99,12 @@ class SettingsAdapter @Inject constructor(@ApplicationContext private val contex
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
private fun updatePreference(name: String?, value: Long) {
|
||||
val editor = sharedPreferences.edit()
|
||||
editor.putLong(name, value)
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
private fun notifyListeners(language: Language) {
|
||||
listenerList.forEach {
|
||||
it.onLanguageChanged(language)
|
||||
|
||||
@@ -7,8 +7,10 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dagger.hilt.android.scopes.ActivityScoped
|
||||
import kotlinx.coroutines.launch
|
||||
import me.zobrist.tichucounter.data.entity.Round
|
||||
import me.zobrist.tichucounter.domain.ReviewService
|
||||
import me.zobrist.tichucounter.repository.GameRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -21,6 +23,8 @@ class MainViewModel @Inject constructor(
|
||||
private var redoRounds = mutableStateListOf<Round>()
|
||||
private var expectedRoundCount = 0
|
||||
|
||||
var onNewGame: (() -> Unit)? = null
|
||||
|
||||
var isUndoActionActive by mutableStateOf(false)
|
||||
|
||||
val isRedoActionActive: Boolean
|
||||
@@ -75,5 +79,6 @@ class MainViewModel @Inject constructor(
|
||||
redoRounds.clear()
|
||||
gameRepository.newGame()
|
||||
}
|
||||
onNewGame?.let { it() }
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.1.0'
|
||||
classpath 'com.android.tools.build:gradle:8.1.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
||||
Reference in New Issue
Block a user