using unified push wrapper to allow for testing
This commit is contained in:
parent
8545d0dab4
commit
1991468a01
|
@ -22,6 +22,7 @@ class PushModule(
|
||||||
) : ProvidableModule {
|
) : ProvidableModule {
|
||||||
|
|
||||||
private val registrars by unsafeLazy {
|
private val registrars by unsafeLazy {
|
||||||
|
val unifiedPush = object : UnifiedPush {}
|
||||||
PushTokenRegistrars(
|
PushTokenRegistrars(
|
||||||
context,
|
context,
|
||||||
MessagingPushTokenRegistrar(
|
MessagingPushTokenRegistrar(
|
||||||
|
@ -29,8 +30,9 @@ class PushModule(
|
||||||
pushHandler,
|
pushHandler,
|
||||||
messaging,
|
messaging,
|
||||||
),
|
),
|
||||||
UnifiedPushRegistrar(context, object : UnifiedPush {}),
|
UnifiedPushRegistrar(context, unifiedPush),
|
||||||
PushTokenRegistrarPreferences(preferences)
|
PushTokenRegistrarPreferences(preferences),
|
||||||
|
unifiedPush,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ package app.dapk.st.push
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import app.dapk.st.domain.push.PushTokenRegistrarPreferences
|
import app.dapk.st.domain.push.PushTokenRegistrarPreferences
|
||||||
import app.dapk.st.push.messaging.MessagingPushTokenRegistrar
|
import app.dapk.st.push.messaging.MessagingPushTokenRegistrar
|
||||||
|
import app.dapk.st.push.unifiedpush.UnifiedPush
|
||||||
import app.dapk.st.push.unifiedpush.UnifiedPushRegistrar
|
import app.dapk.st.push.unifiedpush.UnifiedPushRegistrar
|
||||||
import org.unifiedpush.android.connector.UnifiedPush
|
|
||||||
|
|
||||||
private val FIREBASE_OPTION = Registrar("Google - Firebase (FCM)")
|
private val FIREBASE_OPTION = Registrar("Google - Firebase (FCM)")
|
||||||
private val NONE = Registrar("None")
|
private val NONE = Registrar("None")
|
||||||
|
@ -14,6 +14,7 @@ class PushTokenRegistrars(
|
||||||
private val messagingPushTokenRegistrar: MessagingPushTokenRegistrar,
|
private val messagingPushTokenRegistrar: MessagingPushTokenRegistrar,
|
||||||
private val unifiedPushRegistrar: UnifiedPushRegistrar,
|
private val unifiedPushRegistrar: UnifiedPushRegistrar,
|
||||||
private val pushTokenStore: PushTokenRegistrarPreferences,
|
private val pushTokenStore: PushTokenRegistrarPreferences,
|
||||||
|
private val unifiedPush: UnifiedPush,
|
||||||
) : PushTokenRegistrar {
|
) : PushTokenRegistrar {
|
||||||
|
|
||||||
private var selection: Registrar? = null
|
private var selection: Registrar? = null
|
||||||
|
@ -23,7 +24,7 @@ class PushTokenRegistrars(
|
||||||
true -> FIREBASE_OPTION
|
true -> FIREBASE_OPTION
|
||||||
else -> null
|
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 }
|
suspend fun currentSelection() = selection ?: (pushTokenStore.currentSelection()?.let { Registrar(it) } ?: defaultSelection()).also { selection = it }
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.unifiedpush.android.connector.UnifiedPush
|
||||||
interface UnifiedPush {
|
interface UnifiedPush {
|
||||||
fun saveDistributor(context: Context, distributor: String) = UnifiedPush.saveDistributor(context, distributor)
|
fun saveDistributor(context: Context, distributor: String) = UnifiedPush.saveDistributor(context, distributor)
|
||||||
fun getDistributor(context: Context): String = UnifiedPush.getDistributor(context)
|
fun getDistributor(context: Context): String = UnifiedPush.getDistributor(context)
|
||||||
|
fun getDistributors(context: Context): List<String> = UnifiedPush.getDistributors(context)
|
||||||
fun registerApp(context: Context) = UnifiedPush.registerApp(context)
|
fun registerApp(context: Context) = UnifiedPush.registerApp(context)
|
||||||
fun unregisterApp(context: Context) = UnifiedPush.unregisterApp(context)
|
fun unregisterApp(context: Context) = UnifiedPush.unregisterApp(context)
|
||||||
}
|
}
|
Loading…
Reference in New Issue