LicenseScreen: load license text in worker thread

This commit is contained in:
MM20 2022-01-09 14:59:30 +01:00
parent 4e7275c4aa
commit eaa1848f97
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -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)
}
}