feat(common/config): filename filter
This commit is contained in:
@@ -95,8 +95,10 @@ class RemoteFileHandleManager(
|
||||
}
|
||||
}
|
||||
|
||||
fun getStoredFiles(): List<File> {
|
||||
return userImportFolder.listFiles()?.toList()?.sortedBy { -it.lastModified() } ?: emptyList()
|
||||
fun getStoredFiles(filter: ((File) -> Boolean)? = null): List<File> {
|
||||
return userImportFolder.listFiles()?.toList()?.let { files ->
|
||||
filter?.let { files.filter(it) } ?: files
|
||||
}?.sortedBy { -it.lastModified() } ?: emptyList()
|
||||
}
|
||||
|
||||
fun getFileInfo(name: String): Pair<Long, Long>? {
|
||||
|
||||
@@ -154,10 +154,20 @@ class FeaturesRoot : Routes.Route() {
|
||||
if (property.key.params.flags.contains(ConfigFlag.USER_IMPORT)) {
|
||||
registerDialogOnClickCallback()
|
||||
dialogComposable = {
|
||||
var isEmpty by remember { mutableStateOf(false) }
|
||||
val files = rememberAsyncMutableStateList(defaultValue = listOf()) {
|
||||
context.fileHandleManager.getStoredFiles()
|
||||
context.fileHandleManager.getStoredFiles {
|
||||
property.key.params.filenameFilter?.invoke(it.name) == true
|
||||
}.also {
|
||||
isEmpty = it.isEmpty()
|
||||
if (isEmpty) {
|
||||
propertyValue.setAny(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
var selectedFile by remember(files.size) { mutableStateOf(files.firstOrNull { it.name == propertyValue.getNullable() }?.name) }
|
||||
var selectedFile by remember(files.size) { mutableStateOf(files.firstOrNull { it.name == propertyValue.getNullable() }.also {
|
||||
if (files.isNotEmpty() && it == null) propertyValue.setAny(null)
|
||||
}?.name) }
|
||||
|
||||
Card(
|
||||
shape = MaterialTheme.shapes.large,
|
||||
@@ -177,7 +187,7 @@ class FeaturesRoot : Routes.Route() {
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
)
|
||||
if (files.isEmpty()) {
|
||||
if (isEmpty) {
|
||||
Text(
|
||||
text = context.translation["manager.dialogs.file_imports.no_files_settings_hint"],
|
||||
fontSize = 16.sp,
|
||||
|
||||
@@ -43,6 +43,7 @@ class ConfigParams(
|
||||
var customTranslationPath: String? = null,
|
||||
var customOptionTranslationPath: String? = null,
|
||||
var inputCheck: ((String) -> Boolean)? = { true },
|
||||
var filenameFilter: ((String) -> Boolean)? = null,
|
||||
) {
|
||||
val notices get() = _notices?.let { FeatureNotice.entries.filter { flag -> it and flag.id != 0 } } ?: emptyList()
|
||||
val flags get() = _flags?.let { ConfigFlag.entries.filter { flag -> it and flag.id != 0 } } ?: emptyList()
|
||||
|
||||
Reference in New Issue
Block a user