后台发送图片,但是没有进度条
This commit is contained in:
23
app/src/main/java/com/aiosman/riderpro/llama.py
Normal file
23
app/src/main/java/com/aiosman/riderpro/llama.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
|
||||
def read_files_recursively(directory, output_filename="llama.txt"):
|
||||
"""
|
||||
递归读取指定目录下的所有文件,并将它们的内容按顺序写入一个新文件中。
|
||||
每个文件的内容以文件名和相对路径作为注释开头。
|
||||
"""
|
||||
|
||||
script_filename = os.path.basename(__file__) # 获取当前脚本的文件名
|
||||
|
||||
with open(output_filename, "w", encoding="utf-8") as outfile:
|
||||
for root, dirs, files in os.walk(directory):
|
||||
for filename in sorted(files):
|
||||
if filename != script_filename:
|
||||
filepath = os.path.join(root, filename)
|
||||
relative_path = os.path.relpath(filepath, directory)
|
||||
outfile.write(f"### {relative_path} ###\n")
|
||||
with open(filepath, "r", encoding="utf-8") as infile:
|
||||
outfile.write(infile.read())
|
||||
outfile.write("\n\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
read_files_recursively(".") # 从当前目录开始递归读取
|
||||
12920
app/src/main/java/com/aiosman/riderpro/llama.txt
Normal file
12920
app/src/main/java/com/aiosman/riderpro/llama.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,7 @@ import android.content.Intent
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
@@ -25,6 +26,7 @@ import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.material.LinearProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.Text
|
||||
@@ -80,10 +82,13 @@ fun NewPostScreen() {
|
||||
.fillMaxSize()
|
||||
) {
|
||||
NewPostTopBar {
|
||||
model.viewModelScope.launch {
|
||||
model.createMoment(context = context)
|
||||
navController.popBackStack()
|
||||
}
|
||||
// model.viewModelScope.launch {
|
||||
// model.createMoment(context = context){ progress ->
|
||||
// // 更新进度条
|
||||
// uploadProgress = progress
|
||||
// }
|
||||
// navController.popBackStack()
|
||||
// }
|
||||
}
|
||||
NewPostTextField("Share your adventure…", NewPostViewModel.textContent) {
|
||||
NewPostViewModel.textContent = it
|
||||
@@ -114,6 +119,11 @@ fun NewPostScreen() {
|
||||
@Composable
|
||||
fun NewPostTopBar(onSendClick: () -> Unit = {}) {
|
||||
val navController = LocalNavController.current
|
||||
val context = LocalContext.current
|
||||
val model = NewPostViewModel
|
||||
var showProgressBar by remember { mutableStateOf(false) }
|
||||
var uploadProgress by remember { mutableStateOf(0f) }
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -138,14 +148,40 @@ fun NewPostTopBar(onSendClick: () -> Unit = {}) {
|
||||
modifier = Modifier
|
||||
.size(24.dp)
|
||||
.noRippleClickable {
|
||||
onSendClick()
|
||||
// 点击发送按钮后立即导航回主页
|
||||
navController.popBackStack()
|
||||
// 显示进度条
|
||||
showProgressBar = true
|
||||
|
||||
// 在后台启动协程处理上传逻辑
|
||||
model.viewModelScope.launch {
|
||||
model.createMoment(context = context) { progress ->
|
||||
// 更新进度条
|
||||
uploadProgress = progress
|
||||
}
|
||||
// 上传完成后隐藏进度条
|
||||
showProgressBar = false
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 在底部添加一个进度条
|
||||
AnimatedVisibility(
|
||||
visible = showProgressBar,
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomCenter)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
LinearProgressIndicator(
|
||||
progress = uploadProgress,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(4.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NewPostTextField(hint: String, value: String, onValueChange: (String) -> Unit) {
|
||||
|
||||
|
||||
@@ -48,8 +48,9 @@ object NewPostViewModel : ViewModel() {
|
||||
return tempFile
|
||||
}
|
||||
|
||||
suspend fun createMoment(context: Context) {
|
||||
suspend fun createMoment(context: Context, onUploadProgress: (Float) -> Unit) {
|
||||
val uploadImageList = emptyList<UploadImage>().toMutableList()
|
||||
var index = 0
|
||||
for (uri in imageUriList) {
|
||||
val cursor = context.contentResolver.query(Uri.parse(uri), null, null, null, null)
|
||||
cursor?.use {
|
||||
@@ -63,6 +64,9 @@ object NewPostViewModel : ViewModel() {
|
||||
uploadImageList += UploadImage(file, displayName, uri, extension)
|
||||
}
|
||||
}
|
||||
// 在上传过程中调用 onUploadProgress 更新进度
|
||||
onUploadProgress(((index / imageUriList.size).toFloat())) // progressValue 是当前上传进度,例如 0.5 表示 50%
|
||||
index += 1
|
||||
}
|
||||
momentService.createMoment(textContent, 1, uploadImageList, relPostId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user