Fix search in recycle bin #613

This commit is contained in:
J-Jamet 2020-07-02 12:10:04 +02:00
parent 77ae3a4623
commit 4279825caa
9 changed files with 39 additions and 23 deletions

View file

@ -1,5 +1,6 @@
KeePassDX(2.8)
* Fix TOTP period (> 60s)
* Fix searching in recycle bin
KeePassDX(2.7)
* Add blocklists for autofill

View file

@ -75,7 +75,10 @@ import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Compa
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.MenuUtil
import com.kunzisoft.keepass.view.*
import com.kunzisoft.keepass.view.AddNodeButtonView
import com.kunzisoft.keepass.view.ToolbarAction
import com.kunzisoft.keepass.view.asError
import com.kunzisoft.keepass.view.showActionError
class GroupActivity : LockingActivity(),
GroupEditDialogFragment.EditGroupListener,
@ -389,7 +392,8 @@ class GroupActivity : LockingActivity(),
// If it's a search
if (Intent.ACTION_SEARCH == intent.action) {
val searchString = intent.getStringExtra(SearchManager.QUERY)?.trim { it <= ' ' } ?: ""
return mDatabase?.createVirtualGroupFromSearch(searchString)
return mDatabase?.createVirtualGroupFromSearch(searchString,
PreferencesUtil.omitBackup(this))
}
// else a real group
else {

View file

@ -46,7 +46,8 @@ class SearchEntryCursorAdapter(private val context: Context,
private val cursorInflater: LayoutInflater? = context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
private var displayUsername: Boolean = false
private var mDisplayUsername: Boolean = false
private var mOmitBackup: Boolean = true
private val iconColor: Int
init {
@ -59,7 +60,8 @@ class SearchEntryCursorAdapter(private val context: Context,
}
fun reInit(context: Context) {
this.displayUsername = PreferencesUtil.showUsernamesListEntries(context)
this.mDisplayUsername = PreferencesUtil.showUsernamesListEntries(context)
this.mOmitBackup = PreferencesUtil.omitBackup(context)
}
override fun newView(context: Context, cursor: Cursor, parent: ViewGroup): View {
@ -93,7 +95,7 @@ class SearchEntryCursorAdapter(private val context: Context,
// Assign subtitle
viewHolder.textViewSubTitle?.apply {
val entryUsername = currentEntry.username
text = if (displayUsername && entryUsername.isNotEmpty()) {
text = if (mDisplayUsername && entryUsername.isNotEmpty()) {
String.format("(%s)", entryUsername)
} else {
""
@ -129,7 +131,9 @@ class SearchEntryCursorAdapter(private val context: Context,
if (database.type == DatabaseKDBX.TYPE)
cursorKDBX = EntryCursorKDBX()
val searchGroup = database.createVirtualGroupFromSearch(query, SearchHelper.MAX_SEARCH_ENTRY)
val searchGroup = database.createVirtualGroupFromSearch(query,
mOmitBackup,
SearchHelper.MAX_SEARCH_ENTRY)
if (searchGroup != null) {
// Search in hide entries but not meta-stream
for (entry in searchGroup.getFilteredChildEntries(Group.ChildFilter.getDefaults(context))) {

View file

@ -39,7 +39,6 @@ class LoadDatabaseRunnable(private val context: Context,
private val mKey: Uri?,
private val mReadonly: Boolean,
private val mCipherEntity: CipherDatabaseEntity?,
private val mOmitBackup: Boolean,
private val mFixDuplicateUUID: Boolean,
private val progressTaskUpdater: ProgressTaskUpdater?,
private val mDuplicateUuidAction: ((Result) -> Unit)?)
@ -58,7 +57,6 @@ class LoadDatabaseRunnable(private val context: Context,
mReadonly,
context.contentResolver,
cacheDirectory,
mOmitBackup,
mFixDuplicateUUID,
progressTaskUpdater)
}

View file

@ -46,7 +46,6 @@ import com.kunzisoft.keepass.database.file.output.DatabaseOutputKDBX
import com.kunzisoft.keepass.database.search.SearchHelper
import com.kunzisoft.keepass.database.search.SearchParameters
import com.kunzisoft.keepass.icons.IconDrawableFactory
import com.kunzisoft.keepass.model.SearchInfo
import com.kunzisoft.keepass.stream.readBytes4ToUInt
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
import com.kunzisoft.keepass.utils.SingletonHolder
@ -316,7 +315,6 @@ class Database {
readOnly: Boolean,
contentResolver: ContentResolver,
cacheDirectory: File,
omitBackup: Boolean,
fixDuplicateUUID: Boolean,
progressTaskUpdater: ProgressTaskUpdater?) {
@ -378,7 +376,7 @@ class Database {
else -> throw SignatureDatabaseException()
}
this.mSearchHelper = SearchHelper(omitBackup)
this.mSearchHelper = SearchHelper()
loaded = true
} catch (e: LoadDatabaseException) {
@ -393,20 +391,24 @@ class Database {
}
}
fun isGroupSearchable(group: Group, isOmitBackup: Boolean): Boolean {
return mDatabaseKDB?.isGroupSearchable(group.groupKDB, isOmitBackup) ?:
mDatabaseKDBX?.isGroupSearchable(group.groupKDBX, isOmitBackup) ?:
fun isGroupSearchable(group: Group, omitBackup: Boolean): Boolean {
return mDatabaseKDB?.isGroupSearchable(group.groupKDB, omitBackup) ?:
mDatabaseKDBX?.isGroupSearchable(group.groupKDBX, omitBackup) ?:
false
}
fun createVirtualGroupFromSearch(searchQuery: String,
omitBackup: Boolean,
max: Int = Integer.MAX_VALUE): Group? {
return mSearchHelper?.createVirtualGroupWithSearchResult(this, searchQuery, SearchParameters(), max)
return mSearchHelper?.createVirtualGroupWithSearchResult(this,
searchQuery, SearchParameters(), omitBackup, max)
}
fun createVirtualGroupFromSearchInfo(searchInfoString: String,
omitBackup: Boolean,
max: Int = Integer.MAX_VALUE): Group? {
return mSearchHelper?.createVirtualGroupWithSearchResult(this, searchInfoString, SearchParameters().apply {
return mSearchHelper?.createVirtualGroupWithSearchResult(this,
searchInfoString, SearchParameters().apply {
searchInTitles = false
searchInUserNames = false
searchInPasswords = false
@ -416,7 +418,7 @@ class Database {
searchInUUIDs = false
searchInTags = false
ignoreCase = true
}, max)
}, omitBackup, max)
}
@Throws(DatabaseOutputException::class)

View file

@ -32,7 +32,7 @@ import com.kunzisoft.keepass.model.getSearchString
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.timeout.TimeoutHelper
class SearchHelper(private val isOmitBackup: Boolean) {
class SearchHelper {
companion object {
const val MAX_SEARCH_ENTRY = 6
@ -54,6 +54,7 @@ class SearchHelper(private val isOmitBackup: Boolean) {
// If search provide results
database.createVirtualGroupFromSearchInfo(
searchInfo.getSearchString(context),
PreferencesUtil.omitBackup(context),
MAX_SEARCH_ENTRY
)?.let { searchGroup ->
if (searchGroup.getNumberOfChildEntries() > 0) {
@ -77,6 +78,7 @@ class SearchHelper(private val isOmitBackup: Boolean) {
fun createVirtualGroupWithSearchResult(database: Database,
searchQuery: String,
searchParameters: SearchParameters,
omitBackup: Boolean,
max: Int): Group? {
val searchGroup = database.createGroup()
@ -101,7 +103,7 @@ class SearchHelper(private val isOmitBackup: Boolean) {
override fun operate(node: Group): Boolean {
return when {
incrementEntry >= max -> false
database.isGroupSearchable(node, isOmitBackup) -> true
database.isGroupSearchable(node, omitBackup) -> true
else -> false
}
}

View file

@ -21,19 +21,23 @@ package com.kunzisoft.keepass.notifications
import android.content.Intent
import android.net.Uri
import android.os.*
import android.os.AsyncTask
import android.os.Binder
import android.os.Bundle
import android.os.IBinder
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.app.database.CipherDatabaseEntity
import com.kunzisoft.keepass.database.action.*
import com.kunzisoft.keepass.database.action.history.DeleteEntryHistoryDatabaseRunnable
import com.kunzisoft.keepass.database.action.history.RestoreEntryHistoryDatabaseRunnable
import com.kunzisoft.keepass.database.action.node.*
import com.kunzisoft.keepass.database.element.*
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
import com.kunzisoft.keepass.database.element.node.Node
import com.kunzisoft.keepass.database.element.node.NodeId
import com.kunzisoft.keepass.database.element.node.Type
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
import com.kunzisoft.keepass.utils.DATABASE_START_TASK_ACTION
@ -256,7 +260,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
keyFileUri,
readOnly,
cipherEntity,
PreferencesUtil.omitBackup(this),
intent.getBooleanExtra(FIX_DUPLICATE_UUID_KEY, false),
this
) { result ->

View file

@ -1,2 +1,3 @@
* Fix TOTP period (> 60s)
* Fix searching in recycle bin

View file

@ -1,2 +1,3 @@
* Correction de la période pour le TOTP (> 60s)
* Correction de la recherche dans la corbeille