mirror of
https://github.com/InvertGeek/MixFile.git
synced 2026-05-30 08:00:35 +08:00
fix file rename
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -113,6 +113,7 @@ val Home = MixNavPage(
|
||||
OutlinedButton(
|
||||
onClick = {
|
||||
text = readClipBoardText()
|
||||
tryResolveFileList(text.trim())
|
||||
}, modifier = Modifier
|
||||
.weight(1.0f)
|
||||
.padding(10.dp, 0.dp)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user