|
smiling giraffe posted:ok try this: No change: Kotlin code:
|
# ? Aug 4, 2022 18:41 |
|
|
# ? May 28, 2024 14:26 |
|
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 |
|
smiling giraffe posted: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. Oh derp, yeah if you don’t have composables in a fragment that makes more sense, ty
|
# ? Aug 4, 2022 20:22 |
|
smiling giraffe posted:whats your viewmodel look like now with the StateFlow MainViewModel: Kotlin code:
|
# ? Aug 5, 2022 13:57 |
|
Not sure, looks fine to me. Put it on github if you want I’ll have a look
|
# ? Aug 5, 2022 15:13 |
|
This isn't related to the bug, but you can remove that backing property for the state by changing toKotlin code:
|
# ? Aug 5, 2022 15:45 |
|
smiling giraffe posted:Not sure, looks fine to me. Put it on github if you want I’ll have a look https://github.com/vjkrammes/ToDoPlus Thanks!
|
# ? Aug 5, 2022 16:14 |
|
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 |
|
smiling giraffe posted:The issue is that you're doing IO operations in your repository on the main thread. Welp, I think I made the changes, but it's still not doing anything different. The real I/O is in the serializer classes (they are internal to the repository classes). I changed all the methods that actually do the I/O to suspend functions, (and of course made the necessary adjustments up the line). Then in the view models where I need to call the repository methods, I did as above. Nothing is different. It still doesn't update the screen until I scroll an item off an on again. I also started working on the assignees section, using similar code, and it updates just fine (you can only add assignees at the moment, but they do show up and are persisted to the file system). I updated the git repo to show the code in its current state. Also, as an aside, in the suspend functions in the serializers, the I/O calls (openXXX, read, write, readline, close, etc.) are all flagged as "inappropriate blocking method call" so that seems a bit off.
|
# ? Aug 5, 2022 20:43 |
|
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 |
|
Why is StateFlow still in the viewmodel? You don't seem to be using the actual flow parts of it. You're also still recreating state objects on every attempted recompose https://github.com/vjkrammes/ToDoPl...Activity.kt#L31, that's gonna cause problems like mentioned before.
|
# ? Aug 5, 2022 23:21 |
|
smiling giraffe posted:override fun getItems(): List<ToDoItem> = items.toList() That seems to have done the trick! Thank you for all your input. quote:Why is StateFlow still in the viewmodel? You don't seem to be using the actual flow parts of it. You're also still recreating state objects on every attempted recompose https://github.com/vjkrammes/ToDoPl...Activity.kt#L31, that's gonna cause problems like mentioned before. Those changes were made by suggestion. Now that toList() is in place, I was able to change the state back to MutableState and can pass the state objects directly from the view models to the composables: Kotlin code:
|
# ? Aug 6, 2022 13:40 |
|
Next batch of questions - 1. I'm using Android Studio (Chipmunk, 2021.2.1 Patch 1), and several times a day it will just stop responding to the keyboard and the mouse wheel. The mouse itself still works, so I can hit the menu and save all before I quit and restart. Not the worst thing in the world, but it does get annoying because it kills the emulator and the restart time is irritating. 2. I was loading up some of my view models in the init block, but since switching my I/O methods to suspense, I can't do that any more. I'm using a factory method and @Provides (similar to how I would handle it in C#), but I'm wondering if there's a better way: Kotlin code:
I tried changing the code from a simple navController.navigate("edit/${item.id}") to this: Kotlin code:
Ideas? I have updated the git repo
|
# ? Aug 9, 2022 20:10 |
|
OK, I figured out the navigation thing. My navigation menu is shown below. The saveState was set to true. This was (not surprisingly) causing the state to be retained between page visits. Setting it to false seems to have corrected the problem.Kotlin code:
|
# ? Aug 12, 2022 20:56 |
|
OK, I've made a ton of progress on my todo app. I showed it to a friend a week or so ago, and she said she'd love something where she could organize items by category. So for a shopping list, you could group meat, produce, etc. and have all the things you need in one area of the store all together. So I've rewritten the code to work as a collection of categorized lists, switched to SQLite (using room) instead of JSON, and now have a basic working version of the app. I have only one thing that's driving me crazy. I'm using Toast (I will be switching to Snackbar) popups for status reporting ("Item created successfully", "Changes saved successfully", etc.) and it's working on every single page except one. I've looked at the working / non-working code side by side in Android Studio, and I can't see any differences. I've checked that the same imports are being used. I've also run it on my Galaxy S22 in case it's an emulator issue, but the behavior is the same. I've set some breakpoints, and as best as I can tell, the message(s) are being emitted in the viewmodel, but are not being collected in the page. It doesn't matter whether I use Toast or a Snackbar, the message does not show up. If i put some code inline in the composable as a test, the message shows just fine. I've put the code into a new repository here, but here are the parts in question: ViewModel: Kotlin code:
Kotlin code:
Kotlin code:
|
# ? Aug 22, 2022 20:09 |
|
Have you gone through it step by step in the debugger? That usually works for me
|
# ? Aug 22, 2022 21:57 |
|
smiling giraffe posted:Have you gone through it step by step in the debugger? That usually works for me I have. It’s complicated by the use of coroutines, but setting breakpoints in the viewmodel’s sendToastMessage function shows everything as expected. But setting a breakpoint inside the collect never gets tripped. That’s why i think the root of the problem is that messages are being emitted but not collected, for whatever reason
|
# ? Aug 22, 2022 22:04 |
|
I fixed the toast problem by rewriting the view model. For some reason, it works using the new view model, even though as best as I can tell the code is identical. Code on the left works, code on the right doesn't:
|
# ? Aug 24, 2022 15:42 |
|
Next piece of weirdness. If I have a TextField and set the value to an item in the viewmodel state, then the soft keyboard disappears after every keystroke. The field doesn't lose focus, but the keyboard hides. For example: Kotlin code:
Kotlin code:
Ideas?
|
# ? Sep 1, 2022 15:04 |
|
Any recommendations on a cheap device for Android app testing? Cell service is not needed.
|
# ? Oct 4, 2022 21:27 |
|
Buy an old Pixel device.
|
# ? Oct 4, 2022 21:47 |
|
In Android 13, is it possible to make a pinned shortcut with the icon following the launcher's themed icon setting? Or even a way to query if the default launcher is using themed icons?
|
# ? Oct 29, 2022 23:31 |
|
Feel like i'm losing my mind, this coroutine runs but never recomposes after the state changeKotlin code:
|
# ? Nov 9, 2022 16:18 |
|
Another weird thing, I added this below that TextKotlin code:
|
# ? Nov 9, 2022 16:37 |
|
Put the text inside of the productState lambda?
|
# ? Nov 9, 2022 20:13 |
|
I have an app on Google Play, Word Topics: Unscramble Words. But if you search for Word Topics you won't see it: https://play.google.com/store/search?q=word%20topics&c=apps Ditto if you search for the entire name: https://play.google.com/store/search?q=https%3A%2F%2Fplay.google.com%2Fstore%2Fsearch%3Fq%3Dword%2520topics%26c%3Dapps&c=apps The actual app is here: https://play.google.com/store/apps/details?id=com.oldeskuul.wordtopics What in the name of all that is holy is going on here?
|
# ? Jan 30, 2023 06:27 |
Welcome to the wonderful world of the google play store lol. It's been like that for years
|
|
# ? Jan 30, 2023 07:10 |
|
PokeJoe posted:Welcome to the wonderful world of the google play store lol. It's been like that for years I never encountered it before. Been on Android since the start too. Don't they have people who know how to write a search engine :-) This reminds me of Google Plus. Company is so "Stove Pipped" that they launched Plus without social graph API's for mobile.
|
# ? Jan 30, 2023 07:25 |
|
VideoGameVet posted:I have an app on Google Play, Word Topics: Unscramble Words. You're not including "unscramble words" in your search. Sucks that it doesn't want to do a partial match.
|
# ? Jan 30, 2023 09:38 |
|
And, not sure if this is debugging left on, but please do not slide yourself into the clipboard unsolicited... "User7001 Used 0 Hints To Complete "Sample 001" In Word Topics" E: very cool, you also do not allow me to continue without copying this into the clipboard. Volmarias fucked around with this message at 09:44 on Jan 30, 2023 |
# ? Jan 30, 2023 09:40 |
|
... you also do not allow backing out of dialogs in general, it seems.
|
# ? Jan 30, 2023 09:46 |
|
Good catches. I may need to find a new team because they have been AWOL for over a week. I have source. This thing has been in development for too long.
|
# ? Jan 30, 2023 10:13 |
|
The "please wait" spinner isn't even centered when it rotates. The profile picture is squished. There's probably plenty of other stuff too. The game part of it is fine, the whole thing just has a half-finished look. If you paid someone to develop this in the hopes of making money, you might want to think about whether any future work is just throwing good money after bad.
|
# ? Jan 30, 2023 18:16 |
|
Volmarias posted:The "please wait" spinner isn't even centered when it rotates. The profile picture is squished. There's probably plenty of other stuff too. Well, we fixed the name thing. https://play.google.com/store/search?q=wordtopics&c=apps And yeah, I'm going to have to spend more to get all of this polished, I'm just trying to see if it's worth it. It is my design and this is the 3rd group of developers who have been on it.
|
# ? Jan 31, 2023 09:15 |
|
Anyone used mockk to mock extension functions on a singleton object before? I cant figure out any combination of mockkStatic or mockkObject that works. The specific thing I need to mock is google's firebase initialization, they've got it declared likeKotlin code:
I don't know why google made those extension functions in the same file instead of just being part of the object either, real pain in the rear end. FirebaseApp is in java instead of kotlin
|
# ? Feb 14, 2023 00:56 |
|
Forgot they have the source on github, this is the specific function I was trying to mock for tests https://github.com/firebase/firebas...Firebase.kt#L48
|
# ? Feb 14, 2023 01:02 |
|
I have never mocked context before because those are usually called from a view, service, or application subclass, and we only unit test those via UIAutomator. I’m not sure if you’re using DI in your app, but you may need to mock the repository that is the intermediate between your firebase api call and the view you’re unit testing, or build a dummy class with fake data in your setup function Tldr if you’re trying to mock a function that takes context as an arg, you’re probably doing something wrong
|
# ? Feb 14, 2023 04:17 |
|
I'm trying to mock the initialize function, not a context param
|
# ? Feb 14, 2023 04:30 |
|
|
# ? May 28, 2024 14:26 |
|
You’re going to need to mock context to call the initialiser extension, unless you linked the wrong one
|
# ? Feb 14, 2023 04:47 |