Initial commit.
This commit is contained in:
commit
1a225e3732
54 changed files with 2097 additions and 0 deletions
|
|
@ -0,0 +1,61 @@
|
|||
package com.pixelized.biblib.ui.viewmodel
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.pixelized.biblib.data.ui.BookUio
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.*
|
||||
|
||||
class NavigationViewModel : ViewModel() {
|
||||
|
||||
private val stack = Stack<Page>()
|
||||
|
||||
private val _screen = MutableLiveData<Screen>()
|
||||
val screen: LiveData<Screen> get() = _screen
|
||||
|
||||
private val _page = MutableLiveData<Page>()
|
||||
val page: LiveData<Page> get() = _page
|
||||
|
||||
init {
|
||||
_screen.value = Screen.SplashScreen
|
||||
viewModelScope.launch {
|
||||
delay(3000)
|
||||
navigateTo(Page.HomePage)
|
||||
navigateTo(Screen.MainScreen)
|
||||
}
|
||||
}
|
||||
|
||||
fun navigateTo(screen: Screen): Boolean {
|
||||
_screen.postValue(screen)
|
||||
return true
|
||||
}
|
||||
|
||||
fun navigateTo(page: Page): Boolean {
|
||||
_page.postValue(page)
|
||||
stack.push(page)
|
||||
return true
|
||||
}
|
||||
|
||||
fun navigateBack() : Boolean {
|
||||
stack.pop()
|
||||
return if (stack.empty()) {
|
||||
false
|
||||
} else {
|
||||
_page.postValue(stack.peek())
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Screen {
|
||||
object SplashScreen : Screen()
|
||||
object MainScreen : Screen()
|
||||
}
|
||||
|
||||
sealed class Page {
|
||||
object HomePage : Page()
|
||||
data class Detail(val book: BookUio) : Page()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue