-
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.
androidApp: Initial support for announcements
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
- Loading branch information
1 parent
e4e4f77
commit 0c3b3e2
Showing
5 changed files
with
147 additions
and
1 deletion.
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
100 changes: 100 additions & 0 deletions
100
...oidApp/src/main/java/app/opass/ccip/android/ui/screens/announcement/AnnouncementScreen.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,100 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 OPass | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
*/ | ||
|
||
package app.opass.ccip.android.ui.screens.announcement | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import androidx.navigation.NavHostController | ||
import app.opass.ccip.android.R | ||
import app.opass.ccip.android.ui.components.TopAppBar | ||
import app.opass.ccip.android.ui.extensions.browse | ||
import app.opass.ccip.android.ui.navigation.Screen | ||
import app.opass.ccip.network.models.fastpass.Announcement | ||
|
||
@Composable | ||
fun Screen.Announcement.AnnouncementScreen( | ||
navHostController: NavHostController, | ||
viewModel: AnnouncementViewModel = hiltViewModel() | ||
) { | ||
val context = LocalContext.current | ||
val announcements by viewModel.announcements.collectAsStateWithLifecycle() | ||
|
||
LaunchedEffect(key1 = Unit) { | ||
viewModel.getAnnouncements(this@AnnouncementScreen.eventId, this@AnnouncementScreen.token) | ||
} | ||
|
||
Scaffold( | ||
modifier = Modifier.fillMaxSize(), | ||
topBar = { | ||
TopAppBar( | ||
title = stringResource(this.title), | ||
navHostController = navHostController, | ||
actions = { | ||
IconButton( | ||
onClick = { | ||
viewModel.getAnnouncements( | ||
this@AnnouncementScreen.eventId, | ||
this@AnnouncementScreen.token, | ||
true | ||
) | ||
} | ||
) { | ||
Icon( | ||
painter = painterResource(id = R.drawable.ic_refresh), | ||
contentDescription = null | ||
) | ||
} | ||
} | ||
) | ||
} | ||
) { paddingValues -> | ||
LazyColumn( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(paddingValues), | ||
contentPadding = PaddingValues(10.dp) | ||
) { | ||
items(announcements) { announcement: Announcement -> | ||
AnnouncementItem(announcement) { | ||
context.browse(announcement.url) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun AnnouncementItem(announcement: Announcement, onClicked: () -> Unit = {}) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = 20.dp, vertical = 10.dp) | ||
.clickable(enabled = announcement.url.isNotBlank()) { onClicked() } | ||
) { | ||
Text(text = announcement.message, style = MaterialTheme.typography.bodyLarge) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...App/src/main/java/app/opass/ccip/android/ui/screens/announcement/AnnouncementViewModel.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 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 OPass | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
*/ | ||
|
||
package app.opass.ccip.android.ui.screens.announcement | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import app.opass.ccip.helpers.PortalHelper | ||
import app.opass.ccip.network.models.fastpass.Announcement | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class AnnouncementViewModel @Inject constructor( | ||
private val portalHelper: PortalHelper | ||
): ViewModel() { | ||
|
||
private val _announcements: MutableStateFlow<List<Announcement>> = MutableStateFlow(emptyList()) | ||
val announcements = _announcements.asStateFlow() | ||
|
||
fun getAnnouncements(eventId: String, token: String? = null, forceReload: Boolean = false) { | ||
viewModelScope.launch { | ||
_announcements.value = portalHelper.getAnnouncements(eventId, token, forceReload) | ||
} | ||
} | ||
} |
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