Remove the book update from the splashscreen.

This commit is contained in:
Thomas Andres Gomez 2022-10-21 15:55:29 +02:00
parent 537cf214a9
commit 58ebd970f2

View file

@ -7,15 +7,11 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.pixelized.biblib.network.client.IBibLibClient import com.pixelized.biblib.network.client.IBibLibClient
import com.pixelized.biblib.network.data.query.AuthLoginQuery import com.pixelized.biblib.network.data.query.AuthLoginQuery
import com.pixelized.biblib.repository.apiCache.IAPICacheRepository
import com.pixelized.biblib.repository.book.IBookRepository
import com.pixelized.biblib.repository.book.updateBooks
import com.pixelized.biblib.repository.credential.ICredentialRepository import com.pixelized.biblib.repository.credential.ICredentialRepository
import com.pixelized.biblib.repository.googleSignIn.IGoogleSingInRepository import com.pixelized.biblib.repository.googleSignIn.IGoogleSingInRepository
import com.pixelized.biblib.ui.navigation.Screen import com.pixelized.biblib.ui.navigation.Screen
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
@ -24,8 +20,6 @@ class LauncherViewModel @Inject constructor(
private val credentialRepository: ICredentialRepository, private val credentialRepository: ICredentialRepository,
private val googleSignIn: IGoogleSingInRepository, private val googleSignIn: IGoogleSingInRepository,
private val client: IBibLibClient, private val client: IBibLibClient,
private val bookRepository: IBookRepository,
private val apiCache: IAPICacheRepository,
) : ViewModel() { ) : ViewModel() {
var isLoadingDone by mutableStateOf(false) var isLoadingDone by mutableStateOf(false)
@ -35,20 +29,13 @@ class LauncherViewModel @Inject constructor(
private set private set
init { init {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch {
// Try to Authenticate // Try to Authenticate
if (autoLoginWithGoogle() || autologinWithCredential()) { startDestination = if (autoLoginWithGoogle() || autologinWithCredential()) {
startDestination = try {
// Update book
updateBooks()
// Change the start destination
Screen.Home Screen.Home
} catch (exception: Exception) { } else {
// Force the authentication process.
Screen.Authentication Screen.Authentication
} }
}
delay(1000)
// Update loading state. // Update loading state.
isLoadingDone = true isLoadingDone = true
} }
@ -102,11 +89,4 @@ class LauncherViewModel @Inject constructor(
// endregion // endregion
////////////////////////////////////// //////////////////////////////////////
// region: Books update
private suspend fun updateBooks() = updateBooks(
client = client,
cache = apiCache,
repository = bookRepository,
)
} }