package Ġcom . m ga et an 8 9 . show sr age . fragment Ċ Ċ import Ġandroid . app . Dialog Ċ import Ġandroid . content . DialogInterface Ċ import Ġandroid . content . Intent Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . constraint . Group Ċ import Ġandroid . support . v 4 . app . Dialog Fragment Ċ import Ġandroid . support . v 4 . app . Fragment Activity Ċ import Ġandroid . support . v 7 . app . AlertDialog Ċ import Ġandroid . support . v 7 . widget . Switch Compat Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . LinearLayout Ċ import Ġandroid . widget . Spinner Ċ import Ġcom . m ga et an 8 9 . show sr age . Constants Ċ import Ġcom . m ga et an 8 9 . show sr age . R Ċ import Ġcom . m ga et an 8 9 . show sr age . activity . MainActivity Ċ import Ġcom . m ga et an 8 9 . show sr age . adapter . Root Directories Adapter Ċ import Ġcom . m ga et an 8 9 . show sr age . extension . getRoot Dirs Ċ import Ġcom . m ga et an 8 9 . show sr age . extension . inflate Ċ import Ġcom . m ga et an 8 9 . show sr age . extension . toInt Ċ import Ġcom . m ga et an 8 9 . show sr age . helper . Generic Callback Ċ import Ġcom . m ga et an 8 9 . show sr age . model . Generic Response Ċ import Ġcom . m ga et an 8 9 . show sr age . model . Root Dir Ċ import Ġcom . m ga et an 8 9 . show sr age . network . S ick R age Api Ċ import Ġio . realm . Realm Ċ import Ġretrofit . client . Response Ċ Ċ class ĠAdd Show Options Fragment Ġ: ĠDialog Fragment (), ĠDialog Interface . OnClickListener Ġ{ Ċ ĉ private Ġvar Ġallowed Quality : ĠSp inner ? Ġ= Ġnull Ċ ĉ private Ġvar Ġan ime : ĠSwitch Compat ? Ġ= Ġnull Ċ ĉ private Ġvar Ġfuture Status : ĠSp inner ? Ġ= Ġnull Ċ ĉ private Ġvar Ġlanguage : ĠSp inner ? Ġ= Ġnull Ċ ĉ private Ġvar Ġpreferred Quality : ĠSp inner ? Ġ= Ġnull Ċ ĉ private Ġvar Ġroot Directory : ĠSp inner ? Ġ= Ġnull Ċ ĉ private Ġvar Ġseason Folders : ĠSwitch Compat ? Ġ= Ġnull Ċ ĉ private Ġvar Ġstatus : ĠSp inner ? Ġ= Ġnull Ċ ĉ private Ġvar Ġsub titles : ĠSwitch Compat ? Ġ= Ġnull ĊĊ ĉ override Ġfun ĠonClick ( dialog : ĠDialog Interface ?, Ġwhich : ĠInt ) Ġ{ Ċĉ ĉ val Ġactivity Ġ= Ġthis . activity Ġ?: Ġreturn Ċĉ ĉ val Ġindexer Id Ġ= Ġthis . arguments ?. getInt ( Constants . Bundle . INDEX ER _ ID ) Ġ?: Ġreturn ĊĊĉ ĉ if Ġ( indexer Id Ġ<= Ġ 0 ) Ġ{ Ċĉĉ ĉ return Ċĉ ĉ } ĊĊĉ ĉ val Ġallowed Quality Ġ= Ġthis . get Allowed Quality ( this . allowed Quality ) Ċĉ ĉ val Ġan ime Ġ= Ġthis . anime ?. isChecked . toInt () Ċĉ ĉ val Ġcallback Ġ= ĠAdd Show Callback ( activity ) Ċĉ ĉ val Ġfuture Status Ġ= Ġthis . getStatus ( this . future Status ) Ċĉ ĉ val Ġlanguage Ġ= Ġthis . get Language ( this . language ) Ċĉ ĉ val Ġlocation Ġ= Ġget Location ( this . root Directory ) Ċĉ ĉ val Ġpreferred Quality Ġ= Ġthis . get Preferred Quality ( this . preferred Quality ) Ċĉ ĉ val Ġseason Folders Ġ= Ġthis . season Folders ?. isChecked . toInt () Ċĉ ĉ val Ġstatus Ġ= Ġthis . getStatus ( this . status ) Ċĉ ĉ val Ġsub titles Ġ= Ġthis . subtitle s ?. isChecked . toInt () ĊĊĉ ĉ S ick R age Api . instance . services ?. add New Show ( indexer Id , Ġpreferred Quality , Ġallowed Quality , Ġstatus , Ġfuture Status , Ġlanguage , Ġan ime , Ġseason Folders , Ġsub titles , Ġlocation , Ġcallback ) Ċ ĉ } ĊĊ ĉ override Ġfun ĠonCreate Dialog ( savedInstanceState : ĠBundle ?): ĠDialog Ġ{ Ċĉ ĉ val Ġcontext Ġ= Ġthis . context Ġ?: Ġreturn Ġsuper . onCreate Dialog ( savedInstanceState ) Ċĉ ĉ val Ġview Ġ= Ġcontext . inflate ( R . layout . fragment _ add _ show _ options ) ĊĊĉ ĉ this . allowed Quality Ġ= Ġview . findViewById ( R . id . allowed _ quality ) Ċĉ ĉ this . anime Ġ= Ġview . findViewById ( R . id . anime ) Ċĉ ĉ this . future Status Ġ= Ġview . findViewById ( R . id . future _ status ) Ċĉ ĉ this . language Ġ= Ġview . findViewById ( R . id . language ) Ċĉ ĉ this . preferred Quality Ġ= Ġview . findViewById ( R . id . preferred _ quality ) Ċĉ ĉ this . season Folders Ġ= Ġview . findViewById ( R . id . season _ folders ) Ċĉ ĉ this . status Ġ= Ġview . findViewById ( R . id . status ) Ċĉ ĉ this . subtitle s Ġ= Ġview . findViewById ( R . id . subtitle s ) ĊĊĉ ĉ view . findViewById < Group >( R . id . root _ directory _ layout ). let Ġ{ Ġroot Directory Layout Ġ-> Ċĉĉ ĉ val Ġroot Directories Ġ= ĠRealm . getDefaultInstance (). use Ġ{ Ċĉĉĉ ĉ it . copyFrom Realm ( it . getRoot Dirs ()) Ċĉĉ ĉ } ĊĊĉĉ ĉ if Ġ( root Directories . size Ġ< Ġ 2 ) Ġ{ Ċĉĉĉ ĉ root Directory Layout . visibility Ġ= ĠView . GONE Ċĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉ ĉ this . root Directory Ġ= Ġview . findViewById < Spinner >( R . id . root _ directory ). also Ġ{ Ċĉĉĉĉ ĉ it . adapter Ġ= ĠRoot Directories Adapter ( it . context , Ġroot Directories ) Ċĉĉĉ ĉ } ĊĊĉĉĉ ĉ root Directory Layout . visibility Ġ= ĠView . VISIBLE Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ return ĠAlertDialog . Builder ( context ) Ċĉĉ ĉ . setTitle ( R . string . add _ show ) Ċĉĉ ĉ . setView ( view ) Ċĉĉ ĉ . set Positive Button ( R . string . add , Ġthis ) Ċĉĉ ĉ . set Negative Button ( R . string . cancel , Ġnull ) Ċĉĉ ĉ . show () Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Destroy View () Ġ{ Ċĉ ĉ this . allowed Quality Ġ= Ġnull Ċĉ ĉ this . anime Ġ= Ġnull Ċĉ ĉ this . future Status Ġ= Ġnull Ċĉ ĉ this . language Ġ= Ġnull Ċĉ ĉ this . preferred Quality Ġ= Ġnull Ċĉ ĉ this . root Directory Ġ= Ġnull Ċĉ ĉ this . season Folders Ġ= Ġnull Ċĉ ĉ this . status Ġ= Ġnull Ċĉ ĉ this . subtitle s Ġ= Ġnull ĊĊĉ ĉ super . on Destroy View () Ċ ĉ } ĊĊ ĉ fun Ġget Allowed Quality ( allowed Quality Spinner : ĠSp inner ?): ĠString ? Ġ{ Ċĉ ĉ val Ġallowed Quality Index Ġ= Ġ( allowed Quality Spinner ?. selected Item Position Ġ?: Ġ 1 ) Ġ- Ġ 1 ĊĊĉ ĉ if Ġ( allowed Quality Index Ġ>= Ġ 0 ) Ġ{ Ċĉĉ ĉ val Ġqual ities Ġ= Ġthis . resources . getString Array ( R . array . allowed _ qual ities _ keys ) ĊĊĉĉ ĉ if Ġ( allowed Quality Index Ġ< Ġqual ities . size ) Ġ{ Ċĉĉĉ ĉ return Ġqual ities [ allowed Quality Index ] Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ return Ġnull Ċ ĉ } ĊĊ ĉ fun Ġget Language ( language Spinner : ĠSp inner ?): ĠString ? Ġ{ Ċĉ ĉ val Ġlanguage Index Ġ= Ġlanguage Spinner ?. selected Item Position Ġ?: Ġ 0 ĊĊĉ ĉ if Ġ( language Index Ġ>= Ġ 0 ) Ġ{ Ċĉĉ ĉ val Ġlanguages Ġ= Ġthis . resources . getString Array ( R . array . languages _ keys ) ĊĊĉĉ ĉ if Ġ( language Index Ġ< Ġlanguages . size ) Ġ{ Ċĉĉĉ ĉ return Ġlanguages [ language Index ] Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ return Ġnull Ċ ĉ } ĊĊ ĉ fun Ġget Preferred Quality ( preferred Quality Spinner : ĠSp inner ?): ĠString ? Ġ{ Ċĉ ĉ val Ġpreferred Quality Index Ġ= Ġ( preferred Quality Spinner ?. selected Item Position Ġ?: Ġ 1 ) Ġ- Ġ 1 ĊĊĉ ĉ if Ġ( preferred Quality Index Ġ>= Ġ 0 ) Ġ{ Ċĉĉ ĉ val Ġqual ities Ġ= Ġthis . resources . getString Array ( R . array . preferred _ qual ities _ keys ) ĊĊĉĉ ĉ if Ġ( preferred Quality Index Ġ< Ġqual ities . size ) Ġ{ Ċĉĉĉ ĉ return Ġqual ities [ preferred Quality Index ] Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ return Ġnull Ċ ĉ } ĊĊ ĉ fun ĠgetStatus ( status Spinner : ĠSp inner ?): ĠString ? Ġ{ Ċĉ ĉ val Ġstatus Index Ġ= Ġstatus Spinner ?. selected Item Position Ġ?: Ġ 0 ĊĊĉ ĉ if Ġ( status Index Ġ>= Ġ 0 ) Ġ{ Ċĉĉ ĉ val Ġstatuses Ġ= Ġthis . resources . getString Array ( R . array . status _ keys ) ĊĊĉĉ ĉ if Ġ( status Index Ġ< Ġstatuses . size ) Ġ{ Ċĉĉĉ ĉ return Ġstatuses [ status Index ] Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ return Ġnull Ċ ĉ } ĊĊ ĉ comp anion Ġobject Ġ{ Ċĉ ĉ fun Ġget Location ( root Directory Spinner : ĠSp inner ?): ĠString ? Ġ{ Ċĉĉ ĉ val Ġselected Item Ġ= Ġroot Directory Spinner ?. selected Item ĊĊĉĉ ĉ return Ġ( selected Item Ġas ? ĠRoot Dir )?. location Ċĉ ĉ } ĊĊĉ ĉ fun Ġnew Instance ( indexer Id : ĠInt ) Ġ= ĠAdd Show Options Fragment (). apply Ġ{ Ċĉĉ ĉ this . arguments Ġ= ĠBundle (). apply Ġ{ Ċĉĉĉ ĉ this . put Int ( Constants . Bundle . INDEX ER _ ID , Ġindexer Id ) Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġclass ĠAdd Show Callback ( activity : ĠFragment Activity ) Ġ: ĠGeneric Callback ( activity ) Ġ{ Ċĉ ĉ override Ġfun Ġsuccess ( generic Response : ĠGeneric Response ?, Ġresponse : ĠResponse ?) Ġ{ Ċĉĉ ĉ super . success ( generic Response , Ġresponse ) ĊĊĉĉ ĉ val Ġactivity Ġ= Ġthis . getActivity () Ġ?: Ġreturn Ċĉĉ ĉ val Ġintent Ġ= ĠIntent ( activity , ĠMainActivity :: class . java ) ĊĊĉĉ ĉ activity . startActivity ( intent ) Ċĉ ĉ } Ċ ĉ } Ċ } Ċ