Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26c64806 authored by cketti's avatar cketti
Browse files

Add "Push Info" screen

parent d2ddff56
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -36,4 +36,5 @@ interface CoreResourceProvider {

    val iconPushNotification: Int
    fun pushNotificationText(notificationState: PushNotificationState): String
    fun pushNotificationInfoText(): String
}
+11 −0
Original line number Diff line number Diff line
@@ -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()")

+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,
@@ -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)
+2 −0
Original line number Diff line number Diff line
@@ -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")
}
+2 −0
Original line number Diff line number Diff line
@@ -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