mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-06 00:32:32 -08:00
Manage expires
This commit is contained in:
1 parent
54c2f5a61f
commit
5f96de84b0
16 files changed
+81
-54
No files matched your search
@@ -253,7 +253,8 @@ class EntryActivity : LockingHideActivity() {
|
||||
entryContentsView?.assignCreationDate(entry.creationTime)
|
||||
entryContentsView?.assignModificationDate(entry.lastModificationTime)
|
||||
entryContentsView?.assignLastAccessDate(entry.lastAccessTime)
|
||||
if (entry.isExpires) {
|
||||
entryContentsView?.setExpires(entry.isCurrentlyExpires)
|
||||
if (entry.expires) {
|
||||
entryContentsView?.assignExpiresDate(entry.expiryTime)
|
||||
} else {
|
||||
entryContentsView?.assignExpiresDate(getString(R.string.never))
|
||||
|
||||
@@ -154,13 +154,16 @@ class EntryVersioned : NodeVersioned, PwEntryInterface<GroupVersioned> {
|
||||
pwEntryV4?.expiryTime = value
|
||||
}
|
||||
|
||||
override var isExpires: Boolean
|
||||
get() =pwEntryV3?.isExpires ?: pwEntryV4?.isExpires ?: false
|
||||
override var expires: Boolean
|
||||
get() = pwEntryV3?.expires ?: pwEntryV4?.expires ?: false
|
||||
set(value) {
|
||||
pwEntryV3?.isExpires = value
|
||||
pwEntryV4?.isExpires = value
|
||||
pwEntryV3?.expires = value
|
||||
pwEntryV4?.expires = value
|
||||
}
|
||||
|
||||
override val isCurrentlyExpires: Boolean
|
||||
get() = pwEntryV3?.isCurrentlyExpires ?: pwEntryV4?.isCurrentlyExpires ?: false
|
||||
|
||||
override var username: String
|
||||
get() = pwEntryV3?.username ?: pwEntryV4?.username ?: ""
|
||||
set(value) {
|
||||
|
||||
@@ -158,13 +158,16 @@ class GroupVersioned : NodeVersioned, PwGroupInterface<GroupVersioned, EntryVers
|
||||
pwGroupV4?.expiryTime = value
|
||||
}
|
||||
|
||||
override var isExpires: Boolean
|
||||
get() = pwGroupV3?.isExpires ?: pwGroupV4?.isExpires ?: false
|
||||
override var expires: Boolean
|
||||
get() = pwGroupV3?.expires ?: pwGroupV4?.expires ?: false
|
||||
set(value) {
|
||||
pwGroupV3?.isExpires = value
|
||||
pwGroupV4?.isExpires = value
|
||||
pwGroupV3?.expires = value
|
||||
pwGroupV4?.expires = value
|
||||
}
|
||||
|
||||
override val isCurrentlyExpires: Boolean
|
||||
get() = pwGroupV3?.isCurrentlyExpires ?: pwGroupV4?.isCurrentlyExpires ?: false
|
||||
|
||||
override fun getChildGroups(): MutableList<GroupVersioned> {
|
||||
val children = ArrayList<GroupVersioned>()
|
||||
|
||||
|
||||
@@ -29,5 +29,7 @@ interface NodeTimeInterface {
|
||||
|
||||
var expiryTime: PwDate
|
||||
|
||||
var isExpires: Boolean
|
||||
var expires: Boolean
|
||||
|
||||
val isCurrentlyExpires: Boolean
|
||||
}
|
||||
@@ -149,10 +149,6 @@ class PwDate : Parcelable {
|
||||
private var mCalendar: Calendar? = null
|
||||
|
||||
val NEVER_EXPIRE = neverExpire
|
||||
val DEFAULT_DATE = defaultDate
|
||||
|
||||
val PW_NEVER_EXPIRE = PwDate(NEVER_EXPIRE)
|
||||
val DEFAULT_PWDATE = PwDate(DEFAULT_DATE)
|
||||
|
||||
private val calendar: Calendar?
|
||||
get() {
|
||||
@@ -162,20 +158,7 @@ class PwDate : Parcelable {
|
||||
return mCalendar
|
||||
}
|
||||
|
||||
private val defaultDate: Date
|
||||
get() {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.set(Calendar.YEAR, 2004)
|
||||
cal.set(Calendar.MONTH, Calendar.JANUARY)
|
||||
cal.set(Calendar.DAY_OF_MONTH, 1)
|
||||
cal.set(Calendar.HOUR, 0)
|
||||
cal.set(Calendar.MINUTE, 0)
|
||||
cal.set(Calendar.SECOND, 0)
|
||||
|
||||
return cal.time
|
||||
}
|
||||
|
||||
private val neverExpire: Date
|
||||
private val neverExpire: PwDate
|
||||
get() {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.set(Calendar.YEAR, 2999)
|
||||
@@ -185,7 +168,7 @@ class PwDate : Parcelable {
|
||||
cal.set(Calendar.MINUTE, 59)
|
||||
cal.set(Calendar.SECOND, 59)
|
||||
|
||||
return cal.time
|
||||
return PwDate(cal.time)
|
||||
}
|
||||
|
||||
@JvmField
|
||||
|
||||
@@ -48,7 +48,7 @@ import java.util.UUID
|
||||
* @author Dominik Reichl <dominik.reichl></dominik.reichl>@t-online.de>
|
||||
* @author Jeremy Jamet <jeremy.jamet></jeremy.jamet>@kunzisoft.com>
|
||||
*/
|
||||
class PwEntryV3 : PwEntry<PwGroupV3, PwEntryV3> {
|
||||
class PwEntryV3 : PwEntry<PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
|
||||
/** A string describing what is in pBinaryData */
|
||||
var binaryDesc = ""
|
||||
|
||||
@@ -88,6 +88,8 @@ class PwEntryV4 : PwEntry<PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
return size
|
||||
}
|
||||
|
||||
override var expires: Boolean = false
|
||||
|
||||
constructor() : super()
|
||||
|
||||
constructor(parcel: Parcel) : super(parcel) {
|
||||
|
||||
@@ -23,7 +23,7 @@ package com.kunzisoft.keepass.database.element
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
class PwGroupV3 : PwGroup<Int, PwGroupV3, PwEntryV3> {
|
||||
class PwGroupV3 : PwGroup<Int, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
|
||||
var level = 0 // short
|
||||
/** Used by KeePass internally, don't use */
|
||||
|
||||
@@ -43,12 +43,15 @@ class PwGroupV4 : PwGroup<UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
var iconCustom = PwIconCustom.UNKNOWN_ICON
|
||||
private val customData = HashMap<String, String>()
|
||||
var notes = ""
|
||||
|
||||
var isExpanded = true
|
||||
var defaultAutoTypeSequence = ""
|
||||
var enableAutoType: Boolean? = null
|
||||
var enableSearching: Boolean? = null
|
||||
var lastTopVisibleEntry: UUID = PwDatabase.UUID_ZERO
|
||||
|
||||
override var expires: Boolean = false
|
||||
|
||||
override val type: Type
|
||||
get() = Type.GROUP
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ package com.kunzisoft.keepass.database.element
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import org.joda.time.LocalDate
|
||||
import org.joda.time.LocalDateTime
|
||||
|
||||
/**
|
||||
* Abstract class who manage Groups and Entries
|
||||
@@ -44,6 +44,7 @@ abstract class PwNode<IdType, Parent : PwGroupInterface<Parent, Entry>, Entry :
|
||||
this.lastModificationTime = parcel.readParcelable(PwDate::class.java.classLoader) ?: lastModificationTime
|
||||
this.lastAccessTime = parcel.readParcelable(PwDate::class.java.classLoader) ?: lastAccessTime
|
||||
this.expiryTime = parcel.readParcelable(PwDate::class.java.classLoader) ?: expiryTime
|
||||
this.expires = parcel.readByte().toInt() != 0
|
||||
}
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
@@ -54,6 +55,7 @@ abstract class PwNode<IdType, Parent : PwGroupInterface<Parent, Entry>, Entry :
|
||||
dest.writeParcelable(lastModificationTime, flags)
|
||||
dest.writeParcelable(lastAccessTime, flags)
|
||||
dest.writeParcelable(expiryTime, flags)
|
||||
dest.writeByte((if (expires) 1 else 0).toByte())
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
@@ -68,6 +70,7 @@ abstract class PwNode<IdType, Parent : PwGroupInterface<Parent, Entry>, Entry :
|
||||
this.lastModificationTime = PwDate(source.lastModificationTime)
|
||||
this.lastAccessTime = PwDate(source.lastAccessTime)
|
||||
this.expiryTime = PwDate(source.expiryTime)
|
||||
this.expires = source.expires
|
||||
}
|
||||
|
||||
protected abstract fun initNodeId(): PwNodeId<IdType>
|
||||
@@ -85,17 +88,11 @@ abstract class PwNode<IdType, Parent : PwGroupInterface<Parent, Entry>, Entry :
|
||||
|
||||
final override var lastAccessTime: PwDate = PwDate()
|
||||
|
||||
final override var expiryTime: PwDate = PwDate.PW_NEVER_EXPIRE
|
||||
final override var expiryTime: PwDate = PwDate()
|
||||
|
||||
final override var isExpires: Boolean
|
||||
// If expireDate is before NEVER_EXPIRE date less 1 month (to be sure)
|
||||
get() = expiryTime.date
|
||||
.before(LocalDate.fromDateFields(PwDate.NEVER_EXPIRE).minusMonths(1).toDate())
|
||||
set(value) {
|
||||
if (!value) {
|
||||
expiryTime = PwDate.PW_NEVER_EXPIRE
|
||||
}
|
||||
}
|
||||
final override val isCurrentlyExpires: Boolean
|
||||
get() = expires
|
||||
&& LocalDateTime.fromDateFields(expiryTime.date).isBefore(LocalDateTime.now())
|
||||
|
||||
/**
|
||||
* @return true if parent is present (false if not present, can be a root or a detach element)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
|
||||
import org.joda.time.LocalDateTime
|
||||
|
||||
interface PwNodeV3Interface : NodeTimeInterface {
|
||||
|
||||
override var expires: Boolean
|
||||
// If expireDate is before NEVER_EXPIRE date less 1 month (to be sure)
|
||||
// it is not expires
|
||||
get() = LocalDateTime(expiryTime.date)
|
||||
.isBefore(LocalDateTime.fromDateFields(PwDate.NEVER_EXPIRE.date)
|
||||
.minusMonths(1))
|
||||
set(value) {
|
||||
if (!value)
|
||||
expiryTime = PwDate.NEVER_EXPIRE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -591,7 +591,7 @@ class ImporterV4(private val streamDir: File,
|
||||
name.equals(PwDatabaseV4XML.ElemCreationTime, ignoreCase = true) -> tl?.creationTime = readPwTime(xpp)
|
||||
name.equals(PwDatabaseV4XML.ElemLastAccessTime, ignoreCase = true) -> tl?.lastAccessTime = readPwTime(xpp)
|
||||
name.equals(PwDatabaseV4XML.ElemExpiryTime, ignoreCase = true) -> tl?.expiryTime = readPwTime(xpp)
|
||||
name.equals(PwDatabaseV4XML.ElemExpires, ignoreCase = true) -> tl?.isExpires = readBool(xpp, false)
|
||||
name.equals(PwDatabaseV4XML.ElemExpires, ignoreCase = true) -> tl?.expires = readBool(xpp, false)
|
||||
name.equals(PwDatabaseV4XML.ElemUsageCount, ignoreCase = true) -> tl?.usageCount = readULong(xpp, 0)
|
||||
name.equals(PwDatabaseV4XML.ElemLocationChanged, ignoreCase = true) -> tl?.locationChanged = readPwTime(xpp)
|
||||
else -> readUnknown(xpp)
|
||||
|
||||
@@ -661,7 +661,7 @@ class PwDbV4Output(private val mDatabaseV4: PwDatabaseV4, outputStream: OutputSt
|
||||
writeObject(PwDatabaseV4XML.ElemCreationTime, it.creationTime.date)
|
||||
writeObject(PwDatabaseV4XML.ElemLastAccessTime, it.lastAccessTime.date)
|
||||
writeObject(PwDatabaseV4XML.ElemExpiryTime, it.expiryTime.date)
|
||||
writeObject(PwDatabaseV4XML.ElemExpires, it.isExpires)
|
||||
writeObject(PwDatabaseV4XML.ElemExpires, it.expires)
|
||||
writeObject(PwDatabaseV4XML.ElemUsageCount, it.usageCount)
|
||||
writeObject(PwDatabaseV4XML.ElemLocationChanged, it.locationChanged.date)
|
||||
|
||||
|
||||
@@ -24,16 +24,14 @@ import com.kunzisoft.keepass.database.element.PwEntryV4
|
||||
import com.kunzisoft.keepass.database.search.iterator.EntrySearchStringIteratorV4
|
||||
import com.kunzisoft.keepass.utils.StringUtil
|
||||
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
class EntrySearchHandlerV4(private val mSearchParametersV4: SearchParametersV4, private val mListStorage: MutableList<PwEntryV4>) : NodeHandler<PwEntryV4>() {
|
||||
|
||||
private var now: Date = Date()
|
||||
|
||||
override fun operate(node: PwEntryV4): Boolean {
|
||||
|
||||
if (mSearchParametersV4.excludeExpired && node.isExpires && now.after(node.expiryTime.date)) {
|
||||
if (mSearchParametersV4.excludeExpired
|
||||
&& node.isCurrentlyExpires) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ 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
|
||||
|
||||
private val uuidView: TextView
|
||||
@@ -104,7 +105,8 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
|
||||
creationDateView = findViewById(R.id.entry_created)
|
||||
modificationDateView = findViewById(R.id.entry_modified)
|
||||
lastAccessDateView = findViewById(R.id.entry_accessed)
|
||||
expiresDateView = findViewById(R.id.entry_expires)
|
||||
expiresImageView = findViewById(R.id.entry_expires_image)
|
||||
expiresDateView = findViewById(R.id.entry_expires_date)
|
||||
|
||||
uuidView = findViewById(R.id.entry_UUID)
|
||||
|
||||
@@ -254,8 +256,12 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
|
||||
lastAccessDateView.text = date.getDateTimeString(resources)
|
||||
}
|
||||
|
||||
fun setExpires(isExpires: Boolean) {
|
||||
expiresImageView.visibility = if (isExpires) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
fun assignExpiresDate(date: PwDate) {
|
||||
expiresDateView.text = date.getDateTimeString(resources)
|
||||
assignExpiresDate(date.getDateTimeString(resources))
|
||||
}
|
||||
|
||||
fun assignExpiresDate(constString: String) {
|
||||
|
||||
Reference in new issue
Block a user