Skip to content

Commit 08ddc7b

Browse files
committed
Upgrade kotlin version & gradle dependencies.
1 parent 7afae7b commit 08ddc7b

File tree

11 files changed

+230
-145
lines changed

11 files changed

+230
-145
lines changed

app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ android {
1919
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2020
}
2121
}
22+
namespace 'com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide'
2223
}
2324

2425
dependencies {

app/src/main/AndroidManifest.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
xmlns:tools="http://schemas.android.com/tools"
3-
package="com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide">
2+
xmlns:tools="http://schemas.android.com/tools">
43

54
<uses-permission android:name="android.permission.INTERNET" />
65

app/src/main/java/com/sharmadhiraj/androidpaginglibrarystepbystepimplementationguide/adapter/ListFooterViewHolder.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.R
1010
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.State
1111
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.State.ERROR
1212
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.State.LOADING
13-
import kotlinx.android.synthetic.main.item_list_footer.view.*
13+
import kotlinx.android.synthetic.main.item_list_footer.view.progress_bar
14+
import kotlinx.android.synthetic.main.item_list_footer.view.txt_error
1415

1516
class ListFooterViewHolder(view: View) : RecyclerView.ViewHolder(view) {
1617

app/src/main/java/com/sharmadhiraj/androidpaginglibrarystepbystepimplementationguide/adapter/NewsListAdapter.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.adapter
22

33
import android.view.ViewGroup
4-
import androidx.paging.PagedListAdapter
4+
import androidx.paging.PagingDataAdapter
55
import androidx.recyclerview.widget.DiffUtil
66
import androidx.recyclerview.widget.RecyclerView
77
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.News
88
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.State
99

10-
class NewsListAdapter(private val retry: () -> Unit)
11-
: PagedListAdapter<News, RecyclerView.ViewHolder>(NewsDiffCallback) {
10+
class NewsListAdapter(private val retry: () -> Unit) :
11+
PagingDataAdapter<News, RecyclerView.ViewHolder>(NewsDiffCallback) {
1212

1313
private val DATA_VIEW_TYPE = 1
1414
private val FOOTER_VIEW_TYPE = 2

app/src/main/java/com/sharmadhiraj/androidpaginglibrarystepbystepimplementationguide/adapter/NewsViewHolder.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import androidx.recyclerview.widget.RecyclerView
77
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.R
88
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.News
99
import com.squareup.picasso.Picasso
10-
import kotlinx.android.synthetic.main.item_news.view.*
10+
import kotlinx.android.synthetic.main.item_news.view.img_news_banner
11+
import kotlinx.android.synthetic.main.item_news.view.txt_news_name
1112

1213
class NewsViewHolder(view: View) : RecyclerView.ViewHolder(view) {
1314

app/src/main/java/com/sharmadhiraj/androidpaginglibrarystepbystepimplementationguide/data/NewsDataSource.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data
22

33
import androidx.lifecycle.MutableLiveData
4-
import androidx.paging.PageKeyedDataSource
4+
import androidx.paging.PagingSource
55
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.State.DONE
66
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.State.ERROR
77
import io.reactivex.Completable
@@ -13,7 +13,7 @@ import io.reactivex.schedulers.Schedulers
1313
class NewsDataSource(
1414
private val networkService: NetworkService,
1515
private val compositeDisposable: CompositeDisposable
16-
) : PageKeyedDataSource<Int, News>() {
16+
) : PagingSource<Int, News>() {
1717

1818
var state: MutableLiveData<State> = MutableLiveData()
1919
private var retryCompletable: Completable? = null

app/src/main/java/com/sharmadhiraj/androidpaginglibrarystepbystepimplementationguide/viewModel/NewsListViewModel.kt

+20-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@ package com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.viewM
33
import androidx.lifecycle.LiveData
44
import androidx.lifecycle.Transformations
55
import androidx.lifecycle.ViewModel
6-
import androidx.paging.LivePagedListBuilder
76
import androidx.paging.PagedList
8-
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.*
7+
import androidx.paging.Pager
8+
import androidx.paging.PagingConfig
9+
import androidx.paging.liveData
10+
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.NetworkService
11+
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.News
12+
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.NewsDataSource
13+
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.NewsDataSourceFactory
14+
import com.sharmadhiraj.androidpaginglibrarystepbystepimplementationguide.data.State
915
import io.reactivex.disposables.CompositeDisposable
16+
import kotlinx.coroutines.Dispatchers
1017

1118
class NewsListViewModel : ViewModel() {
1219

@@ -23,7 +30,17 @@ class NewsListViewModel : ViewModel() {
2330
.setInitialLoadSizeHint(pageSize * 2)
2431
.setEnablePlaceholders(false)
2532
.build()
26-
newsList = LivePagedListBuilder(newsDataSourceFactory, config).build()
33+
newsList = Pager<Int, News>(
34+
PagingConfig(
35+
config.pageSize,
36+
config.prefetchDistance,
37+
config.enablePlaceholders,
38+
config.initialLoadSizeHint,
39+
config.maxSize
40+
),
41+
this.initialLoadKey,
42+
newsDataSourceFactory.asPagingSourceFactory(Dispatchers.IO)
43+
).liveData.build()
2744
}
2845

2946

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
buildscript {
2-
ext.kotlin_version = '1.5.0'
2+
ext.kotlin_version = '1.7.10'
33
repositories {
44
google()
55
mavenCentral()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:4.2.1'
8+
classpath 'com.android.tools.build:gradle:7.4.2'
99
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1010
}
1111
}
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Tue May 05 14:03:24 NPT 2020
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

0 commit comments

Comments
 (0)