/* Ċ Copyright Ġ 2 0 2 0 ĠRe think DNS Ġand Ġits Ġauthors Ċ Ċ Licensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ you Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ You Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ċ https :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ċ Unless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ distributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ WITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ See Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ limitations Ġunder Ġthe ĠLicense . Ċ */ Ċ package Ġcom . cel zero . br aved ns . ui Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Log Ċ import Ġandroid . view . View Ċ import Ġandroidx . appcompat . app . AlertDialog Ċ import Ġandroidx . appcompat . widget . Search View Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġby . kir ich 1 4 0 9 . view binding delegate . view Binding Ċ import Ġcom . cel zero . br aved ns . R Ċ import Ġcom . cel zero . br aved ns . adapter . Connection Tracker Adapter Ċ import Ġcom . cel zero . br aved ns . database . Connection Tracker DAO Ċ import Ġcom . cel zero . br aved ns . databinding . Activity Connection Tracker Binding Ċ import Ġcom . cel zero . br aved ns . service . Persistent State Ċ import Ġcom . cel zero . br aved ns . ui . Home Screen Activity . Global Variable . DEBUG Ċ import Ġcom . cel zero . br aved ns . util . Constants . Companion . LOG _ TAG Ċ import Ġcom . cel zero . br aved ns . view model . Connection Tracker ViewModel Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . Global Scope Ċ import Ġkotlinx . coroutines . launch Ċ import Ġorg . k oin . android . ext . android . inject Ċ import Ġorg . k oin . android x . view model . ext . android . viewModel Ċ Ċ /** Ċ Ġ* ĠConnection ĠTracker Ġ- ĠNetwork ĠMonitor . Ċ Ġ* ĠAll Ġthe Ġnetwork Ġactivities Ġare Ġcaptured Ġand Ġstored Ġin Ġthe Ġdatabase . Ċ Ġ* ĠLive Ġdata Ġis Ġused Ġto Ġfetch Ġthe Ġnetwork Ġdetails Ġfrom Ġthe Ġdatabase . Ċ Ġ* ĠDatabase Ġtable Ġname Ġ- ĠConnection Tracker . Ċ Ġ*/ Ċ class ĠConnection Tracker Fragment Ġ: ĠFragment ( R . layout . activity _ connection _ tracker ), ĠSearch View . On Query Text Listener Ġ{ ĊĠĠĠ Ġprivate Ġval Ġb Ġby Ġview Binding ( Activity Connection Tracker Binding :: bind ) ĊĊĠĠĠ Ġprivate Ġvar Ġlayout Manager : ĠRecyclerView . LayoutManager ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġvar Ġre cycler Adapter : ĠConnection Tracker Adapter ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġval ĠviewModel : ĠConnection Tracker ViewModel Ġby ĠviewModel () ĊĠĠĠ Ġprivate Ġvar Ġfilter Value : ĠString Ġ= Ġ"" ĊĠĠĠ Ġprivate Ġvar Ġchecked Item Ġ= Ġ 1 ĊĊĠĠĠ Ġprivate Ġval Ġconnection Tracker DAO Ġby Ġinject < Connection Tracker DAO >() ĊĠĠĠ Ġprivate Ġval Ġpersistent State Ġby Ġinject < Persistent State >() ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠĠĠĠĠ Ġinit View () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġnew Instance () Ġ= ĠConnection Tracker Fragment () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġinit View () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġinclude View Ġ= Ġb . connection List Scroll List ĊĊĠĠĠĠĠĠĠ Ġif Ġ( persistent State . logs Enabled ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinclude View . connection List Logs Disabled Tv . visibility Ġ= ĠView . GONE ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinclude View . connection Card View Top . visibility Ġ= ĠView . VISIBLE ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġinclude View . recycler Connection . set Has Fixed Size ( true ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlayout Manager Ġ= ĠLinearLayoutManager ( require Context ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinclude View . recycler Connection . layout Manager Ġ= Ġlayout Manager ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġre cycler Adapter Ġ= ĠConnection Tracker Adapter ( require Context ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . connection Tracker List . observe ( view Lifecycle Owner , Ġandroidx . lifecycle . Observer ( recycler Adapter !! :: submit List )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinclude View . recycler Connection . adapter Ġ= Ġre cycler Adapter ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// re cyclerView !!. setItem View Cache Size ( 1 0 0 ) ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinclude View . connection List Logs Disabled Tv . visibility Ġ= ĠView . VISIBLE ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinclude View . connection Card View Top . visibility Ġ= ĠView . GONE ĊĠĠĠĠĠĠĠ Ġ} ĊĊĊĠĠĠĠĠĠĠ Ġinclude View . connection Search . setOn Query Text Listener ( this ) ĊĠĠĠĠĠĠĠ Ġinclude View . connection Search . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinclude View . connection Search . request Focus () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinclude View . connection Search . on Action View Expanded () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġinclude View . connection Filter Icon . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġshow Dialog For Filter () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġinclude View . connection Delete Icon . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġshow Dialog For Delete () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Query Text Submit ( query : ĠString ?): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . set Filter ( query !! , Ġfilter Value ) ĊĠĠĠĠĠĠĠ Ġreturn Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Query Text Change ( query : ĠString ?): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . set Filter ( query !! , Ġfilter Value ) ĊĠĠĠĠĠĠĠ Ġreturn Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġshow Dialog For Filter () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġsingle Items Ġ= ĠarrayOf ( getString ( R . string . filter _ network _ blocked _ connections ), ĠgetString ( R . string . filter _ network _ all _ connections )) ĊĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠAlertDialog . Builder ( require Context ()) ĊĠĠĠĠĠĠĠ Ġbuilder . setTitle ( getString ( R . string . ct _ filter _ dialog _ title )) ĊĊĠĠĠĠĠĠĠ Ġ// ĠSingle - choice Ġitems Ġ( initialized Ġwith Ġchecked Ġitem ) ĊĠĠĠĠĠĠĠ Ġbuilder . set Single Choice Items ( single Items , Ġchecked Item ) Ġ{ Ġdialog , Ġwhich Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠRespond Ġto Ġitem Ġchosen ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfilter Value Ġ= Ġif Ġ( which Ġ== Ġ 0 ) Ġ": is Filter " ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ"" ĊĠĠĠĠĠĠĠĠĠĠĠ Ġchecked Item Ġ= Ġwhich ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( DEBUG ) ĠLog . d ( LOG _ TAG , Ġ" Filter ĠOption Ġselected : Ġ$ filter Value ") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . set Filter Blocked ( filter Value ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdialog . dismiss () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġbuilder . show () ĊĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġshow Dialog For Delete () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠAlertDialog . Builder ( require Context ()) ĊĠĠĠĠĠĠĠ Ġ// set Ġtitle Ġfor Ġalert Ġdialog ĊĠĠĠĠĠĠĠ Ġbuilder . setTitle ( R . string . conn _ track _ clear _ logs _ title ) ĊĠĠĠĠĠĠĠ Ġ// set Ġmessage Ġfor Ġalert Ġdialog ĊĠĠĠĠĠĠĠ Ġbuilder . setMessage ( R . string . conn _ track _ clear _ logs _ message ) ĊĠĠĠĠĠĠĠ Ġbuilder . set Cancel able ( true ) ĊĠĠĠĠĠĠĠ Ġ// perform ing Ġpositive Ġaction ĊĠĠĠĠĠĠĠ Ġbuilder . set Positive Button ( getString ( R . string . ct _ delete _ logs _ positive _ btn )) Ġ{ Ġ_, Ġ_ Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠGlobal Scope . launch ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġconnection Tracker DAO . clear All Data () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// perform ing Ġnegative Ġaction ĊĠĠĠĠĠĠĠ Ġbuilder . set Negative Button ( getString ( R . string . ct _ delete _ logs _ negative _ btn )) Ġ{ Ġ_, Ġ_ Ġ-> ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ// ĠCreate Ġthe ĠAlertDialog ĊĠĠĠĠĠĠĠ Ġval Ġalert Dialog : ĠAlertDialog Ġ= Ġbuilder . create () ĊĠĠĠĠĠĠĠ Ġ// ĠSet Ġother Ġdialog Ġproperties ĊĠĠĠĠĠĠĠ Ġalert Dialog . set Cancel able ( true ) ĊĠĠĠĠĠĠĠ Ġalert Dialog . show () ĊĠĠĠ Ġ} Ċ } Ċ