ソースを参照

Fixed refresh hello page

Vadik Sirekanyan 2 年 前
コミット
5c53433d64

+ 1 - 0
app/src/main/java/org/sirekanyan/outline/MainActivity.kt

@@ -48,6 +48,7 @@ class MainActivity : ComponentActivity() {
                                             state.deletingKey = key
                                             state.api.deleteAccessKey(server, key.accessKey.id)
                                             state.refreshCurrentKeys(showLoading = false)
+                                            state.refreshHelloPage(key.server)
                                         }.invokeOnCompletion {
                                             state.deletingKey = null
                                         }

+ 11 - 0
app/src/main/java/org/sirekanyan/outline/MainState.kt

@@ -125,6 +125,17 @@ class MainState(
         }
     }
 
+    suspend fun refreshHelloPage(server: ServerEntity) {
+        if (page !is HelloPage) return
+        withContext(Dispatchers.IO) {
+            try {
+                keys.updateKeys(server)
+            } catch (exception: Exception) {
+                exception.printStackTrace()
+            }
+        }
+    }
+
 }
 
 sealed class Page

+ 2 - 2
app/src/main/java/org/sirekanyan/outline/feature/keys/KeyContent.kt

@@ -19,9 +19,9 @@ import org.sirekanyan.outline.api.model.getHost
 import org.sirekanyan.outline.text.formatTraffic
 
 @Composable
-fun KeyContent(key: Key, withServer: Boolean, onClick: () -> Unit) {
+fun KeyContent(key: Key, withServer: Boolean, modifier: Modifier, onClick: () -> Unit) {
     Row(
-        Modifier
+        modifier
             .clickable(onClick = onClick)
             .fillMaxWidth()
             .heightIn(min = if (withServer) 72.dp else 56.dp)

+ 8 - 8
app/src/main/java/org/sirekanyan/outline/feature/keys/KeysContent.kt

@@ -2,11 +2,11 @@ package org.sirekanyan.outline.feature.keys
 
 import androidx.compose.foundation.layout.PaddingValues
 import androidx.compose.foundation.lazy.LazyColumn
-import androidx.compose.material3.LocalContentColor
 import androidx.compose.runtime.Composable
-import androidx.compose.runtime.CompositionLocalProvider
 import androidx.compose.runtime.getValue
 import androidx.compose.runtime.produceState
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.alpha
 import androidx.compose.ui.unit.dp
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.withContext
@@ -27,12 +27,12 @@ fun KeysContent(insets: PaddingValues, state: MainState, keys: List<Key>, sortin
         sortedKeys.forEach { key ->
             item {
                 val isDeleting = key.accessKey.accessUrl == state.deletingKey?.accessKey?.accessUrl
-                val alpha = if (isDeleting) 0.5f else 1f
-                CompositionLocalProvider(
-                    LocalContentColor provides LocalContentColor.current.copy(alpha = alpha)
-                ) {
-                    KeyContent(key, state.page is HelloPage, onClick = { state.selectedKey = key })
-                }
+                KeyContent(
+                    key = key,
+                    withServer = state.page is HelloPage,
+                    modifier = Modifier.alpha(if (isDeleting) 0.5f else 1f),
+                    onClick = { state.selectedKey = key },
+                )
             }
         }
     }

+ 1 - 6
app/src/main/java/org/sirekanyan/outline/ui/RenameContent.kt

@@ -39,22 +39,17 @@ fun RenameContent(
             onCloseClick = { state.dialog = null },
             action = "Save" to {
                 state.scope.launch {
-                    val isSuccess = try {
+                    try {
                         isLoading = true
                         val newName = draft.text.ifBlank { defaultName }
                         onSaveClicked(newName)
                         state.dialog = null
-                        true
                     } catch (exception: Exception) {
                         exception.printStackTrace()
                         error = "Check name or try again"
-                        false
                     } finally {
                         isLoading = false
                     }
-                    if (isSuccess) {
-                        state.refreshCurrentKeys(showLoading = false)
-                    }
                 }
             },
             isLoading = isLoading,

+ 2 - 0
app/src/main/java/org/sirekanyan/outline/ui/RenameKeyContent.kt

@@ -9,5 +9,7 @@ fun RenameKeyContent(state: MainState, dialog: RenameKeyDialog) {
     val accessKey = dialog.key.accessKey
     RenameContent(state, "Edit key", accessKey.name, accessKey.defaultName) { newName ->
         state.keys.renameKey(dialog.server, accessKey, newName)
+        state.refreshCurrentKeys(showLoading = false)
+        state.refreshHelloPage(dialog.server)
     }
 }

+ 1 - 0
app/src/main/java/org/sirekanyan/outline/ui/RenameServerContent.kt

@@ -9,5 +9,6 @@ import org.sirekanyan.outline.api.model.getHost
 fun RenameServerContent(state: MainState, dialog: RenameServerDialog) {
     RenameContent(state, "Edit server", dialog.server.name, dialog.server.getHost()) { newName ->
         state.servers.renameServer(dialog.server, newName)
+        state.refreshCurrentKeys(showLoading = false)
     }
 }