Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable local notifications with Notification Settings switch #17496

Merged
merged 12 commits into from
Nov 22, 2022

Conversation

irfano
Copy link
Member

@irfano irfano commented Nov 20, 2022

Fixes #15816

This prevents local notifications when the Notification Settings switch is off. Prevented local notifications are

  • Weekly roundup notifications,
  • Blogging reminder notifications,
  • Create site notifications.

Blogging reminders popups are still active and can be displayed in some cases (eg. from Site Settings) even Notification Settings switch is off. If the user sets a new reminder from the popup, it will be scheduled even if the switch is off.

Merge requirements:

  • 1. Merge FluxC PR
  • 2. Update FluxC reference to trunk
  • 3. Remove [Status] Not Ready for Merge label
  • 4. Merge this

To test:

You can wait for scheduled dates to test notifications. It would be the best method but testing all cases takes an unrealistic long time. Alternatively, you can check App Inspection > Background Task Inspector on Android Studio if these notifications are scheduled.

Weekly roundup notifications

  1. Launch the WordPress app.
  2. Navigate to Notifications.
  3. Tap ⚙️ button at the top of the screen.
  4. Turn off the switch at the top of the page.
  5. Verify WeeklyRoundupWorker is canceled on App Inspection > Background Task Inspector.
  6. Turn on the switch again.
  7. Verify WeeklyRoundupWorker is scheduled on App Inspection > Background Task Inspector.
  8. Repeat 1-7 for Jetpack app.

Blogging reminder notifications

  1. Launch the WordPress app.
  2. Navigate to My Site → MENU → Site Settings.
  3. Tap Blogging Reminders.
  4. Set a reminder.
  5. Verify ReminderWorker is scheduled on App Inspection > Background Task Inspector.
  6. Navigate back and change your selected site from the site picker at the top of the MENU page.
  7. Navigate to Site Settings and set another reminder for the selected site.
  8. Verify a new ReminderWorker is scheduled on App Inspection > Background Task Inspector.
  9. Navigate to Notifications. Tap ⚙️ button at the top of the screen.
  10. Turn off the switch at the top of the page.
  11. Verify both ReminderWorkers are canceled on App Inspection > Background Task Inspector.
  12. Turn on the switch.
  13. Verify both ReminderWorkers are scheduled on App Inspection > Background Task Inspector.
  14. Repeat 1-13 for Jetpack app.

Create site notifications

  1. Uninstall the app if it's installed.
  2. Install and launch the WordPress app.
  3. Log in with an account without any site.
  4. Verify LocalNotificationWorker is scheduled on App Inspection > Background Task Inspector.
  5. Navigate to Notifications.
  6. Tap ⚙️ button at the top of the screen.
  7. Turn off the switch at the top of the page.
  8. Verify LocalNotificationWorker is canceled on App Inspection > Background Task Inspector.
    NOTE: Create site notifications won't be rescheduled if you turn on the switch again. Two Create site notifications are scheduled when the app is installed the first time. One is for the next day after the install, another one is for 8 days after the first install. If the switch is turned off and turned on in 8 days, create site notifications won't display. I'll discuss this later and change it in a separate PR if necessary.

Regression Notes

  1. Potential unintended areas of impact
    Rescheduling blogging reminders after turning Notification Settings off and on again.

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Tested manually.

  3. What automated tests I added (or what prevented me from doing so)
    Update CreateSiteNotificationHandlerTest.

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Base automatically changed from Jetpack-Focus-Disable-notifications-for-WP-on-JP-Install to trunk November 21, 2022 01:34
@wpmobilebot
Copy link
Contributor

Found 1 violations:

The PR caused the following dependency changes:

-+--- org.wordpress:fluxc:{strictly trunk-5a4f8132de39ae666f841edc4522f87b1b02a265} -> trunk-5a4f8132de39ae666f841edc4522f87b1b02a265
-|    +--- org.wordpress:wellsql:1.7.0
-|    |    \--- org.wordpress.wellsql:wellsql-annotations:1.7.0
-|    +--- org.wordpress.fluxc:fluxc-annotations:trunk-5a4f8132de39ae666f841edc4522f87b1b02a265
-|    +--- org.greenrobot:eventbus:3.3.1 (*)
-|    +--- com.squareup.okhttp3:okhttp:4.9.0 -> 4.9.2 (*)
-|    +--- com.android.volley:volley:1.1.1 -> 1.2.0
-|    +--- androidx.paging:paging-runtime:2.1.2
-|    |    +--- androidx.paging:paging-common:2.1.2
-|    |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
-|    |    |    \--- androidx.arch.core:core-common:2.0.0 -> 2.1.0 (*)
-|    |    +--- androidx.arch.core:core-runtime:2.0.0 -> 2.1.0 (*)
-|    |    +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.4.1 (*)
-|    |    +--- androidx.lifecycle:lifecycle-livedata:2.0.0 -> 2.4.1 (*)
-|    |    \--- androidx.recyclerview:recyclerview:1.0.0 -> 1.1.0 (*)
-|    +--- com.goterl:lazysodium-android:5.0.2
-|    +--- net.java.dev.jna:jna:5.5.0
-|    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10 (*)
-|    +--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.6.10 (*)
-|    +--- androidx.appcompat:appcompat:1.0.2 -> 1.3.1 (*)
-|    +--- androidx.recyclerview:recyclerview:1.0.0 -> 1.1.0 (*)
-|    +--- androidx.exifinterface:exifinterface:1.0.0 -> 1.3.3 (*)
-|    +--- com.squareup.okhttp3:okhttp-urlconnection:4.9.0 -> 4.9.2
-|    |    +--- com.squareup.okhttp3:okhttp:4.9.2 (*)
-|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10 -> 1.6.10 (*)
-|    +--- com.google.code.gson:gson:2.8.5
-|    +--- org.apache.commons:commons-text:1.1 (*)
-|    +--- androidx.room:room-runtime:2.4.2 (*)
-|    +--- androidx.room:room-ktx:2.4.2
-|    |    +--- androidx.room:room-common:2.4.2 (*)
-|    |    +--- androidx.room:room-runtime:2.4.2 (*)
-|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.10 (*)
-|    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2 (*)
-|    +--- com.google.dagger:dagger:2.42 (*)
-|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9 -> 1.5.2 (*)
-|    \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9 -> 1.5.2 (*)
++--- org.wordpress:fluxc:{strictly trunk-7e1f7406753a72cbed61feab1204ca52ba7f0f77} -> trunk-7e1f7406753a72cbed61feab1204ca52ba7f0f77
+|    +--- org.wordpress:wellsql:1.7.0
+|    |    \--- org.wordpress.wellsql:wellsql-annotations:1.7.0
+|    +--- org.wordpress.fluxc:fluxc-annotations:trunk-7e1f7406753a72cbed61feab1204ca52ba7f0f77
+|    +--- org.greenrobot:eventbus:3.3.1 (*)
+|    +--- com.squareup.okhttp3:okhttp:4.9.0 -> 4.9.2 (*)
+|    +--- com.android.volley:volley:1.1.1 -> 1.2.0
+|    +--- androidx.paging:paging-runtime:2.1.2
+|    |    +--- androidx.paging:paging-common:2.1.2
+|    |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
+|    |    |    \--- androidx.arch.core:core-common:2.0.0 -> 2.1.0 (*)
+|    |    +--- androidx.arch.core:core-runtime:2.0.0 -> 2.1.0 (*)
+|    |    +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.4.1 (*)
+|    |    +--- androidx.lifecycle:lifecycle-livedata:2.0.0 -> 2.4.1 (*)
+|    |    \--- androidx.recyclerview:recyclerview:1.0.0 -> 1.1.0 (*)
+|    +--- com.goterl:lazysodium-android:5.0.2
+|    +--- net.java.dev.jna:jna:5.5.0
+|    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10 (*)
+|    +--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.6.10 (*)
+|    +--- androidx.appcompat:appcompat:1.0.2 -> 1.3.1 (*)
+|    +--- androidx.recyclerview:recyclerview:1.0.0 -> 1.1.0 (*)
+|    +--- androidx.exifinterface:exifinterface:1.0.0 -> 1.3.3 (*)
+|    +--- com.squareup.okhttp3:okhttp-urlconnection:4.9.0 -> 4.9.2
+|    |    +--- com.squareup.okhttp3:okhttp:4.9.2 (*)
+|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10 -> 1.6.10 (*)
+|    +--- com.google.code.gson:gson:2.8.5
+|    +--- org.apache.commons:commons-text:1.1 (*)
+|    +--- androidx.room:room-runtime:2.4.2 (*)
+|    +--- androidx.room:room-ktx:2.4.2
+|    |    +--- androidx.room:room-common:2.4.2 (*)
+|    |    +--- androidx.room:room-runtime:2.4.2 (*)
+|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.10 (*)
+|    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2 (*)
+|    +--- com.google.dagger:dagger:2.42 (*)
+|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9 -> 1.5.2 (*)
+|    \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9 -> 1.5.2 (*)
 \--- org.wordpress:login:1.0.0
