Receive and manage Central Hub notifications.
The CentralHubNotificationsProvider manages three types of notifications:
Bet Share Notifications
Alerts when users you follow share new bets. Includes bet details and user information.
Comment Notifications
Notifies when someone comments on your shared bets. Tracks unread comment counts.
Social Notifications
Updates about new followers, reactions to your bets, and other social interactions.
Mark individual notifications as read by ID or mark all notifications read at once.
The state includes separate unread counts for each notification type, enabling targeted UI updates.
class NotificationsViewModel : ViewModel(), KoinComponent {
private val notificationsProvider:
CentralHubNotificationsProvider = get()
val notificationsState = notificationsProvider.state
init {
notificationsProvider.loadData()
}
fun markAsRead(notificationIds: List<String>) {
notificationsProvider.readNotifications(notificationIds)
}
fun markAllRead() {
notificationsProvider.readAllNotifications()
}
override fun onCleared() {
super.onCleared()
notificationsProvider.destroy()
}
}Compose UI:
@Composable
fun NotificationsScreen(
viewModel: NotificationsViewModel = viewModel()
) {
val state by viewModel.notificationsState
.collectAsStateWithLifecycle()
Column {
// Unread counts
Text("Unread Bets: ${state.numOfUnreadBetSlips}")
Text("Unread Comments: ${state.numOfUnreadComments}")
Text("Unread Social: ${state.numOfUnreadSocial}")
// Notifications list
LazyColumn {
items(state.betslipNotifications) { notification ->
BetNotificationCard(notification) {
viewModel.markAsRead(listOf(notification.id))
}
}
items(state.commentNotifications) { notification ->
CommentNotificationCard(notification)
}
items(state.socialNotifications) { notification ->
SocialNotificationCard(notification)
}
}
}
}State for notifications:
data class CentralHubNotificationsState(
val numOfNewNotifications: Int,
val numOfUnreadBetSlips: Int,
val numOfUnreadSocial: Int,
val numOfUnreadComments: Int,
val betslipNotifications: List<BetShareNotification>,
val socialNotifications: List<SocialNotification>,
val commentNotifications: List<CommentNotification>,
val newFollowersData: NewFollowersData,
val loadingState: LoadingStatus,
// ... additional loading states
)