Should request a review every new game.
All checks were successful
Build Android / build (push) Successful in 8m19s
All checks were successful
Build Android / build (push) Successful in 8m19s
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
package me.zobrist.tichucounter.domain
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
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.qualifiers.ApplicationContext
|
||||||
|
import java.time.Duration
|
||||||
|
import java.time.Period
|
||||||
|
import java.util.Date
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class ReviewService @Inject constructor(@ApplicationContext private val context: Context) {
|
||||||
|
|
||||||
|
private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
|
private val THREE_MONTHS = 3 * 30 * 24 * 60 * 60 * 1000
|
||||||
|
|
||||||
|
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 = FakeReviewManager(context)
|
||||||
|
val manager = ReviewManagerFactory.create(context)
|
||||||
|
|
||||||
|
val request = manager.requestReviewFlow()
|
||||||
|
request.addOnCompleteListener { task ->
|
||||||
|
if (task.isSuccessful) {
|
||||||
|
// We got the ReviewInfo object
|
||||||
|
val reviewInfo = task.result
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import androidx.core.os.LocaleListCompat
|
import androidx.core.os.LocaleListCompat
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import java.util.Date
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@@ -36,6 +37,9 @@ class SettingsAdapter @Inject constructor(@ApplicationContext private val contex
|
|||||||
|
|
||||||
var keepScreenOn: KeepScreenOn
|
var keepScreenOn: KeepScreenOn
|
||||||
private set
|
private set
|
||||||
|
var reviewDialogShownDate: Date
|
||||||
|
get() = Date(sharedPreferences.getLong("reviewDialogShownDate", 0))
|
||||||
|
set(value) = updatePreference("reviewDialogShownDate", value.time)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
language = try {
|
language = try {
|
||||||
@@ -95,6 +99,12 @@ class SettingsAdapter @Inject constructor(@ApplicationContext private val contex
|
|||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updatePreference(name: String?, value: Long) {
|
||||||
|
val editor = sharedPreferences.edit()
|
||||||
|
editor.putLong(name, value)
|
||||||
|
editor.apply()
|
||||||
|
}
|
||||||
|
|
||||||
private fun notifyListeners(language: Language) {
|
private fun notifyListeners(language: Language) {
|
||||||
listenerList.forEach {
|
listenerList.forEach {
|
||||||
it.onLanguageChanged(language)
|
it.onLanguageChanged(language)
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import me.zobrist.tichucounter.data.entity.Round
|
import me.zobrist.tichucounter.data.entity.Round
|
||||||
|
import me.zobrist.tichucounter.domain.ReviewService
|
||||||
import me.zobrist.tichucounter.repository.GameRepository
|
import me.zobrist.tichucounter.repository.GameRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class MainViewModel @Inject constructor(
|
class MainViewModel @Inject constructor(
|
||||||
private val gameRepository: GameRepository
|
private val gameRepository: GameRepository,
|
||||||
|
private val reviewService: ReviewService
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
|
|
||||||
@@ -75,5 +77,7 @@ class MainViewModel @Inject constructor(
|
|||||||
redoRounds.clear()
|
redoRounds.clear()
|
||||||
gameRepository.newGame()
|
gameRepository.newGame()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reviewService.request()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ buildscript {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
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"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
|||||||
Reference in New Issue
Block a user