Skip to content
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
12 changes: 1 addition & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/google-java-format.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 19 additions & 22 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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"
Expand All @@ -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'

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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, Movies.Movie>): Int? {
return state.anchorPosition
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,6 +12,7 @@ class GetMoviesFlowRemoteRepositoryImpl(
private val database: MovieDatabase,
private val remoteMediator: GetMoviesFlowRemoteMediator): GetMoviesFlowRepository {

@OptIn(ExperimentalPagingApi::class)
override fun getMovies(): Flow<PagingData<Movies.Movie>> {
return Pager(
config = PagingConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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, Movies.Movie>): Int? {
return state.anchorPosition
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,6 +14,7 @@ class GetMoviesRxRemoteRepositoryImpl(
private val remoteMediator: GetMoviesRxRemoteMediator
): GetMoviesRxRepository {

@OptIn(ExperimentalPagingApi::class)
override fun getMovies(): Flowable<PagingData<Movies.Movie>> {
return Pager(
config = PagingConfig(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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