diff --git a/app/build.gradle b/app/build.gradle index 13fe279..2215088 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,17 +1,16 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-parcelize' apply plugin: 'kotlin-kapt' apply plugin: 'dagger.hilt.android.plugin' android { - compileSdkVersion 29 - buildToolsVersion "29.0.3" + compileSdkVersion 33 defaultConfig { applicationId "com.mindorks.framework.mvvm" - minSdkVersion 16 - targetSdkVersion 29 + minSdkVersion 21 + targetSdkVersion 33 versionCode 1 versionName "1.0" @@ -28,14 +27,19 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } // work-runtime-ktx 2.1.0 and above now requires Java 8 kotlinOptions { - jvmTarget = "1.8" + jvmTarget = "17" } - + buildFeatures{ + viewBinding true + dataBinding true + buildConfig = true + } + namespace 'com.mindorks.framework.mvvm' } dependencies { @@ -47,6 +51,7 @@ dependencies { testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + implementation "androidx.navigation:navigation-compose:2.5.3" // Added Dependencies implementation "androidx.recyclerview:recyclerview:1.1.0" @@ -56,10 +61,10 @@ dependencies { //Dagger - implementation 'com.google.dagger:hilt-android:2.28-alpha' - kapt 'com.google.dagger:hilt-android-compiler:2.28-alpha' - implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha01' - kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha01' + implementation "com.google.dagger:hilt-android:$hilt_version" + kapt "com.google.dagger:hilt-android-compiler:$hilt_version" + kapt 'androidx.hilt:hilt-compiler:1.0.0' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1' // Networking diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1abaeb3..89b7ccc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + @@ -8,12 +7,13 @@ - + diff --git a/app/src/main/java/com/mindorks/framework/mvvm/di/module/ApplicationModule.kt b/app/src/main/java/com/mindorks/framework/mvvm/di/module/ApplicationModule.kt index ec50f2c..4e51504 100644 --- a/app/src/main/java/com/mindorks/framework/mvvm/di/module/ApplicationModule.kt +++ b/app/src/main/java/com/mindorks/framework/mvvm/di/module/ApplicationModule.kt @@ -11,11 +11,11 @@ import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import javax.inject.Singleton import dagger.hilt.InstallIn -import dagger.hilt.android.components.ApplicationComponent import retrofit2.converter.moshi.MoshiConverterFactory +import dagger.hilt.components.SingletonComponent @Module -@InstallIn(ApplicationComponent::class) +@InstallIn(SingletonComponent::class) class ApplicationModule { @Provides diff --git a/app/src/main/java/com/mindorks/framework/mvvm/ui/main/adapter/MainAdapter.kt b/app/src/main/java/com/mindorks/framework/mvvm/ui/main/adapter/MainAdapter.kt index cff4c10..a1e4ded 100644 --- a/app/src/main/java/com/mindorks/framework/mvvm/ui/main/adapter/MainAdapter.kt +++ b/app/src/main/java/com/mindorks/framework/mvvm/ui/main/adapter/MainAdapter.kt @@ -7,26 +7,27 @@ import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import com.mindorks.framework.mvvm.R import com.mindorks.framework.mvvm.data.model.User -import kotlinx.android.synthetic.main.item_layout.view.* +import com.mindorks.framework.mvvm.databinding.ItemLayoutBinding class MainAdapter( private val users: ArrayList ) : RecyclerView.Adapter() { - class DataViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + class DataViewHolder(val binding: ItemLayoutBinding) : RecyclerView.ViewHolder(binding.root) { fun bind(user: User) { - itemView.textViewUserName.text = user.name - itemView.textViewUserEmail.text = user.email - Glide.with(itemView.imageViewAvatar.context) + binding.textViewUserName.text = user.name + binding.textViewUserEmail.text = user.email + Glide.with(binding.imageViewAvatar.context) .load(user.avatar) - .into(itemView.imageViewAvatar) + .into(binding.imageViewAvatar) } } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = DataViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.item_layout, parent, + ItemLayoutBinding.inflate( + LayoutInflater.from(parent.context), + parent, false ) ) diff --git a/app/src/main/java/com/mindorks/framework/mvvm/ui/main/view/MainActivity.kt b/app/src/main/java/com/mindorks/framework/mvvm/ui/main/view/MainActivity.kt index 387e13a..97b23c5 100644 --- a/app/src/main/java/com/mindorks/framework/mvvm/ui/main/view/MainActivity.kt +++ b/app/src/main/java/com/mindorks/framework/mvvm/ui/main/view/MainActivity.kt @@ -5,58 +5,61 @@ import android.view.View import android.widget.Toast import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity +import androidx.databinding.DataBindingUtil import androidx.lifecycle.Observer import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import com.mindorks.framework.mvvm.R import com.mindorks.framework.mvvm.data.model.User +import com.mindorks.framework.mvvm.databinding.ActivityMainBinding import com.mindorks.framework.mvvm.ui.main.adapter.MainAdapter import com.mindorks.framework.mvvm.ui.main.viewmodel.MainViewModel import com.mindorks.framework.mvvm.utils.Status import dagger.hilt.android.AndroidEntryPoint -import kotlinx.android.synthetic.main.activity_main.* @AndroidEntryPoint class MainActivity : AppCompatActivity() { + private lateinit var binding: ActivityMainBinding private val mainViewModel : MainViewModel by viewModels() private lateinit var adapter: MainAdapter override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) + binding = DataBindingUtil.setContentView(this, R.layout.activity_main) + setupUI() setupObserver() } private fun setupUI() { - recyclerView.layoutManager = LinearLayoutManager(this) + binding.recyclerView.layoutManager = LinearLayoutManager(this) adapter = MainAdapter(arrayListOf()) - recyclerView.addItemDecoration( + binding.recyclerView.addItemDecoration( DividerItemDecoration( - recyclerView.context, - (recyclerView.layoutManager as LinearLayoutManager).orientation + binding.recyclerView.context, + (binding.recyclerView.layoutManager as LinearLayoutManager).orientation ) ) - recyclerView.adapter = adapter + binding.recyclerView.adapter = adapter } private fun setupObserver() { mainViewModel.users.observe(this, Observer { when (it.status) { Status.SUCCESS -> { - progressBar.visibility = View.GONE + binding.progressBar.visibility = View.GONE it.data?.let { users -> renderList(users) } - recyclerView.visibility = View.VISIBLE + binding.recyclerView.visibility = View.VISIBLE } Status.LOADING -> { - progressBar.visibility = View.VISIBLE - recyclerView.visibility = View.GONE + binding.progressBar.visibility = View.VISIBLE + binding.recyclerView.visibility = View.GONE } Status.ERROR -> { //Handle Error - progressBar.visibility = View.GONE + binding.progressBar.visibility = View.GONE Toast.makeText(this, it.message, Toast.LENGTH_LONG).show() } } diff --git a/app/src/main/java/com/mindorks/framework/mvvm/ui/main/viewmodel/MainViewModel.kt b/app/src/main/java/com/mindorks/framework/mvvm/ui/main/viewmodel/MainViewModel.kt index b71b7bf..9a8159e 100644 --- a/app/src/main/java/com/mindorks/framework/mvvm/ui/main/viewmodel/MainViewModel.kt +++ b/app/src/main/java/com/mindorks/framework/mvvm/ui/main/viewmodel/MainViewModel.kt @@ -1,14 +1,19 @@ package com.mindorks.framework.mvvm.ui.main.viewmodel -import androidx.hilt.lifecycle.ViewModelInject -import androidx.lifecycle.* +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.mindorks.framework.mvvm.data.model.User import com.mindorks.framework.mvvm.data.repository.MainRepository import com.mindorks.framework.mvvm.utils.NetworkHelper import com.mindorks.framework.mvvm.utils.Resource import kotlinx.coroutines.launch +import javax.inject.Inject +import dagger.hilt.android.lifecycle.HiltViewModel -class MainViewModel @ViewModelInject constructor( +@HiltViewModel +class MainViewModel @Inject constructor( private val mainRepository: MainRepository, private val networkHelper: NetworkHelper ) : ViewModel() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4c48b41..f4e4e5d 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,6 @@ - + - \ No newline at end of file + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 0c09a82..37510f6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,18 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.72' + ext.kotlin_version = '1.8.20' + ext.hilt_version = '2.46.1' repositories { google() + mavenCentral() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:8.0.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "com.google.dagger:hilt-android-gradle-plugin:2.28-alpha" + classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -19,6 +21,7 @@ buildscript { allprojects { repositories { google() + mavenCentral() jcenter() } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b0ca88f..8509451 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip