package Ġar . edu . ut n . fr ba . mobile . a 2 0 1 9 c 1 . super hero es . ui . fight Ċ Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . app . Activity Ċ import Ġandroid . content . Intent Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġar . edu . ut n . fr ba . mobile . a 2 0 1 9 c 1 . super hero es . R Ċ import Ġar . edu . ut n . fr ba . mobile . a 2 0 1 9 c 1 . super hero es . domain . Fight Ċ import Ġar . edu . ut n . fr ba . mobile . a 2 0 1 9 c 1 . super hero es . domain . Geo location Ċ import Ġar . edu . ut n . fr ba . mobile . a 2 0 1 9 c 1 . super hero es . services . ApiService Ċ import Ġar . edu . ut n . fr ba . mobile . a 2 0 1 9 c 1 . super hero es . services . Sessions Service Ċ import Ġar . edu . ut n . fr ba . mobile . a 2 0 1 9 c 1 . super hero es . ui . registration . Registration Activity Ċ import Ġcom . android . vol ley . Vol ley Error Ċ import Ġkotlinx . android . synt hetic . main . activity _ fight _ search .* Ċ import Ġjava . lang . Thread . sleep Ċ Ċ class ĠF ight Search Activity Ġ: ĠAppCompatActivity () Ġ{ ĊĊ ĉ private Ġval Ġsession Service Ġby Ġlazy Ġ{ ĠS essions Service ( this ) Ġ} Ċ ĉ private Ġval Ġapi Service Ġby Ġlazy Ġ{ ĠApi Service ( this ) Ġ} ĊĊ ĉ override Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ super . onCreate ( savedInstanceState ) Ċĉ ĉ set ContentView ( R . layout . activity _ fight _ search ) Ċĉ ĉ search Opp onent () Ċ ĉ } ĊĊ ĉ @ Suppress Lint (" Missing Permission ") Ċ ĉ private Ġfun Ġsearch Opp onent () Ġ{ Ċĉ ĉ val Ġgeo location Ġ= Ġintent . get Serializable Extra (" geo location ") Ġas ĠGeo location Ċĉ ĉ session Service . get Logged User ()?. let Ġ{ Ġuser Ġ-> Ċĉĉ ĉ api Service . start Fight ( user . id , Ġgeo location , Ġ{ Ġresponse Ġ-> Ċĉĉĉ ĉ process Result ( response ) Ċĉĉĉ ĉ finish () Ċĉĉ ĉ }, Ġ{ Ġerror Ġ-> Ċĉĉĉ ĉ ger ErrorMessage (" Failed Ġto Ġstart Ġfight ", Ġerror ) Ċĉĉĉ ĉ handle Opp onent NotFound () Ċĉĉ ĉ }) Ċĉ ĉ } Ġ?: Ġhandle User Not Logged () Ċ ĉ } ĊĊ ĉ private Ġfun Ġprocess Result ( result : ĠF ight ) Ġ{ Ċĉ ĉ val Ġintent Ġ= ĠIntent ( this , ĠF ight Result Activity :: class . java ) Ċĉ ĉ intent . putExtra (" fight Result ", Ġresult ) Ċĉ ĉ startActivity ( intent ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġhandle Opp onent NotFound () Ġ{ Ċĉ ĉ title _ search _ fight . text Ġ= ĠgetString ( R . string . title _ fight _ not _ found ) Ċĉ ĉ loading _ fig th _ icon . visibility Ġ= ĠView . IN VISIBLE Ċĉ ĉ sleep ( 5 0 0 0 ) Ċĉ ĉ finish () Ċ ĉ } ĊĊ ĉ private Ġfun Ġhandle User Not Logged () Ġ{ Ċĉ ĉ println (" Failed Ġto Ġget Ġlogged Ġuser Ġin Ġcards Ġfragment ") Ċĉ ĉ val Ġintent Ġ= ĠIntent ( this , ĠRegistration Activity :: class . java ) Ċĉ ĉ startActivity ( intent ) Ċĉ ĉ set Result ( Activity . RESULT _ OK ) Ċĉ ĉ finish () Ċ ĉ } ĊĊ ĉ private Ġfun Ġger ErrorMessage ( message : ĠString , Ġerror : ĠVol ley Error ) Ġ{ Ċĉ ĉ val ĠstatusCode Ġ= Ġerror . network Response . statusCode Ċĉ ĉ val Ġdata Ġ= ĠString ( error . network Response . data , ĠChar sets . UTF _ 8 ) Ċĉ ĉ println ("$ message Ġ- ĠstatusCode : Ġ$ statusCode Ġ- Ġdata : Ġ$ data ") Ċ ĉ } Ċ Ċ } Ċ