mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Register WebDomain or ApplicationId
This commit is contained in:
@@ -108,20 +108,17 @@ class AutofillLauncherActivity : AppCompatActivity() {
|
||||
Toast.makeText(this.applicationContext, R.string.autofill_block_restart, Toast.LENGTH_LONG).show()
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
} else {
|
||||
// If database is open
|
||||
SearchHelper.checkAutoSearchInfo(this,
|
||||
Database.getInstance(),
|
||||
searchInfo,
|
||||
{ _ ->
|
||||
// Show the database UI to select the entry
|
||||
GroupActivity.launchForRegistration(this,
|
||||
false,
|
||||
searchInfo)
|
||||
},
|
||||
{
|
||||
// Show the database UI to select the entry
|
||||
GroupActivity.launchForRegistration(this,
|
||||
false,
|
||||
searchInfo)
|
||||
},
|
||||
{
|
||||
@@ -170,6 +167,7 @@ class AutofillLauncherActivity : AppCompatActivity() {
|
||||
intent.putExtra(KEY_SEARCH_APPLICATION_ID, it.applicationId)
|
||||
intent.putExtra(KEY_SEARCH_DOMAIN, it.webDomain)
|
||||
}
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.kunzisoft.keepass.activities
|
||||
import android.app.Activity
|
||||
import android.app.DatePickerDialog
|
||||
import android.app.TimePickerDialog
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
@@ -42,13 +43,16 @@ import com.google.android.material.snackbar.Snackbar
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.dialogs.*
|
||||
import com.kunzisoft.keepass.activities.dialogs.FileTooBigDialogFragment.Companion.MAX_WARNING_BINARY_FILE
|
||||
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
|
||||
import com.kunzisoft.keepass.activities.helpers.SelectFileHelper
|
||||
import com.kunzisoft.keepass.activities.helpers.SpecialMode
|
||||
import com.kunzisoft.keepass.activities.lock.LockingActivity
|
||||
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
|
||||
@@ -64,7 +68,6 @@ import com.kunzisoft.keepass.tasks.AttachmentFileBinderManager
|
||||
import com.kunzisoft.keepass.timeout.TimeoutHelper
|
||||
import com.kunzisoft.keepass.utils.MenuUtil
|
||||
import com.kunzisoft.keepass.utils.UriUtil
|
||||
import com.kunzisoft.keepass.utils.closeDatabase
|
||||
import com.kunzisoft.keepass.view.asError
|
||||
import com.kunzisoft.keepass.view.showActionError
|
||||
import com.kunzisoft.keepass.view.updateLockPaddingLeft
|
||||
@@ -172,6 +175,21 @@ class EntryEditActivity : LockingActivity(),
|
||||
tempEntryInfo?.username = mDatabase?.defaultUsername ?: ""
|
||||
}
|
||||
|
||||
// Retrieve data from registration
|
||||
tempEntryInfo?.customFields
|
||||
val searchInfo = EntrySelectionHelper.retrieveSearchInfoFromIntent(intent)
|
||||
searchInfo?.webDomain?.let { webDomain ->
|
||||
tempEntryInfo?.addUniqueField(Field(EntryInfo.WEB_DOMAIN_FIELD_NAME,
|
||||
ProtectedString(false, webDomain))
|
||||
)
|
||||
} ?: run {
|
||||
searchInfo?.applicationId?.let { applicationId ->
|
||||
tempEntryInfo?.addUniqueField(Field(EntryInfo.APPLICATION_ID_FIELD_NAME,
|
||||
ProtectedString(false, applicationId))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Build fragment to manage entry modification
|
||||
entryEditFragment = supportFragmentManager.findFragmentByTag(ENTRY_EDIT_FRAGMENT_TAG) as? EntryEditFragment?
|
||||
if (entryEditFragment == null) {
|
||||
@@ -725,12 +743,13 @@ class EntryEditActivity : LockingActivity(),
|
||||
* Launch EntryEditActivity to update an existing entry
|
||||
*
|
||||
* @param activity from activity
|
||||
* @param pwEntry Entry to update
|
||||
* @param entry Entry to update
|
||||
*/
|
||||
fun launch(activity: Activity, pwEntry: Entry) {
|
||||
fun launch(activity: Activity,
|
||||
entry: Entry) {
|
||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(activity)) {
|
||||
val intent = Intent(activity, EntryEditActivity::class.java)
|
||||
intent.putExtra(KEY_ENTRY, pwEntry.nodeId)
|
||||
intent.putExtra(KEY_ENTRY, entry.nodeId)
|
||||
activity.startActivityForResult(intent, ADD_OR_UPDATE_ENTRY_REQUEST_CODE)
|
||||
}
|
||||
}
|
||||
@@ -739,14 +758,47 @@ class EntryEditActivity : LockingActivity(),
|
||||
* Launch EntryEditActivity to add a new entry
|
||||
*
|
||||
* @param activity from activity
|
||||
* @param pwGroup Group who will contains new entry
|
||||
* @param group Group who will contains new entry
|
||||
*/
|
||||
fun launch(activity: Activity, pwGroup: Group) {
|
||||
fun launch(activity: Activity,
|
||||
group: Group) {
|
||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(activity)) {
|
||||
val intent = Intent(activity, EntryEditActivity::class.java)
|
||||
intent.putExtra(KEY_PARENT, pwGroup.nodeId)
|
||||
intent.putExtra(KEY_PARENT, group.nodeId)
|
||||
activity.startActivityForResult(intent, ADD_OR_UPDATE_ENTRY_REQUEST_CODE)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch EntryEditActivity to register an updated entry (from autofill)
|
||||
*/
|
||||
fun launchForRegistration(context: Context,
|
||||
entry: Entry,
|
||||
searchInfo: SearchInfo? = null) {
|
||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(context)) {
|
||||
val intent = Intent(context, EntryEditActivity::class.java)
|
||||
intent.putExtra(KEY_ENTRY, entry.nodeId)
|
||||
EntrySelectionHelper.startActivityForSpecialModeResult(context,
|
||||
intent,
|
||||
SpecialMode.REGISTRATION,
|
||||
searchInfo)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch EntryEditActivity to register a new entry (from autofill)
|
||||
*/
|
||||
fun launchForRegistration(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.startActivityForSpecialModeResult(context,
|
||||
intent,
|
||||
SpecialMode.REGISTRATION,
|
||||
searchInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +302,6 @@ class FileDatabaseSelectActivity : SpecialModeActivity(),
|
||||
},
|
||||
{ searchInfo ->
|
||||
GroupActivity.launchForRegistration(this@FileDatabaseSelectActivity,
|
||||
false,
|
||||
searchInfo)
|
||||
// Do not keep history
|
||||
finish()
|
||||
|
||||
@@ -205,16 +205,33 @@ class GroupActivity : LockingActivity(),
|
||||
}
|
||||
|
||||
// Add listeners to the add buttons
|
||||
addNodeButtonView?.setAddGroupClickListener(View.OnClickListener {
|
||||
addNodeButtonView?.setAddGroupClickListener {
|
||||
GroupEditDialogFragment.build()
|
||||
.show(supportFragmentManager,
|
||||
GroupEditDialogFragment.TAG_CREATE_GROUP)
|
||||
})
|
||||
addNodeButtonView?.setAddEntryClickListener(View.OnClickListener {
|
||||
mCurrentGroup?.let { currentGroup ->
|
||||
EntryEditActivity.launch(this@GroupActivity, currentGroup)
|
||||
}
|
||||
})
|
||||
}
|
||||
addNodeButtonView?.setAddEntryClickListener {
|
||||
EntrySelectionHelper.doSpecialAction(intent,
|
||||
{
|
||||
mCurrentGroup?.let { currentGroup ->
|
||||
EntryEditActivity.launch(this@GroupActivity, currentGroup)
|
||||
}
|
||||
},
|
||||
{
|
||||
// Add button is not allowed for keyboard selection
|
||||
},
|
||||
{ _, _ ->
|
||||
// Add button is not allowed for autofill selection
|
||||
},
|
||||
{ searchInfo ->
|
||||
mCurrentGroup?.let { currentGroup ->
|
||||
EntryEditActivity.launchForRegistration(this@GroupActivity,
|
||||
currentGroup, searchInfo)
|
||||
}
|
||||
finish()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
mDatabase?.let { database ->
|
||||
// Search suggestion
|
||||
@@ -551,7 +568,11 @@ class GroupActivity : LockingActivity(),
|
||||
},
|
||||
{ searchInfo ->
|
||||
rebuildListNodes()
|
||||
// TODO Registration
|
||||
// Registration to update the entry
|
||||
// TODO box update confirmation
|
||||
EntryEditActivity.launchForRegistration(this@GroupActivity,
|
||||
entryVersioned, searchInfo)
|
||||
finish()
|
||||
})
|
||||
} catch (e: ClassCastException) {
|
||||
Log.e(TAG, "Node can't be cast in Entry")
|
||||
@@ -1143,10 +1164,9 @@ class GroupActivity : LockingActivity(),
|
||||
* -------------------------
|
||||
*/
|
||||
fun launchForRegistration(context: Context,
|
||||
autoSearch: Boolean = false,
|
||||
searchInfo: SearchInfo? = null) {
|
||||
checkTimeAndBuildIntent(context, null, false) { intent ->
|
||||
intent.putExtra(AUTO_SEARCH_KEY, autoSearch)
|
||||
intent.putExtra(AUTO_SEARCH_KEY, false)
|
||||
EntrySelectionHelper.startActivityForSpecialModeResult(context,
|
||||
intent,
|
||||
SpecialMode.REGISTRATION,
|
||||
|
||||
@@ -361,15 +361,13 @@ open class PasswordActivity : SpecialModeActivity() {
|
||||
Database.getInstance(),
|
||||
searchInfo,
|
||||
{ _ ->
|
||||
// Select the one we want
|
||||
// No auto search, it's a registration
|
||||
GroupActivity.launchForRegistration(this,
|
||||
true,
|
||||
searchInfo)
|
||||
},
|
||||
{
|
||||
// Here no search info found, disable auto search
|
||||
GroupActivity.launchForRegistration(this@PasswordActivity,
|
||||
false,
|
||||
searchInfo)
|
||||
},
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class EntryInfo : Parcelable {
|
||||
|
||||
@@ -101,8 +101,31 @@ class EntryInfo : Parcelable {
|
||||
return customFields.lastOrNull { it.name == label }?.protectedValue?.toString() ?: ""
|
||||
}
|
||||
|
||||
fun addUniqueField(field: Field, number: Int = 0) {
|
||||
var exists = false
|
||||
var sameData = false
|
||||
val suffix = if (number > 0) number.toString() else ""
|
||||
customFields.forEach { currentField ->
|
||||
if (currentField.name == field.name + suffix) {
|
||||
exists = true
|
||||
// Not write the same value again
|
||||
if (currentField.protectedValue.stringValue == field.protectedValue.stringValue) {
|
||||
sameData = true
|
||||
} else {
|
||||
addUniqueField(currentField, number + 1)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
if (!exists && !sameData)
|
||||
(customFields as ArrayList<Field>).add(Field(field.name + suffix, field.protectedValue))
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val WEB_DOMAIN_FIELD_NAME = "WebDomain"
|
||||
const val APPLICATION_ID_FIELD_NAME = "ApplicationId"
|
||||
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<EntryInfo> = object : Parcelable.Creator<EntryInfo> {
|
||||
override fun createFromParcel(parcel: Parcel): EntryInfo {
|
||||
|
||||
@@ -33,14 +33,28 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:theme="?attr/toolbarAppearance"
|
||||
android:popupTheme="?attr/toolbarPopupAppearance"
|
||||
tools:targetApi="lollipop" />
|
||||
android:layout_height="wrap_content" >
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:theme="?attr/toolbarAppearance"
|
||||
android:popupTheme="?attr/toolbarPopupAppearance"
|
||||
tools:targetApi="lollipop" />
|
||||
|
||||
<com.kunzisoft.keepass.view.SpecialModeView
|
||||
android:id="@+id/special_mode_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:theme="?attr/specialToolbarAppearance"
|
||||
app:titleTextAppearance="@style/KeepassDXStyle.TextAppearance.Toolbar.Special.Title"
|
||||
app:subtitleTextAppearance="@style/KeepassDXStyle.TextAppearance.Toolbar.Special.SubTitle"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</FrameLayout>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
|
||||
Reference in New Issue
Block a user