Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class AppReviewSettingsRepository(private val context: Context) {
private fun <T> getInitialValue(key: Preferences.Key<T>) = when (key) {
APP_REVIEW_THRESHOLD_KEY -> appReviewThreshold
ALREADY_GAVE_REVIEW_KEY -> DEFAULT_ALREADY_GAVE_REVIEW
DO_NOT_SHOW_AGAIN_KEY -> DEFAULT_DO_NOT_SHOW_AGAIN
else -> throw IllegalArgumentException("Unknown Preferences.Key")
}

Expand All @@ -82,11 +83,13 @@ class AppReviewSettingsRepository(private val context: Context) {

val APP_REVIEW_THRESHOLD_KEY = intPreferencesKey("appReviewThresholdKey")
val ALREADY_GAVE_REVIEW_KEY = booleanPreferencesKey("alreadyGaveReview")
val DO_NOT_SHOW_AGAIN_KEY = booleanPreferencesKey("doNotShowAgainKey")

internal const val DATA_STORE_NAME = "AppReviewSettingsDataStore"

private const val DEFAULT_ALREADY_GAVE_REVIEW = false

private const val DEFAULT_APP_REVIEW_THRESHOLD = 50
private const val DEFAULT_DO_NOT_SHOW_AGAIN = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.google.android.play.core.review.ReviewManagerFactory
import com.infomaniak.core.inappreview.AppReviewSettingsRepository
import com.infomaniak.core.inappreview.AppReviewSettingsRepository.Companion.ALREADY_GAVE_REVIEW_KEY
import com.infomaniak.core.inappreview.AppReviewSettingsRepository.Companion.APP_REVIEW_THRESHOLD_KEY
import com.infomaniak.core.inappreview.AppReviewSettingsRepository.Companion.DO_NOT_SHOW_AGAIN_KEY
import com.infomaniak.core.inappreview.BaseInAppReviewManager
import com.infomaniak.core.webview.ui.WebViewActivity
import kotlinx.coroutines.Dispatchers
Expand All @@ -39,13 +40,14 @@ class InAppReviewManager(private val activity: ComponentActivity) : BaseInAppRev

private val appReviewCountdown = appReviewSettingsRepository.flowFor(APP_REVIEW_THRESHOLD_KEY)
private val alreadyGaveReview = appReviewSettingsRepository.flowFor(ALREADY_GAVE_REVIEW_KEY)
private val doNotShowAgain = appReviewSettingsRepository.flowFor(DO_NOT_SHOW_AGAIN_KEY)

private var onUserWantsToReview: (() -> Unit)? = null
private var onUserWantsToGiveFeedback: (() -> Unit)? = null

override val shouldDisplayReviewDialog =
combine(alreadyGaveReview, appReviewCountdown) { alreadyGaveReview, countdown ->
!alreadyGaveReview && countdown <= 0
combine(alreadyGaveReview, appReviewCountdown, doNotShowAgain) { alreadyGaveReview, countdown, doNotShowAgain ->
!alreadyGaveReview && countdown <= 0 && !doNotShowAgain
}.distinctUntilChanged()

override fun init(
Expand Down Expand Up @@ -80,6 +82,7 @@ class InAppReviewManager(private val activity: ComponentActivity) : BaseInAppRev
onUserWantsToGiveFeedback?.invoke()
resetAppReviewSettings()
WebViewActivity.startActivity(activity, feedbackUrl)
disableReviewDialog()
}

override fun onUserWantsToDismiss() {
Comment thread
Elouan1411 marked this conversation as resolved.
Expand All @@ -100,6 +103,10 @@ class InAppReviewManager(private val activity: ComponentActivity) : BaseInAppRev
appReviewSettingsRepository.resetReviewSettings()
}

private fun disableReviewDialog() = activity.lifecycleScope.launch(Dispatchers.IO) {
set(DO_NOT_SHOW_AGAIN_KEY, true)
}

private fun setAppReviewedStatus() = activity.lifecycleScope.launch(Dispatchers.IO) {
set(ALREADY_GAVE_REVIEW_KEY, true)
}
Expand Down
Loading