package Ġcom . raz v ant mz . on em ove . core . response Handlers Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . view . View Ċ import Ġandroidx . coordinator layout . widget . Coordinator Layout Ċ import Ġandroidx . lifecycle . Lifecycle Owner Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġcom . raz v ant mz . on em ove . R Ċ import Ġcom . raz v ant mz . on em ove . core . helpers . show Error Snackbar Ċ import Ġcom . raz v ant mz . on em ove . core . helpers . showMessage Snackbar Ċ import Ġcom . raz v ant mz . on em ove . ui . base . Base ViewModel Ċ Ċ class ĠResponse Handler ( view : View , ĠviewModel : Base ViewModel , Ġview Lifecycle Owner : ĠLifecycle Owner ) Ġ: ĠI Response Handler Ġ{ ĊĊĠĠĠ Ġval Ġcoord inator Layout : ĠCoord inator Layout ? Ġ= Ġview . findViewById ( R . id . coordinator Layout ) ĊĠĠĠ Ġval Ġcontext : Context Ġ= Ġview . context ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . on Success Code . observe ( view Lifecycle Owner , ĠObserver Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġshow Message ( it ) ĊĠĠĠĠĠĠĠ Ġ}) ĊĊĠĠĠĠĠĠĠ ĠviewModel . on ErrorCode . observe ( view Lifecycle Owner , ĠObserver Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġshow ErrorMessage ( it ) ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġshow ErrorMessage ( response Code : ĠResponse Code ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcoord inator Layout ?: return ĊĠĠĠĠĠĠĠ Ġval Ġkey Ġ= Ġresponse Map [ response Code ] Ġ?: return ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġcontext . getString ( key ) ĊĠĠĠĠĠĠĠ Ġshow Error Snackbar ( message ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġshow Message ( response Code : ĠResponse Code ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcoord inator Layout ?: return ĊĠĠĠĠĠĠĠ Ġval Ġkey Ġ= Ġresponse Map [ response Code ] Ġ?: return ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġcontext . getString ( key ) ĊĠĠĠĠĠĠĠ Ġshow Message Snackbar ( message ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġshow Validation Message ( response Code : ĠResponse Code , Ġvalidation Field : ĠValidation Field , Ġparam : String ?) ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġcoord inator Layout ?: return ĊĠĠĠĠĠĠĠ Ġval Ġkey Ġ= Ġresponse Map [ response Code ] Ġ?: return ĊĠĠĠĠĠĠĠ Ġval Ġfield Key Ġ= Ġvalidation Field Map [ validation Field ] ?: return ĊĊĠĠĠĠĠĠĠ Ġval ĠfieldName Ġ= Ġcontext . getString ( field Key ) ĊĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġif ( param Ġ== Ġnull ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcontext . getString ( key , ĠfieldName ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcontext . getString ( key , ĠfieldName , Ġparam ) ĊĊĠĠĠĠĠĠĠ Ġshow Error Snackbar ( message ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġresponse Map Ġ= Ġhash Map Of < Response Code , ĠInt >(). apply Ġ{ ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Problem Added ] Ġ= ĠR . string . success _ add _ problem ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Photo Missing ] Ġ= ĠR . string . error _ no _ photo ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Invalid Date ] Ġ= ĠR . string . error _ invalid _ date ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Index Not Set ] Ġ= ĠR . string . error _ index _ not _ set ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Invalid Name ] Ġ= ĠR . string . error _ invalid _ name ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Route NotFound ] Ġ= ĠR . string . email ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . User NotFound ] Ġ= ĠR . string . error _ user _ not _ found ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Invalid Inputs ] Ġ= ĠR . string . error _ invalid _ inputs ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Invalid Credentials ] Ġ= ĠR . string . error _ invalid _ credentials ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . An Error Occurred ] Ġ= ĠR . string . error _ an _ error _ occ urred ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Email Already Taken ] Ġ= ĠR . string . error _ an _ error _ occ urred ĊĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Added To Favorite ] Ġ= ĠR . string . success _ added _ to _ favorite ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Removed From Favorite ]= ĠR . string . success _ removed _ from _ favorite ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . SignIn Successful ]= ĠR . string . success _ sign _ in ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Edit Profile Successful ]= ĠR . string . success _ edit _ profile ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Feedback Submitted Successful ]= ĠR . string . success _ submit _ feedback ĊĠĠĠĠĠĠĠ Ġthis [ Response Code . Problem Was Edited ]= ĠR . string . success _ edit _ problem ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġvalidation Field Map Ġ= Ġhash Map Of < Validation Field , ĠInt >(). apply Ġ{ ĊĠĠĠĠĠĠĠ Ġthis [ Validation Field . Name ] Ġ= ĠR . string . name ĊĠĠĠ Ġ} Ċ } Ċ Ċ fun ĠI Response Handler . validate Min Length ( text : String , Ġvalidation Field : Validation Field , Ġmin : Int , Ġshow Error : Boolean Ġ= Ġtrue ) Ġ: ĠBoolean Ċ { ĊĠĠĠ Ġif ( text . length Ġ< Ġmin ) ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġif ( show Error ) ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthis . show Validation Message ( Response Code . Min Length Error , Ġvalidation Field , Ġmin . toString ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġfalse ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġtrue Ċ } Ċ