Category : mvvm

I am trying to fetch a JSON Object from API using Retrofit2 and RxJava by this way: interface ApiService { @GET("search") fun getTestProducts(@Query("term") term : String , @Query("sort") sort : String) : Single<LatestProducts> } fun createApiServiceInstance(): ApiService { val retrofit = Retrofit.Builder() .baseUrl("https://2sanie.com/api/") .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build() return retrofit.create(ApiService::class.java) } And in Repository: interface TestProductRepository { ..

Read more

I have an application architectured by: View -> ViewModel -> Repository -> Datasource My DataSource is consuming a webservice and then receiving Soap object, which I want to transform to a custom Pojo object. So, by using RxJava I am calling the datasource method by following this flow: ViewModel repository.webserviceCall(data)… .subscribe(); Repository public Single<SoapObject> webserviceCall(String ..

Read more

I have a recyclerView and every elements from it has a ratingBar. I try to take the rating the user will give for every elements. I am using MVVM architecture. This is my code now: <RatingBar android:id="@+id/rating" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numStars="5" android:stepSize="1" android:onClick="@{(view) -> listener.rateMovie(view, model)}" app:layout_constraintTop_toBottomOf="@id/movie_poster" app:layout_constraintEnd_toEndOf="@id/movie_poster" app:layout_constraintStart_toStartOf="@id/movie_poster" /> override fun rateMovie( ratingBar: View, pickedMovieItemViewModel: ..

Read more

I’m currently building android note taking application which uses MVVM pattern and Room for storing data. Besides that I’m using dagger hilt, navigation component and lifecycle aware components. Problem that I face is saving data when user exits the app or he navigates back from note fragment. I want to achieve something similar to google ..

Read more

I have created a extension function as below: fun <A : Activity> Activity.startNewActivity(activity: Class<A>) { Intent(this, activity).also { it.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(it) } } I want to call this from my ViewModel class but since ViewModel is not an activity is there any way to achieve this? In my ViewModel class I want ..

Read more