mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-30 05:43:00 -08:00
Save search info settings
This commit is contained in:
1 parent
17873ef7aa
commit
d8961d2acb
8 files changed
+139
-40
No files matched your search
@@ -183,29 +183,7 @@ class EntryEditActivity : LockingActivity(),
|
||||
tempEntryInfo?.password = it
|
||||
}
|
||||
registerInfo?.searchInfo?.let { searchInfo ->
|
||||
searchInfo.webDomain?.let { webDomain ->
|
||||
// If unable to save web domain in custom field or URL not populate, save in URL
|
||||
if (mDatabase?.allowEntryCustomFields() != true) {
|
||||
//|| tempEntryInfo?.url?.isEmpty() == true) {
|
||||
val scheme = "http"
|
||||
// TODO Retrieve scheme
|
||||
tempEntryInfo?.url = "$scheme://$webDomain"
|
||||
} else {
|
||||
// Save web domain in custom field
|
||||
tempEntryInfo?.addUniqueField(Field(EntryInfo.WEB_DOMAIN_FIELD_NAME,
|
||||
ProtectedString(false, webDomain))
|
||||
)
|
||||
}
|
||||
} ?: run {
|
||||
// Save application id in custom field
|
||||
if (mDatabase?.allowEntryCustomFields() == true) {
|
||||
searchInfo.applicationId?.let { applicationId ->
|
||||
tempEntryInfo?.addUniqueField(Field(EntryInfo.APPLICATION_ID_FIELD_NAME,
|
||||
ProtectedString(false, applicationId))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
tempEntryInfo?.saveSearchInfo(mDatabase, searchInfo)
|
||||
}
|
||||
|
||||
// Build fragment to manage entry modification
|
||||
|
||||
@@ -72,6 +72,7 @@ import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Compa
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_CREATE_GROUP_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_DELETE_NODES_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_MOVE_NODES_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_ENTRY_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_GROUP_TASK
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.NEW_NODES_KEY
|
||||
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.OLD_NODES_KEY
|
||||
@@ -252,6 +253,35 @@ class GroupActivity : LockingActivity(),
|
||||
refreshSearchGroup()
|
||||
|
||||
when (actionTask) {
|
||||
ACTION_DATABASE_UPDATE_ENTRY_TASK -> {
|
||||
if (result.isSuccess) {
|
||||
mListNodesFragment?.updateNodes(oldNodes, newNodes)
|
||||
EntrySelectionHelper.doSpecialAction(intent,
|
||||
{
|
||||
// Not use
|
||||
},
|
||||
{
|
||||
try {
|
||||
val entry = newNodes[0] as Entry
|
||||
entrySelectedForKeyboardSelection(entry)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to perform action for keyboard selection after entry update", e)
|
||||
}
|
||||
},
|
||||
{ _, _ ->
|
||||
try {
|
||||
val entry = newNodes[0] as Entry
|
||||
entrySelectedForAutofillSelection(entry)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to perform action for autofill selection after entry update", e)
|
||||
}
|
||||
},
|
||||
{
|
||||
// Not use
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
ACTION_DATABASE_UPDATE_GROUP_TASK -> {
|
||||
if (result.isSuccess) {
|
||||
mListNodesFragment?.updateNodes(oldNodes, newNodes)
|
||||
@@ -533,24 +563,19 @@ class GroupActivity : LockingActivity(),
|
||||
{
|
||||
EntryActivity.launch(this@GroupActivity, entryVersioned, mReadOnly)
|
||||
},
|
||||
{
|
||||
rebuildListNodes()
|
||||
// Populate Magikeyboard with entry
|
||||
mDatabase?.let { database ->
|
||||
populateKeyboardAndMoveAppToBackground(this@GroupActivity,
|
||||
entryVersioned.getEntryInfo(database),
|
||||
intent)
|
||||
{ searchInfo ->
|
||||
if (PreferencesUtil.isKeyboardSaveSearchInfoEnable(this@GroupActivity)) {
|
||||
updateEntryWithSearchInfo(entryVersioned, searchInfo)
|
||||
} else {
|
||||
entrySelectedForKeyboardSelection(entryVersioned)
|
||||
}
|
||||
},
|
||||
{ _, _ ->
|
||||
// Build response with the entry selected
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mDatabase != null) {
|
||||
mDatabase?.let { database ->
|
||||
AutofillHelper.buildResponse(this@GroupActivity,
|
||||
entryVersioned.getEntryInfo(database))
|
||||
}
|
||||
{ searchInfo, _ ->
|
||||
if (PreferencesUtil.isAutofillSaveSearchInfoEnable(this@GroupActivity)) {
|
||||
updateEntryWithSearchInfo(entryVersioned, searchInfo)
|
||||
} else {
|
||||
entrySelectedForAutofillSelection(entryVersioned)
|
||||
}
|
||||
finish()
|
||||
},
|
||||
{ searchInfo ->
|
||||
rebuildListNodes()
|
||||
@@ -566,6 +591,39 @@ class GroupActivity : LockingActivity(),
|
||||
}
|
||||
}
|
||||
|
||||
private fun entrySelectedForKeyboardSelection(entry: Entry) {
|
||||
rebuildListNodes()
|
||||
// Populate Magikeyboard with entry
|
||||
mDatabase?.let { database ->
|
||||
populateKeyboardAndMoveAppToBackground(this,
|
||||
entry.getEntryInfo(database),
|
||||
intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun entrySelectedForAutofillSelection(entry: Entry) {
|
||||
// Build response with the entry selected
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mDatabase != null) {
|
||||
mDatabase?.let { database ->
|
||||
AutofillHelper.buildResponse(this,
|
||||
entry.getEntryInfo(database))
|
||||
}
|
||||
}
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun updateEntryWithSearchInfo(entry: Entry, searchInfo: SearchInfo?) {
|
||||
val newEntry = Entry(entry)
|
||||
newEntry.setEntryInfo(mDatabase, newEntry.getEntryInfo(mDatabase).apply {
|
||||
saveSearchInfo(mDatabase, searchInfo)
|
||||
})
|
||||
mProgressDatabaseTaskProvider?.startDatabaseUpdateEntry(
|
||||
entry,
|
||||
newEntry,
|
||||
!mReadOnly && mAutoSaveEnable
|
||||
)
|
||||
}
|
||||
|
||||
private fun finishNodeAction() {
|
||||
actionNodeMode?.finish()
|
||||
}
|
||||
|
||||
@@ -22,9 +22,11 @@ package com.kunzisoft.keepass.model
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.Attachment
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD
|
||||
import kotlin.collections.ArrayList
|
||||
@@ -101,7 +103,7 @@ class EntryInfo : Parcelable {
|
||||
return customFields.lastOrNull { it.name == label }?.protectedValue?.toString() ?: ""
|
||||
}
|
||||
|
||||
fun addUniqueField(field: Field, number: Int = 0) {
|
||||
private fun addUniqueField(field: Field, number: Int = 0) {
|
||||
var exists = false
|
||||
var sameData = false
|
||||
val suffix = if (number > 0) number.toString() else ""
|
||||
@@ -121,6 +123,34 @@ class EntryInfo : Parcelable {
|
||||
(customFields as ArrayList<Field>).add(Field(field.name + suffix, field.protectedValue))
|
||||
}
|
||||
|
||||
fun saveSearchInfo(database: Database?, searchInfo: SearchInfo?) {
|
||||
searchInfo?.let { mSearchInfo ->
|
||||
mSearchInfo.webDomain?.let { webDomain ->
|
||||
// If unable to save web domain in custom field or URL not populate, save in URL
|
||||
if (database?.allowEntryCustomFields() != true) {
|
||||
//|| tempEntryInfo?.url?.isEmpty() == true) {
|
||||
val scheme = "http"
|
||||
// TODO Retrieve scheme
|
||||
url = "$scheme://$webDomain"
|
||||
} else {
|
||||
// Save web domain in custom field
|
||||
addUniqueField(Field(WEB_DOMAIN_FIELD_NAME,
|
||||
ProtectedString(false, webDomain))
|
||||
)
|
||||
}
|
||||
} ?: run {
|
||||
// Save application id in custom field
|
||||
if (database?.allowEntryCustomFields() == true) {
|
||||
mSearchInfo.applicationId?.let { applicationId ->
|
||||
addUniqueField(Field(APPLICATION_ID_FIELD_NAME,
|
||||
ProtectedString(false, applicationId))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val WEB_DOMAIN_FIELD_NAME = "WebDomain"
|
||||
|
||||
@@ -345,6 +345,14 @@ object PreferencesUtil {
|
||||
context.resources.getBoolean(R.bool.keyboard_search_share_default))
|
||||
}
|
||||
|
||||
fun isKeyboardSaveSearchInfoEnable(context: Context): Boolean {
|
||||
if (!isKeyboardSearchShareEnable(context))
|
||||
return false
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return prefs.getBoolean(context.getString(R.string.keyboard_save_search_info_key),
|
||||
context.resources.getBoolean(R.bool.keyboard_save_search_info_default))
|
||||
}
|
||||
|
||||
fun isAutoGoActionEnable(context: Context): Boolean {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return prefs.getBoolean(context.getString(R.string.keyboard_auto_go_action_key),
|
||||
@@ -381,6 +389,12 @@ object PreferencesUtil {
|
||||
context.resources.getBoolean(R.bool.autofill_auto_search_default))
|
||||
}
|
||||
|
||||
fun isAutofillSaveSearchInfoEnable(context: Context): Boolean {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return prefs.getBoolean(context.getString(R.string.autofill_save_search_info_key),
|
||||
context.resources.getBoolean(R.bool.autofill_save_search_info_default))
|
||||
}
|
||||
|
||||
fun askToSaveAutofillData(context: Context): Boolean {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return prefs.getBoolean(context.getString(R.string.autofill_ask_to_save_data_key),
|
||||
|
||||
Reference in new issue
Block a user