package Ġcom . app . sky ss _ comp anion . repository Ċ Ċ import Ġandroid . util . Log Ċ import Ġandroidx . annotation . Worker Thread Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġcom . app . sky ss _ comp anion . dao . Stop Group Dao Ċ import Ġcom . app . sky ss _ comp anion . http . Stops Client Ċ import Ġcom . app . sky ss _ comp anion . map pers . Stop Response Entity Mapper Ċ import Ġcom . app . sky ss _ comp anion . model . Stop Group Ċ import Ġkotlinx . coroutines . flow . Flow Ċ import Ġkotlinx . coroutines . flow . map Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Singleton Ċ Ċ @ Singleton Ċ class ĠStop Group Repository Ġ@ Inject Ġconstructor ( private Ġval Ġstop Group Dao : ĠStop Group Dao , Ġprivate Ġval Ġstops Client : ĠSto ps Client ) Ġ{ ĊĊĠĠĠ Ġval Ġtag Ġ= Ġ" Stop Group Repository " ĊĠĠĠ Ġval Ġis Sync ing Ġ= ĠMutable LiveData < Boolean >() ĊĠĠĠ Ġval Ġall Stop Groups : ĠFlow < List < Stop Group >> Ġ= Ġstop Group Dao . getAll () ĊĊĠĠĠ Ġ@ Suppress (" Red undant Suspend Modifier ") ĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġsuspend Ġfun Ġinsert ( stop Group : ĠStop Group ) Ġ{ ĊĠĠĠĠĠĠĠ Ġstop Group Dao . insert ( stop Group ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suppress (" Red undant Suspend Modifier ") ĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġsuspend Ġfun Ġinsert All ( stop Group : ĠList < Stop Group > ){ ĊĠĠĠĠĠĠĠ Ġstop Group Dao . insert All ( stop Group ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suppress (" Red undant Suspend Modifier ") ĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġsuspend Ġfun Ġfind Stop Group ( identifier : ĠString ) Ġ: ĠStop Group ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġstop Group Dao . find ( identifier ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Suppress (" Red undant Suspend Modifier ") ĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġsuspend Ġfun Ġupdate Local Stop Responses (){ ĊĠĠĠĠĠĠĠ Ġval Ġfetched Stop Groups Ġ= Ġstops Client . fetch Stop Groups () ĊĠĠĠĠĠĠĠ ĠLog . d ( tag , Ġ" f etched Ġ${ f etched Stop Groups ?. Stop Groups ?. size } Ġstop Ġresponses Ġfrom Ġapi ") ĊĠĠĠĠĠĠĠ Ġif ( f etched Stop Groups Ġ!= Ġnull Ġ&& Ġfetched Stop Groups . Stop Groups . isNotEmpty ()){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġmapped Stop Groups Ġ= ĠStop Response Entity Mapper . map All Stop Group Responses ( f etched Stop Groups . Stop Groups ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . d ( tag , Ġ" mapped Ġ${ mapped Stop Groups . size } Ġstop Ġresponses Ġfrom Ġstop Group ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstop Group Dao . insert All ( mapped Stop Groups . filter NotNull ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġfun Ġfilter SearchResults ( search Term : ĠString ) Ġ: ĠFlow < List < Stop Group >> Ġ{ ĊĠĠĠĠĠĠ Ġreturn Ġall Stop Groups . map Ġ{ Ġstop Groups List Ġ-> Ġstop Groups List . filter Ġ{ Ġstop Group Ġ-> Ġstop Group . description ?. contains ( search Term , Ġignore Case Ġ= Ġtrue ) Ġ?: Ġfalse Ġ} Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġsuspend Ġfun Ġfind Stop Groups ById ent ifiers ( identifiers : ĠList < String >): ĠList < Stop Group > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġstop Group Dao . find ( identifiers ) ĊĠĠĠ Ġ} Ċ Ċ }