fix: do not update file tree state on background thread

This commit is contained in:
Akash Yadav
2023-08-13 18:32:15 +05:30
parent e4d6adf32c
commit 166a9d1e10
2 changed files with 11 additions and 2 deletions
@@ -20,6 +20,7 @@ package com.itsaky.androidide.viewmodel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.itsaky.androidide.tasks.executeAsync
import com.itsaky.androidide.tasks.runOnUiThread
import com.unnamed.b.atv.view.AndroidTreeView
/**
@@ -36,10 +37,14 @@ internal class FileTreeViewModel : ViewModel() {
fun saveState(treeView: AndroidTreeView?) {
treeView?.let { tree ->
executeAsync {
executeAsync({
// if a large number of directories have been expanded in the tree
// this could block teh UI thread
treeState.value = tree.saveState
return@executeAsync tree.saveState
}) { result ->
runOnUiThread {
treeState.value = result
}
}
}
}
@@ -98,3 +98,7 @@ fun <R : Any?> executeAsyncProvideError(
callback: (R?, Throwable?) -> Unit
): CompletableFuture<R?> =
TaskExecutor.executeAsyncProvideError(callable, callback)
fun runOnUiThread(action : () -> Unit) {
ThreadUtils.runOnUiThread(action)
}