Increase mailbox views count when closing a detail screen
This count will be used to define when a user can be presented with the "rate app" dialog. We increase the count when going back from the detail rather than at some point in the mailbox screen's lifecycle to avoid the case where the dialog is shown when resuming mailbox from the background. MAILAND-3071
This commit is contained in:
parent
b4b8c2e4ad
commit
f3c08abb28
|
@ -62,6 +62,7 @@ import ch.protonmail.android.events.DownloadEmbeddedImagesEvent
|
|||
import ch.protonmail.android.events.DownloadedAttachmentEvent
|
||||
import ch.protonmail.android.events.PostPhishingReportEvent
|
||||
import ch.protonmail.android.events.Status
|
||||
import ch.protonmail.android.feature.rating.ShowReviewAppInMemoryRepository
|
||||
import ch.protonmail.android.jobs.PostSpamJob
|
||||
import ch.protonmail.android.labels.domain.model.LabelId
|
||||
import ch.protonmail.android.labels.domain.model.LabelType
|
||||
|
@ -122,6 +123,9 @@ internal class MessageDetailsActivity : BaseStoragePermissionActivity() {
|
|||
@Inject
|
||||
lateinit var accountSettingsRepository: AccountSettingsRepository
|
||||
|
||||
@Inject
|
||||
lateinit var showReviewAppRepository: ShowReviewAppInMemoryRepository
|
||||
|
||||
private lateinit var messageOrConversationId: String
|
||||
private lateinit var messageExpandableAdapter: MessageDetailsAdapter
|
||||
private lateinit var primaryBaseActivity: Context
|
||||
|
@ -358,6 +362,11 @@ internal class MessageDetailsActivity : BaseStoragePermissionActivity() {
|
|||
mApp.bus.unregister(this)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
showReviewAppRepository.recordMailboxScreenView()
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
|
|
|
@ -22,10 +22,16 @@ package ch.protonmail.android.feature.rating
|
|||
import androidx.annotation.VisibleForTesting
|
||||
import me.proton.core.domain.entity.UserId
|
||||
import me.proton.core.featureflag.domain.entity.FeatureFlag
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class ShowReviewAppInMemoryRepository @Inject constructor() {
|
||||
|
||||
@VisibleForTesting
|
||||
var mailboxScreenViews: Int = 0
|
||||
|
||||
@VisibleForTesting
|
||||
val featureFlags: MutableMap<UserId, Boolean> = mutableMapOf()
|
||||
|
||||
|
@ -33,4 +39,22 @@ class ShowReviewAppInMemoryRepository @Inject constructor() {
|
|||
val userId = featureFlag.userId ?: return
|
||||
featureFlags[userId] = featureFlag.value
|
||||
}
|
||||
|
||||
fun recordMailboxScreenView() {
|
||||
mailboxScreenViews++
|
||||
Timber.d("Recording mailbox screen view: count $mailboxScreenViews")
|
||||
}
|
||||
|
||||
fun shouldShowRateAppDialog(userId: UserId): Boolean {
|
||||
val isFlagEnabled = featureFlags[userId] ?: false
|
||||
if (!isFlagEnabled) {
|
||||
return false
|
||||
}
|
||||
return mailboxScreenViews >= MailboxScreenViewsThreshold
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val MailboxScreenViewsThreshold = 2
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package ch.protonmail.android.feature.rating
|
|||
|
||||
import ch.protonmail.android.testdata.UserTestData
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import me.proton.core.domain.entity.UserId
|
||||
import me.proton.core.featureflag.domain.entity.FeatureFlag
|
||||
import me.proton.core.featureflag.domain.entity.FeatureId
|
||||
import me.proton.core.featureflag.domain.entity.Scope
|
||||
|
@ -46,4 +47,77 @@ class ShowReviewAppInMemoryRepositoryTest {
|
|||
assertEquals(expected, showReviewAppRepository.featureFlags)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun increaseMailboxScreenViewsCounterWhenRecordMailboxScreenViewIsCalled() = runTest {
|
||||
// when
|
||||
showReviewAppRepository.recordMailboxScreenView()
|
||||
|
||||
// then
|
||||
assertEquals(1, showReviewAppRepository.mailboxScreenViews)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldShowRateAppDialogIsTrueWhenFeatureFlagIsTrueAndMailboxScreenHasBeenSeenMoreTimesThanThreshold() =
|
||||
runTest {
|
||||
// given
|
||||
val userId = UserTestData.userId
|
||||
mockFeatureFlagValue(userId, true)
|
||||
mockScreenViews(2)
|
||||
|
||||
// when
|
||||
val actual = showReviewAppRepository.shouldShowRateAppDialog(userId)
|
||||
|
||||
// then
|
||||
assertEquals(true, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldShowRateAppDialogIsFalseWhenFeatureFlagIsFalse() = runTest {
|
||||
// given
|
||||
val userId = UserTestData.userId
|
||||
mockFeatureFlagValue(userId, false)
|
||||
mockScreenViews(2)
|
||||
|
||||
// when
|
||||
val actual = showReviewAppRepository.shouldShowRateAppDialog(userId)
|
||||
|
||||
// then
|
||||
assertEquals(false, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldShowRateAppDialogIsFalseWhenNoFeatureFlagExistsForThisUser() = runTest {
|
||||
// given
|
||||
val userId = UserTestData.userId
|
||||
mockScreenViews(2)
|
||||
|
||||
// when
|
||||
val actual = showReviewAppRepository.shouldShowRateAppDialog(userId)
|
||||
|
||||
// then
|
||||
assertEquals(false, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldShowRateAppDialogIsFalseWhenMailboxScreenHaveNotBeenSeenUpToThresholdTimes() = runTest {
|
||||
// given
|
||||
val userId = UserTestData.userId
|
||||
mockFeatureFlagValue(userId, true)
|
||||
mockScreenViews(1)
|
||||
|
||||
// when
|
||||
val actual = showReviewAppRepository.shouldShowRateAppDialog(userId)
|
||||
|
||||
// then
|
||||
assertEquals(false, actual)
|
||||
}
|
||||
|
||||
private fun mockScreenViews(count: Int) {
|
||||
showReviewAppRepository.mailboxScreenViews = count
|
||||
}
|
||||
|
||||
private fun mockFeatureFlagValue(userId: UserId, isEnabled: Boolean) {
|
||||
showReviewAppRepository.featureFlags[userId] = isEnabled
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue