├── app ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── layout │ │ │ ├── activity_main.xml │ │ │ ├── activity_holiday.xml │ │ │ ├── item_holiday_java.xml │ │ │ └── item_holiday_kotlin.xml │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ └── drawable │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── easymvvm │ │ │ ├── kotlin │ │ │ ├── HolidayModelKotlin.kt │ │ │ ├── HolidayViewModelKotlin.kt │ │ │ ├── HolidayAdapterKotlin.kt │ │ │ ├── HolidayRepoKotlin.kt │ │ │ └── HolidayActivityKotlin.kt │ │ │ ├── commons │ │ │ ├── Constants.java │ │ │ ├── ApiInterface.java │ │ │ └── MyApplication.java │ │ │ ├── java │ │ │ ├── HolidayModel.java │ │ │ ├── HolidayViewModel.java │ │ │ ├── HolidayRepo.java │ │ │ ├── HolidayAdapter.java │ │ │ └── HolidayActivity.java │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── README.md ├── .gitignore ├── gradle └── wrapper │ └── gradle-wrapper.properties └── gradle.properties /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name='Easy MVVM' 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kashifo/EasyMVVM/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kashifo/EasyMVVM/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kashifo/EasyMVVM/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kashifo/EasyMVVM/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kashifo/EasyMVVM/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kashifo/EasyMVVM/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kashifo/EasyMVVM/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kashifo/EasyMVVM/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kashifo/EasyMVVM/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kashifo/EasyMVVM/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasyMVVM 2 | The easiest guide to getting started with MVVM in Android instantly. 3 | 4 | This project contains source-code for the medium article 5 | https://medium.com/@kashifo/4-steps-to-mvvm-in-android-java-b05fb4148523 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Easy MVVM 3 | HolidayActivityJava 4 | HolidayActivityKotlin 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/easymvvm/kotlin/HolidayModelKotlin.kt: -------------------------------------------------------------------------------- 1 | package com.github.easymvvm.kotlin 2 | 3 | /** 4 | * Created by Kashif on 10/23/2019. 5 | */ 6 | class HolidayModelKotlin{ 7 | 8 | var date:String? = null 9 | var name:String? = null 10 | 11 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/easymvvm/commons/Constants.java: -------------------------------------------------------------------------------- 1 | package com.github.easymvvm.commons; 2 | 3 | /** 4 | * Created by Kashif on 9/27/2019. 5 | */ 6 | public class Constants { 7 | 8 | public static String BASE_URL = "https://date.nager.at/api/v2/"; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Oct 19 20:37:35 IST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/easymvvm/java/HolidayModel.java: -------------------------------------------------------------------------------- 1 | package com.github.easymvvm.java; 2 | 3 | /** 4 | * Created by Kashif on 10/19/2019. 5 | */ 6 | public class HolidayModel { 7 | 8 | private String date; 9 | private String name; 10 | 11 | public String getDate() { 12 | return date; 13 | } 14 | 15 | public void setDate(String date) { 16 | this.date = date; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/easymvvm/commons/ApiInterface.java: -------------------------------------------------------------------------------- 1 | package com.github.easymvvm.commons; 2 | 3 | import com.github.easymvvm.java.HolidayModel; 4 | import com.github.easymvvm.kotlin.HolidayModelKotlin; 5 | 6 | import java.util.List; 7 | 8 | import retrofit2.Call; 9 | import retrofit2.http.GET; 10 | 11 | /** 12 | * Created by Kashif on 9/27/2019. 13 | */ 14 | public interface ApiInterface { 15 | 16 | @GET("PublicHolidays/2019/us") 17 | Call> getHolidays(); 18 | 19 | @GET("PublicHolidays/2019/us") 20 | Call> getHolidaysKotlin(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/easymvvm/kotlin/HolidayViewModelKotlin.kt: -------------------------------------------------------------------------------- 1 | package com.github.easymvvm.kotlin 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.lifecycle.MutableLiveData 5 | import androidx.lifecycle.ViewModel 6 | 7 | /** 8 | * Created by Kashif on 10/9/2019. 9 | */ 10 | class HolidayViewModelKotlin() : ViewModel() { 11 | 12 | var holidayRepoKotlin: HolidayRepoKotlin? = null 13 | var mutableLiveData: MutableLiveData>? = null 14 | 15 | init { 16 | holidayRepoKotlin = HolidayRepoKotlin() 17 | } 18 | 19 | fun getHolidays(): LiveData> { 20 | if (mutableLiveData == null) { 21 | mutableLiveData = holidayRepoKotlin!!.fetchHolidays() 22 | } 23 | return mutableLiveData!! 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /app/src/main/java/com/github/easymvvm/java/HolidayViewModel.java: -------------------------------------------------------------------------------- 1 | package com.github.easymvvm.java; 2 | 3 | import java.util.List; 4 | import androidx.lifecycle.LiveData; 5 | import androidx.lifecycle.MutableLiveData; 6 | import androidx.lifecycle.ViewModel; 7 | 8 | /** 9 | * Created by Kashif on 9/27/2019. 10 | */ 11 | public class HolidayViewModel extends ViewModel { 12 | 13 | private HolidayRepo holidayRepo; 14 | private MutableLiveData> mutableLiveData; 15 | 16 | public HolidayViewModel(){ 17 | holidayRepo = new HolidayRepo(); 18 | } 19 | 20 | public LiveData> getHolidays() { 21 | if(mutableLiveData==null){ 22 | mutableLiveData = holidayRepo.requestHolidays(); 23 | } 24 | return mutableLiveData; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/easymvvm/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.easymvvm; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import androidx.databinding.DataBindingUtil; 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import com.github.easymvvm.databinding.ActivityMainBinding; 9 | import com.github.easymvvm.java.HolidayActivity; 10 | import com.github.easymvvm.kotlin.HolidayActivityKotlin; 11 | 12 | public class MainActivity extends AppCompatActivity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); 18 | 19 | binding.btnJava.setOnClickListener(new View.OnClickListener() { 20 | @Override 21 | public void onClick(View v) { 22 | startActivity(new Intent(MainActivity.this, HolidayActivity.class)); 23 | } 24 | }); 25 | 26 | binding.btnKotlin.setOnClickListener(new View.OnClickListener() { 27 | @Override 28 | public void onClick(View v) { 29 | startActivity(new Intent(MainActivity.this, HolidayActivityKotlin.class)); 30 | } 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 |