Add: Paging Ktx Library

Add: Resource.kt sealed class for future async loading
This commit is contained in:
LooKeR 2022-01-16 18:04:53 +05:30
parent 8ddaedc64d
commit ab5c26bec4
3 changed files with 12 additions and 3 deletions

View File

@ -53,7 +53,7 @@ android {
}
composeOptions {
kotlinCompilerExtensionVersion "1.1.0-rc02"
kotlinCompilerExtensionVersion "1.2.0-alpha01"
}
buildTypes {
@ -177,6 +177,9 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0'
// Paging
implementation 'androidx.paging:paging-runtime-ktx:3.1.0'
// Room
implementation 'androidx.room:room-runtime:2.4.1'
implementation 'androidx.room:room-ktx:2.4.1'

View File

@ -0,0 +1,7 @@
package com.looker.droidify
sealed class Resource<T>(val data: T? = null, val message: String? = null) {
class Loading<T>(data: T? = null) : Resource<T>(data)
class Success<T>(data: T?) : Resource<T>(data)
class Error<T>(message: String, data: T? = null) : Resource<T>(data, message)
}

View File

@ -13,7 +13,6 @@ import com.looker.droidify.database.Product
import com.looker.droidify.entity.ProductItem
import com.looker.droidify.ui.fragments.Request
import com.looker.droidify.ui.fragments.Source
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
@ -109,7 +108,7 @@ class MainNavFragmentViewModelX(val db: DatabaseX, source: Source) : ViewModel()
}
fun fillList(source: Source) {
CoroutineScope(Dispatchers.Default).launch {
viewModelScope.launch(Dispatchers.Default) {
// productsList = query(request(source))
}
}