From fa33fad9c6852a7ced80019d9108105301abbf3e Mon Sep 17 00:00:00 2001 From: Florina Muntenescu Date: Fri, 13 Mar 2020 13:23:17 +0000 Subject: [PATCH 1/8] Add a footer that displays progress and error states, using MergeAdapter --- .../android/codelabs/paging/ui/LoadState.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 app/src/main/java/com/example/android/codelabs/paging/ui/LoadState.kt diff --git a/app/src/main/java/com/example/android/codelabs/paging/ui/LoadState.kt b/app/src/main/java/com/example/android/codelabs/paging/ui/LoadState.kt new file mode 100644 index 00000000..068d5dc6 --- /dev/null +++ b/app/src/main/java/com/example/android/codelabs/paging/ui/LoadState.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.codelabs.paging.ui + +/** + * LoadState of a list load + */ +sealed class LoadState { + /** + * Loading is in progress. + */ + object Loading : LoadState() + + /** + * Loading is complete. + */ + object Done : LoadState() + + /** + * Loading hit an error. + * + * @param error [Throwable] that caused the load operation to generate this error state. + * + */ + data class Error(val error: Throwable) : LoadState() { + override fun toString() = "Error: $error" + } +} From 555c31c97073558f6f704c755e57e9b9c59ac0c9 Mon Sep 17 00:00:00 2001 From: Florina Muntenescu Date: Thu, 27 Feb 2020 15:13:49 +0000 Subject: [PATCH 2/8] Remove code no longer needed due to paging --- .../codelabs/paging/api/RepoSearchResponse.kt | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 app/src/main/java/com/example/android/codelabs/paging/api/RepoSearchResponse.kt diff --git a/app/src/main/java/com/example/android/codelabs/paging/api/RepoSearchResponse.kt b/app/src/main/java/com/example/android/codelabs/paging/api/RepoSearchResponse.kt deleted file mode 100644 index b48f15ab..00000000 --- a/app/src/main/java/com/example/android/codelabs/paging/api/RepoSearchResponse.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.codelabs.paging.api - -import com.example.android.codelabs.paging.model.Repo -import com.google.gson.annotations.SerializedName - -/** - * Data class to hold repo responses from searchRepo API calls. - */ -data class RepoSearchResponse( - @SerializedName("total_count") val total: Int = 0, - @SerializedName("items") val items: List = emptyList(), - val nextPage: Int? = null -) From 97c13a8da07155eb8e8a93d5cde19ec1844041b1 Mon Sep 17 00:00:00 2001 From: Florina Muntenescu Date: Sat, 1 Feb 2020 22:31:10 +0000 Subject: [PATCH 3/8] Migrating to Paging 3.0 --- .../android/codelabs/paging/ui/SearchRepositoriesViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt b/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt index 8197f43b..14f3afa7 100644 --- a/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt +++ b/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt @@ -52,4 +52,4 @@ class SearchRepositoriesViewModel(private val repository: GithubRepository) : Vi currentSearchResult = newResult return newResult } -} +} \ No newline at end of file From fb7dc77c194f70e2cd64e71efc89b8aaf12b9e0f Mon Sep 17 00:00:00 2001 From: Florina Muntenescu Date: Fri, 13 Mar 2020 19:38:08 +0000 Subject: [PATCH 4/8] Remove separators code --- .../android/codelabs/paging/ui/LoadState.kt | 42 ------------------- .../codelabs/paging/ui/ReposAdapter.kt | 38 +++++++++++++---- .../paging/ui/SearchRepositoriesViewModel.kt | 34 +++++++++++++-- 3 files changed, 60 insertions(+), 54 deletions(-) delete mode 100644 app/src/main/java/com/example/android/codelabs/paging/ui/LoadState.kt diff --git a/app/src/main/java/com/example/android/codelabs/paging/ui/LoadState.kt b/app/src/main/java/com/example/android/codelabs/paging/ui/LoadState.kt deleted file mode 100644 index 068d5dc6..00000000 --- a/app/src/main/java/com/example/android/codelabs/paging/ui/LoadState.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.codelabs.paging.ui - -/** - * LoadState of a list load - */ -sealed class LoadState { - /** - * Loading is in progress. - */ - object Loading : LoadState() - - /** - * Loading is complete. - */ - object Done : LoadState() - - /** - * Loading hit an error. - * - * @param error [Throwable] that caused the load operation to generate this error state. - * - */ - data class Error(val error: Throwable) : LoadState() { - override fun toString() = "Error: $error" - } -} diff --git a/app/src/main/java/com/example/android/codelabs/paging/ui/ReposAdapter.kt b/app/src/main/java/com/example/android/codelabs/paging/ui/ReposAdapter.kt index e7aecf2f..8561558c 100644 --- a/app/src/main/java/com/example/android/codelabs/paging/ui/ReposAdapter.kt +++ b/app/src/main/java/com/example/android/codelabs/paging/ui/ReposAdapter.kt @@ -26,23 +26,45 @@ import com.example.android.codelabs.paging.model.Repo /** * Adapter for the list of repositories. */ -class ReposAdapter : PagingDataAdapter(REPO_COMPARATOR) { +class ReposAdapter : PagingDataAdapter(UIMODEL_COMPARATOR) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - return RepoViewHolder.create(parent) + return if(viewType == R.layout.repo_view_item) { + RepoViewHolder.create(parent) + } else { + SeparatorViewHolder.create(parent) + } + } + + override fun getItemViewType(position: Int): Int { + return when(getItem(position)){ + is UiModel.RepoItem -> R.layout.repo_view_item + is UiModel.SeparatorItem -> R.layout.separator_view_item + null -> 0 + } } override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val repo = getItem(position) - (holder as RepoViewHolder).bind(repo) + val uiModel = getItem(position) + uiModel.let { + when(uiModel){ + is UiModel.RepoItem -> (holder as RepoViewHolder).bind(uiModel.repo) + is UiModel.SeparatorItem -> (holder as SeparatorViewHolder).bind(uiModel.description) + } + } } companion object { - private val REPO_COMPARATOR = object : DiffUtil.ItemCallback() { - override fun areItemsTheSame(oldItem: Repo, newItem: Repo): Boolean = - oldItem.fullName == newItem.fullName + private val UIMODEL_COMPARATOR = object : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: UiModel, newItem: UiModel): Boolean { + return if (oldItem is UiModel.RepoItem && newItem is UiModel.RepoItem) { + oldItem.repo.fullName == newItem.repo.fullName + } else { + false + } + } - override fun areContentsTheSame(oldItem: Repo, newItem: Repo): Boolean = + override fun areContentsTheSame(oldItem: UiModel, newItem: UiModel): Boolean = oldItem == newItem } } diff --git a/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt b/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt index 14f3afa7..7367b33a 100644 --- a/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt +++ b/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt @@ -16,6 +16,7 @@ package com.example.android.codelabs.paging.ui +import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.paging.PagingData @@ -24,6 +25,7 @@ import com.example.android.codelabs.paging.data.GithubRepository import com.example.android.codelabs.paging.model.Repo import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map /** * ViewModel for the [SearchRepositoriesActivity] screen. @@ -36,20 +38,44 @@ class SearchRepositoriesViewModel(private val repository: GithubRepository) : Vi private var currentQueryValue: String? = null @Volatile - private var currentSearchResult: Flow>? = null + private var currentSearchResult: Flow>? = null /** * Search a repository based on a query string. */ - fun searchRepo(queryString: String): Flow> { + fun searchRepo(queryString: String): Flow> { val lastResult = currentSearchResult if (queryString == currentQueryValue && lastResult != null) { return lastResult } currentQueryValue = queryString - val newResult: Flow> = repository.getSearchResultStream(queryString) + val newResult: Flow> = repository.getSearchResultStream(queryString) + .map { pagingData -> pagingData.map { UiModel.RepoItem(it) } } + .map { + it.insertSeparators { before, after -> + if (before == null && after is UiModel.RepoItem) { + Log.d("ViewModel", "-> adding null separator") + UiModel.SeparatorItem("${after.repo.stars / 10_000}0.000+ stars") + } else if (before is UiModel.RepoItem && after is UiModel.RepoItem + && before.repo.stars / 10_000 > after.repo.stars / 10_000) { + if (after.repo.stars >= 10_000) { + UiModel.SeparatorItem("${after.repo.stars / 10_000}0.000+ stars") + } else { + UiModel.SeparatorItem("< 10.000+ stars") + } + } else { + // no separator + null + } + } + } .cachedIn(viewModelScope) currentSearchResult = newResult return newResult } -} \ No newline at end of file +} + +sealed class UiModel { + data class RepoItem(val repo: Repo) : UiModel() + data class SeparatorItem(val description: String) : UiModel() +} From aeb7744007af8ad327b2b7440363958397e8db06 Mon Sep 17 00:00:00 2001 From: Florina Muntenescu Date: Fri, 13 Mar 2020 20:03:46 +0000 Subject: [PATCH 5/8] Step 3 - Add separators every 10k stars --- .../codelabs/paging/ui/ReposAdapter.kt | 7 ++-- .../paging/ui/ReposLoadStateViewHolder.kt | 1 + .../codelabs/paging/ui/SeparatorViewHolder.kt | 40 +++++++++++++++++++ .../main/res/layout/separator_view_item.xml | 34 ++++++++++++++++ 4 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/com/example/android/codelabs/paging/ui/SeparatorViewHolder.kt create mode 100644 app/src/main/res/layout/separator_view_item.xml diff --git a/app/src/main/java/com/example/android/codelabs/paging/ui/ReposAdapter.kt b/app/src/main/java/com/example/android/codelabs/paging/ui/ReposAdapter.kt index 8561558c..7215fb6e 100644 --- a/app/src/main/java/com/example/android/codelabs/paging/ui/ReposAdapter.kt +++ b/app/src/main/java/com/example/android/codelabs/paging/ui/ReposAdapter.kt @@ -21,7 +21,6 @@ import androidx.paging.PagingDataAdapter import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView.ViewHolder import com.example.android.codelabs.paging.R -import com.example.android.codelabs.paging.model.Repo /** * Adapter for the list of repositories. @@ -29,7 +28,7 @@ import com.example.android.codelabs.paging.model.Repo class ReposAdapter : PagingDataAdapter(UIMODEL_COMPARATOR) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - return if(viewType == R.layout.repo_view_item) { + return if (viewType == R.layout.repo_view_item) { RepoViewHolder.create(parent) } else { SeparatorViewHolder.create(parent) @@ -37,7 +36,7 @@ class ReposAdapter : PagingDataAdapter(UIMODEL_COMPARATOR) } override fun getItemViewType(position: Int): Int { - return when(getItem(position)){ + return when (getItem(position)) { is UiModel.RepoItem -> R.layout.repo_view_item is UiModel.SeparatorItem -> R.layout.separator_view_item null -> 0 @@ -47,7 +46,7 @@ class ReposAdapter : PagingDataAdapter(UIMODEL_COMPARATOR) override fun onBindViewHolder(holder: ViewHolder, position: Int) { val uiModel = getItem(position) uiModel.let { - when(uiModel){ + when (uiModel) { is UiModel.RepoItem -> (holder as RepoViewHolder).bind(uiModel.repo) is UiModel.SeparatorItem -> (holder as SeparatorViewHolder).bind(uiModel.description) } diff --git a/app/src/main/java/com/example/android/codelabs/paging/ui/ReposLoadStateViewHolder.kt b/app/src/main/java/com/example/android/codelabs/paging/ui/ReposLoadStateViewHolder.kt index 19d806f6..dd09a41d 100644 --- a/app/src/main/java/com/example/android/codelabs/paging/ui/ReposLoadStateViewHolder.kt +++ b/app/src/main/java/com/example/android/codelabs/paging/ui/ReposLoadStateViewHolder.kt @@ -62,3 +62,4 @@ class ReposLoadStateViewHolder( } } } + diff --git a/app/src/main/java/com/example/android/codelabs/paging/ui/SeparatorViewHolder.kt b/app/src/main/java/com/example/android/codelabs/paging/ui/SeparatorViewHolder.kt new file mode 100644 index 00000000..22bd5222 --- /dev/null +++ b/app/src/main/java/com/example/android/codelabs/paging/ui/SeparatorViewHolder.kt @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.codelabs.paging.ui + +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 + +class SeparatorViewHolder(view: View) : RecyclerView.ViewHolder(view) { + private val description: TextView = view.findViewById(R.id.separator_description) + + fun bind(separatorText: String) { + description.text = separatorText + } + + companion object { + fun create(parent: ViewGroup): SeparatorViewHolder { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.separator_view_item, parent, false) + return SeparatorViewHolder(view) + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/separator_view_item.xml b/app/src/main/res/layout/separator_view_item.xml new file mode 100644 index 00000000..ad3a5e39 --- /dev/null +++ b/app/src/main/res/layout/separator_view_item.xml @@ -0,0 +1,34 @@ + + + + + From fd662512f13cea35d6467a44ce25be3f314534cc Mon Sep 17 00:00:00 2001 From: Florina Muntenescu Date: Mon, 16 Mar 2020 20:49:06 +0000 Subject: [PATCH 6/8] Addressing review comments: * Simplifying insertSeparators * Simplifying ReposAdapter --- .../codelabs/paging/api/RepoSearchResponse.kt | 29 +++++++++++++++++++ .../codelabs/paging/ui/ReposAdapter.kt | 12 ++++---- .../paging/ui/SearchRepositoriesViewModel.kt | 17 ++++++----- 3 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/com/example/android/codelabs/paging/api/RepoSearchResponse.kt diff --git a/app/src/main/java/com/example/android/codelabs/paging/api/RepoSearchResponse.kt b/app/src/main/java/com/example/android/codelabs/paging/api/RepoSearchResponse.kt new file mode 100644 index 00000000..efd7cee2 --- /dev/null +++ b/app/src/main/java/com/example/android/codelabs/paging/api/RepoSearchResponse.kt @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.codelabs.paging.api + +import com.example.android.codelabs.paging.model.Repo +import com.google.gson.annotations.SerializedName + +/** + * Data class to hold repo responses from searchRepo API calls. + */ +data class RepoSearchResponse( + @SerializedName("total_count") val total: Int = 0, + @SerializedName("items") val items: List = emptyList(), + val nextPage: Int? = null +) \ No newline at end of file diff --git a/app/src/main/java/com/example/android/codelabs/paging/ui/ReposAdapter.kt b/app/src/main/java/com/example/android/codelabs/paging/ui/ReposAdapter.kt index 7215fb6e..4b354a93 100644 --- a/app/src/main/java/com/example/android/codelabs/paging/ui/ReposAdapter.kt +++ b/app/src/main/java/com/example/android/codelabs/paging/ui/ReposAdapter.kt @@ -21,6 +21,7 @@ import androidx.paging.PagingDataAdapter import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView.ViewHolder import com.example.android.codelabs.paging.R +import java.lang.UnsupportedOperationException /** * Adapter for the list of repositories. @@ -39,7 +40,7 @@ class ReposAdapter : PagingDataAdapter(UIMODEL_COMPARATOR) return when (getItem(position)) { is UiModel.RepoItem -> R.layout.repo_view_item is UiModel.SeparatorItem -> R.layout.separator_view_item - null -> 0 + null -> throw UnsupportedOperationException("Unknown view") } } @@ -56,11 +57,10 @@ class ReposAdapter : PagingDataAdapter(UIMODEL_COMPARATOR) companion object { private val UIMODEL_COMPARATOR = object : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: UiModel, newItem: UiModel): Boolean { - return if (oldItem is UiModel.RepoItem && newItem is UiModel.RepoItem) { - oldItem.repo.fullName == newItem.repo.fullName - } else { - false - } + return (oldItem is UiModel.RepoItem && newItem is UiModel.RepoItem && + oldItem.repo.fullName == newItem.repo.fullName) || + (oldItem is UiModel.SeparatorItem && newItem is UiModel.SeparatorItem && + oldItem.description == newItem.description) } override fun areContentsTheSame(oldItem: UiModel, newItem: UiModel): Boolean = diff --git a/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt b/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt index 7367b33a..46f41a33 100644 --- a/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt +++ b/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt @@ -21,6 +21,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.paging.PagingData import androidx.paging.cachedIn +import androidx.paging.insertSeparators import com.example.android.codelabs.paging.data.GithubRepository import com.example.android.codelabs.paging.model.Repo import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -53,13 +54,12 @@ class SearchRepositoriesViewModel(private val repository: GithubRepository) : Vi .map { pagingData -> pagingData.map { UiModel.RepoItem(it) } } .map { it.insertSeparators { before, after -> - if (before == null && after is UiModel.RepoItem) { - Log.d("ViewModel", "-> adding null separator") - UiModel.SeparatorItem("${after.repo.stars / 10_000}0.000+ stars") - } else if (before is UiModel.RepoItem && after is UiModel.RepoItem - && before.repo.stars / 10_000 > after.repo.stars / 10_000) { - if (after.repo.stars >= 10_000) { - UiModel.SeparatorItem("${after.repo.stars / 10_000}0.000+ stars") + if (before == null && after != null) { + UiModel.SeparatorItem("${after.roundedStarCount}0.000+ stars") + } else if (before != null && after != null + && before.roundedStarCount > after.roundedStarCount) { + if (after.roundedStarCount >= 10_000) { + UiModel.SeparatorItem("${after.roundedStarCount}0.000+ stars") } else { UiModel.SeparatorItem("< 10.000+ stars") } @@ -79,3 +79,6 @@ sealed class UiModel { data class RepoItem(val repo: Repo) : UiModel() data class SeparatorItem(val description: String) : UiModel() } + +private val UiModel.RepoItem.roundedStarCount: Int + get() = this.repo.stars / 10_000 \ No newline at end of file From e11756c9f56dd1e97c825c151af41c54a1b194b8 Mon Sep 17 00:00:00 2001 From: Dustin Lam Date: Tue, 24 Mar 2020 13:41:45 -0700 Subject: [PATCH 7/8] Fix for separator logic --- .../android/codelabs/paging/ui/SearchRepositoriesViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt b/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt index 46f41a33..85706c75 100644 --- a/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt +++ b/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt @@ -58,7 +58,7 @@ class SearchRepositoriesViewModel(private val repository: GithubRepository) : Vi UiModel.SeparatorItem("${after.roundedStarCount}0.000+ stars") } else if (before != null && after != null && before.roundedStarCount > after.roundedStarCount) { - if (after.roundedStarCount >= 10_000) { + if (after.roundedStarCount >= 1) { UiModel.SeparatorItem("${after.roundedStarCount}0.000+ stars") } else { UiModel.SeparatorItem("< 10.000+ stars") From 14b1026209d09a88eff2f2c1a8b0856b4c527c72 Mon Sep 17 00:00:00 2001 From: Florina Muntenescu Date: Sun, 29 Mar 2020 18:25:12 +0100 Subject: [PATCH 8/8] Setting correct list visibility --- .../android/codelabs/paging/ui/SearchRepositoriesActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesActivity.kt b/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesActivity.kt index 121fdbb9..8ab04500 100644 --- a/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesActivity.kt +++ b/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesActivity.kt @@ -77,7 +77,7 @@ class SearchRepositoriesActivity : AppCompatActivity() { adapter.addLoadStateListener { loadType, loadState -> Log.d("SearchRepositoriesActivity", "adapter load: type = $loadType state = $loadState") if (loadType == LoadType.REFRESH) { - binding.list.visibility = View.GONE + binding.list.visibility = toVisibility(loadState == LoadState.Idle) binding.progressBar.visibility = toVisibility(loadState == LoadState.Loading) binding.retryButton.visibility = toVisibility(loadState is LoadState.Error) } else {