image array get from tms

This commit is contained in:
moon 2026-06-17 00:25:14 +06:30
parent 4fb6556d1b
commit 13aed803ae
3 changed files with 23 additions and 11 deletions

View File

@ -429,6 +429,7 @@ fun DashboardScreen2(
) {
item {
AdvertisingArea(
carouselUrls = dashboardUiState.carouselUrls,
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
@ -463,19 +464,19 @@ fun DashboardScreen2(
}
@Composable
private fun AdvertisingArea(modifier: Modifier = Modifier) {
val imageArray = listOf(
R.drawable.sunmi1,
R.drawable.sunmi2,
R.drawable.sunmi3
)
val pageState = rememberPagerState(pageCount = { imageArray.size })
private fun AdvertisingArea(
carouselUrls: List<String> = emptyList(),
modifier: Modifier = Modifier
) {
val imageModels: List<Any> = carouselUrls.ifEmpty {
listOf(R.drawable.sunmi1, R.drawable.sunmi2, R.drawable.sunmi3)
}
val pageState = rememberPagerState(pageCount = { imageModels.size })
LaunchedEffect(pageState) {
while (true) {
delay(10000.milliseconds)
val nextPage = (pageState.currentPage + 1) % imageArray.size
val nextPage = (pageState.currentPage + 1) % imageModels.size
pageState.animateScrollToPage(
page = nextPage, animationSpec = tween(durationMillis = 700)
@ -492,7 +493,7 @@ private fun AdvertisingArea(modifier: Modifier = Modifier) {
state = pageState, modifier = Modifier.fillMaxSize()
) { page ->
AsyncImage(
model = imageArray[page],
model = imageModels[page],
contentDescription = "ads images",
modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.Crop

View File

@ -12,5 +12,6 @@ data class TrnxRecord(
data class DashboardUiState(
val recentTransactions: List<TrnxRecord> = emptyList(),
val lastSyncTime: Long? = null
val lastSyncTime: Long? = null,
val carouselUrls: List<String> = emptyList()
)

View File

@ -6,6 +6,7 @@ import androidx.lifecycle.asFlow
import androidx.lifecycle.viewModelScope
import com.utsmyanmar.baselib.repo.Repository
import com.utsmyanmar.paylibs.model.PayDetail
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.MutableStateFlow
@ -35,6 +36,15 @@ class DashboardViewModel @Inject constructor(
}
}
refreshLastSyncTime()
loadCarouselUrls()
}
private fun loadCarouselUrls() {
val raw = runCatching {
SystemParamsOperation.getInstance().carouselUrls
}.getOrDefault("")
val urls = raw.split(",").filter { it.isNotBlank() }
_uiState.update { it.copy(carouselUrls = urls) }
}
fun refreshLastSyncTime() {