可以保存文件排序方式了

This commit is contained in:
coldmint 2022-07-30 21:53:14 +08:00
parent e1c2b55a1c
commit e06508994d
9 changed files with 46 additions and 0 deletions

Binary file not shown.

View File

@ -923,6 +923,22 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
if (value != null) {
setSortType(value)
}
menuBinding.actionSortByType.setOnMenuItemClickListener {
viewModel.sortTypeLiveData.value = FileManagerViewModel.SortType.BY_TYPE
true
}
menuBinding.actionSortByName.setOnMenuItemClickListener {
viewModel.sortTypeLiveData.value = FileManagerViewModel.SortType.BY_NAME
true
}
menuBinding.actionSortBySize.setOnMenuItemClickListener {
viewModel.sortTypeLiveData.value = FileManagerViewModel.SortType.BY_SIZE
true
}
menuBinding.actionSortByLastModified.setOnMenuItemClickListener {
viewModel.sortTypeLiveData.value = FileManagerViewModel.SortType.BY_LAST_MODIFIED
true
}
return true
}
@ -992,6 +1008,7 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
}
adapter?.setSort(sortType)
viewModel.loadFiles(viewModel.getCurrentPath())
viewModel.saveSortType(this)
}
}

View File

@ -78,6 +78,35 @@ class FileManagerViewModel : BaseViewModel() {
}
}
/**
* 保存排序值到设置
* @param context Context
* @return Boolean
*/
fun saveSortType(context: Context):Boolean {
val appSettings = AppSettings.getInstance(context)
val value =
sortTypeLiveData.value ?: SortType.BY_NAME
val text = when (value) {
SortType.BY_NAME -> {
context.getString(R.string.setting_file_list_action_sort_by_name)
}
SortType.BY_LAST_MODIFIED -> {
context.getString(R.string.setting_file_list_action_sort_by_last_modified)
}
SortType.BY_SIZE -> {
context.getString(R.string.setting_file_list_action_sort_by_size)
}
SortType.BY_TYPE -> {
context.getString(R.string.setting_file_list_action_sort_by_type)
}
else -> {
context.getString(R.string.setting_file_list_action_sort_by_name)
}
}
return appSettings.setValue(AppSettings.Setting.FileSortType,text)
}
/**
* 获取当前打开的目录
* @return String