Skip to content

Fix build, upgrade stuff #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'com.google.devtools.ksp'
}

android {
compileSdk 33
compileSdk 36

defaultConfig {
applicationId "me.amitshekhar.learn.kotlin.flow"
minSdk 21
targetSdk 33
minSdk 26
targetSdk 36
versionCode 1
versionName "1.0"

Expand All @@ -31,31 +30,36 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
android {
buildFeatures {
viewBinding true
}
}
namespace "me.amitshekhar.learn.kotlin.flow"
}

dependencies {

implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation 'androidx.core:core-ktx:1.16.0'
implementation 'androidx.appcompat:appcompat:1.7.1'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
implementation "androidx.recyclerview:recyclerview:1.4.0"
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation "androidx.room:room-runtime:2.4.3"
kapt "androidx.room:room-compiler:2.4.3"
implementation "androidx.room:room-ktx:2.4.3"
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.9.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.9.1'
implementation "androidx.room:room-runtime:2.7.1"
ksp "androidx.room:room-compiler:2.7.1"
implementation "androidx.room:room-ktx:2.7.1"

testImplementation 'junit:junit:4.13.2'
testImplementation "org.mockito:mockito-core:3.4.6"
testImplementation 'androidx.arch.core:core-testing:2.1.0'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.1'
testImplementation 'androidx.arch.core:core-testing:2.2.0'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
testImplementation 'app.cash.turbine:turbine:0.11.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
package me.amitshekhar.learn.kotlin.flow.ui.base

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.item_layout.view.*
import me.amitshekhar.learn.kotlin.flow.R
import me.amitshekhar.learn.kotlin.flow.data.model.ApiUser
import me.amitshekhar.learn.kotlin.flow.databinding.ItemLayoutBinding

class ApiUserAdapter(
private val users: ArrayList<ApiUser>
) : RecyclerView.Adapter<ApiUserAdapter.DataViewHolder>() {

class DataViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
class DataViewHolder(private val binding: ItemLayoutBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(user: ApiUser) {
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,
false
)
)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DataViewHolder {
val binding = ItemLayoutBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return DataViewHolder(binding)
}

override fun getItemCount(): Int = users.size

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
package me.amitshekhar.learn.kotlin.flow.ui.base

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.item_layout.view.*
import me.amitshekhar.learn.kotlin.flow.R
import me.amitshekhar.learn.kotlin.flow.data.local.entity.User
import me.amitshekhar.learn.kotlin.flow.databinding.ItemLayoutBinding

class UserAdapter(
private val users: ArrayList<User>
) : RecyclerView.Adapter<UserAdapter.DataViewHolder>() {

class DataViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
class DataViewHolder(private 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,
false
)
)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DataViewHolder {
val binding = ItemLayoutBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return DataViewHolder(binding)
}

override fun getItemCount(): Int = users.size

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.android.synthetic.main.activity_long_running_task.*
import kotlinx.android.synthetic.main.activity_recycler_view.progressBar
import kotlinx.coroutines.launch
import me.amitshekhar.learn.kotlin.flow.R
import me.amitshekhar.learn.kotlin.flow.data.api.ApiHelperImpl
import me.amitshekhar.learn.kotlin.flow.data.api.RetrofitBuilder
import me.amitshekhar.learn.kotlin.flow.data.local.DatabaseBuilder
import me.amitshekhar.learn.kotlin.flow.data.local.DatabaseHelperImpl
import me.amitshekhar.learn.kotlin.flow.ui.base.ApiUserAdapter
import me.amitshekhar.learn.kotlin.flow.databinding.ActivityCompletionBinding
import me.amitshekhar.learn.kotlin.flow.utils.DefaultDispatcherProvider
import me.amitshekhar.learn.kotlin.flow.ui.base.UiState
import me.amitshekhar.learn.kotlin.flow.ui.base.ViewModelFactory

class CompletionActivity : AppCompatActivity() {

private lateinit var viewModel: CompletionViewModel
private lateinit var adapter: ApiUserAdapter
private lateinit var binding: ActivityCompletionBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCompletionBinding.inflate(layoutInflater)
setContentView(R.layout.activity_completion)
setupViewModel()
setupObserver()
Expand All @@ -39,17 +38,17 @@ class CompletionActivity : AppCompatActivity() {
viewModel.uiState.collect {
when (it) {
is UiState.Success -> {
progressBar.visibility = View.GONE
textView.text = it.data
textView.visibility = View.VISIBLE
binding.progressBar.visibility = View.GONE
binding.textView.text = it.data
binding.textView.visibility = View.VISIBLE
}
is UiState.Loading -> {
progressBar.visibility = View.VISIBLE
textView.visibility = View.GONE
binding.progressBar.visibility = View.VISIBLE
binding.textView.visibility = View.GONE
}
is UiState.Error -> {
//Handle Error
progressBar.visibility = View.GONE
binding.progressBar.visibility = View.GONE
Toast.makeText(this@CompletionActivity, it.message, Toast.LENGTH_SHORT)
.show()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.amitshekhar.learn.kotlin.flow.ui.errorhandling.catch

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import android.widget.Toast
Expand All @@ -10,14 +11,14 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_recycler_view.*
import kotlinx.coroutines.launch
import me.amitshekhar.learn.kotlin.flow.R
import me.amitshekhar.learn.kotlin.flow.data.api.ApiHelperImpl
import me.amitshekhar.learn.kotlin.flow.data.api.RetrofitBuilder
import me.amitshekhar.learn.kotlin.flow.data.local.DatabaseBuilder
import me.amitshekhar.learn.kotlin.flow.data.local.DatabaseHelperImpl
import me.amitshekhar.learn.kotlin.flow.data.model.ApiUser
import me.amitshekhar.learn.kotlin.flow.databinding.ActivityRecyclerViewBinding
import me.amitshekhar.learn.kotlin.flow.ui.base.ApiUserAdapter
import me.amitshekhar.learn.kotlin.flow.utils.DefaultDispatcherProvider
import me.amitshekhar.learn.kotlin.flow.ui.base.UiState
Expand All @@ -27,28 +28,30 @@ class CatchActivity : AppCompatActivity() {

private lateinit var viewModel: CatchViewModel
private lateinit var adapter: ApiUserAdapter
private lateinit var binding: ActivityRecyclerViewBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityRecyclerViewBinding.inflate(layoutInflater)
setContentView(R.layout.activity_recycler_view)
setupUI()
setupViewModel()
setupObserver()
}

private fun setupUI() {
recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.layoutManager = LinearLayoutManager(this)
adapter =
ApiUserAdapter(
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() {
Expand All @@ -57,17 +60,17 @@ class CatchActivity : AppCompatActivity() {
viewModel.uiState.collect {
when (it) {
is UiState.Success -> {
progressBar.visibility = View.GONE
binding.progressBar.visibility = View.GONE
renderList(it.data)
recyclerView.visibility = View.VISIBLE
binding.recyclerView.visibility = View.VISIBLE
}
is UiState.Loading -> {
progressBar.visibility = View.VISIBLE
recyclerView.visibility = View.GONE
binding.progressBar.visibility = View.VISIBLE
binding.recyclerView.visibility = View.GONE
}
is UiState.Error -> {
//Handle Error
progressBar.visibility = View.GONE
binding.progressBar.visibility = View.GONE
Toast.makeText(this@CatchActivity, it.message, Toast.LENGTH_SHORT)
.show()
}
Expand All @@ -77,6 +80,7 @@ class CatchActivity : AppCompatActivity() {
}
}

@SuppressLint("NotifyDataSetChanged")
private fun renderList(users: List<ApiUser>) {
adapter.addData(users)
adapter.notifyDataSetChanged()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.amitshekhar.learn.kotlin.flow.ui.errorhandling.emitall

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import android.widget.Toast
Expand All @@ -10,14 +11,14 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_recycler_view.*
import kotlinx.coroutines.launch
import me.amitshekhar.learn.kotlin.flow.R
import me.amitshekhar.learn.kotlin.flow.data.api.ApiHelperImpl
import me.amitshekhar.learn.kotlin.flow.data.api.RetrofitBuilder
import me.amitshekhar.learn.kotlin.flow.data.local.DatabaseBuilder
import me.amitshekhar.learn.kotlin.flow.data.local.DatabaseHelperImpl
import me.amitshekhar.learn.kotlin.flow.data.model.ApiUser
import me.amitshekhar.learn.kotlin.flow.databinding.ActivityRecyclerViewBinding
import me.amitshekhar.learn.kotlin.flow.ui.base.ApiUserAdapter
import me.amitshekhar.learn.kotlin.flow.utils.DefaultDispatcherProvider
import me.amitshekhar.learn.kotlin.flow.ui.base.UiState
Expand All @@ -27,27 +28,29 @@ class EmitAllActivity : AppCompatActivity() {

private lateinit var viewModel: EmitAllViewModel
private lateinit var adapter: ApiUserAdapter
private lateinit var binding: ActivityRecyclerViewBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityRecyclerViewBinding.inflate(layoutInflater)
setContentView(R.layout.activity_recycler_view)
setupUI()
setupViewModel()
setupObserver()
}

private fun setupUI() {
recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.layoutManager = LinearLayoutManager(this)
adapter = ApiUserAdapter(
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() {
Expand All @@ -56,17 +59,17 @@ class EmitAllActivity : AppCompatActivity() {
viewModel.uiState.collect {
when (it) {
is UiState.Success -> {
progressBar.visibility = View.GONE
binding.progressBar.visibility = View.GONE
renderList(it.data)
recyclerView.visibility = View.VISIBLE
binding.recyclerView.visibility = View.VISIBLE
}
is UiState.Loading -> {
progressBar.visibility = View.VISIBLE
recyclerView.visibility = View.GONE
binding.progressBar.visibility = View.VISIBLE
binding.recyclerView.visibility = View.GONE
}
is UiState.Error -> {
//Handle Error
progressBar.visibility = View.GONE
binding.progressBar.visibility = View.GONE
Toast.makeText(this@EmitAllActivity, it.message, Toast.LENGTH_SHORT)
.show()
}
Expand All @@ -76,6 +79,7 @@ class EmitAllActivity : AppCompatActivity() {
}
}

@SuppressLint("NotifyDataSetChanged")
private fun renderList(users: List<ApiUser>) {
adapter.addData(users)
adapter.notifyDataSetChanged()
Expand Down
Loading