mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Select date and time for each field
This commit is contained in:
@@ -241,14 +241,11 @@ class EntryEditActivity : LockingActivity(),
|
||||
.commit()
|
||||
entryEditFragment?.apply {
|
||||
drawFactory = mDatabase?.iconDrawableFactory
|
||||
onDateTimeClickListener = { expiryTime ->
|
||||
expiryTime.date.let { expiresDate ->
|
||||
val dateTime = DateTime(expiresDate)
|
||||
val defaultYear = dateTime.year
|
||||
val defaultMonth = dateTime.monthOfYear-1
|
||||
val defaultDay = dateTime.dayOfMonth
|
||||
DatePickerFragment.getInstance(defaultYear, defaultMonth, defaultDay)
|
||||
.show(supportFragmentManager, "DatePickerFragment")
|
||||
onDateTimeClickListener = { dateInstant ->
|
||||
if (dateInstant.type == DateInstant.Type.TIME) {
|
||||
selectTime(dateInstant)
|
||||
} else {
|
||||
selectDate(dateInstant)
|
||||
}
|
||||
}
|
||||
setOnPasswordGeneratorClickListener = View.OnClickListener {
|
||||
@@ -733,36 +730,53 @@ class EntryEditActivity : LockingActivity(),
|
||||
}
|
||||
}
|
||||
|
||||
// Launch the date picker
|
||||
private fun selectDate(dateInstant: DateInstant) {
|
||||
val dateTime = DateTime(dateInstant.date)
|
||||
val defaultYear = dateTime.year
|
||||
val defaultMonth = dateTime.monthOfYear - 1
|
||||
val defaultDay = dateTime.dayOfMonth
|
||||
DatePickerFragment.getInstance(defaultYear, defaultMonth, defaultDay)
|
||||
.show(supportFragmentManager, "DatePickerFragment")
|
||||
}
|
||||
|
||||
// Launch the time picker
|
||||
private fun selectTime(dateInstant: DateInstant) {
|
||||
val dateTime = DateTime(dateInstant.date)
|
||||
val defaultHour = dateTime.hourOfDay
|
||||
val defaultMinute = dateTime.minuteOfHour
|
||||
TimePickerFragment.getInstance(defaultHour, defaultMinute)
|
||||
.show(supportFragmentManager, "TimePickerFragment")
|
||||
}
|
||||
|
||||
override fun onDateSet(datePicker: DatePicker?, year: Int, month: Int, day: Int) {
|
||||
// To fix android 4.4 issue
|
||||
// https://stackoverflow.com/questions/12436073/datepicker-ondatechangedlistener-called-twice
|
||||
if (datePicker?.isShown == true) {
|
||||
entryEditFragment?.getExpiryTime()?.date?.let { expiresDate ->
|
||||
entryEditFragment?.getCurrentDateTimeSelection()?.let { instant ->
|
||||
// Save the date
|
||||
entryEditFragment?.setExpiryTime(
|
||||
DateInstant(DateTime(expiresDate)
|
||||
entryEditFragment?.setCurrentDateTimeSelection(
|
||||
DateInstant(DateTime(instant.date)
|
||||
.withYear(year)
|
||||
.withMonthOfYear(month + 1)
|
||||
.withDayOfMonth(day)
|
||||
.toDate()))
|
||||
// Launch the time picker
|
||||
val dateTime = DateTime(expiresDate)
|
||||
val defaultHour = dateTime.hourOfDay
|
||||
val defaultMinute = dateTime.minuteOfHour
|
||||
TimePickerFragment.getInstance(defaultHour, defaultMinute)
|
||||
.show(supportFragmentManager, "TimePickerFragment")
|
||||
.toDate(), instant.type))
|
||||
if (instant.type == DateInstant.Type.DATE_TIME) {
|
||||
selectTime(instant)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTimeSet(timePicker: TimePicker?, hours: Int, minutes: Int) {
|
||||
entryEditFragment?.getExpiryTime()?.date?.let { expiresDate ->
|
||||
entryEditFragment?.getCurrentDateTimeSelection()?.let { instant ->
|
||||
// Save the date
|
||||
entryEditFragment?.setExpiryTime(
|
||||
DateInstant(DateTime(expiresDate)
|
||||
entryEditFragment?.setCurrentDateTimeSelection(
|
||||
DateInstant(DateTime(instant.date)
|
||||
.withHourOfDay(hours)
|
||||
.withMinuteOfHour(minutes)
|
||||
.toDate()))
|
||||
.toDate(), instant.type)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,9 @@ class EntryEditFragment : StylishFragment() {
|
||||
private var mLastFocusedEditField: FocusedEditField? = null
|
||||
private var mExtraViewToRequestFocus: EditText? = null
|
||||
|
||||
// Current date time selection
|
||||
private var mTempDateTimeView: DateTimeView? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
super.onCreateView(inflater, container, savedInstanceState)
|
||||
|
||||
@@ -452,7 +455,10 @@ class EntryEditFragment : StylishFragment() {
|
||||
else -> DateInstant.IN_ONE_MONTH_DATE_TIME
|
||||
}
|
||||
}
|
||||
setOnDateClickListener = onDateTimeClickListener
|
||||
setOnDateClickListener = { dateInstant ->
|
||||
mTempDateTimeView = this
|
||||
onDateTimeClickListener?.invoke(dateInstant)
|
||||
}
|
||||
tag = fieldTag
|
||||
}
|
||||
}
|
||||
@@ -509,14 +515,18 @@ class EntryEditFragment : StylishFragment() {
|
||||
passwordView?.setText(password)
|
||||
}
|
||||
|
||||
fun setExpiryTime(expiration: DateInstant) {
|
||||
mEntryInfo.expiryTime = expiration
|
||||
val expirationView: DateTimeView? = templateContainerView.findViewWithTag(FIELD_EXPIRES_TAG)
|
||||
expirationView?.dateTime = expiration
|
||||
/* -------------
|
||||
* Date Time selection
|
||||
* -------------
|
||||
*/
|
||||
|
||||
fun setCurrentDateTimeSelection(expiration: DateInstant) {
|
||||
// TODO fix orientation change
|
||||
mTempDateTimeView?.dateTime = expiration
|
||||
}
|
||||
|
||||
fun getExpiryTime(): DateInstant {
|
||||
return mEntryInfo.expiryTime
|
||||
fun getCurrentDateTimeSelection(): DateInstant? {
|
||||
return mTempDateTimeView?.dateTime
|
||||
}
|
||||
|
||||
/* -------------
|
||||
|
||||
Reference in New Issue
Block a user