Skip to content
Merged
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
2 changes: 0 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion rootProject.compileSdkVersion
Expand Down Expand Up @@ -63,7 +62,6 @@ dependencies {

// architecture components
implementation "androidx.core:core-ktx:$coreVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.example.android.codelabs.paging

import android.content.Context
import androidx.lifecycle.ViewModelProvider
import com.example.android.codelabs.paging.api.GithubService
import com.example.android.codelabs.paging.data.GithubRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.example.android.codelabs.paging.api
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import okhttp3.logging.HttpLoggingInterceptor.Level
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
Expand All @@ -36,9 +35,9 @@ interface GithubService {
*/
@GET("search/repositories?sort=stars")
suspend fun searchRepos(
@Query("q") query: String,
@Query("page") page: Int,
@Query("per_page") itemsPerPage: Int
@Query("q") query: String,
@Query("page") page: Int,
@Query("per_page") itemsPerPage: Int
): RepoSearchResponse

companion object {
Expand All @@ -49,14 +48,14 @@ interface GithubService {
logger.level = Level.BASIC

val client = OkHttpClient.Builder()
.addInterceptor(logger)
.build()
.addInterceptor(logger)
.build()
return Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(GithubService::class.java)
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(GithubService::class.java)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class GithubRepository(private val service: GithubService) {
// the query. Then order the results.
return inMemoryCache.filter {
it.name.contains(query, true) ||
(it.description != null && it.description.contains(query, true))
(it.description != null && it.description.contains(query, true))
}.sortedWith(compareByDescending<Repo> { it.stars }.thenBy { it.name })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package com.example.android.codelabs.paging.ui

import android.content.Intent
import android.net.Uri
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.android.codelabs.paging.R
import com.example.android.codelabs.paging.model.Repo

Expand Down Expand Up @@ -88,7 +88,7 @@ class RepoViewHolder(view: View) : RecyclerView.ViewHolder(view) {
companion object {
fun create(parent: ViewGroup): RepoViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.repo_view_item, parent, false)
.inflate(R.layout.repo_view_item, parent, false)
return RepoViewHolder(view)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ import com.example.android.codelabs.paging.model.Repo
/**
* Adapter for the list of repositories.
*/
class ReposAdapter : ListAdapter<Repo, androidx.recyclerview.widget.RecyclerView.ViewHolder>(REPO_COMPARATOR) {
class ReposAdapter : ListAdapter<Repo, RepoViewHolder>(REPO_COMPARATOR) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): androidx.recyclerview.widget.RecyclerView.ViewHolder {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepoViewHolder {
return RepoViewHolder.create(parent)
}

override fun onBindViewHolder(holder: androidx.recyclerview.widget.RecyclerView.ViewHolder, position: Int) {
override fun onBindViewHolder(holder: RepoViewHolder, position: Int) {
val repoItem = getItem(position)
if (repoItem != null) {
(holder as RepoViewHolder).bind(repoItem)
holder.bind(repoItem)
}
}

companion object {
private val REPO_COMPARATOR = object : DiffUtil.ItemCallback<Repo>() {
override fun areItemsTheSame(oldItem: Repo, newItem: Repo): Boolean =
oldItem.fullName == newItem.fullName
oldItem.fullName == newItem.fullName

override fun areContentsTheSame(oldItem: Repo, newItem: Repo): Boolean =
oldItem == newItem
oldItem == newItem
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SearchRepositoriesActivity : AppCompatActivity() {

// get the view model
viewModel = ViewModelProvider(this, Injection.provideViewModelFactory())
.get(SearchRepositoriesViewModel::class.java)
.get(SearchRepositoriesViewModel::class.java)

// add dividers between RecyclerView's row items
val decoration = DividerItemDecoration(this, DividerItemDecoration.VERTICAL)
Expand Down Expand Up @@ -75,9 +75,9 @@ class SearchRepositoriesActivity : AppCompatActivity() {
}
is RepoSearchResult.Error -> {
Toast.makeText(
this,
"\uD83D\uDE28 Wooops $result.message}",
Toast.LENGTH_LONG
this,
"\uD83D\uDE28 Wooops $result.message}",
Toast.LENGTH_LONG
).show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@

package com.example.android.codelabs.paging.ui

import androidx.lifecycle.*
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import androidx.lifecycle.liveData
import androidx.lifecycle.switchMap
import androidx.lifecycle.viewModelScope
import com.example.android.codelabs.paging.data.GithubRepository
import com.example.android.codelabs.paging.model.RepoSearchResult
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -57,4 +63,4 @@ class SearchRepositoriesViewModel(private val repository: GithubRepository) : Vi
}
}
}
}
}
20 changes: 11 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.21'
ext.kotlin_version = '1.4.30'
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
mavenCentral()
jcenter()
}
}
Expand All @@ -45,13 +47,13 @@ ext {
targetSdkVersion = 28
supportLibVersion = '1.2.0'
coreVersion = '1.3.2'
recyclerViewVersion = '1.2.0-alpha06'
recyclerViewVersion = '1.2.0-beta01'
constraintLayoutVersion = '2.0.4'
materialVersion = '1.2.1'
lifecycleVersion = '2.2.0'
roomVersion = '2.3.0-alpha03'
pagingVersion = '3.0.0-alpha11'
materialVersion = '1.3.0'
lifecycleVersion = '2.3.0'
roomVersion = '2.3.0-beta02'
pagingVersion = '3.0.0-beta01'
retrofitVersion = '2.7.2'
okhttpLoggingInterceptorVersion = '4.0.0'
coroutines = '1.4.1'
okhttpLoggingInterceptorVersion = '4.9.0'
coroutines = '1.4.2'
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Nov 02 16:17:32 GMT 2020
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https://services.gradle.org/distributions/gradle-6.8.2-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME