[fix] Crash when page initialized before view model
This commit is contained in:
@@ -187,7 +187,7 @@ fun ComicScreen(
|
||||
HorizontalDivider(thickness = 1.5.dp)
|
||||
|
||||
LazyVerticalStaggeredGrid(
|
||||
columns = StaggeredGridCells.Adaptive(128.dp),
|
||||
columns = StaggeredGridCells.Adaptive(136.dp),
|
||||
contentPadding = PaddingValues(8.dp),
|
||||
verticalItemSpacing = 8.dp,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
|
||||
@@ -118,7 +118,9 @@ fun VideoScreen(
|
||||
val tabIndex by videoScreenViewModel.tabIndex
|
||||
var menuVisibility by videoScreenViewModel.menuVisibility
|
||||
var searchFilter by videoScreenViewModel.searchFilter
|
||||
var doneInit by videoScreenViewModel.doneInit
|
||||
|
||||
if (doneInit)
|
||||
CardPage(title = "Videos") {
|
||||
Box(Modifier.fillMaxSize())
|
||||
{
|
||||
@@ -165,7 +167,9 @@ fun VideoScreen(
|
||||
Box(Modifier.fillMaxHeight())
|
||||
{
|
||||
Text(
|
||||
text = videoScreenViewModel.videoLibrary.classes.getOrNull(tabIndex)
|
||||
text = videoScreenViewModel.videoLibrary.classes.getOrNull(
|
||||
tabIndex
|
||||
)
|
||||
?: "",
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
fontWeight = FontWeight.Bold,
|
||||
@@ -179,13 +183,15 @@ fun VideoScreen(
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.height(36.dp).widthIn(max = 240.dp)
|
||||
.height(36.dp)
|
||||
.widthIn(max = 240.dp)
|
||||
.background(colorScheme.primary, RoundedCornerShape(8.dp))
|
||||
.padding(horizontal = 6.dp)
|
||||
) {
|
||||
Icon(
|
||||
modifier = Modifier
|
||||
.size(30.dp).align(Alignment.CenterVertically),
|
||||
.size(30.dp)
|
||||
.align(Alignment.CenterVertically),
|
||||
imageVector = Icons.Default.Search,
|
||||
contentDescription = "Catalogue"
|
||||
)
|
||||
@@ -203,12 +209,18 @@ fun VideoScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
HorizontalDivider(Modifier.padding(bottom = 8.dp), 1.5.dp, DividerDefaults.color)
|
||||
HorizontalDivider(
|
||||
Modifier.padding(bottom = 8.dp),
|
||||
1.5.dp,
|
||||
DividerDefaults.color
|
||||
)
|
||||
LazyVerticalStaggeredGrid(
|
||||
columns = StaggeredGridCells.Adaptive(160.dp),
|
||||
contentPadding = PaddingValues(8.dp),
|
||||
verticalItemSpacing = 8.dp,
|
||||
horizontalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(8.dp),
|
||||
horizontalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(
|
||||
8.dp
|
||||
),
|
||||
state = state,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
|
||||
@@ -47,6 +47,7 @@ class VideoScreenViewModel @Inject constructor(
|
||||
var imageLoader: ImageLoader? = null;
|
||||
var menuVisibility = mutableStateOf(false)
|
||||
var searchFilter = mutableStateOf("")
|
||||
var doneInit = mutableStateOf(false)
|
||||
|
||||
suspend fun init() {
|
||||
fetchManager.configured.filter { it }.first()
|
||||
@@ -69,7 +70,8 @@ class VideoScreenViewModel @Inject constructor(
|
||||
val r = vl.sortedWith(compareBy(naturalOrder()) { it.video.name })
|
||||
videoLibrary.classesMap[videoLibrary.classes[0]]?.addAll(r)
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
videoLibrary.classes.add("Offline")
|
||||
videoLibrary.updatingMap[0] = true
|
||||
videoLibrary.classesMap["Offline"] = mutableStateListOf<Video>()
|
||||
@@ -85,6 +87,8 @@ class VideoScreenViewModel @Inject constructor(
|
||||
|
||||
videoLibrary.classesMap[videoLibrary.classes[0]]?.addAll(jsonQuery)
|
||||
}
|
||||
|
||||
doneInit.value = true
|
||||
}
|
||||
|
||||
fun setTabIndex(index: Int) {
|
||||
|
||||
Reference in New Issue
Block a user