Skip to content

Commit

Permalink
Get refresh key function overridden by paging data sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
metinozcura committed Feb 1, 2021
1 parent 6ba6ac4 commit 7d08e88
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.metinozcura.rickandmorty.data.paging.datasource

import android.net.Uri
import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.metinozcura.rickandmorty.data.model.Character
import com.metinozcura.rickandmorty.data.service.CharacterApi

Expand Down Expand Up @@ -30,4 +31,6 @@ class CharactersPagingDataSource(private val service: CharacterApi) :
LoadResult.Error(e)
}
}

override fun getRefreshKey(state: PagingState<Int, Character>): Int = 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.metinozcura.rickandmorty.data.paging.datasource

import android.net.Uri
import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.metinozcura.rickandmorty.data.model.Episode
import com.metinozcura.rickandmorty.data.service.EpisodeApi

Expand Down Expand Up @@ -31,4 +32,6 @@ class EpisodesPagingDataSource(private val service: EpisodeApi) :
LoadResult.Error(e)
}
}

override fun getRefreshKey(state: PagingState<Int, Episode>): Int = 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.metinozcura.rickandmorty.data.paging.datasource

import android.net.Uri
import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.metinozcura.rickandmorty.data.model.Location
import com.metinozcura.rickandmorty.data.service.LocationApi

Expand Down Expand Up @@ -31,4 +32,6 @@ class LocationPagingDataSource(private val service: LocationApi) :
LoadResult.Error(e)
}
}

override fun getRefreshKey(state: PagingState<Int, Location>): Int = 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import androidx.paging.ExperimentalPagingApi
import androidx.paging.LoadType
import androidx.paging.PagingState
import androidx.paging.RemoteMediator
import com.metinozcura.rickandmorty.data.db.AppDB
import com.metinozcura.rickandmorty.data.model.Episode
import javax.inject.Inject

@OptIn(ExperimentalPagingApi::class)
class EpisodeRemoteMediator: RemoteMediator<Int, Episode>() {
@Inject lateinit var db: AppDB

override suspend fun load(
loadType: LoadType,
state: PagingState<Int, Episode>
Expand Down

0 comments on commit 7d08e88

Please sign in to comment.