Skip to content

Commit

Permalink
Search with regular expression #175
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Jamet committed Feb 5, 2022
1 parent ee9b072 commit 7697713
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
KeePassDX(3.3.0)
* Quick search and dynamic filters #163 #462 #521
* Keep search context #1141
* Search with regular expression #175

KeePassDX(3.2.0)
* Manage data merge #840 #977
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,21 @@ class SearchHelper {
private fun checkSearchQuery(stringToCheck: String, searchParameters: SearchParameters): Boolean {
/*
// TODO Search settings
var regularExpression = false
var removeAccents = true <- Too much time, to study
*/
return stringToCheck.isNotEmpty()
&& stringToCheck.contains(
searchParameters.searchQuery, !searchParameters.caseSensitive)
if (stringToCheck.isEmpty())
return false
return if (searchParameters.isRegex) {
val regex = if (searchParameters.caseSensitive) {
searchParameters.searchQuery.toRegex(RegexOption.DOT_MATCHES_ALL)
} else {
searchParameters.searchQuery
.toRegex(setOf(RegexOption.DOT_MATCHES_ALL, RegexOption.IGNORE_CASE))
}
regex.matches(stringToCheck)
} else {
stringToCheck.contains(searchParameters.searchQuery, !searchParameters.caseSensitive)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import android.os.Parcelable
class SearchParameters() : Parcelable{
var searchQuery: String = ""
var caseSensitive = false
var isRegex = false

var searchInTitles = true
var searchInUsernames = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SearchFiltersView @JvmOverloads constructor(context: Context,
private var searchNumbers: TextView
private var searchCurrentGroup: CompoundButton
private var searchCaseSensitive: CompoundButton
private var searchRegex: CompoundButton
private var searchTitle: CompoundButton
private var searchUsername: CompoundButton
private var searchPassword: CompoundButton
Expand All @@ -41,6 +42,7 @@ class SearchFiltersView @JvmOverloads constructor(context: Context,
return field.apply {
this.searchInCurrentGroup = searchCurrentGroup.isChecked
this.caseSensitive = searchCaseSensitive.isChecked
this.isRegex = searchRegex.isChecked
this.searchInTitles = searchTitle.isChecked
this.searchInUsernames = searchUsername.isChecked
this.searchInPasswords = searchPassword.isChecked
Expand All @@ -60,6 +62,7 @@ class SearchFiltersView @JvmOverloads constructor(context: Context,
mOnParametersChangeListener = null
searchCurrentGroup.isChecked = value.searchInCurrentGroup
searchCaseSensitive.isChecked = value.caseSensitive
searchRegex.isChecked = value.isRegex
searchTitle.isChecked = value.searchInTitles
searchUsername.isChecked = value.searchInUsernames
searchPassword.isChecked = value.searchInPasswords
Expand Down Expand Up @@ -96,6 +99,7 @@ class SearchFiltersView @JvmOverloads constructor(context: Context,
searchNumbers = findViewById(R.id.search_numbers)
searchCurrentGroup = findViewById(R.id.search_chip_current_group)
searchCaseSensitive = findViewById(R.id.search_chip_case_sensitive)
searchRegex = findViewById(R.id.search_chip_regex)
searchTitle = findViewById(R.id.search_chip_title)
searchUsername = findViewById(R.id.search_chip_username)
searchPassword = findViewById(R.id.search_chip_password)
Expand Down Expand Up @@ -125,6 +129,10 @@ class SearchFiltersView @JvmOverloads constructor(context: Context,
searchParameters.caseSensitive = isChecked
mOnParametersChangeListener?.invoke(searchParameters)
}
searchRegex.setOnCheckedChangeListener { _, isChecked ->
searchParameters.isRegex = isChecked
mOnParametersChangeListener?.invoke(searchParameters)
}
searchTitle.setOnCheckedChangeListener { _, isChecked ->
searchParameters.searchInTitles = isChecked
mOnParametersChangeListener?.invoke(searchParameters)
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_regex_white_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group>
<path
android:fillColor="#ffffff"
android:pathData="M 4.3105469,5.0878906 a 0.9014779,0.9014779 0 0 0 -0.00586,0.00195 0.9014779,0.9014779 0 0 0 -0.6679687,0.3671874 c -1.6307378,2.1650454 -2.540913,4.467681 -2.5664063,6.853516 -0.025422,2.385835 0.8330899,4.807465 2.5527344,7.212891 a 0.90239526,0.90239526 0 0 0 1.46875,-1.048829 C 3.5374502,16.300396 2.8522647,14.272141 2.8730469,12.328125 2.8938469,10.384107 3.6199739,8.4788746 5.078125,6.5429688 A 0.9014779,0.9014779 0 0 0 4.3105469,5.0878906 Z m 15.2246091,0 a 0.9014779,0.9014779 0 0 0 -0.08984,0.00195 0.9014779,0.9014779 0 0 0 -0.658203,1.453125 c 1.458152,1.9359058 2.184296,3.8411384 2.205079,5.7851564 0.0208,1.944016 -0.664404,3.972271 -2.21875,6.146484 a 0.90239526,0.90239526 0 1 0 1.46875,1.048829 c 1.719644,-2.405426 2.576274,-4.827056 2.550781,-7.212891 C 22.767547,9.9247122 21.8573,7.6220766 20.226562,5.4570312 A 0.9014779,0.9014779 0 0 0 19.535156,5.0878906 Z m -5.050781,1.0292969 a 0.40003999,0.40003999 0 0 0 -0.353516,0.2695313 l -0.833984,2.4628906 -2.597656,0.03125 a 0.40003999,0.40003999 0 0 0 -0.236328,0.71875 l 2.08789,1.5527346 -0.77539,2.478515 a 0.40003999,0.40003999 0 0 0 0.611328,0.447266 l 2.121093,-1.503906 2.119141,1.503906 a 0.40003999,0.40003999 0 0 0 0.615235,-0.447266 l -0.775391,-2.478515 2.083984,-1.5527346 a 0.40003999,0.40003999 0 0 0 -0.232422,-0.71875 L 15.716797,8.8496094 14.886719,6.3867188 A 0.40003999,0.40003999 0 0 0 14.484375,6.1171875 Z M 10,16 a 2,2 0 0 0 -2,2 2,2 0 0 0 2,2 2,2 0 0 0 2,-2 2,2 0 0 0 -2,-2 z" />
</group>
</vector>
8 changes: 8 additions & 0 deletions app/src/main/res/layout/view_search_filters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@
style="@style/KeepassDXStyle.Chip.Filter.Icon"
android:text="@string/case_sensitive"
app:closeIcon="@drawable/ic_case_sensitive_white_24dp" />
<com.google.android.material.chip.Chip
android:id="@+id/search_chip_regex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
style="@style/KeepassDXStyle.Chip.Filter.Icon"
android:text="@string/regex"
app:closeIcon="@drawable/ic_regex_white_24dp" />
</com.google.android.material.chip.ChipGroup>
</LinearLayout>
</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<string name="otp_algorithm">Algorithm</string>
<string name="current_group">Current group</string>
<string name="case_sensitive">Case sensitive</string>
<string name="regex">Regular expression</string>
<string name="debit_credit_card">Debit / Credit Card</string>
<string name="holder">Holder</string>
<string name="number">Number</string>
Expand Down
97 changes: 97 additions & 0 deletions art/ic_regex.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion fastlane/metadata/android/en-US/changelogs/98.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* Quick search and dynamic filters #163 #462 #521
* Keep search context #1141
* Keep search context #1141
* Search with regular expression #175
3 changes: 2 additions & 1 deletion fastlane/metadata/android/fr-FR/changelogs/98.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* Recherche rapide et filtres dynamiques #163 #462 #521
* Garde le contexte de recherche #1141
* Garde le contexte de recherche #1141
* Recherche avec expression régulière #175

0 comments on commit 7697713

Please sign in to comment.