This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by simx on 14,August,2019 | |
*/ | |
class MainVM:BaseObservable() { | |
var movies : LiveData<PagedList<ResponseMovies.ResultsItem>> | |
var dataSource: MovieDataSourceFactory | |
init { | |
val config = PagedList.Config.Builder() | |
.setPageSize(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ApiRequests { | |
suspend fun discover(page:Int, year:Int) = API.Factory.create(BuildConfig.BASE_URL).discoverAsync(BuildConfig.API_KEY,page,year).await() | |
suspend fun search(page:Int, year:Int,query:String) = API.Factory.create(BuildConfig.BASE_URL).searchAsync(BuildConfig.API_KEY,page,year,query).await() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface API { | |
@Headers("Accept: application/json", "Content-type: application/json") | |
@GET("discover/movie") | |
fun discoverAsync(@Query("api_key")apiKey:String, | |
@Query("page")page:Int, | |
@Query("year")year:Int | |
): Deferred<ResponseMovies> | |
@Headers("Accept: application/json", "Content-type: application/json") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.simx.paggingsample.data.paging | |
import androidx.paging.DataSource | |
import com.simx.paggingsample.data.discover.ResponseMovies | |
/** | |
* Created by simx on 14,August,2019 | |
*/ | |
class MovieDataSourceFactory(): DataSource.Factory<Int, ResponseMovies.ResultsItem>() { | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.simx.paggingsample.data.paging | |
import androidx.paging.PageKeyedDataSource | |
import com.simx.paggingsample.data.ApiRequests | |
import com.simx.paggingsample.data.discover.ResponseMovies | |
import kotlinx.coroutines.* | |
import kotlin.coroutines.CoroutineContext | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools"> | |
<data> | |
<variable name="mainVm" type="com.simx.paggingsample.MainVM"/> | |
</data> | |
<RelativeLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
apply plugin: 'kotlin-android' | |
apply plugin: 'kotlin-android-extensions' | |
apply plugin: 'kotlin-kapt' | |
android { | |
compileSdkVersion 29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.main_activity) | |
if (savedInstanceState == null) { | |
supportFragmentManager.beginTransaction() | |
.replace(R.id.container, MainFragment.newInstance()) | |
.commitNow() | |
} |