Skip to content

Commit

Permalink
fix bug and clean up SearchParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
seelchen committed Jan 12, 2024
1 parent 2d1a9a3 commit f56d313
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ package com.amaze.filemanager.asynchronous.asynctasks.searchfilesystem
import java.util.EnumSet

typealias SearchParameters = EnumSet<SearchParameter>
infix fun SearchParameters.allOf(other: SearchParameters) = this.containsAll(other)
infix fun SearchParameters.and(other: SearchParameter): SearchParameters = SearchParameters.of(
other,
*this.toTypedArray()
)
operator fun SearchParameters.plus(other: SearchParameter): SearchParameters = this and other

fun searchParametersFromBoolean(
showHiddenFiles: Boolean,
isRegexEnabled: Boolean,
isRegexMatchesEnabled: Boolean,
isRoot: Boolean
showHiddenFiles: Boolean = false,
isRegexEnabled: Boolean = false,
isRegexMatchesEnabled: Boolean = false,
isRoot: Boolean = false
): SearchParameters {
val searchParameterList = mutableListOf<SearchParameter>()

Expand All @@ -43,5 +42,9 @@ fun searchParametersFromBoolean(
if (isRegexMatchesEnabled) searchParameterList.add(SearchParameter.REGEX_MATCHES)
if (isRoot) searchParameterList.add(SearchParameter.ROOT)

return SearchParameters.copyOf(searchParameterList)
return if (searchParameterList.isEmpty()) {
SearchParameters.noneOf(SearchParameter::class.java)
} else {
SearchParameters.copyOf(searchParameterList)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,11 @@ class MainActivityViewModel(val applicationContext: Application) :
query: String
): MutableLiveData<ArrayList<HybridFileParcelable>> {
val sharedPref = PreferenceManager.getDefaultSharedPreferences(mainActivity)
val showHiddenFiles = sharedPref.getBoolean(PREFERENCE_SHOW_HIDDENFILES, false)
val isRegexEnabled = sharedPref.getBoolean(PREFERENCE_REGEX, false)
val isMatchesEnabled = sharedPref.getBoolean(PREFERENCE_REGEX_MATCHES, false)
val isRoot = mainActivity.isRootExplorer
val searchParameters = searchParametersFromBoolean(
showHiddenFiles,
isRegexEnabled,
isMatchesEnabled,
isRoot
showHiddenFiles = sharedPref.getBoolean(PREFERENCE_SHOW_HIDDENFILES, false),
isRegexEnabled = sharedPref.getBoolean(PREFERENCE_REGEX, false),
isRegexMatchesEnabled = sharedPref.getBoolean(PREFERENCE_REGEX_MATCHES, false),
isRoot = mainActivity.isRootExplorer
)

val path = mainActivity.currentMainFragment?.currentPath ?: ""
Expand Down

0 comments on commit f56d313

Please sign in to comment.