adding an empty state to messages list

This commit is contained in:
Adam Brown 2022-04-26 22:16:07 +01:00
parent 42914ffe53
commit a10f51aa08
4 changed files with 29 additions and 17 deletions

View File

@ -0,0 +1,18 @@
package app.dapk.st.design.components
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@Composable
fun GenericEmpty() {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("Nothing to see here...")
}
}
}

View File

@ -10,7 +10,6 @@ import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.*
@ -33,6 +32,8 @@ import app.dapk.st.core.LifecycleEffect
import app.dapk.st.core.StartObserving
import app.dapk.st.core.components.CenteredLoading
import app.dapk.st.design.components.CircleishAvatar
import app.dapk.st.design.components.GenericEmpty
import app.dapk.st.design.components.GenericError
import app.dapk.st.design.components.Toolbar
import app.dapk.st.directory.DirectoryEvent.OpenDownloadUrl
import app.dapk.st.directory.DirectoryScreenState.Content
@ -85,20 +86,12 @@ fun DirectoryScreen(directoryViewModel: DirectoryViewModel) {
.nestedScroll(nestedScrollConnection)
) {
when (state) {
is Content -> {
Content(listState, state)
}
EmptyLoading -> CenteredLoading()
is Error -> {
Box(contentAlignment = Alignment.Center) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("Something went wrong...")
Button(onClick = {}) {
Text("Retry")
}
}
}
DirectoryScreenState.Empty -> GenericEmpty()
is Error -> GenericError {
// TODO
}
is Content -> Content(listState, state)
}
Toolbar(title = "Messages", offset = { IntOffset(x = 0, y = toolbarOffsetHeightPx.value.roundToInt()) })
}

View File

@ -3,6 +3,7 @@ package app.dapk.st.directory
sealed interface DirectoryScreenState {
object EmptyLoading : DirectoryScreenState
object Empty : DirectoryScreenState
data class Content(
val overviewState: DirectoryState,
) : DirectoryScreenState

View File

@ -1,8 +1,7 @@
package app.dapk.st.directory
import androidx.lifecycle.viewModelScope
import app.dapk.st.directory.DirectoryScreenState.Content
import app.dapk.st.directory.DirectoryScreenState.EmptyLoading
import app.dapk.st.directory.DirectoryScreenState.*
import app.dapk.st.viewmodel.DapkViewModel
import app.dapk.st.viewmodel.MutableStateFactory
import app.dapk.st.viewmodel.defaultStateFactory
@ -26,8 +25,9 @@ class DirectoryViewModel(
syncJob = viewModelScope.launch {
directoryUseCase.state().onEach {
shortcutHandler.onDirectoryUpdate(it.map { it.overview })
if (it.isNotEmpty()) {
state = Content(it)
state = when (it.isEmpty()) {
true -> Empty
false -> Content(it)
}
}.collect()
}