package Ġcz . kot ox . core . webview . ui Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroid . graphics . Bitmap Ċ import Ġandroid . os . Build Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . MenuItem Ċ import Ġandroid . view . View Ċ import Ġandroid . webkit . Web Resource Request Ċ import Ġandroid . webkit . WebView Ċ import Ġandroid . webkit . WebView Client Ċ import Ġandroidx . annotation . Requires Api Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroidx . appcompat . content . res . AppCompat Resources Ċ import Ġandroidx . core . content . Context Compat Ċ import Ġandroidx . core . graphics . drawable . Drawable Compat Ċ import Ġandroidx . databinding . Data Binding Util Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġcz . kot ox . core . webview . R Ċ import Ġcz . kot ox . core . webview . databinding . WebView Activity Binding Ċ import Ġtim ber . log . Tim ber Ċ Ċ fun ĠFragment . show Web ( url : ĠString ) Ġ= ĠstartActivity ( WebView Activity . new Intent ( require Context (), Ġurl )) Ċ Ċ private Ġconst Ġval ĠARG _ URL Ġ= Ġ" url " Ċ Ċ class ĠWebView Activity Ġ: ĠAppCompatActivity () Ġ{ ĊĊ ĉ comp anion Ġobject Ġ{ ĊĊĉ ĉ fun Ġnew Intent ( context : ĠContext , Ġurl : ĠString ) Ġ= ĠIntent ( context , ĠWebView Activity :: class . java ). apply Ġ{ Ċĉĉ ĉ putExtra ( ARG _ URL , Ġurl ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġlateinit Ġvar Ġbinding : ĠWebView Activity Binding ĊĊ ĉ private Ġval Ġweb Client Ġ= Ġobject Ġ: ĠWebView Client () Ġ{ ĊĊĉ ĉ override Ġfun Ġon Page Started ( view : ĠWebView ?, Ġurl : ĠString ?, Ġfav icon : ĠBitmap ?) Ġ{ Ċĉĉ ĉ super . on Page Started ( view , Ġurl , Ġfav icon ) Ċĉĉ ĉ binding . progress . visibility Ġ= ĠView . VISIBLE Ċĉ ĉ } ĊĊĉ ĉ override Ġfun Ġon Page Finished ( view : ĠWebView ?, Ġurl : ĠString ?) Ġ{ Ċĉĉ ĉ super . on Page Finished ( view , Ġurl ) Ċĉĉ ĉ binding . progress . visibility Ġ= ĠView . GONE Ċĉ ĉ } ĊĊĉ ĉ override Ġfun Ġshould Override Url Loading ( view : ĠWebView , Ġurl : ĠString ): ĠBoolean Ġ{ Ċĉĉ ĉ view . load Url ( url ) Ċĉĉ ĉ return Ġtrue Ċĉ ĉ } ĊĊĉ ĉ @ Requires Api ( Build . VERSION _ CODES . LO L LI POP ) Ċĉ ĉ override Ġfun Ġshould Override Url Loading ( view : ĠWebView , Ġrequest : ĠWeb Resource Request ): ĠBoolean Ġ{ Ċĉĉ ĉ view . load Url ( request . url . toString ()) Ċĉĉ ĉ return Ġtrue Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ super . onCreate ( savedInstanceState ) ĊĊĉ ĉ binding Ġ= ĠData Binding Util . inflate ( layout Inflater , ĠR . layout . web _ view _ activity , Ġnull , Ġfalse ) Ċĉ ĉ set ContentView ( binding . root ) ĊĊĉ ĉ setup Toolbar () ĊĊĉ ĉ setup WebView () Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Options ItemSelected ( item : ĠMenuItem ): ĠBoolean Ġ= Ċĉ ĉ when Ġ( item . itemId ) Ġ{ Ċĉĉ ĉ android . R . id . home Ġ-> Ġ{ Ċĉĉĉ ĉ on Back Pressed () Ċĉĉĉ ĉ true Ċĉĉ ĉ } Ċĉĉ ĉ else Ġ-> Ġsuper . on Options ItemSelected ( item ) Ċĉ ĉ } ĊĊ ĉ private Ġfun Ġsetup WebView () Ġ{ Ċĉ ĉ binding . progress . visibility Ġ= ĠView . VISIBLE Ċĉ ĉ binding . webview . apply Ġ{ Ċĉĉ ĉ web View Client Ġ= Ġweb Client Ċ // ĉĉ ĉ settings . java Script Enabled Ġ= Ġtrue Ċĉĉ ĉ val Ġurl : ĠString ? Ġ= Ġintent . getString Extra ( ARG _ URL ) Ċĉĉ ĉ if Ġ( url Ġ!= Ġnull ) Ġ{ Ċĉĉĉ ĉ load Url ( url ) Ċĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉ ĉ Tim ber . d ( IllegalStateException (" Unable Ġto Ġload Ġnull Ġurl Ġfor ĠwebView ! ")) Ċĉĉĉ ĉ finish () Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġsetup Toolbar () Ġ{ Ċĉ ĉ set Support ActionBar ( binding . web View Toolbar ) Ċĉ ĉ binding . web View Toolbar . navigation Icon Ġ= Ċĉĉ ĉ AppCompat Resources . get Drawable ( this @ WebView Activity , ĠR . drawable . abc _ ic _ ab _ back _ material )?. apply Ġ{ Ċĉĉĉ ĉ Drawable Compat . set Tint ( this , ĠContext Compat . getColor ( this @ WebView Activity , Ġ/* R . color . color _ on _ background Ġ- Ġtemporarily Ġcommented Ġout Ġuntil Ġstyles / colors Ġwill Ġbe Ġref actored */ R . color . global _ primary Ġ)) Ċĉĉ ĉ } Ċ ĉ } Ċ Ċ }