What the next step architecture-wise when methods ...
# android-architecture
f
What the next step architecture-wise when methods in my repository become big and complex? Should I just keep it like this in the repository?
u
a function?
๐Ÿ˜‚ 1
๐Ÿ‘ 2
f
I was thinking about another layer
u
why, first functions, then composition
o
On a seperate note, I would advise Flow usage in Repositories, LiveData only for UI.
u
I'd advise to only use one async framework
โ˜๏ธ 4
๐Ÿ’ฏ 1
o
Well, also using Flow in UI and throwing LiveData completely away might be n even better option indeed, but a more radical change in a codebase
๐Ÿ‘ 1
f
yea I've heard that recommendation before but I've also heard other people say that this is a non-sensical guideline (to not put LiveData into repositories)
u
arent live data always main thread?; also, why would anyone use live data in a worlds where rxjava and flow exists, do you hate yourself or what lol, its the same thing just with a subset of features
f
I don't think Flow has the same lifecycle-awareness capabilities
u
Have a scope which is active between activity.onStart/onStop, same thing
โ˜๏ธ 4
๐Ÿ’ฏ 1
f
it would do the same thing with more code
o
Flow does have the same lifecycle awara ness when you either use flow.asLiveData() or lifecyclescope.launch {flow.collect()}
u
Live data its not less code, its just hidden. You can have scope created in some BaseActivity, then its same amount of lines (even if not, bringing in a framework to save 1 vs 3 lines..) + what he said, then built a lifecycleScope if youre into that
๐Ÿ‘ 1
f
alright, I'll try it out, thank you ๐Ÿ‘
n
I have faced this issue and opted to abstract away some of this with use cases, which I have injected into the viewmodels. I also opted to use flow instead, where I've guaranteed that coroutine contexts are all appropriate
f
@Nathan Retta Thank you very much!
Can I find an example of such usecases somewhere?
n

https://www.youtube.com/watch?v=xch4aw7hNcYโ–พ

I will share some of my code here as well for a basic use case
The use cases are meant to be light and easily consumed by the viewmodel. I have found that the abstraction layer is very useful when dealing with screens that have a lot going on, allowing the viewmodel to stay much lighter also. I tend to agree with the talk as presented, where the domain layer tells the story of how your app runs.
This app is a playground for ideas, any comments are welcome
๐Ÿ‘ 1
In this app, CityWeatherViewModel.kt has three use cases that you can use as an example
f
thank you very much!