|
Shadow0 posted:Does anyone know how to use Android's Room (API?)? What are you trying to acheive by doing those things?
|
# ¿ Jul 4, 2019 18:39 |
|
|
# ¿ May 10, 2024 08:18 |
|
Shadow0 posted:I'm keeping track of my expenses with my app, and I want to be able to copy the database as a backup. But I also want the option to import a database for the opposite reason. Being able to do it for a particular month or other grouping would also be nice. I was wondering if you could do what you wanted with some meta-data fields, like adding a import_id field to each table, and another table to keep track of which import is current, etc. This you could do in Room, but I can see it getting really annoying if your table schema is anything beyond basic, and it will add overheard to future changes. To do what you originally asked though, I think you're going to want to use, https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase
|
# ¿ Jul 7, 2019 07:00 |
|
Sistergodiva posted:...a problem... baka kaba posted:...a possible solution... Did you try this? Did it work?
|
# ¿ Aug 10, 2019 16:51 |
|
It could be a bunch of things. Have you got a git repo to look at? As a general point Ive been loving Compose after years of recyclerview bullshit. I appreciate it’s probably not practical to switch for whatever you’re working on now, but seriously consider it for future stuff.
|
# ¿ Feb 17, 2022 11:29 |
|
Anne Bonny posted:https://github.com/kraftski/RecyclerViewError Got it to work by replacing the right hand RelativeLayout with a ConstraintLayout, like this: code:
ConstraintLayouts are generally better then RelativeLayouts though, they are more powerful and you don't need to nest views so much, which is bad for performance.
|
# ¿ Feb 21, 2022 22:19 |
|
Java and RecyclerView are old hat in the Android world now. I don't know what time/cost constraints you are operating under, but long term, adopting kotlin and compose will make your Android dev experience a lot more enjoyable.
|
# ¿ Feb 26, 2022 15:11 |
|
Yeah you can, it’s kotlin, functions don’t need to be a class
|
# ¿ Jul 20, 2022 21:28 |
|
“be in a class”* even, but yeah, kotlin is great and apart from a few minor things, compose is great, and infinitely better than recyclerviews
|
# ¿ Jul 21, 2022 06:14 |
|
You want to hold state in a viewmodel. This is an Android architecture component that is designed to persist as activities move through their lifecycle. View models typically expose their state using some implementation of the observable pattern, historically this has been livedata, but more recently StateFlow. This allows activities/fragments to observe and react to state when they are ready to do so. There should be plenty of good guides out there for getting setup with a viewmodel
|
# ¿ Jul 28, 2022 17:09 |
|
I think you want your viewmodel to expose your UI state in a StateFlow, which is collected in your activity when its in the appropriate lifecycle state. See: https://developer.android.com/kotlin/flow/stateflow-and-sharedflow#stateflow I think the State class you are using in the viewmodel only causes recomposition within the context of a composable function. More generally you shouldn't need to inject your repo into the activity and pass it to the composables. Giving the Activity the Repo you're letting it know to much, the Activity should just be like: "here is some ui state from the viewmodel that I will observe. when a button is clicked i will tell the viewmodel it happened". Then it's the viewmodels job to decide how that button click should result in a change of state. Also not sure why you are wrapping ToDoItem in a MutableState
|
# ¿ Aug 3, 2022 21:16 |
|
LongSack posted:OK based on that page, I changed the state to a (Mutable)StateFlow. Making that change alone didn't change anything. Then I noticed the part about the change in the onCreate method, so I added that: try this: nm smiling giraffe fucked around with this message at 17:32 on Aug 4, 2022 |
# ¿ Aug 4, 2022 17:06 |
|
ok try this:Kotlin code:
|
# ¿ Aug 4, 2022 18:21 |
|
FAT32 SHAMER posted:Wouldn’t it be lifecycle aware by way of the viewmodel? All it needs to know is if it’s active or not, and it’ll flow as soon as everything comes back after an onResume or w/e Done like this, I the activity is going to keep collecting even when in the background. There are flow operators like "flowWithLifecycle" that automatically suspend collection of the flow when not in the correct lifecycle state, which makes the flow act in a simlar way to LiveData. If the activity is collecting the flow to update a view, then this would definately be bad, but if your calling composables I *think* its ok as these don't recompose in the background, but i could be wrong tbh
|
# ¿ Aug 4, 2022 19:53 |
|
LongSack posted:No change: whats your viewmodel look like now with the StateFlow
|
# ¿ Aug 4, 2022 19:58 |
|
Not sure, looks fine to me. Put it on github if you want I’ll have a look
|
# ¿ Aug 5, 2022 15:13 |
|
The issue is that you're doing IO operations in your repository on the main thread. If you change your repo functions that access the disk to suspend functions, and then your completeItem function in the viewmodel to this: Kotlin code:
|
# ¿ Aug 5, 2022 17:53 |
|
yeah you're right its not that. What I had done in addition to adding the coroutine stuff was perform a mapping operation on the result of `getItems()`, which returns a copy of the list, which i think was that actual fix. So changing "getItems()" function in your repo to this seems to work: override fun getItems(): List<ToDoItem> = items.toList() Adding toList() means it returns an immutable copy of the list. So my guess is that by passing around a reference to a mutable list in your StateFlow, the state of the list would change without the StateFlow recognising it. Then when you did post an update to the StateFlow, you're passing it a list which is the same as the existing list, so it doesn't emit a state change as StateFlows only emit if the new state is different to the existing state. Could be wrong, but its safe to say you want to minimise mutable state as much as possible and don't expose it. smiling giraffe fucked around with this message at 23:19 on Aug 5, 2022 |
# ¿ Aug 5, 2022 23:10 |
|
|
# ¿ May 10, 2024 08:18 |
|
Have you gone through it step by step in the debugger? That usually works for me
|
# ¿ Aug 22, 2022 21:57 |