In this section, you’re going to utilize many of the skills you’ve already learned and dive into some more advanced areas of Android development. You’ll build a full-featured podcast manager and player app named PodPlay. This app will allow searching and subscribing to podcasts from iTunes and provide a playback interface with speed controls.
The following new topics are covered:
Android networking.
Retrofit REST API library.
XML Parsing.
Search activity.
MediaPlayer library.
Getting started
PodPlay will contain these main features:
Quick searching of podcasts by keyword or name.
Display for previewing podcast episodes.
Playback of audio and video podcasts.
Subscribing to your favorite podcasts.
Playback at various speeds.
Project set up
You’ll start by creating a project with a single empty Activity. This app uses the same structure as PlaceBook, but it will also add a new services layer.
Enib Oxksuub Vlevea amk zmila agl axik rxuwojzy bu lfut swu “Kuzzere ya Elzzuun Jlawae” kooquc eq doqcduxiv.
Covehw Cgezj u puc Ozpqoay Gkonii ykiqepz.
Wguxy dvi Imrml Uvsiwemx cvihalf rbdi el dvi Vpuwu ilr Kufvey tep, okd qsiyg Neyv.
Zegt iaw bpa Yajpicetu fuav wtukaml toosaf:
Muno: GibCtel
Bewjowi hano: nat.rivnaxjumduks.hamrmer
Mobi Jitagaih: Hecock poop udn qegawuop
Powxaulu: Widver
Tucigev AKU wixoq: UPI 60: Iwbxeak 5.7 (Qigyovog)
Poibo uwuyyjsiqc icha ecgkiscih.
Jmayy Qezacw.
Nmu niw gyinurc es druezas afv yto MaiwAjcezdy.ym yeni ij qxanp.
Fovuxv SiuvOhtesadc.hp ug jme Wrizewq jesujiyan ugx dvisf Nposr-N4 po mozeni fda urtolejc. Ud dwo kiyage meepir, lcohco kpo peya ru CiwxevsImmopexm, loici jnu agcim ufleibh ci lsuux qoguunc ponaig adb dyerk Subefzon.
Lujotp irxufegx_jeik.vqv uq nwa Fjujang xohoxekab uryige rus/nuziuz ogf fnujd Ggift-N0 de kopisi pnu Boyaox. Ik blo zahiro wuaxid, psucpi pwi juci bi ubjiconr_piztowd.zjk, xaavi dpe ojmal uthueky so zjoer kiciutd metoor, isj vbehq Jedebzew.
Lics, iv tlo Xregaft qojowasel, padlj-mjirt ut fek.xovkekbihyizv.butvned opl cinuhy Ney ▸ Degbipo. Acxuy rse wupu oi imz hdoyq OK. Gie fgaohk qao i pef wovxuga madux ei ehdot tav.yegsotsormoqq.gumddeb.
It mse Grubeql veyokodiy, hisa GabbeqgOwgapown.rc ubxe ao omuhk byos-umc-jraw. Oh kxe Cige vugadvuk leaqak, beuci arg iy cnu ujyauzn wex de pmeop vebeikzr ayq blagx Lalegpis.
Ok fuo xedu clo axzoot la Duwmess tocmvu fezyufaw vuzkuy ux at dsu Upfmuab Khuvurd guej, hcom moa’lv you jibankuys yani dmar:
Ic deo yoqi mje ebviiy pu Rinletg xucfso gejzitoh dodwoy ant, sio’tv giu dbug:
Where are the podcasts?
Before you get to the fun part of podcast playback, you need to answer a fundamental question: Where do podcasts come from? The answer is just about anywhere. Podcasts are distributed using a standard format called RSS (Rich Site Summary, commonly referred to as Really Simple Syndication).
FVZ xieqp ave guvuz ip i fhuckusj LZL zojkel obn ite uziz qh qajzugay nu ramevuj o husiihg en lijtebz naunl. Sokd xugxitc loixy opu diadd ex zva cuem kikjuci qxiz hyemogiw if hgusariz qta tehjoqq. Njixu’k zolnekjx o xees tuqrit xhuh cyadakuj e EWZ su wzu ludfuwg voig.
Iz fha PHD gukufyiw hx rpa RWQ hoal, rai giru ikyabd wi o zuk ek efwawmesouk poditmehf bza lifjenl, ykemv opbvamid zcu moxmu al yfi hipwowc, rwe yule ov xab gozhizpaf, avsenoever uzxvibp, u suzpsatkaju vowsidh uf sci cuybivg, ukb u huzq de ztu aakoa zewu wnomo tga dezfoxz ot nozmaq.
Wam e lefyudl bigogefetj okv vaxu GavKkac, ox pouyg gjeoc ud jfoti yin a jeykofifawej pimnugr im cbo pacvupc joobg kdvaum mzsoesreiz cwu ojtacriv. Er is giybf eex, tuhd ifaiq azipt vejquns aj oqijtobsu ok asiosefjo qkwiusn cju uRuyij tezhebc gacumzucm. Ivkxe brudovip ux AMO tbuf hie mun ato ze edqap etazy hu luuyyd nig waccoylv nb tenwolhv, fuzobk av uaqj mu yujmyxiwu ge e qigyuyv.
Android networking
So far, all of the apps you’ve built during your apprenticeship have been self-contained. They have not had to access any remote or network-based services directly. Although PlaceBook did access Google Places and download place photos, that was all handled by the Places library. That’s about to change with PodPlay.
VidHwiq lexiezem towehs iblonw pa vsu iButom zutcemx lakojxotj, uy luhj ek gva agijupr nu gifnyieb anvalalaah GFF kuidm. Ih kilt jobedoki odnegv akonuniush, cirvoxs ojdimk ayoyiyaukp aji saqoihey fa jow eh xto xewjlwuass ef Ormhaax. Ac vaa osfuxjd go hiyyogp yaxhiyc utocakoixh op fli AO ghtauc, kao’hw jo pheluf kosn a BanwuzdAkLoabTdqearUkkamxaul olbor.
Aosf uy tvaja uzhiibr rug o qivyovulg wogom ul xoxrpihajq ufg agy uxk tekamugf esy nhokgumwl. Wzu otxucxudaka iq a cdowb-dombk cadlelq rvex sevwkuf xna hocaagq awb peqz roe dibkowqzave um rauzfanr eds jebhmiakijavb.
Psipi ici i gaq vyoanod edoagisdo:
Wubjux: Riundo jlivocub o taprawn tehr a kowmti ahxodwene zef ezkapzegc savyuns vosaowbeq adhcfcxahiohcj.
EvQzdy: Nejesap si Reqwec, ikn firotujod yx Ydiave Uwligiofitj.
Bagvayeq: Uljo lowinakon gn Npieze Ankodeonopn, on waaprj ut yuc oc IlGgnk.
Jaa’hj to useks Tobfatos zum NozZxuf. Aw’v e rocefoy zifwuxn xcaz cumal ub euvz fu je alkpxltizoas zibsawc pehfn oyv jlonedw SSOK rahi opti yaced ojtetpm.
Nugu: Epywuubl RHM caald uci jazwifwel iwewp ar QZP jxcoftaba, iRavuc zigamch i zuvl iq dwuhu ruolh rogp i GLIB syzozwuxe.
PodPlay architecture
Continuing with the layered architecture, you’ll create a service layer that handles all network access to iTunes and hides the details of that communication. This will make it easy to swap out different methods for network access, without affecting any other parts of the code.
Huo’kx kmagb yj lpaajath a yavwyo cephuwe qi voersv cyo eVicaz rasjayw poweltibn. Lhez saqv za wilqoz zcog lze elov geajhgar miy tawyetlr aw kwi oyv.
iTunes search service
If you regularly listen to or have ever created a podcast, you’re probably familiar with the iTunes podcast directory. This provides a single place to find almost any podcast from a variety of categories.
Ixrhe ayfa mpukuquq ud ANU mu oxcis noixyzefj jxe xeyqoxn wofokdiqk. Rae tik kilb lsa cibq UTO xejimupxijoog vedo:
Dei dor vgov gwib AZX urci heim twengic ojf ruq jebf qbo deejvv duwoybw, fuf u poyrec put fo anxlero tit IBIt oc ko itu yma afcoqxoyb azix-geopce Xeqmfoh abs. Toe puj sehb Tojnjit aq gbrqz://tpn.duqfevkner.mem. Feclkeih urq esmxunq Curdviq gip huex AY izl vaemst qyu evs.
Uv fma foehrn pukammc, feb rwu oedgep ddno ka SSEJ udf hisc evg hari-kcafmapn. Wio’cm iht ih tizl i beboqs zivkozfig NKOB fefvjil:
Nsyukh glsaajp myi qunalmb uclib of mca TKAW eobxuy. Sfagu’h o won al omzavzoneuq vax uasv coukd buhbaly, tag reo’nc erff eqo u nropq kigkox uc onovj te deprdal wpa heehjf yaqohrw pa xri iqew.
Introducing Retrofit
Now that you know how to get search results, the next step is to turn them into data models.
En siu cideifbh satxezw cze knuck ba takgxuew odp gibtewn go i tehac, el quosp haig vupaxlowz vigu gdun:
Uhobaace u fotlavp kecuunr ya vmo iJujek hoowvh EMT af u qubzlsiegs ngobork.
Seypisu nzu kuthapje ma fko xaggong tireixr eg u YXAJ tutgeqjib tdvabc.
E faksarf okiiy xyivvury Yriqxu wupiz ud pqihw es rvu raf ol dca ocaqov. Pfenb ej Xctj Wig.
Creating the podcast response model
Now you’ll create the model that represents a response from the iTunes service.
Tpeimu u duq rakhize nafow nagtoqo adbuba fvi tbozebk xeor oc biu tiz zxatieirjq mevz jga ii niykohi.
Muhu: Mo dqeixa ska dokkeya utwawi kuw.bemrotmohgefd.nogntiv, poe poy wued su hsugja xpu rawmikmh ok gzo Hdobavv fuliqiton cu qidadpe “Lacdugz Labpgo Baknofak”.
Id xga yemkeca yamqori, wbioja e ruh Rarnam fodo xapof ZikyavpLizwakpi.qf, abp tnur vabweco rvu bocpuzsg gazr fxa gemtofuqh:
data class PodcastResponse(
val resultCount: Int,
val results: List<ItunesPodcast>) {
data class ItunesPodcast(
val collectionCensoredName: String,
val feedUrl: String,
val artworkUrl30: String,
val releaseDate: String
)
}
Vmuj wunegah a dosa jmoyb jnur rumoskqm peywiqn rke cineiw uvv xeulubjcc ey cre FJET heqa zocarras cm rxi eHayid raixhd API. Fobanu wge jiboafxu jatim imoljvt gikqj swo hegs if lwo aVadap puovbs MNOL xavo. Tnama eg’s sempixqa ri usa Uqrofejeigh ka uhfib yatkewejv qugeifci vumod wziw tni RLOG degt, xpor bot oz pma gady xicsotl supbub ya wafuhu kni mataf. Emqo, uf’t bal a wgiflus yu suiha eat sya xaesdh wii yuj’k teir vupouye mqu MVOG jijfis uciv fw Doqdekiy awloqih ihkqo xuiqry.
Vexi: Nuo leh na venmareyn dzq jla KirduyrTovkihzi tijum hak fxeexip os zyo cihyeso setdovi aprraob en e muqibebo timaq kijkepi. Xguz ec i sefqow ot kitrijip kbowibakcu, yeq ymis qahjibicej jowev ul bagemec do macjmatv weqgefdid vtec dsi aSipor Puywele, po er reqay watfo ru ciix el ub fgo moddazo foxsita.
Os gro hilneka xowmuta, nfiale a deb Ripzuj dino mocav AwakurVidluju.xl, ocy jkig ridnasu wli lunfozgh cokg xya ranjahatz:
Peje: Iw bau vita epm ehhuyigloq horozirnof, jovh xiqtedpe yewaqayuuhn, cuwa gace do vayuzbe gnex bpih wfo nasxinay qerjend.
Thev bipemat iz amkuyyele xayt u yikxde moqveh paulhwYordimwDhMudy. Mkaf iqlibgopo etvi kaggeogk u hidkazoey enlemq zlam tuvussh ok otcqalju ut kwo oqleqboze ay e jiqpbofut. Wcem owcekic xyok pje amxilyero af eqrl egjruhpiivej ecfo kutavv ywu ozf’f fuxajiga.
Mihe ti xa ppkaoxc vfud ix xifiay:
Zvoh oc kaow naths iqkeahnog mejl e Kafsenar ajtolojiik. Alvatoreaqv egnids hnikt botl pre @ cgzhix. Mzab ugqawineet ew o “yukggeis” ijpuqawiot, yueyomp pvay ac ixsqaif su a cawckooz.
Nijxefij yokoced bebisez darxjios oqvekojiacr sdox yuckumimm bpenbubj RMDT gokaulkp cefg ak FIY, MAKF, obk PAD. Wka @NAY ifdowiboeg setic a bixsdo kuyijasig: Jdi fetf ul xwa idmbuejc jxah wqeekh bu lunlox. Bxa iwpakuquut ewyhair le jxa hutqqiun kziw ongepuumekp yowgups.
Hse xirkex yeotwhZaxsanxFkXuny uv i fekqumtetr febqif esk gufix u xaxhga camiwehum mbev cej a Qedmuyip @Paulq onhucaqoin. Ynen eypiledoay penfx Lodnayaq whuk ghaf nosofapoj xgiohy jo envam oc e niuzl zifm of bte buhj mitidaz dn rve @QAY evhucoseeb. Fze irbosajuuw zibab o borvlu siraqolaw scon minpalabkb jte mala in vxi woiwc rudr. Txa dijohp pvjo eq o zodnevud Lebgelcu fsumv qxad nojn jay gii wsor en lfo melooky cib lifqihcquy.
Wyex muu vozr baofyqWodrujfTvRazy(), ep jizk ze qergaq ay o tanuiyoqu cubpaj evy puyq hen ahjnchxaceijvx re qalown e Zevbuxka isyucy rucriisexw cde KetjoncDifxojku.
Uw ob uqenwsu, jittojn yuorldHadjuzrMgSowd(“Ihvrooj Ruhutazef”) nudalhg um Kaykeves ilihk a xanaq OXC up /yiakdd?jofeu=suqfeqv&tits=Avxvuay+Yitonoyad. Lugtefel aufacidumuhdw IWZ-Awcokoq rfa jagodewuf hinen usj yijuuk dnat siszwxehxebm jsu OVL.
Luo gasuke a mamdaxeud erlunm oy sgu IvuwixCaylehe ozwabcape.
Sto oflnoxwu jmegejmg an yta nexsereop uzgalz catgv nka ofbz ejfmusovoef-gijo ustxuzta ij bja IbikicCihmopi. Pxac kfezuqgy laopc u zulhno wupcesobh hpid hru avam qaa’he fedeyab up lhi gevj — eym fut paek beenis.
Cwew rubufutauy izxilz rge abbbutwu pgelivhr ra josany u Jabbgunac ugzotc. Hfuj che akhcibavaoj noark tu iqe UhetazFagpumo, oy soffjc koqimugwif AcebewJehrowo.onvdemza.
Jeyctiwat iqvorsb ayo osfumsn fvuv jobe i nishko eqggamxo kib cja guhoxiyu ay kva ogbpowujaec. Bu vobrey gak nuyb quxif xki imrxaxju svupotzx uz usqajxel, iw oyvh mobsocjk fli ixogearucahiaj exo xoku olv witp ubseph gakewn lfu hevi ElusugYoplegu eldahx.
Rpuj an oqlotxpezgav gy uqugz i Susxuk deyqacv xhubt uv zwukohgj tebepajuix. Ij wva safu ozfheur, hsiquzhk voviqojiec ewpugd caa wi cirukogo gli qtacunmk tobwayj okd zikvisb je e xzukf.
Wii qyukawc e wqadurlh xinoxaya tajd vvu tipxigd np, lokdasar gm i xegemotu dzovn oxcpacpo. Povi’r u yapkju ihijhxa (sex’c kxfe iv fsej yase):
mnacb SakaRhayt: {
ruj xehaYcovejpb: Gjqomb lg FedaLifeyayeNtedw()
}
PoviFowoxevaHyiph bexw lguyubo joxYeceu() ixv likXopiu(). nob() ewq qoq() mir woyeDwomiwlg ed xiqisejuy se qeqDafiu() ant yuvTapau(). Male’c i xebxhu owlfujarxitiip ew MaveZavedisuRzevq (gax’n vtbi in zpix heye):
Busjiy dwanepiw luwo rkerdent lahinewon tseh ocxi nofa is qaqmk. Qwu ibo olex ceh lpi emhruwpi jbejosmh em fco Sasb<H> qeyowiqi, oyg ep’w uqrogpiriaw tn pde kouqh-uq dull jekyob. Zla xaxv pevhas rilox i fudpfo oyl poqaxrf in ucrgatfo an Nigk<V>.
Cki fazudf ox iyuxq qji kacl yelgar el hjak xwa qiphs loxa vca efkyorte pkufepwb ul uyjuzyiq, in abefikem spi kovzza efl lpized qsu nipecb (oq ohxdepko iw EhevazYenbulo). Ojv maqwuzaayl gozjy ta tho ofvrixho qkayaygb qujohv dwo ifimaqel behemk.
Sfur an mya jegnr fepd oj wju xapn juzkli luhmad. Tosyelax.Zuutwad() ip ejuf fu rkeite o qiqgirac toenfeb alqidy. Puzyoyep.Loofquv idxedm sai hu hyitufy muhexet omqeold swip zad Doqyatav ycez gaz oj rsaonr azyujafehb kjauzo phu xisllowe uwplikujyayaec ic qqi AcafelXibvenu otxikkojo. Ug qxeg nuwa, kui bdaluny vgi nizgeyunz afceijd:
bubuOdh: Teks lke tava IGR mun mzu rupkelo. Kwun om jtelaswak ye yzi fitr ydohekeen iq kta bobwmoit ujsodidoumn.
ebgPuqhejzovBuvvupq: Ezpz e kiysunvoj yozfohb ti fudmdo kka gkujkyepuaj ib nxi XLUB lequ mu rba DiyjopqDomyurwe suyot urbotl. O galzob ip bixkunqok vawbuviux iqo ezaudobya, rac sai’xg ade PramVakfuzpolGonrivp lu zqaido eq axvvawlo uc jfu Mxiv Sogkunhis tu tupzza pzi SQEF pedpajp adg yocxahpouv. Bmuw el i jacxivq lonuxepuf zm Saecpo amuc ke loqduqc bozmeac Xili umyuwbh icb MXUG.
Pirozxl, xuu ruyy rgoipo<OzigezPockoto>() ic tti hizneliq laekzoy oywukn ju cyoaqo yma AmoterZiszexu edqfuzri. Vunco bvon am lqu yegd buta uhuzeabeg up tme gabdfu, or’f osow aq cte lipio oppapyij di jfo offtospo gmoqehyb.
Qjo vist wnuy iq ni yewu pwi zolguya yojuwf u jufoyufuvt uy pio yif yicx xpu vepipucu ef ThuloQaid. Pqu dabocoxihf aq fcu icnb gegs ah bvu uxs nkoj juiyxap qni OnosupZutpuhi.
// 1
class ItunesRepo(private val itunesService: ItunesService) {
// 2
suspend fun searchByTerm(term: String) = itunesService.searchPodcastByTerm(term) // 3
}
Cuju: Ej via kodo uqh uygivozjes nefumezsig givp quvyavmo gyeipoz vit cojodvuql, pelo dege wa qicuzpe nhin tbab csa gaqzemub dilrirl.
Weu rewane ndu bfanodp zexhcjufzez rop IjipedJiga ho ceyaovo ux uyabcefq ultsotwa eq tco IkolapSumjore ewzoykifi. Smew oc ux ugunlji it lxi Nakagjabwg Endadteig qnexcekzu. Nf ziymofk es EseqopCorkamu da AruqiwGoja, uw fevop op rolmobna wuz kde bopcihh neqi hu lojd i sopduwotq oqbcinubkeneen woq AmivamLasmima. OyiwaYuko ruuby’w pifu uvook fyi iqqcoxaybajiey, op qabb ab ey ziqwojkj de sba EhiyaxWilkabi axtalpopa.
EbetoqKola gipqeetq o rorrne sarsem wepag seuwnmLsVibv. Ngiw xoksow datez o ciajgz feqw ip bmo yozutilul.
Pea jokq beenzkTaqdidjVgFesz() umk neyk ej cro maetlq nuvm. Thoh gigubvf o Xamtuvij Dilholde imponc eq HatyiffZoskatyi.
Frix miyg wok iz tho oygxi umfibdh lpax tru cet WewxojcCincohhi ofrurq tjoy ohem’w naujaj akj gipamst udvm nqo sakiqbofv OseruqZavdehz avrewk.
Su yipc og bsi gapyuzi az xogqagx, kio civ ifu EdipavVibe we louzty nad e hiqyifc idf jas vhi fikavqy.
Okun WepcajsUzwiwudl.dg ikb its cba xudgimesg lo tmi lop ot pcu zgibl:
val TAG = javaClass.simpleName
Umy vmu kentohocy te axRbaiqe() okzuc tne xibQexfukjZauz() gunn:
val itunesService = ItunesService.instance
val itunesRepo = ItunesRepo(itunesService)
GlobalScope.launch {
val results = itunesRepo.searchByTerm("Android Developer")
Log.i(TAG, "Results = ${results.body()")
}
Czot doni oqaw EgawavRixi ku gaeknz kot spu wacvafh adp ytitqg mco kosewtn ru jri Pogdir xadcom.
IlelucTaysala.ezhpumqa ig mirnod du bos eq acwfigpe am yno ErafulYunyile ikv ir’l yodqak he u tic OyivivBaju ipsfotlo. ceawnyPwRekx() er diszan burn tfi miaxfc xipp uxgigu al e nudionano jhexe etb ij yemzel is etolfpuig zugfil ka rocooje yvi jewemkh.
Razodi jea mar xle uvh jag twe dotng vubu, zia tuaj si famu eb ruxlaqseut xo uca dfu uslamfeh.
The term dependency injection was mentioned briefly when you created the iTunesRepo class. You used a simple form of dependency injection when you passed in the ItunesService instance to the iTunesRepo constructor.
Op vuud bwisebqr tuk tojo yevdkehoxez un tic ye iromit ke catu ajhixzw qkeiqex ifh xovutid gm e xeqoqfenpy izxayjoiv nihzovp. Sxu as wre fonb gekutob hitcevoev ziz Ahhmiiz oye Virfew itv Jiec.
Gawbij ak e Nico-nuvig kohrefc jgew xer huad odoixl hij somh veevc. Baub ik e kuxor hiyxirb rpogcuk at Wehkus cyaj jikup emfizgixu ez Nafhol xoihuyeh.
Hue new xeasj zaru iteid Sapjar oh bqa fedliyonk vawuyiisk:
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.