diff --git a/app/src/main/java/com/example/myapplication/SettingStorage.kt b/app/src/main/java/com/example/myapplication/SettingStorage.kt index 087ca38..d342ba3 100644 --- a/app/src/main/java/com/example/myapplication/SettingStorage.kt +++ b/app/src/main/java/com/example/myapplication/SettingStorage.kt @@ -16,7 +16,8 @@ import kotlinx.coroutines.runBlocking val Context.settingStore: DataStore by preferencesDataStore(name = "app_settings") class SettingStorage(private val context: Context) { - val showExtension = booleanPreferencesKey("show_extension") + val hideExtension = booleanPreferencesKey("hide_extension") + val hideHiddenFile = booleanPreferencesKey("hide_hidden_file") fun get(key: Preferences.Key): T? = diff --git a/app/src/main/java/com/example/myapplication/compose/SettingActivity.kt b/app/src/main/java/com/example/myapplication/compose/SettingActivity.kt index c628336..7a635bf 100644 --- a/app/src/main/java/com/example/myapplication/compose/SettingActivity.kt +++ b/app/src/main/java/com/example/myapplication/compose/SettingActivity.kt @@ -99,14 +99,22 @@ class SettingActivity : ComponentActivity() { } setting.BooleanSetting( - name = ContextCompat.getString(context, R.string.setting_show_extension), + name = ContextCompat.getString(context, R.string.setting_hide_extension), description = ContextCompat.getString( context, - R.string.setting_show_extension_description + R.string.setting_hide_extension_description ), - initialState = settingStorage.get(settingStorage.showExtension) ?: true - ) { settingStorage.set(settingStorage.showExtension, it) } + initialState = settingStorage.get(settingStorage.hideExtension) ?: false + ) { settingStorage.set(settingStorage.hideExtension, it) } + setting.BooleanSetting( + name = ContextCompat.getString(context, R.string.setting_hide_hidden_file), + description = ContextCompat.getString( + context, + R.string.setting_hide_hidden_file_description + ), + initialState = settingStorage.get(settingStorage.hideHiddenFile) ?: false + ) { settingStorage.set(settingStorage.hideHiddenFile, it) } Spacer(modifier = Modifier.weight(1f)) diff --git a/app/src/main/java/com/example/myapplication/compose/ui/FileColumn.kt b/app/src/main/java/com/example/myapplication/compose/ui/FileColumn.kt index 73d0c26..adac3c9 100644 --- a/app/src/main/java/com/example/myapplication/compose/ui/FileColumn.kt +++ b/app/src/main/java/com/example/myapplication/compose/ui/FileColumn.kt @@ -94,10 +94,18 @@ class FileColumn(val context: Context) { fileList.clear() val wfList = cwd.listFiles()?.map { WrappedFile(it) } if (wfList != null) { - if (sortByTime) { - fileList.addAll(wfList.sortedBy { it.lastModifiedTime }) - } else { - fileList.addAll(wfList.sortedBy { it.size }) + if (settingStorage.get(settingStorage.hideHiddenFile) == true) { // 隐藏点文件,默认 false + if (sortByTime) { + fileList.addAll(wfList.sortedBy { it.lastModifiedTime }.filter { !it.name.startsWith('.') }) + } else { + fileList.addAll(wfList.sortedBy { it.size }.filter { !it.name.startsWith('.') }) + } + }else{ + if (sortByTime) { + fileList.addAll(wfList.sortedBy { it.lastModifiedTime }) + } else { + fileList.addAll(wfList.sortedBy { it.size }) + } } } isOkay = true @@ -529,7 +537,7 @@ class FileColumn(val context: Context) { ) { Text( text = forceName - ?: if (settingStorage.get(settingStorage.showExtension) == false && !file.name.startsWith('.')) { + ?: if (settingStorage.get(settingStorage.hideExtension) == true && !file.name.startsWith('.')) { file.nameWithoutExt } else { file.name diff --git a/app/src/main/java/com/example/myapplication/fileSystem/adapters/Document.kt b/app/src/main/java/com/example/myapplication/fileSystem/adapters/Document.kt index d0b5fed..0fd231d 100644 --- a/app/src/main/java/com/example/myapplication/fileSystem/adapters/Document.kt +++ b/app/src/main/java/com/example/myapplication/fileSystem/adapters/Document.kt @@ -24,14 +24,14 @@ class DocumentModel(document: File) { class DocumentAdapter(context: Context, list: ArrayList) : ArrayAdapter(context, 0, list) { private val settingStorage = SettingStorage(context) - private val showExtension = settingStorage.get(settingStorage.showExtension) + private val hideExtension = settingStorage.get(settingStorage.hideExtension) override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { val listView = convertView ?: LayoutInflater.from(context).inflate( R.layout.document_card_item, parent, false ) val model = getItem(position) ?: throw RuntimeException() val card = listView.findViewById(R.id.iconButton) - card.text = if (showExtension != false) { + card.text = if (hideExtension == false) { model.name } else { model.nameWithoutExt diff --git a/app/src/main/java/com/example/myapplication/fileSystem/adapters/Image.kt b/app/src/main/java/com/example/myapplication/fileSystem/adapters/Image.kt index aeb12bf..e9f8de7 100644 --- a/app/src/main/java/com/example/myapplication/fileSystem/adapters/Image.kt +++ b/app/src/main/java/com/example/myapplication/fileSystem/adapters/Image.kt @@ -32,14 +32,14 @@ class ImageModel(image: File) { class ImageAdapter(context: Context, list: ArrayList) : ArrayAdapter(context, 0, list) { private val settingStorage = SettingStorage(context) - private val showExtension = settingStorage.get(settingStorage.showExtension) + private val hideExtension = settingStorage.get(settingStorage.hideExtension) override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { val listView = convertView ?: LayoutInflater.from(context).inflate( R.layout.picture_card_item, parent, false ) val model = getItem(position) ?: throw RuntimeException() listView.findViewById(R.id.pictureCardImage).setImageBitmap(model.thumbnail) - listView.findViewById(R.id.pictureCardText).text = if (showExtension != false) { + listView.findViewById(R.id.pictureCardText).text = if (hideExtension == false) { model.name } else { model.nameWithoutExt diff --git a/app/src/main/java/com/example/myapplication/fileSystem/adapters/Music.kt b/app/src/main/java/com/example/myapplication/fileSystem/adapters/Music.kt index 5b5515f..7ca0b59 100644 --- a/app/src/main/java/com/example/myapplication/fileSystem/adapters/Music.kt +++ b/app/src/main/java/com/example/myapplication/fileSystem/adapters/Music.kt @@ -24,14 +24,14 @@ class MusicModel(music: File) { class MusicAdapter(context: Context, list: ArrayList) : ArrayAdapter(context, 0, list) { private val settingStorage = SettingStorage(context) - private val showExtension = settingStorage.get(settingStorage.showExtension) + private val hideExtension = settingStorage.get(settingStorage.hideExtension) override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { val listView = convertView ?: LayoutInflater.from(context).inflate( R.layout.music_card_item, parent, false ) val model = getItem(position) ?: throw RuntimeException() val card = listView.findViewById(R.id.iconButton) - card.text = if (showExtension != false) { + card.text = if (hideExtension == false) { model.name } else { model.nameWithoutExt diff --git a/app/src/main/java/com/example/myapplication/fileSystem/adapters/Video.kt b/app/src/main/java/com/example/myapplication/fileSystem/adapters/Video.kt index 6fe664b..83ca763 100644 --- a/app/src/main/java/com/example/myapplication/fileSystem/adapters/Video.kt +++ b/app/src/main/java/com/example/myapplication/fileSystem/adapters/Video.kt @@ -35,14 +35,14 @@ class VideoModel(video: File) { class VideoAdapter(context: Context, list: ArrayList) : ArrayAdapter(context, 0, list) { private val settingStorage = SettingStorage(context) - private val showExtension = settingStorage.get(settingStorage.showExtension) + private val hideExtension = settingStorage.get(settingStorage.hideExtension) override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { val listView = convertView ?: LayoutInflater.from(context).inflate( R.layout.picture_card_item, parent, false ) val model = getItem(position) ?: throw RuntimeException() listView.findViewById(R.id.pictureCardImage).setImageBitmap(model.thumbnail) - listView.findViewById(R.id.pictureCardText).text = if (showExtension != false) { + listView.findViewById(R.id.pictureCardText).text = if (hideExtension == false) { model.name } else { model.nameWithoutExt diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 93df3ae..5b21fb0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,93 +1,96 @@ - 文件管理器 - 文件管理器 - 浏览 - 编辑 - 图片 - 视频 - 音乐 - 文件 - 其他 - 位置 - 内部存储 - 最近删除 - 下载与接收 - 来源 - 浏览器 - 录音机 - Next - Previous - 删除 - 复制 - 剪切 - 粘贴 + 文件管理器 + 文件管理器 + 浏览 + 编辑 + 图片 + 视频 + 音乐 + 文件 + 其他 + 位置 + 内部存储 + 最近删除 + 下载与接收 + 来源 + 浏览器 + 录音机 + Next + Previous + 删除 + 复制 + 剪切 + 粘贴 - RequirePermissionActivity + RequirePermissionActivity - 需要读取/写入存储权限以继续 - 需要管理存储权限以继续 - 授权 + 需要读取/写入存储权限以继续 + 需要管理存储权限以继续 + 授权 - %d%% - 已使用\n%s / %s + %d%% + 已使用\n%s / %s - 加载中 + 加载中 - - 选择操作 - 复制 - 粘贴 - 删除 - 剪切 - 信息 - 新建文件 - 新建文件夹 - 取消 + + 选择操作 + 复制 + 粘贴 + 删除 + 剪切 + 信息 + 新建文件 + 新建文件夹 + 取消 - - 确认 - 好的 - 取消 - 确认删除 - 确认删除文件: %s + + 确认 + 好的 + 取消 + 确认删除 + 确认删除文件: %s - 文件信息 - + 文件信息 + 文件名:%s\n 路径:%s\n 大小:%s\n 最后修改时间:%s - 查看什么 - 软件设置 - 全部文件 - 内部存储信息 + 查看什么 + 软件设置 + 全部文件 + 内部存储信息 - 相机 - 公用图片 - 公用文档 - 上一级目录 + 相机 + 公用图片 + 公用文档 + 上一级目录 - 请输入名称 - 将在 %s 创建文件夹 - 将在 %s 创建文件 + 请输入名称 + 将在 %s 创建文件夹 + 将在 %s 创建文件 + + 未找到可粘贴的内容 + 请输入名称 + 已存在此文件(夹) + ViewFileActivity + SearchActivity + 搜索%s结果 + 请输入要搜索的内容 + 输入的搜索内容不合法 + 搜索文件 + 未找到任何结果 + 找到%d个结果 + 已选择按大小排序 + 已选择按时间排序 + SettingActivity + 隐藏扩展名 + 如果打开,则会显示文件名 abc.efg,否则显示文件全名 abc.efg.txt + 隐藏点文件 + 隐藏所有以 . 开头的文件和文件夹\n. 开头的文件(或文件夹)通常表示隐藏文件(或文件夹)\n此选项只对查看全部文件功能有效 - 未找到可粘贴的内容 - 请输入名称 - 已存在此文件(夹) - ViewFileActivity - SearchActivity - 搜索%s结果 - 请输入要搜索的内容 - 输入的搜索内容不合法 - 搜索文件 - 未找到任何结果 - 找到%d个结果 - 已选择按大小排序 - 已选择按时间排序 - SettingActivity - 显示扩展名 - 如果打开,则会显示 abc.txt,否则只显示 abc 关于 \ No newline at end of file