package Ġcz . kot ox . core . arch Ċ Ċ import Ġandroidx . core . util . Pair Ċ import Ġandroidx . fragment . app . FragmentManager Ċ import Ġcom . google . android . material . datepicker . Calendar Constraints Ċ import Ġcom . google . android . material . datepicker . Material DatePicker Ċ import Ġcz . kot ox . core . entity . Simple Date Ċ import Ġcz . kot ox . core . entity . factory . get Calendar Instance Date Only Ċ import Ġcz . kot ox . core . entity . factory . getSimple Date Instance Ċ import Ġjava . util . Calendar Ċ import Ġjava . util . Calendar . DAY _ OF _ MONTH Ċ import Ġjava . util . Date Ċ Ċ interface ĠMaterial DatePicker Actions Ġ{ ĊĊ ĉ fun Ġshow Material Birth DatePicker ( Ċĉĉ ĉ current FragmentManager : ĠFragment Manager , Ċĉĉ ĉ current Selection : ĠSimple Date ?, Ċĉĉ ĉ minimum User Age In Years : ĠInt Ġ= Ġ 0 , Ċĉĉ ĉ on Date Selected : Ġ( date Selected : ĠSimple Date ) Ġ-> ĠUnit Ċ ĉ ) Ġ{ ĊĊĉ ĉ val Ġend Restriction Ġ= ĠCalendar . getInstance () Ċĉ ĉ end Restriction . add ( Calendar . YEAR , Ġ- minimum User Age In Years Ġ+ Ġ 1 ) ĊĊĉ ĉ val Ġopen At Ġ= Ġif Ġ( current Selection Ġ== Ġnull ) Ġ{ Ċĉĉ ĉ Calendar . getInstance (). apply Ġ{ Ġadd ( Calendar . YEAR , Ġ- minimum User Age In Years ) Ġ} Ċĉ ĉ } Ġelse Ġ{ Ċĉĉ ĉ val Ġcurrent Selection Calendar Ġ= Ġget Calendar Instance Date Only ( current Selection ) Ċĉĉ ĉ // Solve Ġsituation Ġwhen Ġincoming Ġselection Ġis Ġlower Ġthan Ġminimum Ġuser Ġage . Ċĉĉ ĉ if Ġ( current Selection Calendar Ġ> Ġend Restriction ) Ġend Restriction Ġelse Ġcurrent Selection Calendar Ċĉ ĉ } ĊĊĉ ĉ val Ġdate Picker : ĠMaterial DatePicker < Long > Ġ= Ċĉĉ ĉ Material DatePicker . Builder . date Picker () Ċĉĉĉ ĉ . set Calendar Constraints ( Calendar Constraints . Builder () Ċĉĉĉĉ ĉ . set End ( end Restriction . time In Millis ) Ċĉĉĉĉ ĉ . set Open At ( open At . time In Millis ) Ċĉĉĉĉ ĉ . build ()) Ċĉĉĉ ĉ // Se ems Ġlike Ġbug Ġin Ġset Selection Ġbecause ĠI Ġhave Ġto Ġincrease Ġone Ġday Ġfor Ġproper Ġselection Ġ: -( Ċĉĉĉ ĉ . setSelection ( open At . apply Ġ{ Ġthis . add ( DAY _ OF _ MONTH , 1 ) Ġ}. time In Millis ) Ċĉĉĉ ĉ . build () ĊĊĉ ĉ date Picker . add On Positive Button ClickListener Ġ{ Ċĉĉ ĉ on Date Selected . invoke ( getSimple Date Instance ( Date ( it ))) Ċĉ ĉ } ĊĊĉ ĉ date Picker . show ( current FragmentManager , Ġdate Picker . toString ()) Ċ ĉ } ĊĊ ĉ fun Ġshow Material DateRange Picker ( Ċĉĉ ĉ current FragmentManager : ĠFragment Manager , Ċĉĉ ĉ from Date Selection : ĠSimple Date ?, Ċĉĉ ĉ toDate Selection : ĠSimple Date ?, Ċĉĉ ĉ on Date Selected : Ġ( from Date : ĠSimple Date ?, Ġto Date : ĠSimple Date ?) Ġ-> ĠUnit Ċ ĉ ) Ġ{ Ċĉ ĉ // Se ems Ġlike Ġbug Ġin Ġset Selection Ġbecause ĠI Ġhave Ġto Ġincrease Ġone Ġday Ġfor Ġproper Ġselection Ġ: -( Ċĉ ĉ val Ġcurrent Selection Ġ= ĠPair ( from Date Selection ?. let Ġ{ Ġget Calendar Instance Date Only ( it ). apply Ġ{ Ġthis . add ( DAY _ OF _ MONTH , 1 ) Ġ}. time In Millis Ġ}, Ġto Date Selection ?. let Ġ{ Ġget Calendar Instance Date Only ( it ). apply Ġ{ Ġthis . add ( DAY _ OF _ MONTH , 1 ) Ġ}. time In Millis Ġ}) Ċĉ ĉ val Ġdate Picker : ĠMaterial DatePicker < Pair < Long , ĠLong >> Ġ= Ċĉĉ ĉ Material DatePicker . Builder . date Range Picker () Ċĉĉĉ ĉ . set Calendar Constraints ( Calendar Constraints . Builder () Ċĉĉĉĉ ĉ . build ()) Ċĉĉĉ ĉ . setSelection ( current Selection ) Ċĉĉĉ ĉ . build () ĊĊĉ ĉ date Picker . add On Positive Button ClickListener Ġ{ Ċĉĉ ĉ on Date Selected . invoke ( Ċĉĉĉ ĉ it . first ?. let Ġ{ Ġfrom Date Ġ-> Ġget Simple Date Instance ( Date ( from Date )) Ġ}, Ċĉĉĉ ĉ it . second ?. let Ġ{ Ġto Date Ġ-> Ġget Simple Date Instance ( Date ( toDate )) Ġ} Ċĉĉ ĉ ) Ċĉ ĉ } ĊĊĉ ĉ date Picker . show ( current FragmentManager , Ġdate Picker . toString ()) Ċ ĉ } Ċ Ċ }