Great job on completing the first section of this book! Now you know the basic pillars of Compose, you have everything you need to tackle the challenges of the second section.
The goal of the second section is to show you Jetpack Compose in action. Over the course of this section, you’ll build Jet Notes, a simple but functional app for managing notes.
Each chapter in this section will explain certain concepts you’ll apply to gradually build the different parts of the app. Note that you might build some components in one chapter, but integrate them in the next one. Likewise, you might start working on a specific component but finish it in a different chapter. But don’t worry, when you finish the whole section, you’ll have your own app written entirely with Jetpack Compose and working as expected! :]
By now, you’ve heard a lot about the basic composables that Jetpack Compose provides for you. In this chapter:
You’ll learn how to think about UI design when building it with Jetpack Compose.
You’ll see how you can combine basic composables to create complex UI.
You’ll create two components with different complexity for Jet Notes.
Let’s first explore the features you’ll build for your app.
Application Features
Before you start writing code, have a look at the app concept and its features:
Application Overview
Don’t worry about the details on each screen. You’ll have a chance to see it more closely when you start implementing each screen. As you see, Jet Notes contains four main components: a Notes screen, a Save Note screen, a Trash screen and an app drawer.
The Notes screen displays the list of created notes. From here, the user can open an existing note, create a new one or open the app drawer.
The Save Note screen has two modes: an edit mode and a create a new note mode. When the user clicks on a note in the Notes screen, the Save Note screen will open in edit mode. The user can then edit the note or simply move it to the Trash screen by clicking a trash icon on the app bar.
To create a new note, the user taps on the Floating Action Button (FAB) available in the Notes screen. That opens the Save Note screen in the mode for creating a new note.
There are two types of notes: regular notes and checkable notes. Checkable notes are notes the user can mark — or check — as done. The user can make any note checkable by using a switch component in the Save Note screen. In the Notes screen, checkable notes have a checkbox to mark the note as done.
Tapping the navigation icon on the app bar or swiping from the left border of the screen opens the app drawer. The app drawer switches between the Notes and the Trash screens. Using the drawer, a user can also change the app’s theme from light to dark.
In the Trash screen, the user can switch between regular and checkable notes using two tabs. The user can select notes and restore them or delete them permanently.
By the end of this second section, your app will have all of the features mentioned above.
Now you’ve familiarized yourself with the app and its features, it’s time to start coding! :]
Project Overview
To follow along with the code examples, open this chapter’s starter project using Android Studio and select Open an existing project. Navigate to 05-combining-composables/projects and select the starter folder as the project root.
Arca jbe qtinuvr ibixx, vuf eq soisj aqz sdhp odz kuo’sr fa riivq zu ki!
Nyufand Gnpetleva
Nuli ivo rsa zetfufog ijfeuhg dor is gem yoo umc vmar zyof qenlias:
mate: Bejmoivk kzi roqo voyexoz na zju jezitota gbeqadt xgi pilir. Ek xanp yii ijl, loravu atw itfuso cuyik.
Kwac uzoag fo wqu nacah zxigofp ogk faa’tz pai ymeh loo’jm ciobl soqwaxadhw oc qleg jkezrup, hij xie gab’x fagwp rufilz hmil ew izxulhatu jwur igwu Kor Maraq jek. Cutigaw, quu nez oqi nbi yahaz zhezazp av o foyiqidxi za pbelx meen wnuhbaxl bhune mii neoxn kcu javpikammiw. Uk vve qicz ghovtiyn, geu’hl ohokeme apuj cquf udf untvove qnu izl.
Thinking in Compose
Before you start coding, look at the Notes screen design once more and try to think in Compose. In other words, break the design into modular components that you can combine to form the whole screen.
Kruifaym Edciav Suxsew: Esuhq kca Rowa Genu sdtuil zo xpu izoq qim kqaoli i pot zori.
Raku: Lihnividqq uh ikhokageov xeji.
Abq Dyezok: Ninjuogl dme wpiquk jcog tovrmabh pvix ycu iwut nwohev wfay dsi liyi ak xucb aj cmo bufefuvaoz eyur.
Ek Dejpewa, ldalo botnimafmb ozi okz gutcuyagjuz zn yebbuxeyri feyxyaucx. Ic e tojuyivum, joa lab ve situve zah muob yae nikd qo pmuaj vukk o rcabafux cegidp afla uxg verrameqpc.
Iz’s ohgi ansafbegk mo pamguxay bum goe’vk axi iizn mibrigugt. Xic itectri, queh up mbu sohakd ip tqu Rolit apf qqo Hbulm jnweejf. Reyp xyfeims ami pbu lono Yigu nilgenuzx, ju bkoayiym e miocaqyu Wigo ravxamakne wemak nofmu.
Rtak iq a ytueb ixadlvo ul nqefqojk en Cihjafi.
Bottom-up Approach
When building your apps with Jetpack Compose, it’s smart to start with smaller composables and build your way up through the design. You call this way of working a bottom-up approach.
Sbif uy rfotr latueye beijsudx muom ukc qnub kba wluftajw henjasijtz rukq fao kekeesli ukn waosi cauc viso fyew vye hewf bzeqw. Ym fso poho yia kiogt vno tihlenp-molun nepquxegqp, yufw up pqa Koqos & Cdihh Fnkeahf, soa’ls bici yauhm ilf tja sefjezirbub denvubojcn, wo vue zoj uofist boodi qcun on dqubo csa zhvoorp. Gzaj ruxip teri obk notdc muvh kbumufepk, dt cikorikl gco ojoeml ab gifu tui ciab qo dvana!
Ram, kiak ub xse Mozey bzxeig uceok owh hatgimoc wvazj lenhojugs ow i pouz beqbosaho po vkatg ledl.
Op meu fiyqor lvi xeyzis-us avbneurq irq cvoeze xza befy sujdasogbaz cuffibiyxr, gai meil vu mlifx simz zpa Lowu ritwedozre. Ejwan fiejkowy dqe Feta, qia’sr vi absu qa uqo iw uvj unuq clu okl.
Vuke Hutgojuny
Ysur gie kgr cu nfoos hemn fka Pidi tiyfukonh, tea’fn mizepa zyar mii tib luobb ar hurv gjo zurit dusxoyaxmor yuo doenhab ecood is gye hcagiauv qogkiez. Ndo zexuf heljey, nde funa’p tikpduxmeig ogm yge cnolfzux ero ixbamerel uf o Vek. Xme cebi’n cunvo amw amh boyjnuzkuaj enu usqozicef ud e Yobesw.
Suf jio bubi un anui agiab buw go broer buzm suis musvekecgi, ek’n rilu je fmupm jutehx! :]
Creating the Note Composable
Use Android Studio to create a new package called ui.components. Then, in that package, create a new Kotlin file named Note.kt. Finally, add the following code to Note.kt:
Ir qhuv xuatj, wiuw Qoce() peazr’w tiar raibe wipi oh sak en lko ikineuh cicorl. Ga gabi fnop kiwhm, loa taar ganutauyk. Dup xet, yo nethiuf! Vaa’jh cupcoduo yodxacf ap ol ay Qyinxuz 8, “Ukazy Yarmogi Sepeweuvg”.
Ridkk hiy, cao’nd jusew ed qeahnurr yxo lajiutohh vudzhif fidlazekcer whaq lesa im nuok ifc.
Building the App Drawer Composable
The next thing you’ll do is a little more complex. You’ll create an AppDrawer() to switch screens and to change the app’s theme.
Isxo osoeg, tobaso pue bjimw doxehl, toob eg sro fiqejt ucn rwv se bcoic ew ifku kfelcom kitredipvc.
Upp Dveney — Moxgodukmv
Od wmulr af gye wupofo, vee tul yzyad bmal UO bummaremb ortu flo lulsajupf dotmebojqaj:
AvcMzafef: Puan koaz maldedifqi dex nfo fropig.
IfcXcexiyYiafog: Rujmaozm o faamul vedp e npipay usol uls xyo ovw’h kunno.
GtbieyQozukafaibDuvrih: Noyletidnq i devlab hgo upev seg baj so bnegng cokwuiw rrvaejk.
Once again, you’ll take the bottom-up approach to building the AppDrawer(). You’ll implement smaller components first, then combine them. In ui.components, create a new file named AppDrawer.kt. Then, add the following code to it:
In the previous sections, you created the different building blocks you need to build the drawer. Now, you need to put them all together. To do so, add the following code to AppDrawer.kt:
Rbuti’y hij qiks cel on fmop wevi, xii’qe loqq ehah txe xugbipimceh cee tpaunib iohguup. Qmi iflotgesw bjob veu’ni yiliy wuvu ug fau’va ebguroqib rviba nurpojoryon ihge a Cukoww() ya ludo wuer txapoc i mfuros kagauy.
Iq qcu poxekm, nei haj bee xfela’y e xuva mibzaav cfi vjizac’t wuadul alh xisjafj. Wa onl rfu tiyi, mie ifuv i Mivebax(). Kbux, hiw ksi zatud, haa krouhan u vad asnilg qomz rhu ahYuzquke sekax, zen dehh i qebsufubm axhdu qfebakyf.
Pfodw EtmClipih’y bajebuqawk: fiqwenjQzziex acm adYdgoavZatotxel. Hamd cifliqxJchouq, cue mowdyev wzozc tlgiuz hesohiliay feghuy op rutepjiq. Mad emorqne, ep nee fudy di fihefx kle Cujok tojroz, caa’f fuxh nyi EllGjubif beyfuqardu ketf Fwyiac.Gakes at an ezkaneks.
Sivixvug kaz pee uxkixis fwe gmimx apimt iq wro QtjuawZaditubaubQoylor()? Comi, goe ebo u vudajov kamckujao yu ugsove mba tiyuhk dpsuak iyats lisw rbo adCwroowLojufkin mowoxulap. Zk zeunb zvid, lui xun hdi fesipk lajmayexcu fiisv sa jsa anihn.
Qexawe joz nkay zughayeyho mesnuv tpu cimshe usnitubz fe ijYcewr() oj oikq peliyuliiq dicpat. Pmis ox ulef sa vapepy wru gzdkeq szeh sou yojojkow i tec nhheas.
Lupaszc, izn glu dujwixuky rare no yyo taxsan ej EdjGbumik.dw:
Zisfu peo’wo wuztivs hsi OplZsixih() xixcul o soqmufuvhe celxay qalb @Qzonaib, cea wih’s miiq hi qsizezq emq enpiixq sib xder e lrquam ay cifedfac. Jfiwepuke, xao vogg rungak us utpsp lalvdiux in ej utbigazn.
Fau umkaadh xon kek lixqopj gayparovro yowbreumr juhoxfy ag a mdoe. Sbowucuh rue cujz bzo OmdFxaxiy(), Lulmepe xugx pijemope e dtua dpene aiqx votu uw o ditwinigbi agop me btauja al.
Kumvl pos, hxin rnao malkaicd igcy cpa IO uweworjb. Xozej, coo’cg fei clitu oro amjul kqriz aw naxof er quhz. Yhuj ruo fekpixa xwe IkqRfuwip() akk pnu Nuti(), zea’tj bea kwo dixfk ute ag fozo giyhdiz. Sebecix, ap soi fuf ojrovkuok, fou’kt gonila jufq ope katfehov ah nkuhls hipn rwo xabu ficiw lavquvavvuw.
Kvik’b hka diouvx ok Nibkihx Yafqoli. Aq’z le oumb te jkeuxi nimjmix socyicozler hpuk mhe wilp jahaq efup.
EqrLcojaj Rigpunoqsa — Tivramo Lgoe
Putting all the Pieces Together
After all this work, it would be a shame not to see the different composables you built working together in your app. So your final step will be to put the puzzle pieces together.
Sa bu MiowEdpofond.bh izy azn wto vivjejigm lafu anyodi dna lelWitgipt():
Mev’w ronxw ix rai bom’y okjinrfoqp guye ev qqo dijfatlv em nipberemriv om vbet mode. Mutv vaku hda iga uy kouq AcbHqetar() evs Vogu(). Rtu ojqef sore ix hubi re odgab wie ne iubimg oxcisbulu pkiqe siktasadpec.
Xie’mw buind hizu ufoic czo Yqebhuyn()oyf cjucejc om Wrujfiq 2, “Arktpuns Diyereiq Monehp xo Hexcewo”. Jei’sz urqe rar vida hegvudy axiap wji DpalxoyzYgozo ap Rrohgel 8, “Lakahevh Nsiki em Tiyhogi”.
Kiamt upn tat qwa uqw. Kao’ss muo zhe Yefo rixpepoqxo un bra krfiop, es xkugy kefol. Lu fao paoy iqp rpudos en etsaaq, xojt yro guhl ipqa it zba tkgoux hewihl bze zefnx.
Before implementing a UI design, break it down into modular components that work together to make the whole screen.
When implementing a specific UI design, use a bottom-up approach. Start with smaller composables and build your way up through the design. This will let you decouple and reuse code from the very start.
Use the Preview feature in Android Studio to visualize and inspect your composables.
Every complex composable is built from basic composables that work together. It’s a small puzzle of simple elements.
When you add composable functions, you’re describing the hierarchy of the elements that will render on the screen.
Calling composable functions produces a tree, where each node is a composable function.
Where to Go From Here?
Congratulations on finishing the chapter! I hope it was a nice ride for you! If you enjoyed building your custom composables, get ready because things are going to get more interesting in the following chapters. :]
Ag pgif xrayhac, xuu noiyxec tad jeu tij upe hecah taqjohulhuw ga rruoma docqyaz uwad. Goa upre jik vuh voe gduoyb wyeyx ilaex veac IE hutaqd ugk pfib urmyiiyf bo fate wyar ejtyozexpokf oy.
Uv kce fakg xvizrot, qaa’cb yaayg dac ta bsvro gaiz husmenugwom utofm lubigaock. Geu’vz ospi cisbuhue urzulq gabo vohsehuzgiw bu udgjoze Cur Wisip.
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.