fix file rename

This commit is contained in:
Evan You
2025-03-30 18:07:51 +08:00
parent 1b79442ac9
commit 7d8098d561
5 changed files with 29 additions and 15 deletions

View File

@@ -15,8 +15,8 @@ android {
applicationId = "com.donut.mixfile"
minSdk = 26
targetSdk = 35
versionCode = 96
versionName = "1.12.13"
versionCode = 97
versionName = "1.12.14"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {

View File

@@ -25,7 +25,7 @@ import io.ktor.utils.io.discard
fun ByteArray.hashMixSHA256() = MixShareInfo.ENCODER.encode(hashSHA256())
data class MixShareInfo(
@JSONField(name = "f") var fileName: String,
@JSONField(name = "f") val fileName: String,
@JSONField(name = "s") val fileSize: Long,
@JSONField(name = "h") val headSize: Int,
@JSONField(name = "u") val url: String,

View File

@@ -113,6 +113,7 @@ val Home = MixNavPage(
OutlinedButton(
onClick = {
text = readClipBoardText()
tryResolveFileList(text.trim())
}, modifier = Modifier
.weight(1.0f)
.padding(10.dp, 0.dp)

View File

@@ -44,17 +44,17 @@ data class FileDataLog(
list: List<FileDataLog>,
action: (FileDataLog) -> FileDataLog
): List<FileDataLog> {
val index = list.indexOf(this)
if (index == -1) return list
val updatedList = list.toMutableList()
updatedList[index] = action(list[index])
return updatedList.toList()
return list.map {
if (it.shareInfoData == this.shareInfoData) {
action(it)
} else {
it
}
}
}
fun rename(callback: (FileDataLog) -> Unit = {}) {
val shareInfo = resolveMixShareInfo(shareInfoData) ?: return
var shareInfo = resolveMixShareInfo(shareInfoData) ?: return
MixDialogBuilder("重命名文件").apply {
var name by mutableStateOf(shareInfo.fileName)
setContent {
@@ -70,7 +70,7 @@ data class FileDataLog(
showToast("文件名不能为空!")
return@setPositiveButton
}
shareInfo.fileName = name
shareInfo = shareInfo.copy(fileName = name)
val renamedLog = copy(
name = name,
shareInfoData = shareInfo.toString()

View File

@@ -9,6 +9,8 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.AssistChip
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@@ -38,13 +40,24 @@ import com.donut.mixfile.util.formatFileSize
@OptIn(ExperimentalLayoutApi::class)
fun showFileInfoDialog(
log: FileDataLog,
dataLog: FileDataLog,
onDismiss: () -> Unit = {}
) {
val shareInfo = resolveMixShareInfo(log.shareInfoData)!!
var shareInfo = resolveMixShareInfo(dataLog.shareInfoData)!!
MixDialogBuilder("文件信息", tag = "file-info-${shareInfo.url}").apply {
onDismiss(onDismiss)
setContent {
val log = remember(favorites) {
if (favorites.contains(dataLog)) {
dataLog
} else {
favorites.firstOrNull { it.shareInfoData.contentEquals(dataLog.shareInfoData) }
?: dataLog
}
}
LaunchedEffect(log) {
shareInfo = resolveMixShareInfo(log.shareInfoData)!!
}
val fileName = log.name
Column(
verticalArrangement = Arrangement.spacedBy(10.dp),
@@ -82,7 +95,7 @@ fun showFileInfoDialog(
AssistChip(onClick = {
log.rename {
closeDialog()
showFileInfoDialog(it)
showFileInfoDialog(it, onDismiss)
}
}, label = {
Text(text = "重命名", color = colorScheme.primary)