Skip to content

Commit

Permalink
v1 Date-time picker dailog orientation (microsoft#679)
Browse files Browse the repository at this point in the history
* fixing date-picker-dialogue-issues

* removing unused import

* added a const string IS_DIALOG_SHOWING

---------

Co-authored-by: Anubhav Agrawal <anubagrawal@microsoft.com>
  • Loading branch information
Anubhvv and Anubhav Agrawal authored Aug 23, 2024
1 parent 392c806 commit f2b4e70
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DateTimePickerActivity : DemoActivity(), DateTimePickerDialog.OnDateTimePi

private const val DIALOG_DATE_TIME = "dialogDateTime"
private const val DIALOG_MODE = "dialogMode"
private const val IS_DIALOG_SHOWING = "isDialogShowing"
}

enum class DatePickerType(
Expand Down Expand Up @@ -79,6 +80,7 @@ class DateTimePickerActivity : DemoActivity(), DateTimePickerDialog.OnDateTimePi
}

private var dateTimePickerDialog: DateTimePickerDialog? = null
private var isDialogShowing: Boolean = false

private lateinit var dateTimeBinding: ActivityDateTimePickerBinding

Expand Down Expand Up @@ -183,6 +185,7 @@ class DateTimePickerActivity : DemoActivity(), DateTimePickerDialog.OnDateTimePi
singleModeTag = it.getString(SINGLE_MODE_TAG)
dialogMode = it.getSerializable(DIALOG_MODE) as? Mode
dialogDateTime = it.getSerializable(DIALOG_DATE_TIME) as? ZonedDateTime
isDialogShowing = savedInstanceState.getBoolean(IS_DIALOG_SHOWING)
}

// DateTimePickers
Expand All @@ -202,8 +205,14 @@ class DateTimePickerActivity : DemoActivity(), DateTimePickerDialog.OnDateTimePi
accessibilityManager.addAccessibilityStateChangeListener {
updateButtonsForAccessibility(it)
}
if(isDialogShowing) {
dateTimePickerDialog?.dismiss()
createDateTimePickerDialog()
}

}


override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putSerializable(DATE_TIME, dateTime)
Expand All @@ -215,6 +224,7 @@ class DateTimePickerActivity : DemoActivity(), DateTimePickerDialog.OnDateTimePi
outState.putString(FRAGMENT_TAG, fragmentTag)
outState.putSerializable(DIALOG_MODE, dialogMode)
outState.putSerializable(DIALOG_DATE_TIME, dialogDateTime)
outState.putBoolean(IS_DIALOG_SHOWING, dateTimePickerDialog?.isShowing ?: false)
}

override fun onDestroy() {
Expand Down Expand Up @@ -251,6 +261,7 @@ class DateTimePickerActivity : DemoActivity(), DateTimePickerDialog.OnDateTimePi
getFragmentDateTime(),
getFragmentDuration()
)
dateTimePickerDialog?.onDateTimePickedListener = this
dateTimePicker.show(supportFragmentManager, picker.tag)
}

Expand All @@ -272,6 +283,13 @@ class DateTimePickerActivity : DemoActivity(), DateTimePickerDialog.OnDateTimePi
dialogDateTime = dateTime
}
}
dateTimePickerDialog?.onDateTimeSelectedListener =
object : DateTimePickerDialog.OnDateTimeSelectedListener{
override fun onDateTimeSelected(dateTime: ZonedDateTime, duration: Duration) {
dialogMode = getDialogMode()
dialogDateTime = dateTime
}
}

dateTimePickerDialog?.show()
}
Expand Down

0 comments on commit f2b4e70

Please sign in to comment.