Skip to content

Android + MVVM + Retrofit. Let's create a little application to understand how Android and Retrofit implemented in MVVM.

License

Notifications You must be signed in to change notification settings

iamsatishsharma/AndroidMVVM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AndroidMVVM

Follow and give a star ⭐

Connect with me on Linkedin as well to support this project.

Android + MVVM + Retrofit

MVVM: Model-View-ViewModel (MVVM) is a structural design pattern that separates objects into three distinct groups: Models hold application data.

Retrofit: Retrofit turns your HTTP API into a Java interface. A type-safe HTTP client for Android and Java. Introduction. Retrofit turns your HTTP API into a Java interface

Screenshot

The code would look like this:

// MARK: Card Item ViewModel

public class CardItemViewModel extends BaseObservable {

   private CardModel model;
   private Context context;

   public CardItemViewModel(Context context) {
       this.context = context;
   }

   public void setModel(CardModel model) {
       this.model = model;
   }

   public CardModel getModel() {
       return model;
   }

   @Bindable
   public String getName() {
       return getModel().getLogin();
   }

   public String getUserImage() {
       return getModel().getAvatar_url();
   }

   @BindingAdapter({"bind:imgUrl"})
   public static void setProfilePicture(ImageView imageView, String imgUrl) {
       Glide.with(imageView.getContext()).load(imgUrl).into(imageView);
   }
// MARK: Model CardModel

public class CardModel extends BaseModel implements Parcelable {

   private int id;
   private String  login;
   private String  avatar_url;
   
}

Thanks

Retrofit

License

AndroidMVVM is available under the MIT license. See the LICENSE file for more info.

About

Android + MVVM + Retrofit. Let's create a little application to understand how Android and Retrofit implemented in MVVM.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages