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