Fix ref autofill #274

This commit is contained in:
J-Jamet
2019-07-31 14:49:16 +02:00
parent 02ba1dabe7
commit eb2040edbd
4 changed files with 19 additions and 9 deletions

View File

@@ -422,8 +422,9 @@ class GroupActivity : LockingActivity(),
}, },
{ {
// Build response with the entry selected // Build response with the entry selected
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mDatabase != null) {
AutofillHelper.buildResponseWhenEntrySelected(this@GroupActivity, entryVersioned) AutofillHelper.buildResponseWhenEntrySelected(this@GroupActivity,
entryVersioned.getEntry(mDatabase!!))
} }
finish() finish()
}) })

View File

@@ -33,7 +33,7 @@ import android.view.autofill.AutofillValue
import android.widget.RemoteViews import android.widget.RemoteViews
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
import com.kunzisoft.keepass.database.element.EntryVersioned import com.kunzisoft.keepass.model.Entry
import java.util.* import java.util.*
@@ -51,24 +51,25 @@ object AutofillHelper {
return null return null
} }
private fun makeEntryTitle(entry: EntryVersioned): String { private fun makeEntryTitle(entry: Entry): String {
if (entry.title.isNotEmpty() && entry.username.isNotEmpty()) if (entry.title.isNotEmpty() && entry.username.isNotEmpty())
return String.format("%s (%s)", entry.title, entry.username) return String.format("%s (%s)", entry.title, entry.username)
if (entry.title.isNotEmpty()) if (entry.title.isNotEmpty())
return entry.title return entry.title
if (entry.username.isNotEmpty()) if (entry.username.isNotEmpty())
return entry.username return entry.username
return if (!entry.notes.isEmpty()) entry.notes.trim { it <= ' ' } else "" if (entry.url.isNotEmpty())
// TODO No title return entry.url
return ""
} }
private fun buildDataset(context: Context, private fun buildDataset(context: Context,
entry: EntryVersioned, entry: Entry,
struct: StructureParser.Result): Dataset? { struct: StructureParser.Result): Dataset? {
val title = makeEntryTitle(entry) val title = makeEntryTitle(entry)
val views = newRemoteViews(context.packageName, title) val views = newRemoteViews(context.packageName, title)
val builder = Dataset.Builder(views) val builder = Dataset.Builder(views)
builder.setId(entry.nodeId.toString()) builder.setId(entry.id)
struct.password.forEach { id -> builder.setValue(id, AutofillValue.forText(entry.password)) } struct.password.forEach { id -> builder.setValue(id, AutofillValue.forText(entry.password)) }
@@ -88,7 +89,7 @@ object AutofillHelper {
/** /**
* Method to hit when right key is selected * Method to hit when right key is selected
*/ */
fun buildResponseWhenEntrySelected(activity: Activity, entry: EntryVersioned) { fun buildResponseWhenEntrySelected(activity: Activity, entry: Entry) {
var setResultOk = false var setResultOk = false
activity.intent?.extras?.let { extras -> activity.intent?.extras?.let { extras ->
if (extras.containsKey(ASSIST_STRUCTURE)) { if (extras.containsKey(ASSIST_STRUCTURE)) {

View File

@@ -328,10 +328,12 @@ class EntryVersioned : NodeVersioned, PwEntryInterface<GroupVersioned> {
fun getEntry(database: Database): Entry { fun getEntry(database: Database): Entry {
val entryModel = Entry() val entryModel = Entry()
database.startManageEntry(this) database.startManageEntry(this)
entryModel.id = nodeId.toString()
entryModel.title = title entryModel.title = title
entryModel.username = username entryModel.username = username
entryModel.password = password entryModel.password = password
entryModel.url = url entryModel.url = url
entryModel.notes = notes
if (containsCustomFields()) { if (containsCustomFields()) {
fields.doActionToAllCustomProtectedField { key, value -> fields.doActionToAllCustomProtectedField { key, value ->
entryModel.customFields.add( entryModel.customFields.add(

View File

@@ -7,19 +7,23 @@ import java.util.ArrayList
class Entry : Parcelable { class Entry : Parcelable {
var id: String = ""
var title: String = "" var title: String = ""
var username: String = "" var username: String = ""
var password: String = "" var password: String = ""
var url: String = "" var url: String = ""
var notes: String = ""
var customFields: MutableList<Field> = ArrayList() var customFields: MutableList<Field> = ArrayList()
constructor() constructor()
private constructor(parcel: Parcel) { private constructor(parcel: Parcel) {
id = parcel.readString()
title = parcel.readString() title = parcel.readString()
username = parcel.readString() username = parcel.readString()
password = parcel.readString() password = parcel.readString()
url = parcel.readString() url = parcel.readString()
notes = parcel.readString()
parcel.readList(customFields, Field::class.java.classLoader) parcel.readList(customFields, Field::class.java.classLoader)
} }
@@ -28,10 +32,12 @@ class Entry : Parcelable {
} }
override fun writeToParcel(parcel: Parcel, i: Int) { override fun writeToParcel(parcel: Parcel, i: Int) {
parcel.writeString(id)
parcel.writeString(title) parcel.writeString(title)
parcel.writeString(username) parcel.writeString(username)
parcel.writeString(password) parcel.writeString(password)
parcel.writeString(url) parcel.writeString(url)
parcel.writeString(notes)
parcel.writeArray(customFields.toTypedArray()) parcel.writeArray(customFields.toTypedArray())
} }