feat: showExt -> hideExt
This commit is contained in:
parent
56216de51b
commit
f316a3c663
8 changed files with 112 additions and 92 deletions
|
@ -16,7 +16,8 @@ import kotlinx.coroutines.runBlocking
|
||||||
val Context.settingStore: DataStore<Preferences> by preferencesDataStore(name = "app_settings")
|
val Context.settingStore: DataStore<Preferences> by preferencesDataStore(name = "app_settings")
|
||||||
|
|
||||||
class SettingStorage(private val context: Context) {
|
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? =
|
fun <T> get(key: Preferences.Key<T>): T? =
|
||||||
|
|
|
@ -99,14 +99,22 @@ class SettingActivity : ComponentActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
setting.BooleanSetting(
|
setting.BooleanSetting(
|
||||||
name = ContextCompat.getString(context, R.string.setting_show_extension),
|
name = ContextCompat.getString(context, R.string.setting_hide_extension),
|
||||||
description = ContextCompat.getString(
|
description = ContextCompat.getString(
|
||||||
context,
|
context,
|
||||||
R.string.setting_show_extension_description
|
R.string.setting_hide_extension_description
|
||||||
),
|
),
|
||||||
initialState = settingStorage.get(settingStorage.showExtension) ?: true
|
initialState = settingStorage.get(settingStorage.hideExtension) ?: false
|
||||||
) { settingStorage.set(settingStorage.showExtension, it) }
|
) { 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))
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
|
||||||
|
|
|
@ -94,12 +94,20 @@ class FileColumn(val context: Context) {
|
||||||
fileList.clear()
|
fileList.clear()
|
||||||
val wfList = cwd.listFiles()?.map { WrappedFile(it) }
|
val wfList = cwd.listFiles()?.map { WrappedFile(it) }
|
||||||
if (wfList != null) {
|
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) {
|
if (sortByTime) {
|
||||||
fileList.addAll(wfList.sortedBy { it.lastModifiedTime })
|
fileList.addAll(wfList.sortedBy { it.lastModifiedTime })
|
||||||
} else {
|
} else {
|
||||||
fileList.addAll(wfList.sortedBy { it.size })
|
fileList.addAll(wfList.sortedBy { it.size })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
isOkay = true
|
isOkay = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,7 +537,7 @@ class FileColumn(val context: Context) {
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = forceName
|
text = forceName
|
||||||
?: if (settingStorage.get(settingStorage.showExtension) == false && !file.name.startsWith('.')) {
|
?: if (settingStorage.get(settingStorage.hideExtension) == true && !file.name.startsWith('.')) {
|
||||||
file.nameWithoutExt
|
file.nameWithoutExt
|
||||||
} else {
|
} else {
|
||||||
file.name
|
file.name
|
||||||
|
|
|
@ -24,14 +24,14 @@ class DocumentModel(document: File) {
|
||||||
class DocumentAdapter(context: Context, list: ArrayList<DocumentModel>) :
|
class DocumentAdapter(context: Context, list: ArrayList<DocumentModel>) :
|
||||||
ArrayAdapter<DocumentModel>(context, 0, list) {
|
ArrayAdapter<DocumentModel>(context, 0, list) {
|
||||||
private val settingStorage = SettingStorage(context)
|
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 {
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
val listView = convertView ?: LayoutInflater.from(context).inflate(
|
val listView = convertView ?: LayoutInflater.from(context).inflate(
|
||||||
R.layout.document_card_item, parent, false
|
R.layout.document_card_item, parent, false
|
||||||
)
|
)
|
||||||
val model = getItem(position) ?: throw RuntimeException()
|
val model = getItem(position) ?: throw RuntimeException()
|
||||||
val card = listView.findViewById<TextView>(R.id.iconButton)
|
val card = listView.findViewById<TextView>(R.id.iconButton)
|
||||||
card.text = if (showExtension != false) {
|
card.text = if (hideExtension == false) {
|
||||||
model.name
|
model.name
|
||||||
} else {
|
} else {
|
||||||
model.nameWithoutExt
|
model.nameWithoutExt
|
||||||
|
|
|
@ -32,14 +32,14 @@ class ImageModel(image: File) {
|
||||||
class ImageAdapter(context: Context, list: ArrayList<ImageModel>) :
|
class ImageAdapter(context: Context, list: ArrayList<ImageModel>) :
|
||||||
ArrayAdapter<ImageModel>(context, 0, list) {
|
ArrayAdapter<ImageModel>(context, 0, list) {
|
||||||
private val settingStorage = SettingStorage(context)
|
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 {
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
val listView = convertView ?: LayoutInflater.from(context).inflate(
|
val listView = convertView ?: LayoutInflater.from(context).inflate(
|
||||||
R.layout.picture_card_item, parent, false
|
R.layout.picture_card_item, parent, false
|
||||||
)
|
)
|
||||||
val model = getItem(position) ?: throw RuntimeException()
|
val model = getItem(position) ?: throw RuntimeException()
|
||||||
listView.findViewById<ImageView>(R.id.pictureCardImage).setImageBitmap(model.thumbnail)
|
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
|
model.name
|
||||||
} else {
|
} else {
|
||||||
model.nameWithoutExt
|
model.nameWithoutExt
|
||||||
|
|
|
@ -24,14 +24,14 @@ class MusicModel(music: File) {
|
||||||
class MusicAdapter(context: Context, list: ArrayList<MusicModel>) :
|
class MusicAdapter(context: Context, list: ArrayList<MusicModel>) :
|
||||||
ArrayAdapter<MusicModel>(context, 0, list) {
|
ArrayAdapter<MusicModel>(context, 0, list) {
|
||||||
private val settingStorage = SettingStorage(context)
|
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 {
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
val listView = convertView ?: LayoutInflater.from(context).inflate(
|
val listView = convertView ?: LayoutInflater.from(context).inflate(
|
||||||
R.layout.music_card_item, parent, false
|
R.layout.music_card_item, parent, false
|
||||||
)
|
)
|
||||||
val model = getItem(position) ?: throw RuntimeException()
|
val model = getItem(position) ?: throw RuntimeException()
|
||||||
val card = listView.findViewById<TextView>(R.id.iconButton)
|
val card = listView.findViewById<TextView>(R.id.iconButton)
|
||||||
card.text = if (showExtension != false) {
|
card.text = if (hideExtension == false) {
|
||||||
model.name
|
model.name
|
||||||
} else {
|
} else {
|
||||||
model.nameWithoutExt
|
model.nameWithoutExt
|
||||||
|
|
|
@ -35,14 +35,14 @@ class VideoModel(video: File) {
|
||||||
class VideoAdapter(context: Context, list: ArrayList<VideoModel>) :
|
class VideoAdapter(context: Context, list: ArrayList<VideoModel>) :
|
||||||
ArrayAdapter<VideoModel>(context, 0, list) {
|
ArrayAdapter<VideoModel>(context, 0, list) {
|
||||||
private val settingStorage = SettingStorage(context)
|
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 {
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
val listView = convertView ?: LayoutInflater.from(context).inflate(
|
val listView = convertView ?: LayoutInflater.from(context).inflate(
|
||||||
R.layout.picture_card_item, parent, false
|
R.layout.picture_card_item, parent, false
|
||||||
)
|
)
|
||||||
val model = getItem(position) ?: throw RuntimeException()
|
val model = getItem(position) ?: throw RuntimeException()
|
||||||
listView.findViewById<ImageView>(R.id.pictureCardImage).setImageBitmap(model.thumbnail)
|
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
|
model.name
|
||||||
} else {
|
} else {
|
||||||
model.nameWithoutExt
|
model.nameWithoutExt
|
||||||
|
|
|
@ -87,7 +87,10 @@
|
||||||
<string name="sort_by_size">已选择按大小排序</string>
|
<string name="sort_by_size">已选择按大小排序</string>
|
||||||
<string name="sort_by_time">已选择按时间排序</string>
|
<string name="sort_by_time">已选择按时间排序</string>
|
||||||
<string name="title_activity_setting">SettingActivity</string>
|
<string name="title_activity_setting">SettingActivity</string>
|
||||||
<string name="setting_show_extension">显示扩展名</string>
|
<string name="setting_hide_extension">隐藏扩展名</string>
|
||||||
<string name="setting_show_extension_description">如果打开,则会显示 abc.txt,否则只显示 abc</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>
|
<string name="about">关于</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in a new issue