mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Manually save search in selection mode
This commit is contained in:
@@ -21,6 +21,7 @@ package com.kunzisoft.keepass.activities
|
||||
import android.app.Activity
|
||||
import android.app.DatePickerDialog
|
||||
import android.app.TimePickerDialog
|
||||
import android.app.assist.AssistStructure
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
@@ -34,6 +35,7 @@ import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.DatePicker
|
||||
import android.widget.TimePicker
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
@@ -46,12 +48,12 @@ import com.kunzisoft.keepass.activities.dialogs.FileTooBigDialogFragment.Compani
|
||||
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
|
||||
import com.kunzisoft.keepass.activities.helpers.SelectFileHelper
|
||||
import com.kunzisoft.keepass.activities.lock.LockingActivity
|
||||
import com.kunzisoft.keepass.autofill.AutofillHelper
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.education.EntryEditActivityEducation
|
||||
import com.kunzisoft.keepass.model.*
|
||||
import com.kunzisoft.keepass.notifications.AttachmentFileNotificationService
|
||||
@@ -176,14 +178,16 @@ class EntryEditActivity : LockingActivity(),
|
||||
|
||||
// Retrieve data from registration
|
||||
val registerInfo = EntrySelectionHelper.retrieveRegisterInfoFromIntent(intent)
|
||||
val searchInfo: SearchInfo? = registerInfo?.searchInfo
|
||||
?: EntrySelectionHelper.retrieveSearchInfoFromIntent(intent)
|
||||
registerInfo?.username?.let {
|
||||
tempEntryInfo?.username = it
|
||||
}
|
||||
registerInfo?.password?.let {
|
||||
tempEntryInfo?.password = it
|
||||
}
|
||||
registerInfo?.searchInfo?.let { searchInfo ->
|
||||
tempEntryInfo?.saveSearchInfo(mDatabase, searchInfo)
|
||||
searchInfo?.let { tempSearchInfo ->
|
||||
tempEntryInfo?.saveSearchInfo(mDatabase, tempSearchInfo)
|
||||
}
|
||||
|
||||
// Build fragment to manage entry modification
|
||||
@@ -297,8 +301,24 @@ class EntryEditActivity : LockingActivity(),
|
||||
}
|
||||
}
|
||||
if (newNodes.size == 1) {
|
||||
mEntry = newNodes[0] as Entry?
|
||||
cancelSpecialModeAndFinish()
|
||||
(newNodes[0] as? Entry?)?.let { entry ->
|
||||
mEntry = entry
|
||||
EntrySelectionHelper.doSpecialAction(intent,
|
||||
{
|
||||
// Finish naturally
|
||||
finish()
|
||||
},
|
||||
{
|
||||
entryValidatedForKeyboardSelection(entry)
|
||||
},
|
||||
{ _, _ ->
|
||||
entryValidatedForAutofillSelection(entry)
|
||||
},
|
||||
{
|
||||
entryValidatedForRegistration()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
@@ -310,6 +330,35 @@ class EntryEditActivity : LockingActivity(),
|
||||
}
|
||||
}
|
||||
|
||||
private fun entryValidatedForKeyboardSelection(entry: Entry) {
|
||||
// Populate Magikeyboard with entry
|
||||
mDatabase?.let { database ->
|
||||
populateKeyboardAndMoveAppToBackground(this,
|
||||
entry.getEntryInfo(database),
|
||||
intent)
|
||||
}
|
||||
super.onCancelSpecialMode()
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun entryValidatedForAutofillSelection(entry: Entry) {
|
||||
// Build Autofill response with the entry selected
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
mDatabase?.let { database ->
|
||||
AutofillHelper.buildResponse(this@EntryEditActivity,
|
||||
entry.getEntryInfo(database))
|
||||
}
|
||||
}
|
||||
super.onCancelSpecialMode()
|
||||
super.finish()
|
||||
}
|
||||
|
||||
private fun entryValidatedForRegistration() {
|
||||
// Entry registered, finish naturally
|
||||
super.onCancelSpecialMode()
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
@@ -692,7 +741,8 @@ class EntryEditActivity : LockingActivity(),
|
||||
|
||||
override fun onCancelSpecialMode() {
|
||||
onApprovedBackPressed {
|
||||
cancelSpecialModeAndFinish()
|
||||
super.onCancelSpecialMode()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -705,11 +755,6 @@ class EntryEditActivity : LockingActivity(),
|
||||
}.create().show()
|
||||
}
|
||||
|
||||
private fun cancelSpecialModeAndFinish() {
|
||||
super.onCancelSpecialMode()
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun finish() {
|
||||
// Assign entry callback as a result in all case
|
||||
try {
|
||||
@@ -780,6 +825,39 @@ class EntryEditActivity : LockingActivity(),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch EntryEditActivity to add a new entry in keyboard selection
|
||||
*/
|
||||
fun launchForKeyboardSelectionResult(context: Context,
|
||||
group: Group,
|
||||
searchInfo: SearchInfo? = null) {
|
||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(context)) {
|
||||
val intent = Intent(context, EntryEditActivity::class.java)
|
||||
intent.putExtra(KEY_PARENT, group.nodeId)
|
||||
EntrySelectionHelper.startActivityForKeyboardSelectionModeResult(context,
|
||||
intent,
|
||||
searchInfo)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch EntryEditActivity to add a new entry in autofill selection
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
fun launchForAutofillResult(activity: Activity,
|
||||
assistStructure: AssistStructure,
|
||||
group: Group,
|
||||
searchInfo: SearchInfo? = null) {
|
||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(activity)) {
|
||||
val intent = Intent(activity, EntryEditActivity::class.java)
|
||||
intent.putExtra(KEY_PARENT, group.nodeId)
|
||||
AutofillHelper.startActivityForAutofillResult(activity,
|
||||
intent,
|
||||
assistStructure,
|
||||
searchInfo)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch EntryEditActivity to register an updated entry (from autofill)
|
||||
*/
|
||||
|
||||
@@ -218,11 +218,29 @@ class GroupActivity : LockingActivity(),
|
||||
EntryEditActivity.launch(this@GroupActivity, currentGroup)
|
||||
}
|
||||
},
|
||||
{
|
||||
// Add button is not allowed for keyboard selection
|
||||
{ searchInfo ->
|
||||
if (PreferencesUtil.isKeyboardSaveSearchInfoEnable(this@GroupActivity)) {
|
||||
mCurrentGroup?.let { currentGroup ->
|
||||
EntryEditActivity.launchForKeyboardSelectionResult(this@GroupActivity,
|
||||
currentGroup, searchInfo)
|
||||
}
|
||||
}
|
||||
},
|
||||
{ _, _ ->
|
||||
// Add button is not allowed for autofill selection
|
||||
{ searchInfo, assistStructure ->
|
||||
var finishActivity = true
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
&& PreferencesUtil.isAutofillSaveSearchInfoEnable(this@GroupActivity)) {
|
||||
mCurrentGroup?.let { currentGroup ->
|
||||
assistStructure?.let { autofillStructure ->
|
||||
finishActivity = false
|
||||
EntryEditActivity.launchForAutofillResult(this@GroupActivity,
|
||||
autofillStructure,
|
||||
currentGroup, searchInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (finishActivity)
|
||||
finish()
|
||||
},
|
||||
{ searchInfo ->
|
||||
mCurrentGroup?.let { currentGroup ->
|
||||
@@ -577,13 +595,8 @@ class GroupActivity : LockingActivity(),
|
||||
entrySelectedForAutofillSelection(entryVersioned)
|
||||
}
|
||||
},
|
||||
{ searchInfo ->
|
||||
rebuildListNodes()
|
||||
// Registration to update the entry
|
||||
// TODO box update confirmation
|
||||
EntryEditActivity.launchForRegistration(this@GroupActivity,
|
||||
entryVersioned, searchInfo)
|
||||
finish()
|
||||
{ registerInfo ->
|
||||
entrySelectedForRegistration(entryVersioned, registerInfo)
|
||||
})
|
||||
} catch (e: ClassCastException) {
|
||||
Log.e(TAG, "Node can't be cast in Entry")
|
||||
@@ -599,6 +612,7 @@ class GroupActivity : LockingActivity(),
|
||||
entry.getEntryInfo(database),
|
||||
intent)
|
||||
}
|
||||
super.onCancelSpecialMode()
|
||||
}
|
||||
|
||||
private fun entrySelectedForAutofillSelection(entry: Entry) {
|
||||
@@ -609,6 +623,16 @@ class GroupActivity : LockingActivity(),
|
||||
entry.getEntryInfo(database))
|
||||
}
|
||||
}
|
||||
super.onCancelSpecialMode()
|
||||
}
|
||||
|
||||
private fun entrySelectedForRegistration(entry: Entry, registerInfo: RegisterInfo?) {
|
||||
rebuildListNodes()
|
||||
// Registration to update the entry
|
||||
// TODO box update confirmation
|
||||
EntryEditActivity.launchForRegistration(this@GroupActivity,
|
||||
entry, registerInfo)
|
||||
super.onCancelSpecialMode()
|
||||
finish()
|
||||
}
|
||||
|
||||
@@ -617,11 +641,11 @@ class GroupActivity : LockingActivity(),
|
||||
newEntry.setEntryInfo(mDatabase, newEntry.getEntryInfo(mDatabase).apply {
|
||||
saveSearchInfo(mDatabase, searchInfo)
|
||||
})
|
||||
// In selection mode, it's forced read-only, just checked if AutoSave is enabled
|
||||
// In selection mode, it's forced read-only, so update not allowed
|
||||
mProgressDatabaseTaskProvider?.startDatabaseUpdateEntry(
|
||||
entry,
|
||||
newEntry,
|
||||
mAutoSaveEnable
|
||||
!mReadOnly && mAutoSaveEnable
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -70,9 +70,6 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
|
||||
|
||||
private var readOnly: Boolean = false
|
||||
get() {
|
||||
return field || specialMode.readOnly
|
||||
}
|
||||
private var specialMode: SpecialMode = SpecialMode.DEFAULT
|
||||
|
||||
val isEmpty: Boolean
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kunzisoft.keepass.activities.helpers
|
||||
|
||||
enum class SpecialMode(val readOnly: Boolean) {
|
||||
DEFAULT(false), SELECTION(true), REGISTRATION(false);
|
||||
enum class SpecialMode {
|
||||
DEFAULT,
|
||||
SELECTION,
|
||||
REGISTRATION;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ abstract class LockingActivity : SpecialModeActivity() {
|
||||
// Force readOnly if Entry Selection mode
|
||||
protected var mReadOnly: Boolean
|
||||
get() {
|
||||
return mReadOnlyToSave || mSpecialMode.readOnly
|
||||
return mReadOnlyToSave
|
||||
}
|
||||
set(value) {
|
||||
mReadOnlyToSave = value
|
||||
|
||||
@@ -36,19 +36,28 @@ abstract class SpecialModeActivity : StylishActivity() {
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
/**
|
||||
* Intent sender uses special retains data in callback
|
||||
*/
|
||||
private fun isIntentSender(): Boolean {
|
||||
return (mSpecialMode == SpecialMode.SELECTION
|
||||
&& mTypeMode == TypeMode.AUTOFILL)
|
||||
|| (mSpecialMode == SpecialMode.REGISTRATION
|
||||
&& mTypeMode == TypeMode.AUTOFILL
|
||||
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||
}
|
||||
|
||||
open fun onCancelSpecialMode() {
|
||||
EntrySelectionHelper.removeModesFromIntent(intent)
|
||||
EntrySelectionHelper.removeInfoFromIntent(intent)
|
||||
if (mSpecialMode != SpecialMode.DEFAULT)
|
||||
backToTheAppCaller()
|
||||
if (!isIntentSender()) {
|
||||
EntrySelectionHelper.removeModesFromIntent(intent)
|
||||
EntrySelectionHelper.removeInfoFromIntent(intent)
|
||||
if (mSpecialMode != SpecialMode.DEFAULT)
|
||||
backToTheAppCaller()
|
||||
}
|
||||
}
|
||||
|
||||
protected fun backToTheAppCaller() {
|
||||
if ((mSpecialMode == SpecialMode.SELECTION
|
||||
&& mTypeMode == TypeMode.AUTOFILL)
|
||||
|| (mSpecialMode == SpecialMode.REGISTRATION
|
||||
&& mTypeMode == TypeMode.AUTOFILL
|
||||
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)) {
|
||||
if (isIntentSender()) {
|
||||
// To get the app caller, only for IntentSender
|
||||
super.onBackPressed()
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user