feat: showExt -> hideExt

This commit is contained in:
Kagura 2024-10-11 21:29:51 +08:00
parent 56216de51b
commit f316a3c663
8 changed files with 112 additions and 92 deletions

View file

@ -16,7 +16,8 @@ import kotlinx.coroutines.runBlocking
val Context.settingStore: DataStore<Preferences> 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 <T> get(key: Preferences.Key<T>): T? =

View file

@ -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))

View file

@ -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

View file

@ -24,14 +24,14 @@ class DocumentModel(document: File) {
class DocumentAdapter(context: Context, list: ArrayList<DocumentModel>) :
ArrayAdapter<DocumentModel>(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<TextView>(R.id.iconButton)
card.text = if (showExtension != false) {
card.text = if (hideExtension == false) {
model.name
} else {
model.nameWithoutExt

View file

@ -32,14 +32,14 @@ class ImageModel(image: File) {
class ImageAdapter(context: Context, list: ArrayList<ImageModel>) :
ArrayAdapter<ImageModel>(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<ImageView>(R.id.pictureCardImage).setImageBitmap(model.thumbnail)
listView.findViewById<TextView>(R.id.pictureCardText).text = if (showExtension != false) {
listView.findViewById<TextView>(R.id.pictureCardText).text = if (hideExtension == false) {
model.name
} else {
model.nameWithoutExt

View file

@ -24,14 +24,14 @@ class MusicModel(music: File) {
class MusicAdapter(context: Context, list: ArrayList<MusicModel>) :
ArrayAdapter<MusicModel>(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<TextView>(R.id.iconButton)
card.text = if (showExtension != false) {
card.text = if (hideExtension == false) {
model.name
} else {
model.nameWithoutExt

View file

@ -35,14 +35,14 @@ class VideoModel(video: File) {
class VideoAdapter(context: Context, list: ArrayList<VideoModel>) :
ArrayAdapter<VideoModel>(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<ImageView>(R.id.pictureCardImage).setImageBitmap(model.thumbnail)
listView.findViewById<TextView>(R.id.pictureCardText).text = if (showExtension != false) {
listView.findViewById<TextView>(R.id.pictureCardText).text = if (hideExtension == false) {
model.name
} else {
model.nameWithoutExt

View file

@ -1,93 +1,96 @@
<resources>
<string name="app_name">文件管理器</string>
<string name="hello">文件管理器</string>
<string name="search">浏览</string>
<string name="edit">编辑</string>
<string name="picture">图片</string>
<string name="video">视频</string>
<string name="music">音乐</string>
<string name="document">文件</string>
<string name="app">其他</string>
<string name="location">位置</string>
<string name="store">内部存储</string>
<string name="delete">最近删除</string>
<string name="download">下载与接收</string>
<string name="source">来源</string>
<string name="internet">浏览器</string>
<string name="radio">录音机</string>
<string name="next">Next</string>
<string name="previous">Previous</string>
<string name="Delete">删除</string>
<string name="copy">复制</string>
<string name="cut">剪切</string>
<string name="paste">粘贴</string>
<string name="app_name">文件管理器</string>
<string name="hello">文件管理器</string>
<string name="search">浏览</string>
<string name="edit">编辑</string>
<string name="picture">图片</string>
<string name="video">视频</string>
<string name="music">音乐</string>
<string name="document">文件</string>
<string name="app">其他</string>
<string name="location">位置</string>
<string name="store">内部存储</string>
<string name="delete">最近删除</string>
<string name="download">下载与接收</string>
<string name="source">来源</string>
<string name="internet">浏览器</string>
<string name="radio">录音机</string>
<string name="next">Next</string>
<string name="previous">Previous</string>
<string name="Delete">删除</string>
<string name="copy">复制</string>
<string name="cut">剪切</string>
<string name="paste">粘贴</string>
<string name="title_activity_require_permission">RequirePermissionActivity</string>
<string name="title_activity_require_permission">RequirePermissionActivity</string>
<string name="require_permission_readwrite">需要读取/写入存储权限以继续</string>
<string name="require_manage_storage">需要管理存储权限以继续</string>
<string name="give_permission">授权</string>
<string name="require_permission_readwrite">需要读取/写入存储权限以继续</string>
<string name="require_manage_storage">需要管理存储权限以继续</string>
<string name="give_permission">授权</string>
<string name="used_storage_percentage">%d%%</string>
<string name="used_storage">已使用\n%s / %s</string>
<string name="used_storage_percentage">%d%%</string>
<string name="used_storage">已使用\n%s / %s</string>
<string name="loading">加载中</string>
<string name="loading">加载中</string>
<!-- Actions -->
<string name="select_action">选择操作</string>
<string name="action_copy">复制</string>
<string name="action_paste">粘贴</string>
<string name="action_delete">删除</string>
<string name="action_cut">剪切</string>
<string name="action_info">信息</string>
<string name="action_new_file">新建文件</string>
<string name="action_new_folder">新建文件夹</string>
<string name="action_cancel">取消</string>
<!-- Actions -->
<string name="select_action">选择操作</string>
<string name="action_copy">复制</string>
<string name="action_paste">粘贴</string>
<string name="action_delete">删除</string>
<string name="action_cut">剪切</string>
<string name="action_info">信息</string>
<string name="action_new_file">新建文件</string>
<string name="action_new_folder">新建文件夹</string>
<string name="action_cancel">取消</string>
<!-- Confirmations -->
<string name="confirm">确认</string>
<string name="okay">好的</string>
<string name="cancel">取消</string>
<string name="confirm_to_delete">确认删除</string>
<string name="confirm_to_delete_file">确认删除文件: %s</string>
<!-- Confirmations -->
<string name="confirm">确认</string>
<string name="okay">好的</string>
<string name="cancel">取消</string>
<string name="confirm_to_delete">确认删除</string>
<string name="confirm_to_delete_file">确认删除文件: %s</string>
<string name="file_info">文件信息</string>
<string name="file_info_text">
<string name="file_info">文件信息</string>
<string name="file_info_text">
文件名:%s\n
路径:%s\n
大小:%s\n
最后修改时间:%s
</string>
<string name="advanced">查看什么</string>
<string name="settings">软件设置</string>
<string name="all_files">全部文件</string>
<string name="storage_info">内部存储信息</string>
<string name="advanced">查看什么</string>
<string name="settings">软件设置</string>
<string name="all_files">全部文件</string>
<string name="storage_info">内部存储信息</string>
<string name="camera">相机</string>
<string name="pictures">公用图片</string>
<string name="documents">公用文档</string>
<string name="prev_folder">上一级目录</string>
<string name="camera">相机</string>
<string name="pictures">公用图片</string>
<string name="documents">公用文档</string>
<string name="prev_folder">上一级目录</string>
<string name="input_name">请输入名称</string>
<string name="create_directory">将在 %s 创建文件夹</string>
<string name="create_file">将在 %s 创建文件</string>
<string name="input_name">请输入名称</string>
<string name="create_directory">将在 %s 创建文件夹</string>
<string name="create_file">将在 %s 创建文件</string>
<string name="error_nothing_to_paste">未找到可粘贴的内容</string>
<string name="error_need_input_name">请输入名称</string>
<string name="error_already_exist">已存在此文件(夹)</string>
<string name="title_activity_view_file">ViewFileActivity</string>
<string name="title_activity_search">SearchActivity</string>
<string name="search_result">搜索%s结果</string>
<string name="error_need_search_input">请输入要搜索的内容</string>
<string name="error_search_input_illegal">输入的搜索内容不合法</string>
<string name="search_file">搜索文件</string>
<string name="search_no_result">未找到任何结果</string>
<string name="search_some_result">找到%d个结果</string>
<string name="sort_by_size">已选择按大小排序</string>
<string name="sort_by_time">已选择按时间排序</string>
<string name="title_activity_setting">SettingActivity</string>
<string name="setting_hide_extension">隐藏扩展名</string>
<string name="setting_hide_extension_description">如果打开,则会显示文件名 abc.efg否则显示文件全名 abc.efg.txt</string>
<string name="setting_hide_hidden_file">隐藏点文件</string>
<string name="setting_hide_hidden_file_description">隐藏所有以 . 开头的文件和文件夹\n. 开头的文件(或文件夹)通常表示隐藏文件(或文件夹)\n此选项只对查看全部文件功能有效</string>
<string name="error_nothing_to_paste">未找到可粘贴的内容</string>
<string name="error_need_input_name">请输入名称</string>
<string name="error_already_exist">已存在此文件(夹)</string>
<string name="title_activity_view_file">ViewFileActivity</string>
<string name="title_activity_search">SearchActivity</string>
<string name="search_result">搜索%s结果</string>
<string name="error_need_search_input">请输入要搜索的内容</string>
<string name="error_search_input_illegal">输入的搜索内容不合法</string>
<string name="search_file">搜索文件</string>
<string name="search_no_result">未找到任何结果</string>
<string name="search_some_result">找到%d个结果</string>
<string name="sort_by_size">已选择按大小排序</string>
<string name="sort_by_time">已选择按时间排序</string>
<string name="title_activity_setting">SettingActivity</string>
<string name="setting_show_extension">显示扩展名</string>
<string name="setting_show_extension_description">如果打开,则会显示 abc.txt否则只显示 abc</string>
<string name="about">关于</string>
</resources>