Loading app/core/src/main/java/com/fsck/k9/CoreResourceProvider.kt +1 −0 Original line number Diff line number Diff line Loading @@ -36,4 +36,5 @@ interface CoreResourceProvider { val iconPushNotification: Int fun pushNotificationText(notificationState: PushNotificationState): String fun pushNotificationInfoText(): String } app/core/src/main/java/com/fsck/k9/controller/push/PushController.kt +11 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,17 @@ class PushController internal constructor( } } fun disablePush() { Timber.v("PushController.disablePush()") coroutineScope.launch(coroutineDispatcher) { for (account in preferences.accounts) { account.folderPushMode = FolderMode.NONE preferences.saveAccount(account) } } } private fun initInBackground() { Timber.v("PushController.initInBackground()") Loading app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt +15 −0 Original line number Diff line number Diff line package com.fsck.k9.notification import android.app.Notification import android.app.PendingIntent import android.content.Context import android.content.Intent import android.os.Build import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import com.fsck.k9.CoreResourceProvider private const val PUSH_INFO_ACTION = "app.k9mail.action.PUSH_INFO" internal class PushNotificationManager( private val context: Context, private val resourceProvider: CoreResourceProvider, Loading Loading @@ -44,9 +49,19 @@ internal class PushNotificationManager( } private fun createNotification(): Notification { val intent = Intent(PUSH_INFO_ACTION).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) setPackage(context.packageName) } val flag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0 val contentIntent = PendingIntent.getActivity(context, 1, intent, flag) return NotificationCompat.Builder(context, notificationChannelManager.pushChannelId) .setSmallIcon(resourceProvider.iconPushNotification) .setContentTitle(resourceProvider.pushNotificationText(notificationState)) .setContentText(resourceProvider.pushNotificationInfoText()) .setContentIntent(contentIntent) .setOngoing(true) .setNotificationSilent() .setBadgeIconType(NotificationCompat.BADGE_ICON_NONE) Loading app/core/src/test/java/com/fsck/k9/TestCoreResourceProvider.kt +2 −0 Original line number Diff line number Diff line Loading @@ -47,4 +47,6 @@ class TestCoreResourceProvider : CoreResourceProvider { override fun pushNotificationText(notificationState: PushNotificationState): String { throw UnsupportedOperationException("not implemented") } override fun pushNotificationInfoText(): String = throw UnsupportedOperationException("not implemented") } app/k9mail-jmap/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt +2 −0 Original line number Diff line number Diff line Loading @@ -55,4 +55,6 @@ class K9CoreResourceProvider(private val context: Context) : CoreResourceProvide } return context.getString(resId) } override fun pushNotificationInfoText(): String = context.getString(R.string.push_notification_info) } Loading
app/core/src/main/java/com/fsck/k9/CoreResourceProvider.kt +1 −0 Original line number Diff line number Diff line Loading @@ -36,4 +36,5 @@ interface CoreResourceProvider { val iconPushNotification: Int fun pushNotificationText(notificationState: PushNotificationState): String fun pushNotificationInfoText(): String }
app/core/src/main/java/com/fsck/k9/controller/push/PushController.kt +11 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,17 @@ class PushController internal constructor( } } fun disablePush() { Timber.v("PushController.disablePush()") coroutineScope.launch(coroutineDispatcher) { for (account in preferences.accounts) { account.folderPushMode = FolderMode.NONE preferences.saveAccount(account) } } } private fun initInBackground() { Timber.v("PushController.initInBackground()") Loading
app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt +15 −0 Original line number Diff line number Diff line package com.fsck.k9.notification import android.app.Notification import android.app.PendingIntent import android.content.Context import android.content.Intent import android.os.Build import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import com.fsck.k9.CoreResourceProvider private const val PUSH_INFO_ACTION = "app.k9mail.action.PUSH_INFO" internal class PushNotificationManager( private val context: Context, private val resourceProvider: CoreResourceProvider, Loading Loading @@ -44,9 +49,19 @@ internal class PushNotificationManager( } private fun createNotification(): Notification { val intent = Intent(PUSH_INFO_ACTION).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) setPackage(context.packageName) } val flag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0 val contentIntent = PendingIntent.getActivity(context, 1, intent, flag) return NotificationCompat.Builder(context, notificationChannelManager.pushChannelId) .setSmallIcon(resourceProvider.iconPushNotification) .setContentTitle(resourceProvider.pushNotificationText(notificationState)) .setContentText(resourceProvider.pushNotificationInfoText()) .setContentIntent(contentIntent) .setOngoing(true) .setNotificationSilent() .setBadgeIconType(NotificationCompat.BADGE_ICON_NONE) Loading
app/core/src/test/java/com/fsck/k9/TestCoreResourceProvider.kt +2 −0 Original line number Diff line number Diff line Loading @@ -47,4 +47,6 @@ class TestCoreResourceProvider : CoreResourceProvider { override fun pushNotificationText(notificationState: PushNotificationState): String { throw UnsupportedOperationException("not implemented") } override fun pushNotificationInfoText(): String = throw UnsupportedOperationException("not implemented") }
app/k9mail-jmap/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt +2 −0 Original line number Diff line number Diff line Loading @@ -55,4 +55,6 @@ class K9CoreResourceProvider(private val context: Context) : CoreResourceProvide } return context.getString(resId) } override fun pushNotificationInfoText(): String = context.getString(R.string.push_notification_info) }