LicenseScreen: load license text in worker thread
This commit is contained in:
parent
4e7275c4aa
commit
eaa1848f97
@ -4,11 +4,15 @@ import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.liveData
|
||||
import de.mm20.launcher2.licenses.OpenSourceLibrary
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class LicenseScreenVM(private val context: Application) : AndroidViewModel(context) {
|
||||
fun getLicenseText(library: OpenSourceLibrary) = liveData<String?> {
|
||||
val text = context.resources.openRawResource(library.licenseText).reader()
|
||||
.readText()
|
||||
val text = withContext(Dispatchers.IO) {
|
||||
context.resources.openRawResource(library.licenseText).reader()
|
||||
.readText()
|
||||
}
|
||||
emit(text)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user