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

Commit ab192ece authored by cketti's avatar cketti
Browse files

Pass in dependencies via constructor

parent 05c09121
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
package com.fsck.k9.notification

import android.app.NotificationManager
import android.content.Context
import android.support.v4.app.NotificationManagerCompat
import org.koin.dsl.module.applicationContext
import java.util.concurrent.Executors

val coreNotificationModule = applicationContext {
    bean { NotificationController(get(), get(), get(), get(), get()) }
    bean { NotificationManagerCompat.from(get()) }
    bean { NotificationHelper(get(), get(), get()) }
    bean { NotificationChannelManager(get(), get()) }
    bean {
        NotificationChannelManager(
                get(),
                Executors.newSingleThreadExecutor(),
                get<Context>().getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        )
    }
    bean { CertificateErrorNotifications(get(), get(), get()) }
    bean { AuthenticationErrorNotifications(get(), get(), get()) }
    bean { SyncNotifications(get(), get(), get()) }
+7 −6
Original line number Diff line number Diff line
@@ -4,14 +4,17 @@ package com.fsck.k9.notification
import android.app.NotificationChannel
import android.app.NotificationChannelGroup
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import android.support.annotation.RequiresApi
import com.fsck.k9.Account
import com.fsck.k9.Preferences
import java.util.concurrent.Executors
import java.util.concurrent.Executor

class NotificationChannelManager(private val context: Context, private val preferences: Preferences) {
class NotificationChannelManager(
        private val preferences: Preferences,
        private val backgroundExecutor: Executor,
        private val notificationManager: NotificationManager
) {

    enum class ChannelType {
        MESSAGES, MISCELLANEOUS
@@ -22,9 +25,7 @@ class NotificationChannelManager(private val context: Context, private val prefe
            return
        }

        Executors.newSingleThreadExecutor().execute {
            val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE)
                    as NotificationManager
        backgroundExecutor.execute {
            val accounts = preferences.accounts

            removeChannelsForNonExistingOrChangedAccounts(notificationManager, accounts)