Skip to content

Commit

Permalink
Better entry visualisation
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Jamet committed Jan 14, 2021
1 parent dc40b50 commit 2bfb9b0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 81 deletions.
100 changes: 44 additions & 56 deletions app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import com.kunzisoft.keepass.notifications.ClipboardEntryNotificationService
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_DELETE_ENTRY_HISTORY
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_RELOAD_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_RESTORE_ENTRY_HISTORY
import com.kunzisoft.keepass.otp.OtpEntryFields
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.tasks.AttachmentFileBinderManager
import com.kunzisoft.keepass.timeout.ClipboardHelper
Expand Down Expand Up @@ -205,8 +206,7 @@ class EntryActivity : LockingActivity() {
// Refresh Menu
invalidateOptionsMenu()

val entryInfo = entry.getEntryInfo(Database.getInstance())

val entryInfo = entry.getEntryInfo(mDatabase)
// Manage entry copy to start notification if allowed
if (mFirstLaunchOfActivity) {
// Manage entry to launch copying notification if allowed
Expand Down Expand Up @@ -238,23 +238,21 @@ class EntryActivity : LockingActivity() {

private fun fillEntryDataInContentsView(entry: Entry) {

val database = Database.getInstance()
database.startManageEntry(entry)
val entryInfo = entry.getEntryInfo(mDatabase)

// Assign title icon
titleIconView?.assignDatabaseIcon(database.drawFactory, entry.icon, iconColor)
titleIconView?.assignDatabaseIcon(mDatabase!!.drawFactory, entryInfo.icon, iconColor)

// Assign title text
val entryTitle = entry.title
val entryTitle = entryInfo.title
collapsingToolbarLayout?.title = entryTitle
toolbar?.title = entryTitle

// Assign basic fields
entryContentsView?.assignUserName(entry.username) {
database.startManageEntry(entry)
clipboardHelper?.timeoutCopyToClipboard(entry.username,
entryContentsView?.assignUserName(entryInfo.username) {
clipboardHelper?.timeoutCopyToClipboard(entryInfo.username,
getString(R.string.copy_field,
getString(R.string.entry_user_name)))
database.stopManageEntry(entry)
}

val isFirstTimeAskAllowCopyPasswordAndProtectedFields =
Expand Down Expand Up @@ -284,11 +282,9 @@ class EntryActivity : LockingActivity() {

val onPasswordCopyClickListener: View.OnClickListener? = if (allowCopyPasswordAndProtectedFields) {
View.OnClickListener {
database.startManageEntry(entry)
clipboardHelper?.timeoutCopyToClipboard(entry.password,
clipboardHelper?.timeoutCopyToClipboard(entryInfo.password,
getString(R.string.copy_field,
getString(R.string.entry_password)))
database.stopManageEntry(entry)
}
} else {
// If dialog not already shown
Expand All @@ -298,69 +294,63 @@ class EntryActivity : LockingActivity() {
null
}
}
entryContentsView?.assignPassword(entry.password,
entryContentsView?.assignPassword(entryInfo.password,
allowCopyPasswordAndProtectedFields,
onPasswordCopyClickListener)

//Assign OTP field
entryContentsView?.assignOtp(entry.getOtpElement(), entryProgress,
View.OnClickListener {
entry.getOtpElement()?.let { otpElement ->
clipboardHelper?.timeoutCopyToClipboard(
otpElement.token,
getString(R.string.copy_field, getString(R.string.entry_otp))
)
}
})
entry.getOtpElement()?.let { otpElement ->
entryContentsView?.assignOtp(otpElement, entryProgress) {
clipboardHelper?.timeoutCopyToClipboard(
otpElement.token,
getString(R.string.copy_field, getString(R.string.entry_otp))
)
}
}

entryContentsView?.assignURL(entry.url)
entryContentsView?.assignNotes(entry.notes)
entryContentsView?.assignURL(entryInfo.url)
entryContentsView?.assignNotes(entryInfo.notes)

// Assign custom fields
if (mDatabase?.allowEntryCustomFields() == true) {
entryContentsView?.clearExtraFields()
entry.getExtraFields().forEach { field ->
entryInfo.customFields.forEach { field ->
val label = field.name
val value = field.protectedValue
val allowCopyProtectedField = !value.isProtected || allowCopyPasswordAndProtectedFields
if (allowCopyProtectedField) {
entryContentsView?.addExtraField(label, value, allowCopyProtectedField) {
clipboardHelper?.timeoutCopyToClipboard(
value.toString(),
getString(R.string.copy_field, label)
)
}
} else {
// If dialog not already shown
if (isFirstTimeAskAllowCopyPasswordAndProtectedFields) {
entryContentsView?.addExtraField(label, value, allowCopyProtectedField, showWarningClipboardDialogOnClickListener)
// OTP field is already managed in dedicated view
if (label != OtpEntryFields.OTP_TOKEN_FIELD) {
val value = field.protectedValue
val allowCopyProtectedField = !value.isProtected || allowCopyPasswordAndProtectedFields
if (allowCopyProtectedField) {
entryContentsView?.addExtraField(label, value, allowCopyProtectedField) {
clipboardHelper?.timeoutCopyToClipboard(
value.toString(),
getString(R.string.copy_field, label)
)
}
} else {
entryContentsView?.addExtraField(label, value, allowCopyProtectedField, null)
// If dialog not already shown
if (isFirstTimeAskAllowCopyPasswordAndProtectedFields) {
entryContentsView?.addExtraField(label, value, allowCopyProtectedField, showWarningClipboardDialogOnClickListener)
} else {
entryContentsView?.addExtraField(label, value, allowCopyProtectedField, null)
}
}
}
}
}
entryContentsView?.setHiddenProtectedValue(!mShowPassword)

// Manage attachments
mDatabase?.binaryPool?.let { binaryPool ->
entryContentsView?.assignAttachments(entry.getAttachments(binaryPool).toSet(), StreamDirection.DOWNLOAD) { attachmentItem ->
createDocument(this, attachmentItem.name)?.let { requestCode ->
mAttachmentsToDownload[requestCode] = attachmentItem
}
entryContentsView?.assignAttachments(entryInfo.attachments.toSet(), StreamDirection.DOWNLOAD) { attachmentItem ->
createDocument(this, attachmentItem.name)?.let { requestCode ->
mAttachmentsToDownload[requestCode] = attachmentItem
}
}

// Assign dates
entryContentsView?.assignCreationDate(entry.creationTime)
entryContentsView?.assignModificationDate(entry.lastModificationTime)
entryContentsView?.assignLastAccessDate(entry.lastAccessTime)
entryContentsView?.setExpires(entry.isCurrentlyExpires)
if (entry.expires) {
entryContentsView?.assignExpiresDate(entry.expiryTime)
} else {
entryContentsView?.assignExpiresDate(getString(R.string.never))
}
entryContentsView?.assignCreationDate(entryInfo.creationTime)
entryContentsView?.assignModificationDate(entryInfo.modificationTime)
entryContentsView?.setExpires(entryInfo.expires, entryInfo.expiryTime)

// Manage history
historyView?.visibility = if (mIsHistory) View.VISIBLE else View.GONE
Expand All @@ -375,8 +365,6 @@ class EntryActivity : LockingActivity() {

// Assign special data
entryContentsView?.assignUUID(entry.nodeId.id)

database.stopManageEntry(entry)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ class Entry : Node, EntryVersionedInterface<Group> {
entryInfo.icon = icon
entryInfo.username = username
entryInfo.password = password
entryInfo.creationTime = creationTime
entryInfo.modificationTime = lastModificationTime
entryInfo.expires = expires
entryInfo.expiryTime = expiryTime
entryInfo.url = url
Expand Down Expand Up @@ -456,6 +458,9 @@ class Entry : Node, EntryVersionedInterface<Group> {
icon = newEntryInfo.icon
username = newEntryInfo.username
password = newEntryInfo.password
// Update date time, creation time stay as is
lastModificationTime = DateInstant()
lastAccessTime = DateInstant()
expires = newEntryInfo.expires
expiryTime = newEntryInfo.expiryTime
url = newEntryInfo.url
Expand All @@ -464,9 +469,6 @@ class Entry : Node, EntryVersionedInterface<Group> {
database?.binaryPool?.let { binaryPool ->
addAttachments(binaryPool, newEntryInfo.attachments)
}
// Update date time
lastAccessTime = DateInstant()
lastModificationTime = DateInstant()

database?.stopManageEntry(this)
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/kunzisoft/keepass/model/EntryInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class EntryInfo : Parcelable {
var icon: IconImage = IconImageStandard()
var username: String = ""
var password: String = ""
var creationTime: DateInstant = DateInstant()
var modificationTime: DateInstant = DateInstant()
var expires: Boolean = false
var expiryTime: DateInstant = DateInstant.IN_ONE_MONTH
var url: String = ""
Expand All @@ -55,6 +57,8 @@ class EntryInfo : Parcelable {
icon = parcel.readParcelable(IconImage::class.java.classLoader) ?: icon
username = parcel.readString() ?: username
password = parcel.readString() ?: password
creationTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: creationTime
modificationTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: modificationTime
expires = parcel.readInt() != 0
expiryTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: expiryTime
url = parcel.readString() ?: url
Expand All @@ -74,6 +78,8 @@ class EntryInfo : Parcelable {
parcel.writeParcelable(icon, flags)
parcel.writeString(username)
parcel.writeString(password)
parcel.writeParcelable(creationTime, flags)
parcel.writeParcelable(modificationTime, flags)
parcel.writeInt(if (expires) 1 else 0)
parcel.writeParcelable(expiryTime, flags)
parcel.writeString(url)
Expand Down
22 changes: 6 additions & 16 deletions app/src/main/java/com/kunzisoft/keepass/view/EntryContentsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class EntryContentsView @JvmOverloads constructor(context: Context,

private val creationDateView: TextView
private val modificationDateView: TextView
private val lastAccessDateView: TextView
private val expiresImageView: ImageView
private val expiresDateView: TextView

Expand Down Expand Up @@ -117,7 +116,6 @@ class EntryContentsView @JvmOverloads constructor(context: Context,

creationDateView = findViewById(R.id.entry_created)
modificationDateView = findViewById(R.id.entry_modified)
lastAccessDateView = findViewById(R.id.entry_accessed)
expiresImageView = findViewById(R.id.entry_expires_image)
expiresDateView = findViewById(R.id.entry_expires_date)

Expand Down Expand Up @@ -258,28 +256,20 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
modificationDateView.text = date.getDateTimeString(resources)
}

fun assignLastAccessDate(date: DateInstant) {
lastAccessDateView.text = date.getDateTimeString(resources)
}

fun setExpires(isExpires: Boolean) {
fun setExpires(isExpires: Boolean, expiryTime: DateInstant) {
expiresImageView.visibility = if (isExpires) View.VISIBLE else View.GONE
}

fun assignExpiresDate(date: DateInstant) {
assignExpiresDate(date.getDateTimeString(resources))
}

fun assignExpiresDate(constString: String) {
expiresDateView.text = constString
expiresDateView.text = if (isExpires) {
expiryTime.getDateTimeString(resources)
} else {
resources.getString(R.string.never)
}
}

fun assignUUID(uuid: UUID) {
uuidView.text = uuid.toString()
uuidReferenceView.text = UuidUtil.toHexString(uuid)
}


fun setHiddenProtectedValue(hiddenProtectedValue: Boolean) {
passwordFieldView.hiddenProtectedValue = hiddenProtectedValue
// Hidden style for custom fields
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/layout/view_entry_contents.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@
android:layout_height="wrap_content"
android:text="@string/entry_accessed"
style="@style/KeepassDXStyle.TextAppearance.LabelTextStyle" />
<androidx.appcompat.widget.AppCompatTextView
android:visibility="gone"
android:id="@+id/entry_accessed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/KeepassDXStyle.TextAppearance.TextEntryItem" />

<!-- Expires -->
<androidx.appcompat.widget.AppCompatTextView
Expand Down

0 comments on commit 2bfb9b0

Please sign in to comment.