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

Jetpack focus: Disable push notifications for WP #17371

Merged
Merged
Show file tree
Hide file tree
Changes from 18 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
6 changes: 6 additions & 0 deletions WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<!-- GCM all build types configuration -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission
android:name="org.wordpress.android.permission.DISABLE_NOTIFICATIONS"
android:description="@string/notification_disable_broadcast_permission_desc"
android:label="@string/notification_disable_broadcast_permission_label" />

<uses-permission android:name="org.wordpress.android.permission.DISABLE_NOTIFICATIONS"/>

<uses-feature
android:name="android.hardware.camera"
Expand Down
2 changes: 2 additions & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,8 @@
<string name="search_sites">Search sites</string>
<string name="notifications_no_search_results">No sites matched \'%s\'</string>
<string name="notification_sound_has_invalid_path">The chosen sound has invalid path. Please choose another.</string>
<string name="notification_disable_broadcast_permission_label">disable WordPress notifications</string>
<string name="notification_disable_broadcast_permission_desc">Allows the app to disable WordPress notifications.</string>

<string name="notification_settings_followed_dialog_email_posts_switch">Email me new posts</string>
<string name="notification_settings_followed_dialog_notification_posts_description">Receive notifications for new posts from this site</string>
Expand Down
9 changes: 9 additions & 0 deletions WordPress/src/wordpress/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@
android:name=".localcontentmigration.LocalMigrationContentProvider"
android:authorities="${applicationId}.LocalMigrationContentProvider"
android:exported="true" />

<receiver
android:name=".ui.mysite.jetpackbadge.JetpackAppInstallReceiver"
android:exported="true"
android:permission="org.wordpress.android.permission.DISABLE_NOTIFICATIONS">
<intent-filter>
<action android:name="org.wordpress.android.broadcast.DISABLE_NOTIFICATIONS"/>
</intent-filter>
</receiver>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.wordpress.android.ui.mysite.jetpackbadge

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.preference.PreferenceManager
import dagger.hilt.android.AndroidEntryPoint
import org.wordpress.android.R
import org.wordpress.android.push.GCMMessageHandler
import javax.inject.Inject

@AndroidEntryPoint
class JetpackAppInstallReceiver : BroadcastReceiver() {
@Inject lateinit var gcmMessageHandler: GCMMessageHandler

override fun onReceive(context: Context, intent: Intent) {
disableNotifications(context)
}

private fun disableNotifications(context: Context) {
// Turn toggle off on Notifications Settings screen
val mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
mSharedPreferences
.edit()
.putBoolean(context.getString(R.string.wp_pref_notifications_main), false)
.apply()

gcmMessageHandler.removeAllNotifications(context)
}

companion object {
fun newIntent(context: Context): Intent = Intent(context, JetpackAppInstallReceiver::class.java)
}
}