Skip to content

Instantly share code, notes, and snippets.

@nyxee
nyxee / providersForGenerics.kt
Last active Apr 7, 2021
Hilt and Generic classes in ViewModels
View providersForGenerics.kt
class ClubsViewModel<T> @ViewModelInject constructor(clazz: Class<T>) : BaseViewModel<T>(clazz) {
listenToFireStoreCollection("Clubs", _mClubs)
...
}
class BViewModel<T> @ViewModelInject constructor(clazz: Class<T>) : BaseViewModel<T>(clazz) {
private var _mBs = MutableLiveData<List<T>>()
listenToFireStoreCollection("Bname", _mBs)
...
@nyxee
nyxee / currentPosition.kt
Last active Apr 6, 2021
The Problem has been solved
View currentPosition.kt
//CURRENT POSITION
class ClubsViewModel<T> (clazz: Class<T>) : BaseViewModel<T>(clazz) { //<< THIS IS WHERE THE CURRENT PROBLEM WAS.
private var _mClubs = MutableLiveData<List<T>>()
listenToFireStoreCollection("Clubs", _mClubs)
...
}
class BViewModel<T> (clazz: Class<T>) : BaseViewModel<T>(clazz) { //<< THIS IS WHERE THE CURRENT PROBLEM WAS.
View initialProblem.kt
//INITIAL POSITION
class ClubsViewModel(): BaseViewModel() {
private var _mClubs = MutableLiveData<ArrayList<ClubFSEntity>>()
...
private fun listenToFireStoreClubs() {
mFirestore.collection("Clubs").addSnapshotListener { snapshot, e ->
// if there is an exception we want to skip.
if (e != null) {
return@addSnapshotListener