package Ġcom . pop da . weather for cast . ui . search _ screen Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . location . Geo coder Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġcom . pop da . weather for cast . data . datasource . City Name Db Source Ċ import Ġcom . pop da . weather for cast . data . entity . City Entity Ċ import Ġkotlinx . coroutines . Global Scope Ċ import Ġkotlinx . coroutines . launch Ċ import Ġjavax . inject . Inject Ċ Ċ private Ġval ĠTAG Ġ= ĠSearch ViewModel :: class . simple Name Ċ Ċ class ĠSearch ViewModel Ġ@ Inject Ġconstructor ( private Ġval Ġcity DataSource : ĠCity Name Db Source ) Ġ: ĠViewModel () Ġ{ ĊĠĠĠ Ġval Ġcity LiveData : ĠLive Data < List < City Entity >> ĊĠĠĠĠĠĠĠ Ġget () Ġ{ Ġreturn Ġcity DataSource . city Dao (). getAll () Ġ} ĊĊĠĠĠ Ġfun Ġsearch New Location ( name : String , Ġactivity : ĠActivity ) Ġ: ĠString ? Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlist Ġ= ĠGeo coder ( activity ). get From Location Name ( name , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( list . isNotEmpty ()) Ġlist [ 0 ]. locality Ġelse Ġnull ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġadd City To Favorite ( city Name : ĠString , Ġactivity : ĠActivity ){ ĊĠĠĠĠĠĠĠ Ġsearch New Location ( city Name , Ġactivity )?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠGlobal Scope . launch Ġ{ Ġcity DataSource . city Dao (). addTo Fav ( City Entity ( it )) Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġdelete City ( city Entity : ĠCity Entity ){ ĊĠĠĠĠĠĠĠ ĠGlobal Scope . launch Ġ{ Ġcity DataSource . city Dao (). delete ( city Entity )} ĊĠĠĠ Ġ} Ċ }