Bryan L
06/17/2021, 2:50 PMDay 80
• Bug Fixes
◦ issue (solved) - When logging in, the current note was not being cached correctly.
▪︎ Added a LaunchedEffect here so whenever the user data changes, the current note also updates
val username by userVm.currentUsername.observeAsState()
LaunchedEffect(username) {
vm.checkForCurrentNote()
}
◦ issue (discovered) - App crashes when moving to the background (only when a user is logged in)
◦ issue (?) - If logged into another account immediately after signing out of previous, it will load 0-all notes from previous account. Coroutine issue here. Bryan L
06/17/2021, 5:07 PMcurNotesResponse?.body()?.let { notes ->
noteDao.deleteAllNotes()
insertNotes(notes.onEach { note -> note.isSynced = true } )
To:
curNotesResponse?.body()?.let { notes ->
withContext(Dispatchers.Default) {
noteDao.deleteAllNotes()
}
insertNotes(notes.onEach { note -> note.isSynced = true } )
}
Still had issues, after some trial and error I've left the change by adding LaunchedEffect in NoteListScreen. A big issue here is due to not using fragments/activites, so I'm trying to update the screen in the background while logging in/out inside of the drawerstate.
I have quite a few LaunchedEffects going on, I don't believe it's intended to be used this way and I'm completely abusing it. lol.. Code could use refactoring to work on Single Source of Truth..
Until I fix the coroutine to make sure the user data loads correctly before making this check, I set a delay
Added:
val user by userVm.currentUsername.observeAsState(userVm.currentUsername.value ?: "")
LaunchedEffect(user) {
delay(100)
if (user.isNullOrEmpty()) {
vm.clearLocalDatabase()
}
}
Bryan L
06/17/2021, 5:43 PM2021-06-17 13:09:30.488 3081-3081/com.lid.dailydoc E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lid.dailydoc, PID: 3081
java.lang.RuntimeException: Parcel: unable to marshal value Note(
date=18795, noteId=80a9499d-c1d8-4029-aedf-fac20c810c52, summary=some text5, content=111, survey1=, survey2=, survey3=, owner=test, users=[], isSynced=true)
at android.os.Parcel.writeValue(Parcel.java:1782)
at android.os.Parcel.writeList(Parcel.java:1045)
at android.os.Parcel.writeValue(Parcel.java:1729)
at androidx.compose.runtime.ParcelableSnapshotMutableState.writeToParcel(ParcelableSnapshotMutableState.kt:30)
....
Changed:
val currentNotes = rememberSaveable { mutableStateOf<List<Note>>(emptyList()) }
To:
val currentNotes = remember { mutableStateOf<List<Note>>(emptyList()) }