Commit 3c8469db authored by Mark Murphy's avatar Mark Murphy
Browse files

bug fixes for FINAL edition

parent b6df63c3
......@@ -57,10 +57,10 @@ class RosterListFragment : Fragment() {
adapter.submitList(state.items)
binding?.apply {
loading.visibility = View.GONE
loading.visibility = if (state.isLoaded) View.GONE else View.VISIBLE
when {
state.items.isEmpty() -> {
state.items.isEmpty() && state.isLoaded -> {
empty.visibility = View.VISIBLE
empty.setText(R.string.msg_empty)
}
......
......@@ -10,12 +10,13 @@ import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
data class RosterViewState(
val items: List<ToDoModel> = listOf()
val items: List<ToDoModel> = listOf(),
val isLoaded: Boolean = false
)
class RosterMotor(private val repo: ToDoRepository) : ViewModel() {
val states = repo.items()
.map { RosterViewState(it) }
.map { RosterViewState(it, true) }
.stateIn(viewModelScope, SharingStarted.Eagerly, RosterViewState())
fun save(model: ToDoModel) {
......
......@@ -59,7 +59,7 @@ class RosterListFragment : Fragment() {
adapter.submitList(state.items)
binding?.apply {
loading.visibility = View.GONE
loading.visibility = if (state.isLoaded) View.GONE else View.VISIBLE
when {
state.items.isEmpty() && state.filterMode == FilterMode.ALL -> {
......
......@@ -13,6 +13,7 @@ import kotlinx.coroutines.launch
data class RosterViewState(
val items: List<ToDoModel> = listOf(),
val isLoaded: Boolean = false,
val filterMode: FilterMode = FilterMode.ALL
)
......@@ -30,7 +31,7 @@ class RosterMotor(private val repo: ToDoRepository) : ViewModel() {
job = viewModelScope.launch {
repo.items(filterMode).collect {
_states.emit(RosterViewState(it, filterMode))
_states.emit(RosterViewState(it, true, filterMode))
}
}
}
......
......@@ -71,7 +71,7 @@ class RosterListFragment : Fragment() {
adapter.submitList(state.items)
binding?.apply {
loading.visibility = View.GONE
loading.visibility = if (state.isLoaded) View.GONE else View.VISIBLE
when {
state.items.isEmpty() && state.filterMode == FilterMode.ALL -> {
......
......@@ -13,6 +13,7 @@ import kotlinx.coroutines.launch
data class RosterViewState(
val items: List<ToDoModel> = listOf(),
val isLoaded: Boolean = false,
val filterMode: FilterMode = FilterMode.ALL
)
......@@ -39,7 +40,7 @@ class RosterMotor(
job = viewModelScope.launch {
repo.items(filterMode).collect {
_states.emit(RosterViewState(it, filterMode))
_states.emit(RosterViewState(it, true, filterMode))
}
}
}
......
......@@ -71,7 +71,7 @@ class RosterListFragment : Fragment() {
adapter.submitList(state.items)
binding?.apply {
loading.visibility = View.GONE
loading.visibility = if (state.isLoaded) View.GONE else View.VISIBLE
when {
state.items.isEmpty() && state.filterMode == FilterMode.ALL -> {
......
......@@ -19,6 +19,7 @@ private const val AUTHORITY = BuildConfig.APPLICATION_ID + ".provider"
data class RosterViewState(
val items: List<ToDoModel> = listOf(),
val isLoaded: Boolean = false,
val filterMode: FilterMode = FilterMode.ALL
)
......@@ -48,7 +49,7 @@ class RosterMotor(
job = viewModelScope.launch {
repo.items(filterMode).collect {
_states.emit(RosterViewState(it, filterMode))
_states.emit(RosterViewState(it, true, filterMode))
}
}
}
......
......@@ -71,7 +71,7 @@ class RosterListFragment : Fragment() {
adapter.submitList(state.items)
binding?.apply {
loading.visibility = View.GONE
loading.visibility = if (state.isLoaded) View.GONE else View.VISIBLE
when {
state.items.isEmpty() && state.filterMode == FilterMode.ALL -> {
......
......@@ -19,6 +19,7 @@ private const val AUTHORITY = BuildConfig.APPLICATION_ID + ".provider"
data class RosterViewState(
val items: List<ToDoModel> = listOf(),
val isLoaded: Boolean = false,
val filterMode: FilterMode = FilterMode.ALL
)
......@@ -48,7 +49,7 @@ class RosterMotor(
job = viewModelScope.launch {
repo.items(filterMode).collect {
_states.emit(RosterViewState(it, filterMode))
_states.emit(RosterViewState(it, true, filterMode))
}
}
}
......
......@@ -71,7 +71,7 @@ class RosterListFragment : Fragment() {
adapter.submitList(state.items)
binding?.apply {
loading.visibility = View.GONE
loading.visibility = if (state.isLoaded) View.GONE else View.VISIBLE
when {
state.items.isEmpty() && state.filterMode == FilterMode.ALL -> {
......
......@@ -20,6 +20,7 @@ private const val AUTHORITY = BuildConfig.APPLICATION_ID + ".provider"
data class RosterViewState(
val items: List<ToDoModel> = listOf(),
val isLoaded: Boolean = false,
val filterMode: FilterMode = FilterMode.ALL
)
......@@ -50,7 +51,7 @@ class RosterMotor(
job = viewModelScope.launch {
repo.items(filterMode).collect {
_states.emit(RosterViewState(it, filterMode))
_states.emit(RosterViewState(it, true, filterMode))
}
}
}
......
......@@ -30,4 +30,4 @@ class ErrorDialogFragment : DialogFragment() {
}
}
enum class ErrorScenario { Import }
enum class ErrorScenario { Import, None }
......@@ -73,7 +73,7 @@ class RosterListFragment : Fragment() {
adapter.submitList(state.items)
binding?.apply {
loading.visibility = View.GONE
loading.visibility = if (state.isLoaded) View.GONE else View.VISIBLE
when {
state.items.isEmpty() && state.filterMode == FilterMode.ALL -> {
......@@ -114,10 +114,11 @@ class RosterListFragment : Fragment() {
.savedStateHandle
.getLiveData<ErrorScenario>(ErrorDialogFragment.KEY_RETRY)
.observe(viewLifecycleOwner) { retryScenario ->
clearImportError()
when (retryScenario) {
ErrorScenario.Import -> motor.importItems()
ErrorScenario.Import -> {
clearImportError()
motor.importItems()
}
}
}
}
......@@ -232,6 +233,6 @@ class RosterListFragment : Fragment() {
findNavController()
.getBackStackEntry(R.id.rosterListFragment)
.savedStateHandle
.remove<ErrorScenario>(ErrorDialogFragment.KEY_RETRY)
.set(ErrorDialogFragment.KEY_RETRY, ErrorScenario.None)
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ private const val AUTHORITY = BuildConfig.APPLICATION_ID + ".provider"
data class RosterViewState(
val items: List<ToDoModel> = listOf(),
val isLoaded: Boolean = false,
val filterMode: FilterMode = FilterMode.ALL
)
......@@ -54,7 +55,7 @@ class RosterMotor(
job = viewModelScope.launch {
repo.items(filterMode).collect {
_states.emit(RosterViewState(it, filterMode))
_states.emit(RosterViewState(it, true, filterMode))
}
}
}
......
......@@ -30,4 +30,4 @@ class ErrorDialogFragment : DialogFragment() {
}
}
enum class ErrorScenario { Import }
enum class ErrorScenario { Import, None }
......@@ -73,7 +73,7 @@ class RosterListFragment : Fragment() {
adapter.submitList(state.items)
binding?.apply {
loading.visibility = View.GONE
loading.visibility = if (state.isLoaded) View.GONE else View.VISIBLE
when {
state.items.isEmpty() && state.filterMode == FilterMode.ALL -> {
......@@ -114,10 +114,11 @@ class RosterListFragment : Fragment() {
.savedStateHandle
.getLiveData<ErrorScenario>(ErrorDialogFragment.KEY_RETRY)
.observe(viewLifecycleOwner) { retryScenario ->
clearImportError()
when (retryScenario) {
ErrorScenario.Import -> motor.importItems()
ErrorScenario.Import -> {
clearImportError()
motor.importItems()
}
}
}
}
......@@ -232,6 +233,6 @@ class RosterListFragment : Fragment() {
findNavController()
.getBackStackEntry(R.id.rosterListFragment)
.savedStateHandle
.remove<ErrorScenario>(ErrorDialogFragment.KEY_RETRY)
.set(ErrorDialogFragment.KEY_RETRY, ErrorScenario.None)
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ private const val AUTHORITY = BuildConfig.APPLICATION_ID + ".provider"
data class RosterViewState(
val items: List<ToDoModel> = listOf(),
val isLoaded: Boolean = false,
val filterMode: FilterMode = FilterMode.ALL
)
......@@ -54,7 +55,7 @@ class RosterMotor(
job = viewModelScope.launch {
repo.items(filterMode).collect {
_states.emit(RosterViewState(it, filterMode))
_states.emit(RosterViewState(it, true, filterMode))
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment