diff --git a/.gitignore b/.gitignore
index 57c25a3..b014d7f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,17 +40,7 @@ captures/
# IntelliJ
*.iml
-.idea/workspace.xml
-.idea/tasks.xml
-.idea/gradle.xml
-.idea/assetWizardSettings.xml
-.idea/dictionaries
-.idea/libraries
-# Android Studio 3 in .gitignore file.
-.idea/caches
-.idea/modules.xml
-# Comment next line if keeping position of elements in Navigation Editor is relevant for you
-.idea/navEditor.xml
+.idea/
# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 88ea3aa..3cc336b 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -1,6 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/google-java-format.xml b/.idea/google-java-format.xml
new file mode 100644
index 0000000..2aa056d
--- /dev/null
+++ b/.idea/google-java-format.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 703e5d4..7c7f635 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
index 7f68460..e497da9 100644
--- a/.idea/runConfigurations.xml
+++ b/.idea/runConfigurations.xml
@@ -3,6 +3,7 @@
+
diff --git a/app/build.gradle b/app/build.gradle
index 42d6e37..c4290b4 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,16 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
-apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
-
+apply plugin: 'kotlin-parcelize'
android {
- compileSdkVersion 29
- buildToolsVersion "30.0.1"
+ compileSdkVersion 30
+ buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.adrena.commerce.paging3"
- minSdkVersion 17
- targetSdkVersion 29
+ minSdkVersion 22
+ targetSdkVersion 30
versionCode 1
versionName "1.0"
@@ -40,22 +39,20 @@ android {
}
dependencies {
- def paging_version = "3.0.0-alpha03"
+ def paging_version = '3.0.0-alpha13'
def coroutines_version = "1.3.7"
- def retrofit_version = "2.7.2"
- def okhttp_logging_version = "4.3.1"
- def room_version = "2.3.0-alpha02"
+ def retrofit_version = '2.9.0'
+ def okhttp_logging_version = '4.9.0'
+ def room_version = '2.3.0-alpha04'
def lifecycle_version = "2.2.0"
- def navigation_version = "2.3.0"
+ def navigation_version = '2.3.3'
implementation fileTree(dir: "libs", include: ["*.jar"])
- implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
-
- implementation 'androidx.core:core-ktx:1.3.1'
- implementation 'androidx.appcompat:appcompat:1.1.0'
+ implementation 'androidx.core:core-ktx:1.3.2'
+ implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
- implementation "androidx.constraintlayout:constraintlayout:1.1.3"
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
@@ -72,22 +69,22 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
- implementation "androidx.paging:paging-runtime:$paging_version"
- implementation "androidx.paging:paging-rxjava2:$paging_version"
+ implementation "androidx.paging:paging-runtime-ktx:$paging_version"
+ implementation "androidx.paging:paging-rxjava2-ktx:$paging_version"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:$room_version"
- implementation "io.coil-kt:coil:0.11.0"
+ implementation 'io.coil-kt:coil:1.1.1'
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_logging_version"
- testImplementation 'junit:junit:4.13'
- androidTestImplementation 'androidx.test.ext:junit:1.1.1'
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+ testImplementation 'junit:junit:4.13.1'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.2'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
\ No newline at end of file
diff --git a/app/src/main/java/com/adrena/commerce/paging3/Injection.kt b/app/src/main/java/com/adrena/commerce/paging3/data/Injection.kt
similarity index 97%
rename from app/src/main/java/com/adrena/commerce/paging3/Injection.kt
rename to app/src/main/java/com/adrena/commerce/paging3/data/Injection.kt
index 6d7652a..d78a959 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/Injection.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/data/Injection.kt
@@ -19,7 +19,7 @@ import java.util.*
object Injection {
fun provideLocale(): Locale = Locale.getDefault()
- fun provideDatabase(context: Context): MovieDatabase = MovieDatabase.getInstance(context)
+ private fun provideDatabase(context: Context): MovieDatabase = MovieDatabase.getInstance(context)
fun provideFlowViewModel(context: Context): ViewModelProvider.Factory {
val pagingSource =
diff --git a/app/src/main/java/com/adrena/commerce/paging3/data/db/MovieDatabase.kt b/app/src/main/java/com/adrena/commerce/paging3/data/db/MovieDatabase.kt
index f91d198..88753e8 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/data/db/MovieDatabase.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/data/db/MovieDatabase.kt
@@ -13,7 +13,7 @@ import com.adrena.commerce.paging3.data.model.Movies
@Database(
entities = [Movies.Movie::class, Movies.MovieRemoteKeys::class],
- version = 1,
+ version = 2,
exportSchema = false
)
@TypeConverters(Converters::class)
diff --git a/app/src/main/java/com/adrena/commerce/paging3/data/flow/GetMoviesFlowPagingSource.kt b/app/src/main/java/com/adrena/commerce/paging3/data/flow/GetMoviesFlowPagingSource.kt
index b3ddb57..7ce00f8 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/data/flow/GetMoviesFlowPagingSource.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/data/flow/GetMoviesFlowPagingSource.kt
@@ -1,6 +1,7 @@
package com.adrena.commerce.paging3.data.flow
import androidx.paging.PagingSource
+import androidx.paging.PagingState
import com.adrena.commerce.paging3.data.TMDBService
import com.adrena.commerce.paging3.data.model.Movies
import com.adrena.commerce.paging3.data.model.MoviesMapper
@@ -34,4 +35,33 @@ class GetMoviesFlowPagingSource(
return LoadResult.Error(e)
}
}
+
+ /**
+ * Provide a [Key] used for the initial [load] for the next [PagingSource] due to invalidation
+ * of this [PagingSource]. The [Key] is provided to [load] via [LoadParams.key].
+ *
+ * The [Key] returned by this method should cause [load] to load enough items to
+ * fill the viewport around the last accessed position, allowing the next generation to
+ * transparently animate in. The last accessed position can be retrieved via
+ * [state.anchorPosition][PagingState.anchorPosition], which is typically
+ * the top-most or bottom-most item in the viewport due to access being triggered by binding
+ * items as they scroll into view.
+ *
+ * For example, if items are loaded based on integer position keys, you can return
+ * [state.anchorPosition][PagingState.anchorPosition].
+ *
+ * Alternately, if items contain a key used to load, get the key from the item in the page at
+ * index [state.anchorPosition][PagingState.anchorPosition].
+ *
+ * @param state [PagingState] of the currently fetched data, which includes the most recently
+ * accessed position in the list via [PagingState.anchorPosition].
+ *
+ * @return [Key] passed to [load] after invalidation used for initial load of the next
+ * generation. The [Key] returned by [getRefreshKey] should load pages centered around
+ * user's current viewport. If the correct [Key] cannot be determined, `null` can be returned
+ * to allow [load] decide what default key to use.
+ */
+ override fun getRefreshKey(state: PagingState): Int? {
+ return state.anchorPosition
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/adrena/commerce/paging3/data/flow/GetMoviesFlowRemoteRepositoryImpl.kt b/app/src/main/java/com/adrena/commerce/paging3/data/flow/GetMoviesFlowRemoteRepositoryImpl.kt
index 80a73a1..ec842c6 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/data/flow/GetMoviesFlowRemoteRepositoryImpl.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/data/flow/GetMoviesFlowRemoteRepositoryImpl.kt
@@ -1,5 +1,6 @@
package com.adrena.commerce.paging3.data.flow
+import androidx.paging.ExperimentalPagingApi
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
@@ -11,6 +12,7 @@ class GetMoviesFlowRemoteRepositoryImpl(
private val database: MovieDatabase,
private val remoteMediator: GetMoviesFlowRemoteMediator): GetMoviesFlowRepository {
+ @OptIn(ExperimentalPagingApi::class)
override fun getMovies(): Flow> {
return Pager(
config = PagingConfig(
diff --git a/app/src/main/java/com/adrena/commerce/paging3/data/model/Image.kt b/app/src/main/java/com/adrena/commerce/paging3/data/model/Image.kt
index 20b14d9..41ad8d4 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/data/model/Image.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/data/model/Image.kt
@@ -2,8 +2,8 @@ package com.adrena.commerce.paging3.data.model
import android.net.Uri
import android.os.Parcelable
-import kotlinx.android.parcel.IgnoredOnParcel
-import kotlinx.android.parcel.Parcelize
+import kotlinx.parcelize.IgnoredOnParcel
+import kotlinx.parcelize.Parcelize
@Parcelize
data class Image(val url: String): Parcelable {
diff --git a/app/src/main/java/com/adrena/commerce/paging3/data/model/Movies.kt b/app/src/main/java/com/adrena/commerce/paging3/data/model/Movies.kt
index 20ae59a..c5a5d9d 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/data/model/Movies.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/data/model/Movies.kt
@@ -3,8 +3,8 @@ package com.adrena.commerce.paging3.data.model
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey
-import kotlinx.android.parcel.IgnoredOnParcel
-import kotlinx.android.parcel.Parcelize
+import kotlinx.parcelize.IgnoredOnParcel
+import kotlinx.parcelize.Parcelize
import java.util.*
@Parcelize
diff --git a/app/src/main/java/com/adrena/commerce/paging3/data/rx/GetMoviesRxPagingSource.kt b/app/src/main/java/com/adrena/commerce/paging3/data/rx/GetMoviesRxPagingSource.kt
index 48da1e1..bfe14d8 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/data/rx/GetMoviesRxPagingSource.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/data/rx/GetMoviesRxPagingSource.kt
@@ -1,5 +1,6 @@
package com.adrena.commerce.paging3.data.rx
+import androidx.paging.PagingState
import androidx.paging.rxjava2.RxPagingSource
import com.adrena.commerce.paging3.data.TMDBService
import com.adrena.commerce.paging3.data.model.Movies
@@ -32,4 +33,33 @@ class GetMoviesRxPagingSource(
nextKey = if (position == data.total) null else position + 1
)
}
+
+ /**
+ * Provide a [Key] used for the initial [load] for the next [PagingSource] due to invalidation
+ * of this [PagingSource]. The [Key] is provided to [load] via [LoadParams.key].
+ *
+ * The [Key] returned by this method should cause [load] to load enough items to
+ * fill the viewport around the last accessed position, allowing the next generation to
+ * transparently animate in. The last accessed position can be retrieved via
+ * [state.anchorPosition][PagingState.anchorPosition], which is typically
+ * the top-most or bottom-most item in the viewport due to access being triggered by binding
+ * items as they scroll into view.
+ *
+ * For example, if items are loaded based on integer position keys, you can return
+ * [state.anchorPosition][PagingState.anchorPosition].
+ *
+ * Alternately, if items contain a key used to load, get the key from the item in the page at
+ * index [state.anchorPosition][PagingState.anchorPosition].
+ *
+ * @param state [PagingState] of the currently fetched data, which includes the most recently
+ * accessed position in the list via [PagingState.anchorPosition].
+ *
+ * @return [Key] passed to [load] after invalidation used for initial load of the next
+ * generation. The [Key] returned by [getRefreshKey] should load pages centered around
+ * user's current viewport. If the correct [Key] cannot be determined, `null` can be returned
+ * to allow [load] decide what default key to use.
+ */
+ override fun getRefreshKey(state: PagingState): Int? {
+ return state.anchorPosition
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/adrena/commerce/paging3/data/rx/GetMoviesRxRemoteRepositoryImpl.kt b/app/src/main/java/com/adrena/commerce/paging3/data/rx/GetMoviesRxRemoteRepositoryImpl.kt
index 6fd59cc..d54abd1 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/data/rx/GetMoviesRxRemoteRepositoryImpl.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/data/rx/GetMoviesRxRemoteRepositoryImpl.kt
@@ -1,5 +1,6 @@
package com.adrena.commerce.paging3.data.rx
+import androidx.paging.ExperimentalPagingApi
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
@@ -13,6 +14,7 @@ class GetMoviesRxRemoteRepositoryImpl(
private val remoteMediator: GetMoviesRxRemoteMediator
): GetMoviesRxRepository {
+ @OptIn(ExperimentalPagingApi::class)
override fun getMovies(): Flowable> {
return Pager(
config = PagingConfig(
diff --git a/app/src/main/java/com/adrena/commerce/paging3/data/rx/GetMoviesRxRepository.kt b/app/src/main/java/com/adrena/commerce/paging3/data/rx/GetMoviesRxRepository.kt
index 237149f..8647665 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/data/rx/GetMoviesRxRepository.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/data/rx/GetMoviesRxRepository.kt
@@ -1,6 +1,5 @@
package com.adrena.commerce.paging3.data.rx
-import androidx.paging.Pager
import androidx.paging.PagingData
import com.adrena.commerce.paging3.data.model.Movies
import io.reactivex.Flowable
diff --git a/app/src/main/java/com/adrena/commerce/paging3/view/MovieFlowFragment.kt b/app/src/main/java/com/adrena/commerce/paging3/view/MovieFlowFragment.kt
index 9fa996b..88fb9aa 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/view/MovieFlowFragment.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/view/MovieFlowFragment.kt
@@ -2,7 +2,6 @@ package com.adrena.commerce.paging3.view
import android.app.AlertDialog
import android.os.Bundle
-import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
diff --git a/app/src/main/java/com/adrena/commerce/paging3/view/MovieFlowRemoteFragment.kt b/app/src/main/java/com/adrena/commerce/paging3/view/MovieFlowRemoteFragment.kt
index 9ec2fb4..996ddc5 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/view/MovieFlowRemoteFragment.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/view/MovieFlowRemoteFragment.kt
@@ -2,7 +2,6 @@ package com.adrena.commerce.paging3.view
import android.app.AlertDialog
import android.os.Bundle
-import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
diff --git a/app/src/main/java/com/adrena/commerce/paging3/view/viewholder/MovieGridViewHolder.kt b/app/src/main/java/com/adrena/commerce/paging3/view/viewholder/MovieGridViewHolder.kt
index 3c3392d..fd70c50 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/view/viewholder/MovieGridViewHolder.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/view/viewholder/MovieGridViewHolder.kt
@@ -3,7 +3,7 @@ package com.adrena.commerce.paging3.view.viewholder
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
-import coil.api.load
+import coil.load
import com.adrena.commerce.paging3.R
import com.adrena.commerce.paging3.data.model.Movies
import com.adrena.commerce.paging3.databinding.MovieGridItemBinding
diff --git a/app/src/main/java/com/adrena/commerce/paging3/view/viewholder/MovieViewHolder.kt b/app/src/main/java/com/adrena/commerce/paging3/view/viewholder/MovieViewHolder.kt
index dc93b68..000e90b 100644
--- a/app/src/main/java/com/adrena/commerce/paging3/view/viewholder/MovieViewHolder.kt
+++ b/app/src/main/java/com/adrena/commerce/paging3/view/viewholder/MovieViewHolder.kt
@@ -3,7 +3,7 @@ package com.adrena.commerce.paging3.view.viewholder
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
-import coil.api.load
+import coil.load
import com.adrena.commerce.paging3.R
import com.adrena.commerce.paging3.data.model.Movies
import com.adrena.commerce.paging3.databinding.MovieItemBinding
diff --git a/build.gradle b/build.gradle
index 1241d12..63b2d7a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,12 +1,12 @@
// 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.4.21'
repositories {
google()
jcenter()
}
dependencies {
- classpath "com.android.tools.build:gradle:4.0.1"
+ classpath 'com.android.tools.build:gradle:4.2.0-beta04'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 4b53af2..b3bad36 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-6.7.1-all.zip