dawidhyzy
09/16/2018, 3:59 AMghedeon
09/16/2018, 11:43 AMMr Unlimited
09/18/2018, 11:09 AModay
10/13/2018, 12:12 PMubu
10/24/2018, 9:55 AMAAC MVVM
implementation. I have an activity with several view models
, and I need to connect these. Currently I use activity
as a kind of proxy between them. But that feels wrong. What would be the best way for one view model
to observe events from other view model
? Or is it completely wrong way of implementing MVVM architecture
?miha-x64
10/24/2018, 10:38 AModay
10/26/2018, 10:37 AMubu
11/04/2018, 11:31 AMFragment
(A) that subscribes a ViewModel
(V) in OnActivityCreated()
. When opening this Fragment
(A), I receive an update from LiveData
.
Then I open another Fragment
(B), then get back to the first one (A). It gets inflated, and onCreateView()
, onViewCreated()
and OnActivityCreated()
are called. We've just subscribed the ViewModel
(V), but it does not emit any item (the most recent update). I'd expect a LiveData
would behave like a BehaviorSubject
in RxJava2
(tell me if this comparison is appropriate), but there are no updates.
What could go wrong?
Any help would be appreciated.Zaidi
11/12/2018, 9:47 AMrezenebe
11/16/2018, 6:34 PMtenprint
11/28/2018, 11:02 PMbodo
12/13/2018, 10:29 AM@ContributesAndroidInjector(modules = [FooFragmentModule::class])
abstract fun bindFooFragment(): FooFragment -> FooFragment can not be accessed
Does someone have an solution for this issue?
Slack Conversationursus
12/18/2018, 3:48 AMrezenebe
12/18/2018, 3:43 PMgildor
12/28/2018, 2:39 AMghedeon
01/08/2019, 11:54 AModay
01/16/2019, 3:35 PModay
01/17/2019, 7:30 PMaksh1618
01/18/2019, 5:11 PMgetAll
as suspend
? As currently it isn't required due to Room (Using LiveData<List>), but may be required if/when some other source of data is added?
2. Should the code to fetch data from server and populate Room's db be written in the Repository?smilecs
01/19/2019, 10:23 AMSchadenfreude
01/22/2019, 5:59 PMursus
01/25/2019, 3:35 AMgumil
01/25/2019, 1:59 PMDavide Giuseppe Farella
02/05/2019, 8:57 PMAndroidComponent
that will be implemented by `Activity`es, `Fragment`s, `Worker`s/`Service`s
( and basically nothing else ) that provides a reference to Notifier
.
Notifier
jobs are 1 inform Timber
( that will eventually inform Crashlytics
) and 2 show a message to the user.
Actually the message to the user is delivered through an abstraction of Toast
injected in the constructor; but I would like to use a SnackBar
instead, if the app is in foreground: so I was thinking about a SnackBarManager
( fantasy name 😁 ) that will be implemented by the Activity
which will pass the set/remove the interface to Notifier
( onStart()' /' onStop()
) , so the Notifier could call snackBarManager?.let { it.showSomething() } ?: showToast()
What do you think about that? 🙂ursus
02/07/2019, 6:27 PMursus
02/10/2019, 1:58 AMghedeon
02/10/2019, 10:31 PMRouter/Navigator
pattern in your apps? If yes, do you inject it into the ViewModel or activity? I've been using it for a while, for the sake of SRP and stuff.. but honestly it's tightly coupled with activity/fragment anyways (context, animations, fragmentManager, etc) so I hardly see any benefit of another abstraction.oday
02/16/2019, 12:09 AMleaseCarsVM.getLeaseCarsResult().observe(this, getLeaseCarsObserver)
leaseCarsVM.getLeaseCars(true)
swiperefreshLayout.setOnRefreshListener {
leaseCarsVM.getLeaseCarsResult().observe(this, getLeaseCarsObserver)
leaseCarsVM.getLeaseCars()
}
try moving it to say the beginning of the screen, all of them together hooked up to the various other observers, and then make the VM calls later, they don’t come back successfully, has to be before the call..ghedeon
02/18/2019, 10:07 PMclass StringResource private constructor(
val string: String?,
@StringRes val stringRes: Int?,
vararg val args: Any?
) {
constructor(@StringRes stringRes: Int, vararg args: Any? = emptyArray()) : this(null, stringRes, args)
constructor(string: String) : this(string, null, null)
fun resolve(context: Context): String =
if (stringRes != null) {
context.getString(stringRes, args)
} else requireNotNull(string)
}
=============
Usage:
ViewModel: StringResource(R.string.foo, arg1, arg2)
View: stringResource.resolve(context)
I'm wondering if other people do something similar and how their wrapper looks like.ursus
02/19/2019, 3:01 AM