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
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AutofillHelper.buildResponseWhenEntrySelected(this@GroupActivity, entryVersioned)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mDatabase != null) {
AutofillHelper.buildResponseWhenEntrySelected(this@GroupActivity,
entryVersioned.getEntry(mDatabase!!))
}
finish()
})

View File

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

View File

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

View File

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