mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix: do not update file tree state on background thread
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user