-     \--- org.wordpress:fluxc:2.0.0 -> trunk-5a4f8132de39ae666f841edc4522f87b1b02a265 (*)
+     \--- org.wordpress:fluxc:2.0.0 -> trunk-7e1f7406753a72cbed61feab1204ca52ba7f0f77 (*)

Please review and act accordingly

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Nov 21, 2022

WordPress📲 You can test these changes on WordPress by downloading wordpress-installable-build-pr17496-7df6d32.apk
💡 Scan this QR code with your Android phone to download and install the APK directly on it.
AppWordPress
Build FlavorJalapeno
Build TypeDebug
Commit7df6d32
Note: This installable build uses the JalapenoDebug build flavor, and does not support Google Login.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Nov 21, 2022

Jetpack📲 You can test these changes on Jetpack by downloading jetpack-installable-build-pr17496-7df6d32.apk
💡 Scan this QR code with your Android phone to download and install the APK directly on it.
AppJetpack
Build FlavorJalapeno
Build TypeDebug
Commit7df6d32
Note: This installable build uses the JalapenoDebug build flavor, and does not support Google Login.

@irfano irfano requested a review from ravishanker November 21, 2022 20:42
@irfano irfano marked this pull request as ready for review November 21, 2022 20:43
Copy link
Contributor

@ravishanker ravishanker left a comment

Choose a reason for hiding this comment

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

Nice work 👍

Feel free to merge it after resolving build issues

// Set up primary toolbar
setUpToolbar()

// Set up main switch
Copy link
Contributor

Choose a reason for hiding this comment

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

comment is redundant here

Copy link
Member Author

Choose a reason for hiding this comment

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

I just copied Java while converting. But I agree. The code is already explaining itself.
Removed! 7df6d32

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this@NotificationsSettingsActivity)

// Set up primary toolbar
setUpToolbar()
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be renamed to setupPrimaryToolbar() and remove the comment

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! 7df6d32

fragmentContainer = findViewById(id.fragment_container)

// Get shared preferences for main switch.
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this@NotificationsSettingsActivity)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, renaming it to mainSwitchPrefs would remove the need for comment

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, sharedPreferences doesn't have to be a class variable. I moved it to the function. 7df6d32

@@ -2,6 +2,7 @@

21.3
-----
* [*] Disable local notifications with Notification Settings switch. [https://github.com/wordpress-mobile/WordPress-Android/pull/17496]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be marked as [internal]

Copy link
Member Author

Choose a reason for hiding this comment

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

I think an important issue was fixed. This is not only about Jetpack Focus. With this PR, the Notifications Settings switch will affect local notifications too. So, I think it should not be internal.

import javax.inject.Named

@AndroidEntryPoint
class NotificationsSettingsActivity : LocaleAwareActivity(), MainSwitchToolbarListener {
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉 Kudos for converting it to Kotlin

hideDisabledView(isMainChecked)
}

override fun onMainSwitchCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This was removed in a previous PR right?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, onMainSwitchCheckedChanged was being called unnecessarily at launch. I fixed that in #17498. It didn't change this class.

@irfano irfano merged commit cb9c999 into trunk Nov 22, 2022
@irfano irfano deleted the issue/15816-manage-local-notifs-with-switch branch November 22, 2022 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Weekly roundup notification despite notifications off
3 participants