package Ġcom . she ve lev . wizard _ camera . activity _ main . fragment _ camera . view Ċ Ċ import Ġandroid . Manifest Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . content . Intent Ċ import Ġandroid . graphics . Surface Texture Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . Texture View Ċ import Ġandroid . view . View Ċ import Ġcom . she ve lev . wizard _ camera . R Ċ import Ġcom . she ve lev . wizard _ camera . activity _ gallery . Gallery Activity Ċ import Ġcom . she ve lev . wizard _ camera . activity _ main . fragment _ camera . di . Camera Fragment Component Ċ import Ġcom . she ve lev . wizard _ camera . activity _ main . fragment _ camera . model . dto .* Ċ import Ġcom . she ve lev . wizard _ camera . activity _ main . fragment _ camera . view . gest ures . Gest ures Detector Ċ import Ġcom . she ve lev . wizard _ camera . activity _ main . fragment _ camera . view _ model . Camera Fragment ViewModel Ċ import Ġcom . she ve lev . wizard _ camera . application . App Ċ import Ġcom . she ve lev . wizard _ camera . camera . manager . Camera Manager Ċ import Ġcom . she ve lev . wizard _ camera . camera . renderer . GL Renderer Ċ import Ġcom . she ve lev . wizard _ camera . camera . settings _ repository . Camera Settings Repository Ċ import Ġcom . she ve lev . wizard _ camera . camera . filter . Camera Filter Ċ import Ġcom . she ve lev . wizard _ camera . databinding . Fragment Camera Binding Ċ import Ġcom . she ve lev . wizard _ camera . shared . mv vm . view . Fragment Base MV VM Ċ import Ġcom . she ve lev . wizard _ camera . shared . mv vm . view _ commands . View Command Ċ import Ġpermissions . dispatcher . Needs Permission Ċ import Ġpermissions . dispatcher . On Permission Denied Ċ import Ġpermissions . dispatcher . Runtime Permissions Ċ import Ġjavax . inject . Inject Ċ Ċ @ Runtime Permissions Ċ class ĠCamera Fragment Ġ: ĠFragment Base MV VM < Fragment Camera Binding , ĠCamera Fragment ViewModel >(), ĠTexture View . Surface Texture Listener Ġ{ ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġtexture View : ĠTexture View ĊĊĠĠĠ Ġprivate Ġvar Ġrenderer : ĠGL Renderer ? Ġ= Ġnull ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcamera Manager : ĠCamera Manager ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġgesture Detector : ĠGest ures Detector ĊĊĠĠĠ Ġ@ Inject ĊĠĠĠ Ġinternal Ġlateinit Ġvar Ġcamera Settings Repository : ĠCamera Settings Repository ĊĊĠĠĠ Ġoverride Ġfun Ġprovide ViewModel Type (): ĠClass < Camera Fragment ViewModel > Ġ= ĠCamera Fragment ViewModel :: class . java ĊĊĠĠĠ Ġoverride Ġfun Ġlayout Res Id (): ĠInt Ġ= ĠR . layout . fragment _ camera ĊĊĠĠĠ Ġoverride Ġfun Ġlink ViewModel ( binding : ĠFragment Camera Binding , ĠviewModel : ĠCamera Fragment ViewModel ) Ġ{ ĊĠĠĠĠĠĠĠ Ġbinding . viewModel Ġ= ĠviewModel ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġinject () Ġ= ĠApp . injection s . get < Camera Fragment Component >(). inject ( this ) ĊĊĠĠĠ Ġoverride Ġfun Ġrelease Injection () Ġ= ĠApp . injection s . release < Camera Fragment Component >() ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĊĠĠĠĠĠĠĠ Ġgesture Detector Ġ= ĠGest ures Detector ( require Context ()). apply Ġ{ Ġset On Gesture Listener Ġ{ ĠviewModel . process Gesture ( it ) Ġ} Ġ} ĊĊĠĠĠĠĠĠĠ ĠviewModel . selected Filter . observe ( view Lifecycle Owner ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrenderer ?. set Filter ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠviewModel . all Filters List Data . observe ( view Lifecycle Owner ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . all Filters Carousel . set Start Data ( it , ĠviewModel ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠviewModel . favorite Filters List Data . observe ( view Lifecycle Owner ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . favorites Filters Carousel . set Start Data ( it , ĠviewModel ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġbinding . shoot Button . setOnClickListener Ġ{ Ġtexture View . let Ġ{ ĠviewModel . on Capture Click () Ġ} Ġ} ĊĠĠĠĠĠĠĠ Ġbinding . flash Button . setOnClickListener Ġ{ ĠviewModel . on Flash Click () Ġ} ĊĠĠĠĠĠĠĠ Ġbinding . filters Mode Button . setOn Mode ChangeListener Ġ{ ĠviewModel . on Switch Filter Mode Click ( it ) Ġ} ĊĠĠĠĠĠĠĠ Ġbinding . ex position Bar . setOn Value ChangeListener Ġ{ ĠviewModel . on Expose Value Updated ( it ) Ġ} ĊĠĠĠĠĠĠĠ Ġbinding . gallery Button . setOnClickListener Ġ{ ĠviewModel . on G alley Click () Ġ} ĊĊĠĠĠĠĠĠĠ Ġbinding . all Filters Carousel . setOn ItemSelected Listener Ġ{ ĠviewModel . on Filter Selected ( it ) Ġ} ĊĠĠĠĠĠĠĠ Ġbinding . favorites Filters Carousel . setOn ItemSelected Listener Ġ{ ĠviewModel . on Favorite Filter Selected ( it ) Ġ} ĊĊĠĠĠĠĠĠĠ Ġbinding . settings . setOn Settings ChangeListener Ġ{ ĠviewModel . on Filter Settings Change ( it ) Ġ} ĊĊĠĠĠĠĠĠĠ Ġbinding . root . layout Transition . set Duration ( resources . getInteger ( android . R . integer . config _ short Anim Time ). to Long ()) ĊĊĠĠĠĠĠĠĠ Ġsetup Camera With Permission Check () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Resume () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Resume () ĊĠĠĠĠĠĠĠ ĠviewModel . on Active () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Pause () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Pause () ĊĠĠĠĠĠĠĠ ĠviewModel . on Inactive () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Request Permissions Result ( request Code : ĠInt , Ġpermissions : ĠArray < out ĠString >, Ġgrant Results : ĠInt Array ) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Request Permissions Result ( request Code , Ġpermissions , Ġgrant Results ) ĊĠĠĠĠĠĠĠ Ġon Request Permissions Result ( request Code , Ġgrant Results ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġprocess View Command ( command : ĠView Command ) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhen ( command ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠShow Capt uring Success Command Ġ-> Ġbinding . capture Success . show ( command . screen Orientation ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠZoom Command Ġ-> Ġcamera Manager . zoom ( command . scale Factor ). let Ġ{ ĠviewModel . on Zoom Updated ( it ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠReset Exposure Command Ġ-> Ġbinding . ex position Bar . reset () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠSet Exposure Command Ġ-> Ġcamera Manager . update Exposure ( command . ex posure Value ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠNavigate To Gallery Command Ġ-> Ġnavigate To Gallery () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠShow Filter Settings Command Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . settings . hide () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . settings . show ( command . settings ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠHide Filter Settings Command Ġ-> Ġbinding . settings . hide () ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠStart Capture Command Ġ-> Ġcamera Manager . capture ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcommand . target File , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcommand . is Flash Light Active , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcommand . rotation ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) Ġ{ Ġis Success Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . on Capture Complete ( is Success ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Surface Texture Available ( surface : ĠSurface Texture , Ġwidth : ĠInt , Ġheight : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġbinding . root . post Delayed ({ Ġstart Rendering ( surface , Ġwidth , Ġheight ) Ġ}, Ġ 5 0 0 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Surface Texture Size Changed ( surface : ĠSurface Texture , Ġwidth : ĠInt , Ġheight : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġstart Rendering ( surface , Ġwidth , Ġheight ) ĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Surface Texture Destroyed ( surface : ĠSurface Texture ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġstop Rendering () ĊĠĠĠĠĠĠĠ Ġreturn Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Surface Texture Updated ( surface : ĠSurface Texture ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġdo Ġnothing ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suppress Lint (" Click ableView Accessibility ") ĊĠĠĠ Ġ@ Needs Permission ( Manifest . permission . CAMERA ) ĊĠĠĠ Ġinternal Ġfun Ġsetup Camera () Ġ{ ĊĠĠĠĠĠĠĠ Ġtexture View Ġ= ĠTexture View ( require Context ()). also Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . texture Container . addView ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . surface Texture Listener Ġ= Ġthis ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . setOn Touch Listener Ġ{ Ġview , Ġevent Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġgesture Detector . on Touch Event ( view , Ġevent ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ On Permission Denied ( Manifest . permission . CAMERA ) ĊĠĠĠ Ġinternal Ġfun Ġon Camera Permissions Denied () Ġ= ĠviewModel . on Permission Denied () ĊĊĠĠĠ Ġprivate Ġfun Ġstart Rendering ( surface : ĠSurface Texture , Ġwidth : ĠInt , Ġheight : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif ( renderer Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġrenderer Ġ= ĠGL Renderer (- width , Ġ- height , Ġrequire Context (). application Context ). also Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . init GL ( surface ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . set Filter ( viewModel . selected Filter . value !! ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcamera Manager Ġ= ĠCamera Manager ( camera Settings Repository ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcamera Manager . init Camera ( require Context (), Ġthis , Ġit . camera Surface Texture , Ġtexture View ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . root . post Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . on Camera IsSet Up ( camera Manager . is Flash Light Supported ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġstop Rendering () Ġ{ ĊĠĠĠĠĠĠĠ Ġif ( renderer Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġrenderer ?. release GL () ĊĠĠĠĠĠĠĠ Ġrenderer Ġ= Ġnull ĊĊĠĠĠĠĠĠĠ Ġcamera Manager . release Camera () ĊĊĠĠĠĠĠĠĠ ĠCamera Filter . release () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġnavigate To Gallery () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġgallery Intent Ġ= ĠIntent ( require Context (), ĠGallery Activity :: class . java ) ĊĠĠĠĠĠĠĠ ĠstartActivity ( gallery Intent ) ĊĠĠĠ Ġ} Ċ }