android-mvvm

When submitting a new list to RecyclerView ListAdapter the diff check always returns true for areContentsTheSame()

ぃ、小莉子 提交于 2019-12-23 23:24:22
问题 I am using an MVVM architechture to build a simple ordering app. I am using a RecyclerView in my ProductsFragment to list all the products that can be ordered. I am also using LiveData in my ViewModel and observable in my Fragment to check for any changes to the List of products. In my list item I have 3 buttons: 1 button to add a product to the basket, another to increment the quantity that customer wants to add to the basket and a third to decrement the quantity the customer wants to add to

Error: Cannot find ActivitySplashBinding

耗尽温柔 提交于 2019-12-23 22:46:55
问题 I am trying to check that if user is logged on or not. If yes then show a specific view group otherwise show different view group. To check whether user is logged on or not I am fetching the user from shared preference (at the time of login user is saved in shared preference). Let me show my code. SplashViewModel public class SplashViewModel extends ViewModel { public final String TAG = "SplashViewModel"; private final String GREETING = "Hi "; public ObservableBoolean isLoggedIn = new

request in another request called several times with rxJava and retrofit

a 夏天 提交于 2019-12-23 05:15:28
问题 I'm using MVVM and rxJava and retrofit to send my request. I have a bottom navigation view which has 5 fragments and in one of them, I have to send a request and after it, the response is delivered, I have to send another request to my server. this is my ViewModel class : class MyViewModel: ViewModel() { val compositeDisposable = CompositeDisposable() val myFirstReqLiveData = MutableLiveData<myFirstReqModel>() val mySecondReqLiveData = MutableLiveData<mySecondReqModel>() fun getFirstReq(token

Android ViewModel recreated when its Host Activity was not in the top of Activity Stack and the device was rotated

匆匆过客 提交于 2019-12-21 12:54:39
问题 I am in the following scenario: I have an OnboardActivity which contains a ViewModel , I can rotate this OnboardActivity many times and the ViewModel persist across configuration changes without issues. However, if I launch another Activity(FirebaseAuthActivity) on top of this one ( OnboardActivity ) with startActivityForResult(...) , and then in FirebaseAuthActivity I rotate the device and press the back button. When the OnboardActivity is brought to the top of the stack it recreates the

Login Example using Retrofit, MVVM, LiveData in android

有些话、适合烂在心里 提交于 2019-12-14 03:12:22
问题 I checked this article but observe the response changes in MainActivity. Here is my code for LoginRepo public MutableLiveData<LoginResponseModel> checkLogin(LoginRequestModel loginRequestModel) { final MutableLiveData<LoginResponseModel> data = new MutableLiveData<>(); Map<String, String> params = new HashMap<>(); params.put("email", loginRequestModel.getEmail()); params.put("password", loginRequestModel.getPassword()); apiService.checkLogin(params) .enqueue(new Callback<LoginResponseModel>()

How to make this ViewModelFactory more flexible and accept different kinds of ViewModel classes?

心已入冬 提交于 2019-12-13 03:49:17
问题 I copied an example of MVVM with Android Architecture Components, Retrofit, Dagger, and data binding. I am using this code as a starting point to my app in order to start using better architectures in Android app development. However, take these codes: interface ViewModelInjector { /** * Injects required dependencies into the specified PostListViewModel. * @param postListViewModel PostListViewModel in which to inject the dependencies */ fun inject(postListViewModel: PostListViewModel)

Google SignInButton's onClick doesn't work using DataBinding

荒凉一梦 提交于 2019-12-11 18:56:37
问题 When I try to set the onClick method in my Google's SignInButton : android:onClick="@{() -> viewModel.onGoogleLoginClick()}" I always get this error: Found data binding errors. ****/ data binding error ****msg:Cannot find the proper callback class for android:onClick. Tried android.view.View but it has 0 abstract methods, should have 1 abstract methods. file:/Users/user/Android/project/app/src/main/res/layout/activity_login.xml loc:53:31 - 53:66 ****\ data binding error **** Here is my code:

Unable to display data from remote server using MVVM architecture in android

末鹿安然 提交于 2019-12-11 07:56:17
问题 I am not able to parse json data from remote server. I am using MVVM architecture and volley library to parse json data. I tried to debug and the message says "An attempt to invoke virtual method has been made on a null object reference". I thought that the problem is due to LiveData class, so i removed it. Then, also it's not working. Please, also tell how to use LiveData class. BikesRepository.java package com.example.osama.dashbike.Repository; import android.content.Context; import com

Android MVVM - How to make LiveData emits the data it has (forcing to trigger the observer)

喜夏-厌秋 提交于 2019-12-10 13:33:49
问题 I have this ViewModel that gets a list from the network and I populate a RecyclerView with the data ( MyAvailabilityRepository returns a MutableLiveData , that's why i'm using Transformations.switchMap ): class MyAvailabilityViewModel : ViewModel() { private val getListsParams = MutableLiveData<String>() private val getListsObservable = Transformations.switchMap(getListsParams) { organizationId -> MyAvailabilityRepository.getSectionedLists(organizationId) } fun getListsObservable() : LiveData

Best practices and patterns in ViewModel + Data Binding. Is ObservableField in ViewModel OK?

允我心安 提交于 2019-12-06 05:19:12
问题 Looking through the samples I seen 2 approaches to MVVM using Android Architecture Components. First approach: ViewModel provides LiveData Activity subscribes to LiveData When observer called Activity is setting data to ViewModel ObservableField . Whole ViewModel is passed to binding. In xml you just set ObservableField as value <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" app:visibleGone="@{viewmodel.listLoading}"/>