yayan пре 1 година
родитељ
комит
f4b0f1ea8c
1 измењених фајлова са 38 додато и 34 уклоњено
  1. 38 34
      app/src/main/java/io/nexilis/alpha/ui/components/ContentChat.kt

+ 38 - 34
app/src/main/java/io/nexilis/alpha/ui/components/ContentChat.kt

@@ -134,19 +134,7 @@ fun ContentChat(modifier: Modifier = Modifier, message: Message) {
                     )
                     FileDesc(file = message.file_id)
                 }
-                val file = File(context.filesDir, message.file_id)
-                if (!file.exists()) {
-                    IconButton(
-                        onClick = { /*TODO*/ },
-                        modifier = Modifier.align(Alignment.CenterVertically)
-                    ) {
-                        Icon(
-                            imageVector = Icons.Default.DownloadForOffline,
-                            contentDescription = null,
-                            tint = Color.LightGray
-                        )
-                    }
-                }
+                FileProgress(message = message)
             }
             val messageText = message.message_text.split("|").last()
             if (messageText.isNotEmpty()) {
@@ -253,27 +241,12 @@ fun FileType(message: Message, modifier: Modifier) {
         "zip", "gz", "rar" -> ImageVector.vectorResource(id = R.drawable.ic_zip)
         else -> ImageVector.vectorResource(id = R.drawable.ic_file)
     }
-    val progressViewModel: ProgressViewModel = hiltViewModel()
-    val progress by progressViewModel.get(message.message_id).observeAsState()
-    Box {
-        Image(
-            modifier = modifier
-                .size(48.dp),
-            imageVector = imageVector,
-            contentDescription = null
-        )
-        progress?.let {
-            if (it.value > 0f && it.value < 1f) {
-                CircularProgressIndicator(
-                    progress = { it.value },
-                    modifier = Modifier
-                        .align(Alignment.Center)
-                        .size(32.dp),
-                )
-            }
-        }
-
-    }
+    Image(
+        modifier = modifier
+            .size(48.dp),
+        imageVector = imageVector,
+        contentDescription = null
+    )
 }
 
 @Composable
@@ -290,4 +263,35 @@ fun FileDesc(file: String, modifier: Modifier = Modifier) {
             style = MaterialTheme.typography.labelSmall,
         )
     }
+}
+
+@Composable
+fun FileProgress(message: Message, modifier: Modifier = Modifier) {
+    val context = LocalContext.current
+    val progressViewModel: ProgressViewModel = hiltViewModel()
+    Box {
+        val progress by progressViewModel.get(message.message_id).observeAsState()
+        progress?.let {
+            if (it.value > 0f && it.value < 1f) {
+                CircularProgressIndicator(
+                    progress = { it.value },
+                    modifier = modifier
+                        .size(32.dp),
+                )
+            }
+        }
+        val file = File(context.filesDir, message.file_id)
+        if (!file.exists()) {
+            IconButton(
+                onClick = { /*TODO*/ },
+                modifier = modifier
+            ) {
+                Icon(
+                    imageVector = Icons.Default.DownloadForOffline,
+                    contentDescription = null,
+                    tint = Color.LightGray
+                )
+            }
+        }
+    }
 }