mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
79 lines
2.4 KiB
Kotlin
79 lines
2.4 KiB
Kotlin
package com.kunzisoft.keepass.model
|
|
|
|
import android.os.Parcel
|
|
import android.os.Parcelable
|
|
import com.kunzisoft.keepass.otp.OtpElement
|
|
import com.kunzisoft.keepass.otp.OtpEntryFields.Companion.OTP_TOKEN_FIELD
|
|
import java.util.*
|
|
|
|
class EntryInfo : Parcelable {
|
|
|
|
var id: String = ""
|
|
var title: String = ""
|
|
var username: String = ""
|
|
var password: String = ""
|
|
var url: String = ""
|
|
var notes: String = ""
|
|
var customFields: MutableList<Field> = ArrayList()
|
|
var otpElement: OtpElement = OtpElement()
|
|
|
|
constructor()
|
|
|
|
private constructor(parcel: Parcel) {
|
|
id = parcel.readString() ?: id
|
|
title = parcel.readString() ?: title
|
|
username = parcel.readString() ?: username
|
|
password = parcel.readString() ?: password
|
|
url = parcel.readString() ?: url
|
|
notes = parcel.readString() ?: notes
|
|
parcel.readList(customFields, Field::class.java.classLoader)
|
|
otpElement = parcel.readParcelable(OtpElement::class.java.classLoader) ?: otpElement
|
|
}
|
|
|
|
override fun describeContents(): Int {
|
|
return 0
|
|
}
|
|
|
|
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
|
parcel.writeString(id)
|
|
parcel.writeString(title)
|
|
parcel.writeString(username)
|
|
parcel.writeString(password)
|
|
parcel.writeString(url)
|
|
parcel.writeString(notes)
|
|
parcel.writeArray(customFields.toTypedArray())
|
|
parcel.writeParcelable(otpElement, flags)
|
|
}
|
|
|
|
fun containsCustomFieldsProtected(): Boolean {
|
|
return customFields.any { it.protectedValue.isProtected }
|
|
}
|
|
|
|
fun containsCustomFieldsNotProtected(): Boolean {
|
|
return customFields.any { !it.protectedValue.isProtected }
|
|
}
|
|
|
|
fun isAutoGeneratedField(field: Field): Boolean {
|
|
return field.name == OTP_TOKEN_FIELD
|
|
}
|
|
|
|
fun doForAutoGeneratedField(field: Field, action: (valueGenerated: String) -> Unit) {
|
|
if (field.name == OTP_TOKEN_FIELD)
|
|
action.invoke(otpElement.token)
|
|
}
|
|
|
|
companion object {
|
|
|
|
@JvmField
|
|
val CREATOR: Parcelable.Creator<EntryInfo> = object : Parcelable.Creator<EntryInfo> {
|
|
override fun createFromParcel(parcel: Parcel): EntryInfo {
|
|
return EntryInfo(parcel)
|
|
}
|
|
|
|
override fun newArray(size: Int): Array<EntryInfo?> {
|
|
return arrayOfNulls(size)
|
|
}
|
|
}
|
|
}
|
|
}
|