From 1991468a010040f0df16effa971cd74cc7d2933e Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 3 Nov 2022 14:37:06 +0000 Subject: [PATCH] using unified push wrapper to allow for testing --- .../push/src/main/kotlin/app/dapk/st/push/PushModule.kt | 6 ++++-- .../src/main/kotlin/app/dapk/st/push/PushTokenRegistrars.kt | 5 +++-- .../main/kotlin/app/dapk/st/push/unifiedpush/UnifiedPush.kt | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/domains/android/push/src/main/kotlin/app/dapk/st/push/PushModule.kt b/domains/android/push/src/main/kotlin/app/dapk/st/push/PushModule.kt index 221342e..92767c8 100644 --- a/domains/android/push/src/main/kotlin/app/dapk/st/push/PushModule.kt +++ b/domains/android/push/src/main/kotlin/app/dapk/st/push/PushModule.kt @@ -22,6 +22,7 @@ class PushModule( ) : ProvidableModule { private val registrars by unsafeLazy { + val unifiedPush = object : UnifiedPush {} PushTokenRegistrars( context, MessagingPushTokenRegistrar( @@ -29,8 +30,9 @@ class PushModule( pushHandler, messaging, ), - UnifiedPushRegistrar(context, object : UnifiedPush {}), - PushTokenRegistrarPreferences(preferences) + UnifiedPushRegistrar(context, unifiedPush), + PushTokenRegistrarPreferences(preferences), + unifiedPush, ) } diff --git a/domains/android/push/src/main/kotlin/app/dapk/st/push/PushTokenRegistrars.kt b/domains/android/push/src/main/kotlin/app/dapk/st/push/PushTokenRegistrars.kt index eb29104..5b4ccc9 100644 --- a/domains/android/push/src/main/kotlin/app/dapk/st/push/PushTokenRegistrars.kt +++ b/domains/android/push/src/main/kotlin/app/dapk/st/push/PushTokenRegistrars.kt @@ -3,8 +3,8 @@ package app.dapk.st.push import android.content.Context import app.dapk.st.domain.push.PushTokenRegistrarPreferences import app.dapk.st.push.messaging.MessagingPushTokenRegistrar +import app.dapk.st.push.unifiedpush.UnifiedPush import app.dapk.st.push.unifiedpush.UnifiedPushRegistrar -import org.unifiedpush.android.connector.UnifiedPush private val FIREBASE_OPTION = Registrar("Google - Firebase (FCM)") private val NONE = Registrar("None") @@ -14,6 +14,7 @@ class PushTokenRegistrars( private val messagingPushTokenRegistrar: MessagingPushTokenRegistrar, private val unifiedPushRegistrar: UnifiedPushRegistrar, private val pushTokenStore: PushTokenRegistrarPreferences, + private val unifiedPush: UnifiedPush, ) : PushTokenRegistrar { private var selection: Registrar? = null @@ -23,7 +24,7 @@ class PushTokenRegistrars( true -> FIREBASE_OPTION else -> null } - return listOfNotNull(NONE, messagingOption) + UnifiedPush.getDistributors(context).map { Registrar(it) } + return listOfNotNull(NONE, messagingOption) + unifiedPush.getDistributors(context).map { Registrar(it) } } suspend fun currentSelection() = selection ?: (pushTokenStore.currentSelection()?.let { Registrar(it) } ?: defaultSelection()).also { selection = it } diff --git a/domains/android/push/src/main/kotlin/app/dapk/st/push/unifiedpush/UnifiedPush.kt b/domains/android/push/src/main/kotlin/app/dapk/st/push/unifiedpush/UnifiedPush.kt index 8ebf2d5..61429c4 100644 --- a/domains/android/push/src/main/kotlin/app/dapk/st/push/unifiedpush/UnifiedPush.kt +++ b/domains/android/push/src/main/kotlin/app/dapk/st/push/unifiedpush/UnifiedPush.kt @@ -6,6 +6,7 @@ import org.unifiedpush.android.connector.UnifiedPush interface UnifiedPush { fun saveDistributor(context: Context, distributor: String) = UnifiedPush.saveDistributor(context, distributor) fun getDistributor(context: Context): String = UnifiedPush.getDistributor(context) + fun getDistributors(context: Context): List = UnifiedPush.getDistributors(context) fun registerApp(context: Context) = UnifiedPush.registerApp(context) fun unregisterApp(context: Context) = UnifiedPush.unregisterApp(context) } \ No newline at end of file