diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 4fc4d66319a6..3272f997fa1d 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -5,6 +5,7 @@ * [*] Disable local notifications with Notification Settings switch. [https://github.com/wordpress-mobile/WordPress-Android/pull/17496] * [*] [Jetpack-only] Comments: fix a crash in My Site > Comments with Jetpack standalone plugins. [https://github.com/wordpress-mobile/WordPress-Android/pull/17456] * [*] [internal] Fix an issue preventing the text and button on the 'WordPress is Better with Jetpack' overlay to be entirely visible with big fonts. [https://github.com/wordpress-mobile/WordPress-Android/pull/17503] +* [***] [internal] Disable notifications on WP in migration flow when JP app is installed, behind a feature flag. [https://github.com/wordpress-mobile/WordPress-Android/pull/17513 and https://github.com/wordpress-mobile/WordPress-Android/pull/17371] * [*] [internal] Avoid truncation of the 'Try the new Jetpack app' button text on the Jetpack Powered bottom sheets with big fonts. [https://github.com/wordpress-mobile/WordPress-Android/pull/17511] 21.2 diff --git a/WordPress/build.gradle b/WordPress/build.gradle index 53784ae1a260..1a9130e71411 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -132,7 +132,7 @@ android { buildConfigField "boolean", "JETPACK_FEATURE_REMOVAL_PHASE_THREE", "false" buildConfigField "boolean", "JETPACK_FEATURE_REMOVAL_PHASE_FOUR", "false" buildConfigField "boolean", "JETPACK_FEATURE_REMOVAL_NEW_USERS", "false" - buildConfigField "boolean", "PREVENT_DUPLICATE_NOTIFS_REMOTE_FIELD", "false" + buildConfigField "boolean", "PREVENT_DUPLICATE_NOTIFS_REMOTE_FIELD", "true" buildConfigField "boolean", "OPEN_WEB_LINKS_WITH_JETPACK_FLOW", "false" // Override these constants in jetpack product flavor to enable/ disable features diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt index 4ea2077529c3..399978b47f9f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt @@ -1,5 +1,6 @@ package org.wordpress.android.ui.main.jetpack.migration +import android.content.Intent import androidx.annotation.DrawableRes import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -10,6 +11,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combineTransform import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.launch +import org.wordpress.android.BuildConfig import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.localcontentmigration.LocalMigrationState @@ -40,14 +42,20 @@ import org.wordpress.android.ui.main.jetpack.migration.JetpackMigrationViewModel import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.ui.utils.UiString import org.wordpress.android.ui.utils.UiString.UiStringRes +import org.wordpress.android.util.AppLog +import org.wordpress.android.util.AppLog.T import org.wordpress.android.util.GravatarUtilsWrapper import org.wordpress.android.util.SiteUtilsWrapper +import org.wordpress.android.util.config.PreventDuplicateNotifsFeatureConfig +import org.wordpress.android.viewmodel.ContextProvider import javax.inject.Inject @HiltViewModel class JetpackMigrationViewModel @Inject constructor( private val siteUtilsWrapper: SiteUtilsWrapper, private val gravatarUtilsWrapper: GravatarUtilsWrapper, + private val contextProvider: ContextProvider, + private val preventDuplicateNotifsFeatureConfig: PreventDuplicateNotifsFeatureConfig, private val appPrefsWrapper: AppPrefsWrapper, private val localMigrationOrchestrator: LocalMigrationOrchestrator, private val migrationEmailHelper: MigrationEmailHelper, @@ -156,13 +164,22 @@ class JetpackMigrationViewModel @Inject constructor( } } - @Suppress("ForbiddenComment") private fun onContinueFromNotificationsClicked() { - // TODO: Disable notifications in WP app - // See https://github.com/wordpress-mobile/WordPress-Android/pull/17371 + if (preventDuplicateNotifsFeatureConfig.isEnabled()) disableNotificationsOnWP() notificationContinueClickedFlow.value = true } + private fun disableNotificationsOnWP() { + AppLog.d(T.NOTIFS, "Disable Notifications") + Intent().also { intent -> + intent.action = "org.wordpress.android.broadcast.DISABLE_NOTIFICATIONS" + val appPackage = BuildConfig.APPLICATION_ID.replace("com.jetpack", "org.wordpress") + intent.setPackage(appPackage) + AppLog.d(T.NOTIFS, intent.toString()) + contextProvider.getContext().sendBroadcast(intent, "org.wordpress.android.permission.DISABLE_NOTIFICATIONS") + } + } + private fun onDoneClicked() { migrationEmailHelper.notifyMigrationComplete() appPrefsWrapper.setJetpackMigrationCompleted(true) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index c3f9f9771f30..15f5f57461cd 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -4253,7 +4253,7 @@ translators: %s: Select control option value e.g: "Auto, 25%". --> Need help? Notifications now come from Jetpack You’ll get all the same notifications but now they’ll come from the Jetpack app. - We’ve disabled notifications for the WordPress app. + We\'ll turn off notifications from the WordPress app. Thanks for switching to Jetpack! We’ve transferred all your data and settings. Everything is right where you left it. Please <b>delete the WordPress app</b> to<br>avoid data conflicts. diff --git a/WordPress/src/test/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt index 5ae81c3ceebb..6088f397168a 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt @@ -27,6 +27,8 @@ import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.GravatarUtilsWrapper import org.wordpress.android.util.SiteUtilsWrapper +import org.wordpress.android.util.config.PreventDuplicateNotifsFeatureConfig +import org.wordpress.android.viewmodel.ContextProvider @RunWith(MockitoJUnitRunner::class) class JetpackMigrationViewModelTest : BaseUnitTest() { @@ -35,9 +37,13 @@ class JetpackMigrationViewModelTest : BaseUnitTest() { private val appPrefsWrapper: AppPrefsWrapper = mock() private val localMigrationOrchestrator: LocalMigrationOrchestrator = mock() private val migrationEmailHelper: MigrationEmailHelper = mock() + private val preventDuplicateNotifsFeatureConfig: PreventDuplicateNotifsFeatureConfig = mock() + private val contextProvider: ContextProvider = mock() private val classToTest = JetpackMigrationViewModel( siteUtilsWrapper = siteUtilsWrapper, gravatarUtilsWrapper = gravatarUtilsWrapper, + contextProvider = contextProvider, + preventDuplicateNotifsFeatureConfig = preventDuplicateNotifsFeatureConfig, appPrefsWrapper = appPrefsWrapper, localMigrationOrchestrator = localMigrationOrchestrator, migrationEmailHelper = migrationEmailHelper