/* Ċ Ġ* ĠCopyright ĠÂ© Ġ 2 0 1 7 - 2 0 1 9 ĠWire Guard ĠLLC . ĠAll ĠRights ĠReserved . Ċ Ġ* ĠSPDX - License - Identifier : ĠApache - 2 . 0 Ċ Ġ*/ Ċ package Ġcom . wire guard . android . activity Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroidx . databinding . Callback Registry Ċ import Ġandroidx . databinding . Callback Registry . Notifier Callback Ċ import Ġandroidx . lifecycle . lifecycle Scope Ċ import Ġcom . wire guard . android . Application Ċ import Ġcom . wire guard . android . model . Observable Tunnel Ċ Ċ /** Ċ Ġ* ĠBase Ġclass Ġfor Ġactivities Ġthat Ġneed Ġto Ġremember Ġthe Ġcurrently - selected Ġtunnel . Ċ Ġ*/ Ċ abstract Ġclass ĠBase Activity Ġ: ĠTheme Change Aware Activity () Ġ{ ĊĠĠĠ Ġprivate Ġval Ġselection Change Registry Ġ= ĠSelection Change Registry () ĊĠĠĠ Ġvar Ġselected Tunnel : ĠObservable Tunnel ? Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġset ( value ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġold Tunnel Ġ= Ġfield ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( old Tunnel Ġ== Ġvalue ) Ġreturn ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfield Ġ= Ġvalue ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon Selected Tunnel Changed ( old Tunnel , Ġvalue ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġselection Change Registry . notify Callbacks ( old Tunnel , Ġ 0 , Ġvalue ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġadd On Selected Tunnel Changed Listener ( listener : ĠOn Selected Tunnel Changed Listener ) Ġ{ ĊĠĠĠĠĠĠĠ Ġselection Change Registry . add ( listener ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠRestore Ġthe Ġsaved Ġtunnel Ġif Ġthere Ġis Ġone ; Ġotherwise Ġgrab Ġit Ġfrom Ġthe Ġarguments . ĊĠĠĠĠĠĠĠ Ġval Ġsaved Tunnel Name Ġ= Ġwhen Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠsavedInstanceState Ġ!= Ġnull Ġ-> ĠsavedInstanceState . getString ( KEY _ SELECTED _ T UN NEL ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġintent Ġ!= Ġnull Ġ-> Ġintent . getString Extra ( KEY _ SELECTED _ T UN NEL ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġnull ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġif Ġ( saved Tunnel Name Ġ!= Ġnull ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlifecycle Scope . launch When Created Ġ{ Ġselected Tunnel Ġ= ĠApplication . get Tunnel Manager (). get Tunnel s ()[ saved Tunnel Name ] Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// ĠThe Ġselected Ġtunnel Ġmust Ġbe Ġset Ġbefore Ġthe Ġsuperclass Ġmethod Ġre creates Ġfragments . ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Save InstanceState ( out State : ĠBundle ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( selected Tunnel Ġ!= Ġnull ) Ġout State . putString ( KEY _ SELECTED _ T UN NEL , Ġselected Tunnel !!. name ) ĊĠĠĠĠĠĠĠ Ġsuper . on Save InstanceState ( out State ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprotected Ġabstract Ġfun Ġon Selected Tunnel Changed ( old Tunnel : ĠObservable Tunnel ?, Ġnew Tunnel : ĠObservable Tunnel ?) ĊĊĠĠĠ Ġfun Ġremove On Selected Tunnel Changed Listener ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlistener : ĠOn Selected Tunnel Changed Listener ) Ġ{ ĊĠĠĠĠĠĠĠ Ġselection Change Registry . remove ( listener ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġinterface ĠOn Selected Tunnel Changed Listener Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġon Selected Tunnel Changed ( old Tunnel : ĠObservable Tunnel ?, Ġnew Tunnel : ĠObservable Tunnel ?) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġclass ĠSelection Change Notifier Ġ: ĠNot ifier Callback < On Selected Tunnel Changed Listener , ĠObservable Tunnel , ĠObservable Tunnel >() Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Notify Callback ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlistener : ĠOn Selected Tunnel Changed Listener , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġold Tunnel : ĠObservable Tunnel ?, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġignored : ĠInt , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnew Tunnel : ĠObservable Tunnel ? ĊĠĠĠĠĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlistener . on Selected Tunnel Changed ( old Tunnel , Ġnew Tunnel ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġclass ĠSelection Change Registry Ġ: ĊĠĠĠĠĠĠĠĠĠĠĠ ĠCallback Registry < On Selected Tunnel Changed Listener , ĠObservable Tunnel , ĠObservable Tunnel >( Selection Change Notifier ()) ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠKEY _ SELECTED _ T UN NEL Ġ= Ġ" selected _ tunnel " ĊĠĠĠ Ġ} Ċ } Ċ