Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: do not update file tree state on background thread
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Aug 16, 2023
1 parent 51fa66d commit f7934ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit f7934ab

Please sign in to comment.