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,12 +94,20 @@ class FileColumn(val context: Context) {
fileList.clear()
val wfList = cwd.listFiles()?.map { WrappedFile(it) }
if (wfList != null) {
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

@ -87,7 +87,10 @@
<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="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="about">关于</string>
</resources>