package Ġme . cyber . n uk le os . ui . find Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . v 7 . widget . Linear LayoutManager Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroid . widget . Toast Ċ import Ġdagger . android . support . Android Support Injection Ċ import Ġkotlinx . android . synt hetic . main . layout _ scan _ device .* Ċ import Ġme . cyber . n uk le os . Base Fragment Ċ import Ġme . cyber . n uk le os . ui . MainActivity Ċ import Ġme . cyber . n uk le os . ui . model . Sensor Stuff Ċ import Ġme . cyber . n uk le os . utils . Device Adapter Ċ import Ġme . cyber . n uk le os . utils . Device Selected Listener Ċ import Ġme . cyber . n uk le os . utils . Recycler Item Fade Animator Ċ import Ġme . cyber . n uk le us . R Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠFind Sensor Fragment Ġ: ĠBase Fragment < Find Sensor Interface . Presenter >(), ĠFind Sensor Interface . View Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġnew Instance () Ġ= ĠFind Sensor Fragment () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Inject ĊĠĠĠ Ġlateinit Ġvar Ġscan Device Presenter : ĠFind Sensor Presenter ĊĊĠĠĠ Ġprivate Ġval Ġm List Device Adapter Ġby Ġlazy Ġ{ ĊĠĠĠĠĠĠĠ ĠDevice Adapter ( object Ġ: ĠDevice Selected Listener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Device Selected ( v : ĠView , Ġposition : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġscan Device Presenter . on Sensor Selected ( position ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĠsavedInstanceState : ĠBundle ?) Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinflater . inflate ( R . layout . layout _ scan _ device , Ġcontainer , Ġfalse ). apply Ġ{ Ġset Has Options Menu ( true ) Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠĠĠĠĠ Ġfab _ scan . setOnClickListener Ġ{ Ġscan Device Presenter . on Find Button Clicked () Ġ} ĊĠĠĠĠĠĠĠ Ġwith ( list _ device _ found ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlayout Manager Ġ= ĠLinearLayoutManager ( this . context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġitem Animator Ġ= ĠRe cycler Item Fade Animator () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadapter Ġ= Ġm List Device Adapter ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Attach ( context : ĠContext ?) Ġ{ ĊĠĠĠĠĠĠĠ ĠAndroid Support Injection . inject ( this ) ĊĠĠĠĠĠĠĠ Ġattach Presenter ( scan Device Presenter ) ĊĠĠĠĠĠĠĠ Ġsuper . on Attach ( context ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġshow Empty List Text () Ġ= Ġwith ( text _ empty _ list ) Ġ{ ĊĠĠĠĠĠĠĠ Ġtext Ġ= ĠgetString ( R . string . sensor _ is _ not _ found ) ĊĠĠĠĠĠĠĠ Ġvisibility Ġ= ĠView . VISIBLE ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġshow Pre paring Text () Ġ= Ġwith ( text _ empty _ list ) Ġ{ ĊĠĠĠĠĠĠĠ Ġtext Ġ= ĠgetString ( R . string . first _ do _ a _ scan ) ĊĠĠĠĠĠĠĠ Ġvisibility Ġ= ĠView . VISIBLE ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġhide Empty List Text () Ġ{ ĊĠĠĠĠĠĠĠ Ġtext _ empty _ list . visibility Ġ= ĠView . IN VISIBLE ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġpopulate Sensor List ( list : ĠList < Sensor Stuff >) Ġ= Ġwith ( m List Device Adapter ) Ġ{ ĊĠĠĠĠĠĠĠ Ġdevice List Ġ= Ġlist . to Mutable List () ĊĠĠĠĠĠĠĠ Ġnotify DataSet Changed () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġadd Sensor ToList ( device : ĠSensor Stuff ) Ġ= Ġwith ( m List Device Adapter ) Ġ{ ĊĠĠĠĠĠĠĠ Ġdevice List . add ( device ) ĊĠĠĠĠĠĠĠ Ġnotify Item Inserted ( item Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġclear Sensor List () Ġ= Ġwith ( m List Device Adapter ) Ġ{ ĊĠĠĠĠĠĠĠ Ġdevice List Ġ= Ġmutable ListOf () ĊĠĠĠĠĠĠĠ Ġnotify Item Range Removed ( 0 , Ġitem Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġshow Find Loader () Ġ{ ĊĠĠĠĠĠĠĠ Ġfab _ scan . setImage Drawable ( context ?. get Drawable ( R . drawable . ic _ stop )) ĊĠĠĠĠĠĠĠ Ġprogress _ bar _ search . animate (). alpha ( 1 . 0 f ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġhide Find Loader () Ġ{ ĊĠĠĠĠĠĠĠ Ġfab _ scan ?. setImage Drawable ( context ?. get Drawable ( R . drawable . abc _ ic _ search _ api _ material )) ĊĠĠĠĠĠĠĠ Ġprogress _ bar _ search ?. animate ()?. alpha ( 0 . 0 f ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġshow Find Error () Ġ= ĠToast . makeText ( this . context , ĠgetString ( R . string . scan _ failed ), ĠToast . LENGTH _ SHORT ). show () ĊĠĠĠ Ġoverride Ġfun Ġshow Find Success () Ġ= ĠToast . makeText ( this . context , ĠgetString ( R . string . scan _ completed ), ĠToast . LENGTH _ SHORT ). show () ĊĠĠĠ Ġoverride Ġfun Ġgo To Sensor Control () Ġ= Ġ( activity Ġas ĠMainActivity ). navigate To Page ( 1 ) Ċ }