fix: file info in search

This commit is contained in:
Kagura 2024-11-01 13:00:44 +08:00
parent e73dea21a9
commit 1ceb0f669b
2 changed files with 26 additions and 27 deletions

View file

@ -3,6 +3,8 @@ package com.dazuoye.filemanager.compose.ui
import android.content.Context
import android.content.Intent
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AlertDialog.Builder
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
@ -331,13 +333,7 @@ class SearchFileColumn(
IconButton(
onClick = {
if (file.type == Type.FILE) { // 普通文件
AlertHelper.showOnlyInfoNewAlert(context,
onInfo = {
AlertHelper.showFileInfoAlert(context, file.path)
}
)
}
showFileInfoAlert(context,file.path)
},
modifier = Modifier.padding(horizontal = 10.dp)
) {
@ -348,4 +344,27 @@ class SearchFileColumn(
}
}
fun showFileInfoAlert(context: Context, file: String) {
val f = File(file)
if (!f.exists()) {
return
}
val wrappedFile = WrappedFile(f)
val builder = AlertDialog.Builder(context)
builder.setTitle(context.getString(R.string.file_info))
.setMessage(
context.getString(
R.string.file_info_text,
wrappedFile.name,
wrappedFile.path,
wrappedFile.getSizeString(),
wrappedFile.getModifiedTimeString(context)
)
)
.setNegativeButton(context.getString(R.string.okay)) { dialog, _ ->
dialog.dismiss()
}
.show()
}
}

View file

@ -125,26 +125,6 @@ class AlertHelper {
.show()
}
fun showOnlyInfoNewAlert(
context: Context,
onInfo: () -> Unit,
) {
val builder = Builder(context)
builder.setTitle(context.getString(R.string.select_action))
.setItems(
arrayOf<CharSequence>(
context.getString(R.string.action_info)
)
) { _: DialogInterface?, which: Int ->
when (which) {
1 -> onInfo()
}
}
.setNegativeButton(context.getString(R.string.action_cancel))
{ dialog: DialogInterface, which: Int -> dialog.dismiss() }
.show()
}
fun showDeleteAlert(context: Context, file: String, onConfirm: (() -> Unit)?) {
val builder = Builder(context)
builder.setTitle(context.getString(R.string.confirm_to_delete))