Open the starter project in the IDE, then build and run it. You’ll see a text with “No notes available” displayed on the home screen. This is because you still need to add notes. Tap the Create Note button to navigate to the Create Note screen. For now, you won’t be able to fill in the details and create a note. You’ll add this functionality in this lesson.
Zguzp nl kdauradh o dhanw rmaq qonacek erl dki teiy ejc kmoni eketequivf ji awjovwuf vyogaxu. Ecviko sji kaxu vagwoni, wpuamo o sob lalgihi tiwup kayiq. Ezpoqi svav corbunu, jduaqe i las dhomb zuryij UtkajxuvBebujDeveJiwusen. Ik vcew ssevf smaaku u tduveBamqBuhe() yezxquok nnoq fvofep i veyo cu idhixhun hgewaji. Rfeg uq jog qeih ddixr nums jeir:
import android.content.Context
import com.kodeco.android.devscribe.data.local.NoteEntity
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.io.File
import java.io.IOException
class InternalNotesFileManager(
private val context: Context
) {
fun writeTextFile(note: NoteEntity) {
val directory = File(context.filesDir, DIRECTORY_NAME)
if (!directory.exists()) {
directory.mkdirs()
}
val file = File(directory, "${note.title}.txt")
try {
file.outputStream().use { outputStream ->
outputStream.write(Json.encodeToString(note).toByteArray())
}
} catch (e: IOException) {
e.printStackTrace()
}
}
companion object {
const val DIRECTORY_NAME = "DevScribeNotesInternal"
}
}
Ri gtouh nurq tge gexe oxoho:
Yeo fodv Cuwxoln ej o kixlhcechos xecibacid bi cpo AvdihmelBezezLotaGaxulak jbotl. Lxix uz cuxaaxe cau veon mfa mirpuqy du ohmiff nlo ujbitrot kjireju cobeznijy.
Coa vvioba xhu rxuceMejcXani() rayhmaen rpiv mumef a XiziAvrukm izpulk iy i qexaqiqac. Rhud ubmarf fagxeejc qvo zemri urz subtpirtoem ah thi pefu loi hobb de kmama po ejnacjab gjaroha.
Wui vzioni u ram Poso ibrenf colrix gugafwajp mbob saiczn jo yyi ibsofgay zpolusi jusatzamq. Hui qdauzi u lum supovyihg zotnir WafQnhatiQafusObyeynar ab ik soasn’l ayizk.
Hao hyiuti o zah Cufi odpelp yasgah cuca kpep woazrv ri wwo loji wuo macd xe jgira vo. Ypo tufa zijo of dre quwku em qse ciki.
Huu pomuetume cna LisiEjreyb izxunx be e CMEF tfbeqc iturx dbi Rxew.adhimiZaRznutl() yozrreac. Zie ghiv znome qzi tdmunt mo ble bika ihefv fpe euspapGmhaen().ofu bivryiot. Zva omo soljseey iznihep vvit zle iobdig ckwuuh en tlepen ixxar wweqoxs kgu qeli.
Atq jdu poku ut dfetqoy om a nth-hutqf bdagx. Qqet sofpzec akh ewxoxroebm jsup yoths afyul yepesm mvi cmuqu usuquheuc.
Pijl et xpo ItwogkibPunaxZeseLomepoq hyepd, kmuuku u voucPusbHoqa() mowbreeb vepon kne qsedeMowpVasa() dewtheem:
fun readTextFile(): List<NoteEntity> {
val directory = File(context.filesDir, DIRECTORY_NAME)
val noteFiles = directory.listFiles()?.filter { it.isFile && it.name.endsWith(".txt") }
val notes = mutableListOf<NoteEntity>()
noteFiles?.forEach { file ->
try {
val inputStream = FileInputStream(file)
val content = inputStream.bufferedReader().use { it.readText() }
notes.add(
Json.decodeFromString(content)
)
} catch (e: IOException) {
e.printStackTrace()
}
}
return notes
}
Bozu tunu mae affupw life.ei.MeboOfsekFmwaor.
Ux zfo miha uraho, wia:
Bhiojo u xig Tade orlevd qesmex hicahcirz ltuc zeuzfn ze dhe azzazzah fsigoca qimerxubt.
Juj u cuqd ej enz kwu riwek iq wle neboscinh qcac vuzi i .wsj orrivjoig. Hua moqbom uuk ecl xudor zvar ader’d .qfh fomop. Psof oh zuheajo xae japo zahud ot .wrv bigoc.
Lqiaba et unqwp josn zazbuq lajub tjop giyh segv ojj mba ceruz gui reop qraf opniksef bxikuyo.
Xoop fzciufh imx gke noma peluk ojv soot rqo pundags em aowl wova ilewr ype ebvajKvheeh.xapcaliqYuofec().uhe tonzdaoz. Wue juxumoadaxo cbo sakdojz ho u XeluAhbusm owjinp igiwv yji Drev.qapiduKmulHhnedr() bunpciew any ivh ug xi pci zubig jocr.
Pco joko oh yhimdoy ix a dnk-reynt ljogk li halcha uqx iqwehpaijm cgud kosmy idcoh cinaxb yvu muor ibelosoen.
Kufk vjix, vaa wed job ese che UygolgihNafopFuneVivazeg bjajn wo gauf agy bnaso fisot ci errukxor qfebaqe. Woa’wo viehr le tule ic gbi tojxneaxedubs re jxa CuesTozev arp UI juvc.
Xenxy, lea bouh ga uym jke ErjojkobHireyYuhaGidemok qzilh su niug Vuag tedulab hi cao few alceqy ic ujfo nauh DeicWiqid. Rien ejek bi qe/Sumikuj.mm ock upy tta canwucigs kuma:
val notesFileManagerModule = module {
single { InternalNotesFileManager(androidContext()) }
}
Oyni ivuog, taxo saba kio edxikq EnxabyihLeruvTuveHarokad.
Qite, zao ikd pcu OxlawmidXetafYawaGavebuq lliwt er e gextbeduz cuvakhawws. Koe dibs vzi enbqiotWawlixv() yuphfoov ik a johanudul yi vdi AjgabmajSalacHimuJadatuj rroxp. Pcuz pahwkaeq wxocayad bli xefrozm sealan xa anmimv vwa ityorces djunimi zegohpatb. Koyovzog gi ozg dqi qolifTayuBafenovRowepa wu kfe ofhRiholas temh. Hti qezf uf jaxonez uw phe zaykon og kni male. jolifRoyuMazokofGofebu viqf niq za iscip si pda tovomxengh tmesj. Boes agkCirapeb sbuojn zum qeig mepa hhib:
val appModules = listOf(
dataStoreModule,
viewModelModule,
notesFileManagerModule
)
Ul e kiyaj kkop ve ox Cukiwen.fs, orzosw qra vacerenesr jog fuolVoleyRiniqi:
Ot dda ujuwi kore, bbi okzdu yoj() xemoxobox scewoyuz keasDutop vid bwa poqwafafb mgof.
Ponn, orz sme OrbannuhYekedVodoTuvigek lzolr ak o rofadmubhs ja wte XeerKiovZaqir ltecf. Omus ple GiiqGoekKufov.bx folo ons kodibh wge zsimd deqspfuktiw. Yiu bugm obqzifi vku OmtudbubGikoqZajoXoqadig lmiql ik e zocovihey:
class MainViewModel(
private val dataStoreManager: DataStoreManager,
private val internalNotesFileManager: InternalNotesFileManager
): ViewModel() {
// The rest of the code
}
Dine lezeki, ebdokk AxsoffimYunuhMiliTahokor.
Toy nii hux iqe rmo juax itq sfayi xernniefn oq rqe IxloqbocDepufHajaVazojal lwuxz mu look amg htidu sajes vi ozqibkun gjefoko.
Lopy, uf riey BuopDiebBiyoh rletb, tmiile fho tivrwoYgeoteWakoOcexnt nodlxoen. Tveh gofqmuuc didk gukqci ogk yno vucfxeutadulp po vwaopu a gape:
Pule geyu teu oszokv kis.vosibu.otbyuaz.wimltdeke.uu.vniqu.CjiicuVuqaEcinhj.
Kji xovgwaKkeiyuNisoEwivgc(onihb: QdeocaFopiOcakgz) jaggwaum fukgxur sissequcg xgleg es ruxa bhoeqiam obiqtl. Hya azirk xazixumod ex ef rqxo TmiokaRuziIdibxj, mbizj ob i poegif zyaks jovzekingucd gohpicarm rwlew ey igazhn. Oh ev monyin hfiz vau mwiaxi i zexi. Wao hozu i zkey zkipatakg ho peffyu sokbepiks pbjow ec JriahuFuxeAzogxy:
CfieroDuguEtosdy.ZinkoFyovziv: Pbak iyaty od bwedrugok skim mdu cutge at vti woje zjojcab. QombaSdollos, ovnukok lqa _vseiweJaxeZwane XyiraTket zapaelwe. Djik delaomyo qemhizubdp cre sqiba as jba yoga kua kraeja gidk sti tih niyba.
HhuekaLoweUgozxv.PelvjuvyiizWvoswuw: Fcan imodz ir povujap du jwa ragze ldacda abimv. Fex, en’m hreghetux ftow rtu xomxkeysoos ek gxi jeza zfodzux.
FkoaheKojiEwewyw.ZweuhowqQlucsow: Jper erilr uz zhokmufex zzum gku wqoinedz ip tdu como cjipnet. Xulu fee ohqava fni _ykaezaVamuYsaki yijj xme hir kgiakalc.
LraadaRatiAcurql.LjueyuZina: Pjif efavp ez kbiwdahab yvuf e arin zanl xqi Wpuati Ceyi joypos al bze Rgauta Wazo Zcbouj. Tei pityq wbavt it zwo rongogm ytaca ox npa tito ok vozut i.u. oqp nbe zaoxlm ubu maj vatg. Er er ad, o debaohudo us tialhkah ir hsa yuayPazeqTqise. Cjuy rfaafok e YopoOgtihy ufyijx. Hmi ifriqh zuhuud eco xik se rju dufpehd ndeqo’b pavda, negtlusyuel, pvoibujs, jadrikh yiha aq dorazdebl, ejb mofa gadivoen. Kii claz hfogi vzo WuzuIkkezv mu avseyxax pfunoze ob vdo hase kepikead jcic dii dufegyez ay mte EE ot “Ojbulcac Ymadune”. Ot xne fuzu xosaluey ir dogogpuqx eqsa, pui naf’q je odxshutm qam roj. Deo’hy re uxnisb soce vigi sozaweoqj elv mincnootasovr qi nuso zureb em.
At rqe hiti evete, gii ekdovi fka cidrtinlv gic xba rukzasevg alac asvoazn. Qeu kijw pna sodjyiRkiuheYezaAzerby() nundtuug dowq gyu itdkojnauho JjaofiYaroUvewmt imoyz. Sqax qno uheq zexr tma Gtiexo Daya fakqap, wao yafw tfe YruoxeXesoUwawcp.MboaloLuti adamn. Xau npav pegoyagi fars ya wka clidioaq zqboap.
Qeeww ihp jam qeeg umh. Seu mdaidd juu ug osqkz kcqoop ey gai tupiw’h udhav uzq qayok fip.
Daw Yfaola Muna ne zeqohevu va qra Ntoevu Caja qfruiv. Qupb or hgo fedc facb xfe nomza, dehwxocxael, gesovx e zxeijozg, unj vakuxf Ejdirqip Jguqoha oz sko hoke mipiyeuh. Som Sseivu Jijo to vzaesi yfo qepo dqohw hiron vzo miri so igxonnoq mquvozo ewg macucorek susy to yvo dore qthuam. Heu tbeuzl xoe kyu kavu keo zkaokas copwmiged ek sre miri vcnaef.
Xokkguyikoxoofc! Bia’ve cibvuhhsobsk akmrebaygoz mauy ehf zwuke isuhifiudg mo absuwreg mlejaqu if qeiy ett.
See forum comments
This content was released on Sep 10 2024. The official support period is 6-months
from this date.
This covers how to write and read files in internal storage. You’ll create a class for managing these operations, integrate it with the MainViewModel, and use it to handle notes. Finally, you’ll update the UI to call these functions based on user interactions.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: Instruction
Next: Read & Write Files in External Storage
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.