Closed neuberfran closed 2 years ago
Hi @neuberfran it could be the case that the version of the arch component may be old, so try out in this way Transformations.switchMap(_registerAttendee) rather than trying directly on mutablelivedata object or update to ktx version of livedata and viewmodel to leverage the ktx benefits.
def lifecycle_version = "2.2.0" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
Hi @raipankaj Tks. I solved with Transformations.map, But not solved with KTX solution:
I'm using map and not switchMap because I need to transform a list that comes from the firestore (image below) and use (for now) only the alarmstate field in my XML (DATABINDING): android: text = '@ {viewmodel.hotStockLiveData.alarmstate? "On off"}'
If you can help more, I’m happy.
I'm trying to change my ### repository (ProducRepository.kt and/or Repositor.kt files)
To consume it in the viewmodel (binding) and meet the requirements of the XML databinding that wants 1 boolean and not a <List
Firestore support, is very busy and hasn't answered me yet
The warning which you got with the ktx version is because of jvm-8, u should use java 8 version android { compileSdkVersion 29 buildToolsVersion "29.0.2" .... compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
In case you read the collection like "products" it will give you a list of documents whereas when you read the document directly by providing its id while doing a query from the client-side it will directly fetch the document snapshot instead of list of documents snapshot. If possible provide an id to your document inside products collection, if that is not possible then you have to fetch a list of documents and thereafter extract the document which you want. It all depends on your use case.
@raipankaj How can I do this without making any changes to my repository (ProducRepository.kt file) and solving the problem below:
https://github.com/neuberfran/FirestoreEverything02/blob/master/app/src/main/java/neuberfran/firestoreioteverything/viewmodel/EstadoViewModel.kt I will make changes only in the ViewModel(EstadoViewModel.kt). Which are?
@raipankaj ORIGINAL ViewModel class to be changed:
class ProductViewModel : ViewModel() {
private var product: MutableLiveData
val allProducts: MutableLiveData<List<Product>>
get() {
if (products == null) {
products = ProductRepository.getInstance().products
}
return products as MutableLiveData<List<Product>>
}
fun getProductById(productId: String): MutableLiveData<Product> {
if (product == null) {
product = ProductRepository.getInstance().getProductById(productId)
}
return product as MutableLiveData<Product>
}
fun clearProducts() {
products = null
}
}
@neuberfran get the individual record from the document using the following method Firestore.collection("products").document("xa.....").get().addOnCompleteListener()
In the case of current viewmodel then you should return the livedata from function
private var product: MutableLiveData
or switch to
private var _productLiveData = MutableLiveData
fun getProductById(productId: String) { _productLiveData.value = productId }
whenever you will call getProductById method the _productLiveData value will change that will call the Transformation.switchMap
Hi,
Please, help-me with issue in slideshare project: kotlin Any type only contains 3 methods: equals, toString and hashcode.
https://pt.slideshare.net/PankajRai3/android-architecture-components-with-cloud-firestore