package Ġcom . pro labs . the story writer Ċ Ċ import Ġandroid . graphics . drawable . Animation Drawable Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . os . Handler Ċ import Ġandroid . view . View Ċ import Ġandroid . view . animation . Animation Utils Ċ import Ġandroid . widget .* Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġio . realm . Realm Ċ import Ġio . realm . Sort Ċ import Ġio . realm . kotlin . where Ċ import Ġretrofit 2 . Call Ċ import Ġjava . lang . Exception Ċ Ċ class ĠTemplate Selector Ġ: ĠAppCompatActivity () Ġ{ ĊĠĠĠ Ġlateinit Ġvar Ġrelative Layout : ĠRelative Layout ĊĠĠĠ Ġlateinit Ġvar Ġanimation : Animation Drawable ĊĠĠĠ Ġlateinit Ġvar Ġtemplate RecyclerView : ĠRecyclerView ĊĠĠĠ Ġlateinit Ġvar Ġwaiting : ProgressBar ĊĠĠĠ Ġ@ Volatile ĊĠĠĠ Ġlateinit Ġvar Ġstandard Adapter : Template Recycler Adapter ĊĠĠĠ Ġ@ Volatile ĊĠĠĠ Ġlateinit Ġvar Ġseason al Adapter : ĠTemplate Recycler Adapter ĊĠĠĠ Ġ@ Volatile ĊĠĠĠ Ġlateinit Ġvar Ġfest ive Adapter : ĠTemplate Recycler Adapter ĊĠĠĠ Ġ@ Volatile ĊĠĠĠ Ġlateinit Ġvar Ġspecial Adapter : ĠTemplate Recycler Adapter ĊĠĠĠ Ġlateinit Ġvar Ġfavorite Adapter : Favorite Recycler Adapter ĊĠĠĠ Ġvar Ġclient : Ret rofit Client = Ret rofit Client (). build () ĊĊĠĠĠ Ġlateinit Ġvar Ġstandard Button : Button ĊĠĠĠ Ġlateinit Ġvar Ġspecial Button : Button ĊĠĠĠ Ġlateinit Ġvar Ġfest ive Button : ĠButton ĊĠĠĠ Ġlateinit Ġvar Ġseason al Button : ĠButton ĊĠĠĠ Ġlateinit Ġvar Ġrealm : ĠRealm ĊĠĠĠ Ġlateinit Ġvar Ġfavorite Button : ĠImage Button ĊĠĠĠ Ġlateinit Ġvar Ġdelete Favorite : Image Button ĊĠĠĠ Ġlateinit Ġvar Ġtitle Select Template : TextView ĊĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ template _ selector ) ĊĠĠĠĠĠĠĠ Ġwaiting = findViewById ( R . id . waiting ) ĊĠĠĠĠĠĠĠ Ġrealm = ĠRealm Init . getInstance () ĊĠĠĠĠĠĠĠ Ġstandard Button = findViewById ( R . id . standard Button ) ĊĠĠĠĠĠĠĠ Ġspecial Button = findViewById ( R . id . special Button ) ĊĠĠĠĠĠĠĠ Ġseason al Button = findViewById ( R . id . season al Button ) ĊĠĠĠĠĠĠĠ Ġfest ive Button = findViewById ( R . id . F est ive Button ) ĊĠĠĠĠĠĠĠ Ġfavorite Button = findViewById ( R . id . get Favorite Button ) ĊĠĠĠĠĠĠĠ Ġdelete Favorite = findViewById ( R . id . delete Favorite Button ) ĊĠĠĠĠĠĠĠ Ġtitle Select Template = findViewById ( R . id . title Select Template ) ĊĊĠĠĠĠĠĠĠ Ġrelative Layout = findViewById ( R . id . template layout ) ĊĠĠĠĠĠĠĠ Ġanimation = relative Layout . background Ġas ĠAnimation Drawable ĊĠĠĠĠĠĠĠ Ġanimation . set Enter Fade Duration ( 2 5 0 0 ) ĊĠĠĠĠĠĠĠ Ġanimation . set Exit Fade Duration ( 2 5 0 0 ) ĊĠĠĠĠĠĠĠ Ġanimation . start () ĊĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtemplate RecyclerView Ġ= ĠfindViewById ( R . id . Template RecyclerView ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtemplate RecyclerView . layout Manager Ġ= ĠLinearLayoutManager ( this ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠHandler (). post Delayed ({ run Threads ()}, 5 0 0 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġcatch Ġ( e : Exception ) ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠToast . makeText ( this , e . message , Toast . LENGTH _ LONG ). show () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġfun Ġrun Threads (){ ĊĠĠĠĠĠĠĠ Ġvar Ġstand at d Thread = Thread (){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvar Ġcall : Call < ArrayList < Template >> Ġ= Ġclient . fetch Templates (" standard ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstandard Adapter = ĠTemplate Recycler Adapter ( call . execute (). body (), this ," standard ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġvar Ġspecial Thread = Thread (){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvar Ġcall : Call < ArrayList < Template >> Ġ= Ġclient . fetch Templates (" special ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġspecial Adapter = ĠTemplate Recycler Adapter ( call . execute (). body (), this ," special ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġvar Ġseason al Thread = Thread (){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvar Ġcall : Call < ArrayList < Template >> Ġ= Ġclient . fetch Templates (" season al ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġseason al Adapter = ĠTemplate Recycler Adapter ( call . execute (). body (), this ," season al ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġvar Ġfest ive Thread = Thread (){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvar Ġcall : Call < ArrayList < Template >> Ġ= Ġclient . fetch Templates (" fest ive ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfest ive Adapter = ĠTemplate Recycler Adapter ( call . execute (). body (), this ," fest ive ") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġstand at d Thread . start () ĊĠĠĠĠĠĠĠ Ġspecial Thread . start () ĊĠĠĠĠĠĠĠ Ġseason al Thread . start () ĊĠĠĠĠĠĠĠ Ġfest ive Thread . start () ĊĊĠĠĠĠĠĠĠ Ġstand at d Thread . join () ĊĠĠĠĠĠĠĠ Ġspecial Thread . join () ĊĠĠĠĠĠĠĠ Ġseason al Thread . join () ĊĠĠĠĠĠĠĠ Ġfest ive Thread . join () ĊĊĠĠĠĠĠĠĠ Ġwaiting . visibility = View . GONE ĊĠĠĠĠĠĠĠ Ġtemplate RecyclerView . adapter Ġ= Ġstandard Adapter ĊĠĠĠĠĠĠĠ Ġbutton Functions Init () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġbutton Functions Init (){ ĊĠĠĠĠĠĠĠ Ġstandard Button . setOnClickListener (){ v -> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdelete Favorite . visibility = View . GONE ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtemplate RecyclerView . adapter = standard Adapter ĊĠĠĠĠĠĠĠĠĠĠĠ Ġchange Title (" Standard ĠTemplates ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġseason al Button . setOnClickListener (){ v -> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdelete Favorite . visibility = View . GONE ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtemplate RecyclerView . adapter = season al Adapter ĊĠĠĠĠĠĠĠĠĠĠĠ Ġchange Title (" Season al ĠTemplates ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġspecial Button . setOnClickListener (){ v -> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdelete Favorite . visibility = View . GONE ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtemplate RecyclerView . adapter = special Adapter ĊĠĠĠĠĠĠĠĠĠĠĠ Ġchange Title (" Special ĠTemplates ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġfest ive Button . setOnClickListener (){ v -> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdelete Favorite . visibility = View . GONE ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtemplate RecyclerView . adapter = fest ive Adapter ĊĠĠĠĠĠĠĠĠĠĠĠ Ġchange Title (" F est ive ĠTemplates ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġfavorite Button . setOnClickListener (){ v -> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġget F avorites () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġchange Title (" Your ĠF avorites ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġdelete Favorite . setOnClickListener (){ v -> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwaiting . visibility = View . VISIBLE ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrealm . beginTransaction () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġrealm Result = realm . where < Favorite Model >(). findAll () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrealm Result . delete All From Realm () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrealm . commit Transaction () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠToast . makeText ( this ," History ĠC le ared ", Toast . LENGTH _ SHORT ). show () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġget F avorites () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget F avorites (){ ĊĠĠĠĠĠĠĠ Ġdelete Favorite . visibility = View . VISIBLE ĊĠĠĠĠĠĠĠ Ġwaiting . visibility = View . GONE ĊĠĠĠĠĠĠĠ Ġvar Ġfavor ites = realm . where < Favorite Model >(). sort (" url "). findAll () ĊĠĠĠĠĠĠĠ Ġfavorite Adapter = Favorite Recycler Adapter ( favorites , this ) ĊĠĠĠĠĠĠĠ Ġtemplate RecyclerView . adapter = favorite Adapter ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġchange Title ( title : String ){ ĊĠĠĠĠĠĠĠ Ġvar Ġanimation = ĠAnimation Utils . load Animation ( this , ĠR . anim . transition ) ĊĠĠĠĠĠĠĠ Ġtitle Select Template . start Animation ( animation ) ĊĠĠĠĠĠĠĠ Ġtitle Select Template . text Ġ= Ġtitle ĊĠĠĠ Ġ} ĊĊ Ċ } Ċ