File tree Expand file tree Collapse file tree
composeApp/src/commonMain/kotlin/me/lkl/dalvikus/ui Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ fun EditorView(tabElement: TabElement) {
119119 Scaffold (
120120 containerColor = Color .Transparent ,
121121 floatingActionButton = {
122- if (viewModel.hasUnsavedChanges())
122+ if (viewModel.hasUnsavedChanges() && ! viewModel.isSaving )
123123 ExtendedFloatingActionButton (
124124 modifier = Modifier .padding(bottom = 8 .dp, end = 8 .dp),
125125 onClick = { viewModel.saveCode(coroutine) },
Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ class EditorViewModel(private val tab: TabElement) {
4646
4747 val editable by mutableStateOf(tab.contentProvider.isEditable())
4848
49+ var isSaving by mutableStateOf(false )
50+ private set
51+
4952 var openable by
5053 mutableStateOf(tab.contentProvider.getSizeEstimate() < maxEditorFileSize && tab.contentProvider.isDisplayable())
5154 private set
@@ -89,7 +92,7 @@ class EditorViewModel(private val tab: TabElement) {
8992 }
9093
9194 suspend fun loadCode () {
92- withContext(Dispatchers .IO ) {
95+ withContext(Dispatchers .Default ) {
9396 tab.contentProvider.loadContent()
9497 internalContent = internalContent.copy(text = tab.contentProvider.contentFlow.value.decodeToString())
9598
@@ -203,9 +206,13 @@ class EditorViewModel(private val tab: TabElement) {
203206
204207 fun saveCode (coroutineScope : CoroutineScope ) {
205208 if (! isLoaded) throw IllegalArgumentException (" code not initialized." )
206- coroutineScope.launch(crtExHandler) {
209+ isSaving = true
210+ coroutineScope.launch(Dispatchers .Default + crtExHandler) {
207211 tab.contentProvider.updateContent(internalContent.text.toByteArray())
208212 tab.hasUnsavedChanges.value = false
213+ withContext(Dispatchers .Main ) {
214+ isSaving = false
215+ }
209216 }
210217 }
211218
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ class PackagingViewModel() {
5757 apk : File ,
5858 onError : (Throwable ) -> Unit ,
5959 onSuccess : (ApkVerifier .Result ) -> Unit ,
60- ) = withContext(Dispatchers .IO ) {
60+ ) = withContext(Dispatchers .Default ) {
6161 try {
6262 val keystoreFile = keystoreInfo.keystoreFile
6363 val keyAlias = keystoreInfo.keyAlias
@@ -150,7 +150,7 @@ class PackagingViewModel() {
150150 onError : (Throwable ) -> Unit ,
151151 onSuccess : () -> Unit ,
152152 packageName : String? = null
153- ) = withContext(Dispatchers .IO ) {
153+ ) = withContext(Dispatchers .Default ) {
154154 // TODO add string resources for messages here.
155155 try {
156156 AndroidDebugBridge .init (false )
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import androidx.compose.ui.graphics.Color
1919import androidx.compose.ui.text.style.TextOverflow
2020import androidx.compose.ui.unit.dp
2121import co.touchlab.kermit.Logger
22+ import kotlinx.coroutines.Dispatchers
2223import kotlinx.coroutines.launch
2324import me.lkl.dalvikus.snackbarManager
2425import me.lkl.dalvikus.tree.ContainerNode
@@ -94,7 +95,7 @@ fun TreeView(
9495 indent = indent,
9596 isExpanded = expandedState[node] == true ,
9697 onToggleExpand = { shouldExpand ->
97- coroutineScope.launch(crtExHandler) {
98+ coroutineScope.launch(Dispatchers . IO + crtExHandler) {
9899 if (node is ContainerNode ) {
99100 if (shouldExpand) {
100101 try {
You can’t perform that action at this time.
0 commit comments