In this chapter, you’ll add the ability to edit bookmarks. This involves creating a new Activity to display the bookmark details with editable fields.
Getting started
If you’re following along with your own app, copy ic_action_done.png from the starter project in the res/drawable-xxxx/ folders into your project. Make sure to copy the files from all of the drawable folders, including everything with the .hdpi, .mdpi, .xhdpi, and .xxhdpi extensions.
If you want to use the starter project instead, locate the projects folder for this chapter and open the PlaceBook app inside the starter folder. If you do use the starter app, don’t forget to add your google_maps_key in google_maps_api.xml. Read Chapter 13 for more details about the Google Maps key.
The first time you open the project, Android Studio takes a few minutes to set up your environment and update its dependencies.
Fixing the info window
Before moving on, you need to track down and fix that pesky bug left over from the previous chapter where the app crashes when tapping on a blue marker. The desired behavior is:
Ij wvu iyur xitf o fet fgotu, ic nxogd u gon yuttik ofm gpa Admo mejdoj. Av hri oguq htep kifn aq cso Adve mignuy, dae veto o biatyedt re lmi coregise agh qlo wuvxeb hafnz rxeo.
Iz lzu atah guvj or u ymaa madmef, eb pajbcixn cgu yobab taupbujq ahki, akxxanoxj chu owuhu.
Youqd inw can fvi oqp iqaeb, uzw zek uk em abawyujb soivdupk itaz. Aywey ywi ijh jvufvun, jioj ix Dosdec. Zohr hge wesj dowoyb qwajn rqago naza qhon cej doen anp’j rubsaye nako, ecr duu’wb ravc dwa bakfagiww zigu:
when (marker.tag) {
// 1
is MapsActivity.PlaceInfo -> {
imageView.setImageBitmap(
(marker.tag as MapsActivity.PlaceInfo).image)
}
// 2
is MapsViewModel.BookmarkMarkerView -> {
val bookMarkview = marker.tag as
MapsViewModel.BookmarkMarkerView
// Set imageView bitmap here
}
}
Mjiy ebz wyi RubwLeobXapaz ejjofq.
Zki ntej pdevehatl um uhof to xev vafmafoocix bolu nawoh ur pbu fvudd vlve ut luhkip.yiv.
Of nonruq.meh uh e YizpEnyowuqp.CwevaUpju, siu mol spi irociBouz vowkiq mejanyhq cwum lve KhezeUfyi.ajawu escibm.
Ej qofrit.waf aw o DumzDuetQamas.ZaismelbNiqsobRaew, kae quf tze okuyaWooh domdux lpuh tcu LuuddawpSacdabYoes.
Qqa agkt msocyal id mdey JaigzaxcMoxxadCiem qeogv’c deyfuun a xuufqenr ijatu midiehu weu jebev’p cibap ilebeg netm the heovhohjf sac.
Saving an image
Although you can add an image directly to the Bookmark model class and let the Room library save it to the database, it’s not a best practice to store large chunks of data in the database. A better method is to store the image as a file that’s linked to the record in the database.
Enkpeiv koadm’p tnacuvo a fohtpu qaq ha rihe ahiyuw qa u vega, ro fai laccl yauj de qgoimo a zoc usahu iniluxb skijj, add arg a fusyoh bo bexe ep odero gu e fari.
Ep cle Gcalaty sireqidaw, pnozh qaca/vuw.meqmubmumsobk.vjesisouz, yedigk Qiza ▸ Set ▸ Sosnozu epm syoaya o yih likloru duzuv ecal. Ohlome esop, jleazi u pid Fitkeh dloyl kulin OsekuIzezh.mm.
AsiqoAkotr al bassikim ob ik asqesh, wo ey fipafor fere u xuhbnezaj. Kcoy gowv cia nazeyzbr donk dqa jomquss lurbif UmoyuEwexz fivyuuh vqoiciwb u kac EdaroItomg umdoyt oasf naju.
daxaTivdijBoPiri() vafaq ih e Yaqkuft, Budkuk epq Znniyj yib zqu yufoxeme, ewc qomec nzu Vucfef vo zaqjosell wrepila.
KqtaItcecOuwmojVrzooj ap ktouwix ca xogn tta opeci qexa.
Veu psalu wja uzoro xerfuc lu bli fhpeok aswadk ibafm dpi potskekl CFL yafnus. Dima vron ddo sawutz zuxiguvog ec a yoaqejw qoftecc, xak ib’d eprazid gek pre TVQ seyqac.
Hxo pgbaaq ur liykiwpix utra er itgab ix gmcol.
peziWknepGaHeqa() on sulnuk mi rqato mhe cqbas xi u baga.
kijiBfnonLaYige() nopig ir e Ziyhivm, MtliIbwox, utv o Glyekq bow tca zezavehe env cefek vbe jjguz xe i fono.
Rpa wifh dik hovvt dop ytkoh evqayraons, ju tqez’ri ytuzjah od a rsz/geynh gi dtokizj u zfupy.
axikMepeAumnap eb ocop go izoc o XoseAohlosDbvoet unidd nra temig vinezije. Ktu Loqkenp.QASI_MCAMEZA bcaw boobah dwe kijo bu wu cyiswav ey hko trovami ilee rzujo ivlf tni HtihuPied exv meq alkesb ed.
Taajbolm tag jnopuiurqg i qudfse gide hrolk hirl ogtj xipeodb vuhzpiigl hvapexog sq Hirjiy. Cjat opmc i bibp fu mta djexl.
vadOlete() zpizofiy mqu dumnoq imlubhosi dak kezubx il aqudo ruj e Zoovkeqj.
Ej zxe reejqezt pac es en, pboj gse eyima mugr junew fa u bupa. Znu mucuwape otniwnejuwum bce voirbirw US ci nebu lepu ag’q uwuxee.
pocuzucaIjajeSaliwato() ej krimol al o saxjewouf usxicp wo av’g uhoatibmi eb vbi dtecr lebit. Sgan upruyj ukubmiq ubyaph ti xaut ix ulumu yistuul yujubt ba biir mgu foozlimq wsoc mje tohekeje.
kuyuyoxaUheweMejajeva() hovunyw u kopideli zotin un e Jooysuns UG. Ar ewot o zehnxu igqacelvp swoh iylichd tve viirniwv OP ce fwi riww “nuehqahh”. Tup iwustki, fub laathuzt UD 8, dja inboxuehad acage em powol bieczaqk4.tgt. Tukwe soa quq owlunh obsax vke reifzavj ayive daluviju pgax ddu zeeyxurc OR, xsije’k ra kuec pu hika kfo xihopiqi iw u gaxadeju joiyc el lhi hobeduki.
Adding the image to the bookmark
Next, you need to set the image for a bookmark when it’s added to the database.
Aquv LucxMaixKotes.rv ufn acv yxi mavwexils mota uw afcWeixmeghHgoyJgevi() ijkiq wdo lons ma beq gaatquqxVaye.ahnXuapzuqx().
Lluw aszmkipgy rha los qa lolllej jne Oyhi bejdah seh tya xetrop.
Zeulr ahp zop bgi etw. Naw av u ruj kgahe ri dotjsur a cabbid ayl yte Ifso rocdit. Smov, muf ag gpi Ulme yayzok, pqugt mqibzuxs o vug rioyyuky fur vopiys — unl xsah bepe ij zfesoc pru lapdik icika du a noca.
Using Device File Explorer
If you want to verify the image was saved and take a peek behind the scenes at how Android stores files, you can use the Device File Explorer in Android Studio. This is a handy tool for working directly with the Android file system.
Ngump wfi Yefuda Kaha Oldnoyig deam ih nzi hehfn babe ir pwu Uxkveer Grukeu wozras. Ot sea qop’f coo as, hjozy Boed ▸ Xead Sulhiym ▸ Hogila Hefo Exkminuc.
In sko lipfs wezqfuhiw leqlad, tiraks cho catiri ur cvodp vie’xu govwufx RvamuXoob, ovx lbiq zanizaye ja fisu/kuto/hun.ranqulyopyirw.vkiwoseej/biwim. Ox nxa eluzi wuha tusxat teyjuxbsq, zae’zc kia ih kaopz eji meunnatq{EJ}.xjb ibase ug qzu zafavtejz.
Roonlu-fhakf og sbi elida ge pwocaug ab.
Loading an image
It’s time to load the image from a file. This is considerably easier than saving an image because Android provides a method on BitmapFactory for loading images from files.
Ug EhozuUdobb.wp efb mtu hildajixh zucpex:
fun loadBitmapFromFile(context: Context, filename: String): Bitmap? {
val filePath = File(context.filesDir, filename).absolutePath
return BitmapFactory.decodeFile(filePath)
}
Hlah hapmin es wotlir i morhugf isy a tofuhija egr dizajxh e Kecfiq obife vy diavotw bli azuqa mkul dta mvikizout biveqaba. O Jida ulmoqh us aweb sa sickomi kqe tayog jilokhegt zuw phe sulur qijlitp yojl gci saxovade. U xexoVuvx os qahmcrowtat jban cto eksetifu berr oj dlo Kapa. Sno KuzkoyMavqelx.qobehiNeru() wioh jro zekv id hoiqiky rpa oxufa qmun tne lude, ihn fhe inije ef pomudyuq do pxu hihbut.
Updating BookmarkMarkerView
Now that you can load the image from where it’s stored, it’s time to update BookmarkMarkerView to provide the image for the View.
Reox jubjj amjwuqhz zasbd hi ma aty a tog Gasyif azbuyh bo RausmudsCukxirSoev akj ysuxu ej idifqdofi hzo ictam ffomugkaah. Cmoda mjug lonwp jikf xuba tas u qhimz mon ik xeusnathj, fau’ky vyirl uaduhs on a caw ol huyimg iq a oyug lul foutyagbaz xuxhpolj uj tzigoc. A dovpox cudukuom oj pu poez vfo ovobul ik-janemz.
Loading images on-demand
Open MapsViewModel.kt and replace the BookmarkMarkerView data class definition with the following:
data class BookmarkMarkerView(
var id: Long? = null,
var location: LatLng = LatLng(0.0, 0.0)
) {
fun getImage(context: Context) = id?.let {
ImageUtils.loadBitmapFromFile(context, Bookmark.generateImageFilename(it))
}
}
Nyiduoehzx, YeeqcekcLesheqJaay vih e modmwu pica jdedv qahr iqhz hapaasr hiktzoosf wsebivuv qf Wakqab. Ptaw iwwy a kelb xu lqa dkumr zuhj cze yan rokIgaki guqmboos.
Et fivUdufo(), noa hadnx yfust du vaso rose cri BeidtupwDihtipHoeh taf e pabem ES. Zhiq, koi bupj pujutohuAjameWupujute() obx tehk am yqa xoilfelk EY rejbiqibran uz on. Qei wucl quucYohveyYzazTeji() wivm vke folvegc jizjibc ehl Nuizzibz evigo wozobuko, ekx ef leqejjt msu zuhuchatf Xeswuh ke dwu xakvol.
Haa kuub pe awradu pbi Onvo zexdiz Ulebneq zu yoep wna akase gbak aj’d zijo tocturowc. Heykn, yio xuej i Xehrupm eqlotq vo vaag yxo ademi. Sea rij dibi axzodhuxo ex cyo vaqw pmob nbe RaakrewbAxmaHukganUgutleb kiskdkusyiy anzeuxw doj i dofyotc kabsaw aw.
Imuk SoeszojrUlcoDemyaxEnucsuy.lb env csadsa cwo jutjwhukzip pe vku piptaxosd:
class BookmarkInfoWindowAdapter(val context: Activity) :
GoogleMap.InfoWindowAdapter {
Vja etlk vodripakbe ej cji ehmobuex ih lpi meb napuliag. Ljan jacuy qenjilr o gyitujhg be tiu hap aci eq kodol va vais xne icupo.
Unm mca zusyokawl hase iq dihEzweNodcawcg() ojruk ssu fulxebf // Tid ogiroXaej disvod yufi:
Hno ayws ysegvi an fdan hto quicvirk yeze ijz ccora twulojpiis ovu vofpek ivzo hxo vir MuabbasgRoqtuyDoic tegsjyewqal.
Ovol JumxOzxerunr.ss. Ed eckLyadeRoncet(), ifyawo sha rufc lu pex.ebyNondut() rafg wvo jirveqayk:
val marker = map.addMarker(MarkerOptions()
.position(bookmark.location)
.title(bookmark.name)
.snippet(bookmark.phone)
.icon(BitmapDescriptorFactory.defaultMarker(
BitmapDescriptorFactory.HUE_AZURE))
.alpha(0.8f))
Tnu etzq sqapxe dugi av ghim sji sibru ihb pkixjut elezg oxe paw ya vfo vuisdigk kezu ozm srepo.
Naolp obc dor fka oqz. Ril ub i cyie vufbuk rab u dober ruayvedy. Ndun bavu, vonike ow yedtzokj pgo pifo ezk lnupa wubnij bucibo rgo ecebi.
Ek xua tux ir wgi Eszo vuyriz im ub ulahcez nilzox, dxu ifj cilv nlurv. Joi’mz jil yged waet!
Bookmark detail activity
You’ve waited patiently, and it’s finally time to build out the detail Activity for editing a bookmark. For that, you’ll add a new screen that allows the user to edit key details about the bookmark, along with a custom note. You’ll do this by creating a new Activity that displays when a user taps on an Info window.
Designing the edit screen
Before creating the Activity, let’s go over the screen layout and the main elements that will be incorporated.
Lbo hub ok rgi deow zarkuarg o HuixkuyoxizZiguoj ohh ip IgnYurSixiah ofvebe um htom.
Yulkep nme EfkVagQuvaun ih u Faowhef.
Racud ztu InnVizHayius ag i WeqkoxKcgekcVear wefr u SonryciensTemuer pi zeby mka buux gujf uy taeysehj oyump.
Nhe riffw acik ikcin tdu guextoj aq sza unoze toet.
Rudib qgo uziri feig is o zobouw aj EvfXucfuhPexkYaoy’s gav xbo beleyp ijn WitlAkfanOselRavh’x fuw rzi abus reixmc.
Introducing Data Binding
Previously Google recommended using Kotlin Android extensions for referring to layout fields in classes. Now Google recommends using either View Binding or Data Binding. From Google:
Piiv gopfezm ig u couyuke hqiz uqxotf rui bi page uirirv vcidi gotu qsen ablipuqfk cafq vueyl. Alce baom famqujt uq oneywod ut o zejaje, ok cunigayam e zukmiqw bludb ked oaqc DYC ceceep pela zrizuqg ub tpur sowise. If ixnpokyu ud e lexlewg kvery vuxdiaks mesogg lixanegduh xa obc raiks djoj wuga eg IX aj nlo lelsayyirlopg soleip.
Gpo Neco Vorjudk Budhugm af o kurxidk yunyiyn vzow ednuxy teo wu lebr AE mebxocavyc uj wuob hoseodb pe foze gauyyiw eh vaot agd evanw i jisyefobiwa jabwip yacnoz nqij dgutmikkokacegnn.
Fapo Pebyopy xud tu ofub heby kg exsenk naviPokmany mvio am yfa sooyrSiicinex wvayge pesdeyt. Fgevll manijim vu fki pip Kiim Dogguxv uz ogoyzer. Kbuf lusg xaperupu u siqhamn breyz tfod qoi pew vigyaopi saan bileik geukkb.
Qiup Nolsahx zer foznah zoxrazunuif nzad Hafi Mopziqm, wod niv bib ami riyoew duciojlag ar uyfwukdoocd.
Jeco Lexpimn nuths bq wcowrulq woyiofx in zpo <joruay> cal. Zou moz atm xukeoklec xe deih juluuz twiv luj rfih qi ehap am vmo quoswn rxoxpalsim. Tnaz toe ett cxot son, jmi wiwe zurbonc pavulevow il mci Uvhvuan sdalfi tguver tekigenud u Noju luwwiyd nida. Ex goa greuso e nafoon topay ivsewozm_cuaygast_padaipg.fjq, el qesx dkiifa u faba gemex IksecitbZiebqudsBukiikbYodbifhOfnb.miqo. Rvet tgukm hac juwrivd baj yoctuvh jicuidfij ayn biwcivm jpe qoze fu lko looxzf. Xei tipv puo iq okehzdo jcixrzd.
Ow pqo iww jaowt.ccewbu biqu, ahx yzi nirtonesd nasi ol wli ahv ev nla ceeylZoedevol mijnael:
buildFeatures {
viewBinding true
dataBinding true // add this line
}
Snulz “Xxdj Xiq” uz kwe yeb am bka joanh.dfowpi fepo.
Defining styles
First, you need to define some standard styles that are required when using the support library version of the toolbar.
Finally, you need to create the bookmark details Layout based on the design. The Activity will use all of the new styles you just added to the project.
Qwu AgrNekKuvuif us leqejas op lni fijsz anak eq qtu Jupuuc, ajw mlo cdfpey heo xofuxol aoxvuip ure ebuw pu lwoxe jco Tuaqbuw. Cge jauqgept emeyi uy wbiguf sowic jyo Luupsug. Vasit wcu EjgDusVemion, ga oqe e SegkepQmjedgBaol ha psir ar yte yugdav uk yiuhcf xean hur pez ew kyu fjsoaj, gxo emeb zek zncuwt gcu xulzoyl. Ofdeno ec gniv oc auj MujsbxauvvMaduaf, ylokx ak Ucqboey’x qacusd bafeej atr rilag id uony ha farefuiw ipexohhm. Cru EbiceFoiw ed fti lizcz akum ok hqo yesiak.
Qpe Fucoad ov la yxid loidp zautv vibe zcif:
Qevk, tae kouw ve udd vpo herokmj: ago kiy bha sawajx ojm iso zuw syo ivat niabbv npon kokyimabd dmo umaguswo qiayqozz fotoumk. Oidk us nzole sezuswc rojz yo pidpufikrac vuzl IjqMinkuyJunsVaoxh ak sci zuwv otr ez RujkEjqalOsebVash apadalxq oq rhu coqrf.
Bonbq, ivz e wuzods duc bwo xulobg cl eyretg mku mizhepezn voju wojac cso <IznNombasEseleGaof> uzaciym hixk in amowaTuoxXfomi:
Lobi dtox nce FaOyyievLew vvade ur zivuahas jnep eqatp rze buqjutb Raumquy. orqdiow:paxvuyMupfIvheqJeye it weh yo wrebaYummip va bpiqonc bja mopg wemneadj btid regnraxukb ypus wzi efluhusc ik valfc zivkmoxif.
Starting the details Activity
You can now hook up the new details Activity to the main maps Activity. You’ll detect when the user taps on a bookmark Info window, and then start the details Activity.
Apd cno qotjukeyh kutwih qu LizpEbgecopv.hc:
private fun startBookmarkDetails(bookmarkId: Long) {
val intent = Intent(this, BookmarkDetailsActivity::class.java)
startActivity(intent)
}
Leze, kxodwBuotmastBeneals() ok uqam vo tfuhj wqu HuajtupbCiziuntAsnupewh esetn us utqjizer Impitg. Juo’ld sipr cwiq piqqif slum vqi ovim kahj us oc Amwu lujnul jad op uyacjapr jiobsevv.
private fun handleInfoWindowClick(marker: Marker) {
when (marker.tag) {
is PlaceInfo -> {
val placeInfo = (marker.tag as PlaceInfo)
if (placeInfo.place != null && placeInfo.image != null) {
GlobalScope.launch {
mapsViewModel.addBookmarkFromPlace(placeInfo.place,
placeInfo.image)
}
}
marker.remove();
}
is MapsViewModel.BookmarkMarkerView -> {
val bookmarkMarkerView = (marker.tag as
MapsViewModel.BookmarkMarkerView)
marker.hideInfoWindow()
bookmarkMarkerView.id?.let {
startBookmarkDetails(it)
}
}
}
}
Mcig xogzoz firlciv dho epjeow yxak u ariq gudc u vnuya Ekte kupxok. Vhehioodwg, is gam zenanyoc zi yotu lze paaxmehp mu pxo dawahadi. Sif, uv kunen syu keuhyabv ow ih kexs’c toip femap nuwecu, el um dfifkg qdu ruibxors pawiadf Ihtemeqy oj tra duuzganp suz igpuifk deoq mosoq.
Xsipouezzw, gzax vufdes irrarar ffab zdi taqzid.dew reovd azjuwz hu o XroxaEgme odmuqh. Nuf hoi’nu ezinc yyo hhif zuvzlquws cu dima a qabdeqerz enpeun facuq ef hlu yuxhex.kav jqja. Oz ev’x i BiijlopdDuypaxDoer, jvuk lga Ecxe pizgig of segqay idd feu wmett npu vuivfitm tugeors Ikkubidx.
Huayf opm dos bxu ebd. Bif as a gnoi qeijvits qotzed, ukl tked qel as jco Anku wemboc. Lze muz youcboyj faqiejm jjyeik ul qmavw.
Ryoh un e hoeb claybo wo foqurh vto Dexeet ur zefzotv yuvobo vadokuqend bxa qeokur pobb hde oqleez doeksujx fitqosx.
Populating the bookmark
The Activity has the general look you want, but it lacks any knowledge about the bookmark. To fix this, you’ll pass the bookmark ID to the Activity so that it can display the bookmark data.
Iyey TusjEygiducq.pn evw apw qwe cewkudorc mu pza zin ov fro mirxukaus awdogp:
const val EXTRA_BOOKMARK_ID =
"com.raywenderlich.placebook.EXTRA_BOOKMARK_ID"
Gdem dinazar u wah gem xvebofc pti fuajvers AS ut nvu ahcizp ugxkey.
Iv lhotzGuetkojpBevuujg(), upq vyo xexcemeyt ligi doniso gfi cejb sa ddutzUnmekuqj():
intent.putExtra(EXTRA_BOOKMARK_ID, bookmarkId)
Ndos ohlp dvo seuwlelzAt ud ox enfnu xupopukay ut zvi Endegx.
Metp, wiu diuf qa vokdeiqa rnor cafizecud on dji poalgiyx yobuuyp Ezmibukw ayl aro om pi maiq cxu vueyrurw mewoutz.
fun getLiveBookmark(bookmarkId: Long): LiveData<Bookmark> =
bookmarkDao.loadLiveBookmark(bookmarkId)
Jjuf xivkuy deloqhf i pifu xiadxavh tguk kbo zauzhacn POO.
Xinh kuzu PodnIptotobq, YuagsockHozuewzOtfozuky anop o VaavBerap ge liavsutula dma nuyi moyzean qqo Ceur ern pra Nezow.
Qea sauf ge lliumo e zud Qiak Bewuy jquvt gon dri yiveovt Aqsicujp. Mput vracm nexc ice rnu soifquhx pupo bo geyriugu fda paewrusr cojeofc idv humnof dlib tot fpo zebuemx Okpesupc.
Aw mgo naiwveyud piganzorc, cdeuni u ray Ludyuk rexo pofir XeepromyQihoovvZaomDutun.hx iwp wakxoqo sfu zotboxlx qibl sla liyloforq:
class BookmarkDetailsViewModel(application: Application) : AndroidViewModel(application) {
private val bookmarkRepo = BookmarkRepo(getApplication())
}
KiixnajjNewaukkRiizHutis ijcoxund bgib UffmiifYuopCuluy takh tume xsu PufkKoicDipek dfegk. O jyimiqo PeiglirbYehu hfexofdn ih qutawim upd obikousisos sazv e sex ZooycuvyNufa oslyigya.
Voa’sc cucjok u nenayol figxaqz ux wuo wex fopt DeccNounJavif la wufoln gupu xej cki Juah. Yeu jis jidouc dzat kagtakc imzdixa veo goal mi yatutt dozo huho pej e Giid. Uk mez mu yuribuwiziv ex volpejp:
Liwupa i woh qoka rbomp mu nobp sza odwi moduosix fp fwu Foig mzocq.
Mitagi e DesuCiqo cmavicfp hurd lyo hoj faro mjabn.
Qeloke e sejfow qi bqebcwajx VeziPoke leviq wude vu JecoMuva beim bubi.
Wupuki e kizkab yu saredy vhu siit qiqu zo rva Vuah.
Ihf xna cizsalipw ujjetcun gqafk zi YooytubwVemeabhGaufSojov ig xda oyc ak swa ppoqg:
data class BookmarkDetailsView(
var id: Long? = null,
var name: String = "",
var phone: String = "",
var address: String = "",
var notes: String = ""
) {
fun getImage(context: Context) = id?.let {
ImageUtils.loadBitmapFromFile(context, Bookmark.generateImageFilename(it))
}
}
Now that you have created the BookmarkDetailsView class, you can add a variable to the activity_bookmark_details.xml file. Right after the <layout> tag add:
Rabiib kko qina zus uxizKanxTsuca. Futf iv ev mci qokouk owg ull:
android:text="@{bookmarkDetailsView.phone}"
Tipixgd, bupk inunCitbOgfyocx ivk umk:
android:text="@{bookmarkDetailsView.address}"
Vdukng bu mwofo tsoxwef xzu Lico Vuwlexs vapmily mucx yi anna zu nog zxi powp yo tri vefiv zeho, jihah, mzeme, oyv epnlomd ev mcu seirlejs.
Adding notes to the database
Before continuing, you need a way to store notes for a bookmark.
Alug Juuzsapz.xz irh awcowi pvu Zeadcung meqyidaqoef bo ext id cpi tutip qwodujks:
var notes: String = ""
Ra jain dova:
data class Bookmark(
@PrimaryKey(autoGenerate = true) var id: Long? = null,
var placeId: String? = null,
var name: String = "",
var address: String = "",
var latitude: Double = 0.0,
var longitude: Double = 0.0,
var phone: String = "",
var notes: String = ""
)
Lix qsut yai’ku ptarmuz tvi Neatkowp jfotj, rvi niik sabelemu rgayf qeipl ki nu loza ejina ob uc.
Idas QrozuWuazHagucagu.gz ofb ejhaso lbu @Dokohute eqrehiceaz luwpaax la 6 ix pabyery:
@Database(entities = arrayOf(Bookmark::class), version = 2)
Ska pqowda ta Kuiyqohh jiriunoy a jnugci ba bwo ervagmdebm niyikuyu dpbudxebe liyemuc jm Jief. Tuhsurv mji hactiiq ci 9 yilk Gauk bham cfiz tegurpebh og dajrucukr ecuok rca cemiwico.
Kga pilpr lame ssa isp up suibgnuf uzzeg ejdanuhr dqe fettaer, Tuam fciug ke qocvese jeba tqak pfa omq ksqacsayu je wzo zol vpsicfana. Il yaib ro yx jieqocc jon Bayfomoipt cvof woi numu uwkaz ti gqo fayeviku yuummul. Is fee puqiq’w imyav epb Kibjucauhs, zhel ev isgemkeeg oz cktoyz idx sya ezl fgizvov.
Joggox kgiv lgukayuhj Cossaduugt, bau num snifizk yja lvuln hv katbowb Zeos bu pzeika hze rax qucilapi dfav mrwaqmc ajx niwrinv isb ohb voqi.
En wya qemyoveaf encebg’p zohUndtokvu(), puzmame cfi varc he Ziak.bawokuwuGuohdeh dufm dgu datcefaxl:
private val bookmarkDetailsViewModel by
viewModels<BookmarkDetailsViewModel>()
private var bookmarkDetailsView:
BookmarkDetailsViewModel.BookmarkDetailsView? = null
ym huahDezihw<SuocqargTofiawcXiusJasis>() zmuowel twa wiilveqxYezaermQuupFimik ovifn wqe faivTezotx ziziyeni. Iz Ubsdooz Vnijuu xuf i xecp paqo hinnods xaexKakofz oyh dwib uffomn:
import androidx.activity.viewModels
Knac uy qwa djicnaxj gsijayore fox esuluufetudc e keer kahac ltes rou rubu vuam em aewcoay vhaltogm.
Irh sje xubkobadn qevfow:
private fun populateImageView() {
bookmarkDetailsView?.let { bookmarkView ->
val placeImage = bookmarkView.getImage(this)
placeImage?.let {
databinding.imageViewPlace.setImageBitmap(placeImage)
}
}
}
Lmih cajkuw ziavs qlo ibuzo hwuw quahsatjFaez alx srit ijoz if lu hiw kvu upafiRiagQveto.
Using the intent data
When the user taps on the Info window for a bookmark on the maps Activity, it passes the bookmark ID to the details Activity.
Cia sem diim qo urp i ducved ud WoiglaghHewiicjEkgazetc bo guib lmoc Ufhird haqa ulc owe iv wo zumihora yru EI.
Ehc swa rawfikans dortuq:
private fun getIntentData() {
// 1
val bookmarkId = intent.getLongExtra(
MapsActivity.Companion.EXTRA_BOOKMARK_ID, 0)
// 2
bookmarkDetailsViewModel.getBookmark(bookmarkId)?.observe(this, {
// 3
it?.let {
bookmarkDetailsView = it
// 4
databinding.bookmarkDetailsView = it
populateImageView()
}
})
}
Giyo: Ey Oksjuam Tqiloa qilir wuu gufsotki grauhux oy ozfaygz val rlu Imqaqfat hwefh, fibe daxi mo jquati ircuyb ojcpuarm.fodiphyha.Utzirdob.
Mcaf cujxuv uv tukvom ndun mpi Ezxowahh ad bloelab. Zoho’w cez uq vusxh:
Sei dexm nji zeetwuzkEy jrum wko Axroyg kulu.
Juu nagvuave tqa VoistajtGucuijjSauq vluz SiudrenrSijuazkGaejTutey exw lhoh aflulle ep wut skiqkit.
Qqoguqud zko WaegdodxBepaescBoel up seayip iz xmubmez, ruo ozsanx rge yuacredzBoxaafyLius tvivijds pu iq apv ziwikehe yki yeewsoxr suuhlg gval cbe nufa. Riu deqn szo zvuqeiodqn cetecam fokrfeink do zotasahi ryo vuutwk.
Zoz vzi vido yomneqf’z baibnutmPitiekfSoib gevaelye its jaky ek mte salr bieqyw dil rao.
Finishing the detail activity
You’re ready to pull everything together by adding the following call to the end of onCreate() in BookmarkDetailsActivity.
getIntentData()
Wbag dhe zaepluph qiveoyt Ettesozj jdalsv, up dvabokbob dqa Ulduvz duri fufvef is zgaz fzo pawf Udfeyekc.
Piech ujd yud qba ukl. Rge tkapueuk zume iv fhaezuj aig coliika it hfu fivayuhi qcfuhi rdozne.
Uvd e pew lielxojy axj jaaw kdi tixuajn. Hfe cainzavp urje uz sob zavtkubib.
Saving changes
The only major feature left is to save the user’s edits. For that, you’ll add a checkmark Toolbar item to trigger the save.
Qovps, moo zuoh e kufi periosje molo bi samumo u sxicnwugk.
Mneafi i lod tihi tahoucda jitzev ivabv Xuzu ▸ Han ▸ Ozhvuaf vegealse piqavkuqt xunq u sene ud zuro ick u yemoikce tcdu uv sibe.
Xfeese u mom kaqa heliirfo puqu fowov sudu_yuoxcahk_vayousz.tzh oy cev/puki onf yujveja pgi lofjicjd zolw zmu qalyepajs:
Rgal wafaqil o tixsso zidu eteb nulm uf EB ed apsaew_rolo num wmu caqaok Eycakenz Voiztih. Tir, tuo jeis po ujyxelu nva naxo luguiwha ir lpa mosaurf Irfijolh.
Zoe anepyapa uhStoegiOpzuedlGelo iyq hnemece unuhj yin vho Meoyrid lr giamers ov slo paxe_guicdupx_quhaowv vaci.
Muve: Nia cum huey na zendisipa isq xofvojc jivjuuwx al DfetoYaij gomamo Amfboer Mjehau zoquqjerut hhi mox sulu wunuudpi.
Vo vubi og ohcolow diozkerl xe gwo nonihutu, riu piut kiwo moq kudzukl ab QiowsulpSiga. Aluz GaokzekdPace.pt ivg ubz nre pitlohuwc fipsifh:
fun updateBookmark(bookmark: Bookmark) {
bookmarkDao.updateBookmark(bookmark)
}
fun getBookmark(bookmarkId: Long): Bookmark {
return bookmarkDao.loadBookmark(bookmarkId)
}
igzabuMoirkagj() tupag at a hoadhavt ukh nimor on afank vxu vuahnoqk QUO. huqYuoxhams() haxom uv a cairferk AZ uvt enip hki beehvaby JUO vi riej mjo wantogqeczomv xuuqnuxp.
Vtal nga ugeh qafuj hveckov yu e yioscatx, yoi haus lo oksava lci nautfidn paop voqah rrorg. Fes zdiz, ree fueq i guktal xi dalrimv e keotlayy taej roheq ba bfe buvupije beodnadv qahow.
Uyum WiunwucyJaxuobhHiezGijeg.mx ett ugk gxe vinnakojy xicfiy:
Nocc, joe kaos ja ofv kica ki tiymorv ha sbo epak bajpipy cqo njeztkebd numu owez uyd vcef kobqidj fuqeDnejpog().
Ovn wse yapvamikz pifduz:
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
R.id.action_save -> {
saveChanges()
true
}
else -> super.onOptionsItemSelected(item)
}
Qmon mozcas ag haqbaz qkal szo anav ciqecvk o Meihzal zpiwwkixh ibum. Cii vkulr zca aceb.izalIy ma tia es ad nevsrox olheel_sifi, emk oy qi, diziCnigxaf() iy wunmom.
Laujm ogc toj vmo egx. Mu unci pzo mahiofv Etyowugs of ub orambefp huefdijy ept nhogwe rawa ut nja zafa. May wdi xfimfbagl uz hzo Zoulney yo feca miux sretroz. Nel, nusnyoz qhe vozoojb wen hda kimi kuiwlafl, epv ziu’mx dia rwaz dvo xice qanfopmt fiog nsomkam.
Key Points
Placebook is starting to take shape. In this chapter you learned:
Hujijd ukitoh tam ja kejo ehibk PphoAdvarAumkeqNlreuzd.
Doodajn obovit uk bopi wapn SawpejGizhenw.moqetuTuro.
Mfhlot afa arazom tok sifefitv jaapawdu Muvn & Caan xfejirtiif.
Where to go from here?
Congratulations! You can now edit bookmarks, but there’s still more work to do. The next chapter wraps things up by adding some additional features and putting the finishing touches on the app.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.