-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly update push state and request actions
Remove eventBus dependency
- Loading branch information
Showing
9 changed files
with
102 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
samples/client/src/main/java/global/covesa/sdk/client/ActionEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package global.covesa.sdk.client | ||
|
||
import android.app.Activity | ||
import org.unifiedpush.android.connector.UnifiedPush | ||
|
||
class ActionEvent(private val type: Type) { | ||
enum class Type { | ||
RegisterPush, | ||
UnregisterPush, | ||
SendNotification, | ||
} | ||
|
||
fun handleAction(activity: Activity) { | ||
when(type) { | ||
Type.RegisterPush -> registerPush(activity) | ||
Type.UnregisterPush -> UnifiedPush.unregisterApp(activity) | ||
Type.SendNotification -> MockApplicationServer(activity).MockApi().sendNotification() | ||
} | ||
} | ||
|
||
private fun registerPush(activity: Activity) { | ||
UnifiedPush.tryUseCurrentOrDefaultDistributor( | ||
activity | ||
) { | ||
UnifiedPush.registerApp( | ||
activity, | ||
vapid = MockApplicationServer(activity).MockApi().getVapidPubKey() | ||
) | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
samples/client/src/main/java/global/covesa/sdk/client/EventBus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package global.covesa.sdk.client | ||
|
||
import kotlinx.coroutines.ensureActive | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.flow.collectLatest | ||
import kotlinx.coroutines.flow.filterIsInstance | ||
import kotlin.coroutines.coroutineContext | ||
|
||
|
||
object EventBus { | ||
private val _events = MutableSharedFlow<Any>() | ||
val events = _events.asSharedFlow() | ||
|
||
suspend fun publish(event: Any) { | ||
_events.emit(event) | ||
} | ||
|
||
suspend inline fun <reified T> subscribe(crossinline onEvent: (T) -> Unit) { | ||
events.filterIsInstance<T>() | ||
.collectLatest { event -> | ||
coroutineContext.ensureActive() | ||
onEvent(event) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
samples/client/src/main/java/global/covesa/sdk/client/PushSubscriptionEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
package global.covesa.sdk.client | ||
|
||
class PushSubscriptionEvent { | ||
} | ||
data class PushSubscriptionEvent( | ||
val registered: Boolean | ||
) |
9 changes: 8 additions & 1 deletion
9
samples/client/src/main/java/global/covesa/sdk/client/ui/PushUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
package global.covesa.sdk.client.ui | ||
|
||
import android.content.Context | ||
import org.unifiedpush.android.connector.UnifiedPush | ||
|
||
data class PushUiState ( | ||
val registered: Boolean = false | ||
) | ||
) { | ||
constructor(context: Context) : this( | ||
registered = UnifiedPush.getAckDistributor(context) != null | ||
) | ||
} |