package Ġua . sy tor . w if ip ass . screen . splash Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroidx . appcompat . app . AlertDialog Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġandroidx . navigation . fragment . find Nav Controller Ċ import Ġkotlinx . android . synt hetic . main . dialog _ check _ password .* Ċ import Ġkotlinx . android . synt hetic . main . dialog _ check _ password . view .* Ċ import Ġorg . k oin . android x . view model . ext . android . viewModel Ċ import Ġua . sy tor . w if ip ass . R Ċ import Ġua . sy tor . w if ip ass . core . logger . Logger Ċ Ċ class ĠSpl ash Fragment Ġ: ĠFragment () Ġ{ ĊĊ ĉ private Ġval ĠviewModel Ġby ĠviewModel < Splash ViewModel >() ĊĊ ĉ private Ġval Ġobserver Ġ= ĠObserver < State > Ġ{ Ġstate Ġ-> Ċĉ ĉ Logger . log (" state [$ state ]") Ċĉ ĉ when Ġ( state ) Ġ{ Ċĉĉ ĉ State . Init Ġ-> Ġ{ Ċĉĉĉ ĉ viewModel . load Route () Ċĉĉ ĉ } ĊĊĉĉ ĉ State . Loading Ġ-> Ġ{ Ċĉĉ ĉ } ĊĊĉĉ ĉ State . Waiting For Password Ġ-> Ġ{ Ċĉĉĉ ĉ show Password Check Dialog () Ċĉĉ ĉ } ĊĊĉĉ ĉ State . Check Successfully Completed Ġ-> Ġ{ Ċĉĉĉ ĉ navigate Next () Ċĉĉ ĉ } ĊĊĉĉ ĉ State . Check Failed Ġ-> Ġ{ Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ super . onCreate ( savedInstanceState ) Ċĉ ĉ viewModel . subscribe On State (). observe ( this , Ġobserver ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġnavigate Next () Ġ{ Ċĉ ĉ Logger . log (" navigate Next ") Ċĉ ĉ find Nav Controller (). navigate ( R . id . splash _ to _ wifi _ action ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġshow Password Check Dialog () Ġ{ Ċĉ ĉ val Ġview Ġ= ĠLayoutInflater . from ( context ). inflate ( R . layout . dialog _ check _ password , Ġnull ) ĊĊĉ ĉ val Ġdialog Ġ= ĠAlertDialog . Builder ( require Context (), ĠR . style . AlertDialog ) Ċĉĉ ĉ . setTitle ( R . string . check _ password _ dialog _ title ) Ċĉĉ ĉ . setView ( view ) Ċĉĉ ĉ . set Positive Button ( R . string . check _ password _ dialog _ positive _ button ) Ġ{ Ġ_, Ġ_ Ġ-> Ġ} Ċĉĉ ĉ . set Negative Button ( R . string . check _ password _ dialog _ negative _ button ) Ġ{ Ġ_, Ġ_ Ġ-> Ġ} Ċĉĉ ĉ . create () ĊĊĉ ĉ val Ġon Positive Click : Ġ( View ) Ġ-> ĠUnit Ġ= Ġ{ Ċĉĉ ĉ val Ġpassword Ġ= Ġview . password EditText . text . toString () Ċĉĉ ĉ val ĠisValid Ġ= ĠviewModel . check Password ( password ) Ċĉĉ ĉ if Ġ( isValid ) Ġ{ Ċĉĉĉ ĉ dialog . cancel () Ċĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉ ĉ dialog . password Input Layout . error Ġ= Ġit . context . getString ( R . string . check _ password _ error _ text ) Ċĉĉĉ ĉ view . password Input Layout . password EditText . setText ("") Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ dialog . show () ĊĊĉ ĉ dialog . get Button ( AlertDialog . BUTTON _ POSITIVE ). setOnClickListener ( on Positive Click ) Ċĉ ĉ dialog . get Button ( AlertDialog . BUTTON _ NEGATIVE ). setOnClickListener Ġ{ Ġexit App () Ġ} Ċ ĉ } ĊĊ ĉ private Ġfun Ġexit App () Ġ{ Ċĉ ĉ Logger . log (" exit App ") Ċĉ ĉ require Activity (). finish And Remove Task () Ċ ĉ } Ċ Ċ }