Skip to content
Merged
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 @@ -62,4 +62,18 @@ sealed class LocalNotification(
return resourceProvider.getString(description, expiryDate)
}
}

data class FreeTrialExpiredNotification(val name: String, val siteId: Long) : LocalNotification(
title = R.string.local_notification_one_day_after_free_trial_expires_title,
description = R.string.local_notification_one_day_after_free_trial_expires_description,
type = LocalNotificationType.FREE_TRIAL_EXPIRED,
delay = 15,
delayUnit = TimeUnit.DAYS
) {
override val data: String = siteId.toString()

override fun getDescriptionString(resourceProvider: ResourceProvider): String {
return resourceProvider.getString(description, name)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ class PreconditionCheckWorker @AssistedInject constructor(
type == null -> cancelWork("Notification check data is invalid")
type == LocalNotificationType.STORE_CREATION_FINISHED.value -> Result.success()
type == LocalNotificationType.STORE_CREATION_INCOMPLETE.value -> Result.success()
type == LocalNotificationType.FREE_TRIAL_EXPIRING.value -> {
val site = selectedSite.get()
if (site.isFreeTrial && site.siteId == data?.toLongOrNull()) {
Result.success()
} else {
cancelWork("Store plan upgraded or a different site. Cancelling work.")
}
}
type == LocalNotificationType.FREE_TRIAL_EXPIRED.value -> Result.success()
type == LocalNotificationType.FREE_TRIAL_EXPIRING.value -> proceedIfFreeMatchingSite(data?.toLongOrNull())
type == LocalNotificationType.FREE_TRIAL_EXPIRED.value -> proceedIfFreeMatchingSite(data?.toLongOrNull())
else -> {
cancelWork("Unknown notification $type. Cancelling work.")
}
}
}

private fun proceedIfFreeMatchingSite(siteId: Long?): Result {
val site = selectedSite.get()
return if (site.isFreeTrial && site.siteId == siteId) {
Result.success()
} else {
cancelWork("Store plan upgraded or a different site. Cancelling work.")
}
}

Comment on lines +43 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware this is coming from another PR. And I don't think we need to change anything in this PR, but I still believe it would be useful to show this notifications even when the user has switched to a different site. As long as the original site is still free trial I think it's worth notifying the user they have expired free trial sites.

Anyway, is sort of a corner case and maybe the work involved to support this is not worth it. Just some food for thought.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree. Although we'd need to modify the message that would identify the other site and tapping on it would switch sites 🤷

private val canDisplayNotifications: Boolean
get() = VERSION.SDK_INT < VERSION_CODES.TIRAMISU || WooPermissionUtils.hasNotificationsPermission(appContext)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.woocommerce.android.R.string
import com.woocommerce.android.analytics.AnalyticsEvent
import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.extensions.isNotNullOrEmpty
import com.woocommerce.android.notifications.local.LocalNotification.FreeTrialExpiredNotification
import com.woocommerce.android.notifications.local.LocalNotification.FreeTrialExpiringNotification
import com.woocommerce.android.notifications.local.LocalNotificationScheduler
import com.woocommerce.android.tools.SelectedSite
Expand All @@ -22,6 +24,7 @@ import com.woocommerce.android.ui.login.storecreation.installation.StoreInstalla
import com.woocommerce.android.ui.login.storecreation.installation.StoreInstallationViewModel.ViewState.SuccessState
import com.woocommerce.android.util.FeatureFlag
import com.woocommerce.android.util.IsRemoteFeatureFlagEnabled
import com.woocommerce.android.util.RemoteFeatureFlag.LOCAL_NOTIFICATION_1D_AFTER_FREE_TRIAL_EXPIRES
import com.woocommerce.android.util.RemoteFeatureFlag.LOCAL_NOTIFICATION_1D_BEFORE_FREE_TRIAL_EXPIRES
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.Exit
Expand All @@ -35,6 +38,7 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.parcelize.Parcelize
import org.wordpress.android.fluxc.store.AccountStore
import org.wordpress.android.fluxc.utils.extensions.slashJoin
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
Expand All @@ -52,7 +56,8 @@ class StoreInstallationViewModel @Inject constructor(
private val installationTransactionLauncher: InstallationTransactionLauncher,
private val observeSiteInstallation: ObserveSiteInstallation,
private val localNotificationScheduler: LocalNotificationScheduler,
private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled
private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled,
private val accountStore: AccountStore
) : ScopedViewModel(savedStateHandle) {

companion object {
Expand Down Expand Up @@ -151,6 +156,17 @@ class StoreInstallationViewModel @Inject constructor(
FreeTrialExpiringNotification(in14days, selectedSite.get().siteId)
)
}

if (isRemoteFeatureFlagEnabled(LOCAL_NOTIFICATION_1D_AFTER_FREE_TRIAL_EXPIRES)) {
val name = if (accountStore.account.firstName.isNotNullOrEmpty())
accountStore.account.firstName
else
accountStore.account.userName

localNotificationScheduler.scheduleNotification(
FreeTrialExpiredNotification(name, selectedSite.get().siteId)
)
}
}

private fun loadNewStore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class MainActivityViewModel @Inject constructor(
LocalNotificationType.STORE_CREATION_INCOMPLETE.value -> {
triggerEvent(ShortcutOpenStoreCreation(storeName = notification.data))
}
LocalNotificationType.FREE_TRIAL_EXPIRED.value,
LocalNotificationType.FREE_TRIAL_EXPIRING.value -> {
triggerEvent(ViewStorePlanUpgrade(NOTIFICATION))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.mockito.kotlin.stub
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.store.AccountStore
import org.wordpress.android.fluxc.utils.extensions.slashJoin
import kotlin.test.assertEquals

Expand All @@ -48,6 +49,7 @@ class StoreInstallationViewModelTest : BaseUnitTest() {
private val observeSiteInstallation: ObserveSiteInstallation = mock()
private val localNotificationScheduler: LocalNotificationScheduler = mock()
private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled = mock()
private val accountStore: AccountStore = mock()

private lateinit var viewModel: StoreInstallationViewModel

Expand All @@ -72,7 +74,8 @@ class StoreInstallationViewModelTest : BaseUnitTest() {
installationTransactionLauncher,
observeSiteInstallation,
localNotificationScheduler,
isRemoteFeatureFlagEnabled
isRemoteFeatureFlagEnabled,
accountStore
)
viewModel.viewState.observeForever {}
}
Expand Down