From 785180c64ff3818ce3692eaec2e2878772b66d9f Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 19 Dec 2022 17:13:50 +0100 Subject: [PATCH] fix the search when no results were found --- .../ui/fragments/SearchResultFragment.kt | 15 ++- .../res/layout/fragment_search_result.xml | 124 +++++++++--------- 2 files changed, 67 insertions(+), 72 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt index 91eed4f95..b36382665 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt @@ -18,8 +18,8 @@ import com.github.libretube.extensions.hideKeyboard import com.github.libretube.ui.adapters.SearchAdapter import com.github.libretube.ui.base.BaseFragment import com.github.libretube.util.PreferenceHelper -import java.io.IOException import retrofit2.HttpException +import java.io.IOException class SearchResultFragment : BaseFragment() { private lateinit var binding: FragmentSearchResultBinding @@ -47,6 +47,8 @@ class SearchResultFragment : BaseFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + binding.searchRecycler.layoutManager = LinearLayoutManager(requireContext()) + // add the query to the history addToHistory(query) @@ -92,13 +94,12 @@ class SearchResultFragment : BaseFragment() { return@launchWhenCreated } runOnUiThread { - if (response.items?.isNotEmpty() == true) { - binding.searchRecycler.layoutManager = LinearLayoutManager(requireContext()) - searchAdapter = SearchAdapter(response.items) - binding.searchRecycler.adapter = searchAdapter + searchAdapter = SearchAdapter(response.items.orEmpty().toMutableList()) + binding.searchRecycler.adapter = searchAdapter + binding.noSearchResult.visibility = if (response.items.orEmpty().isEmpty()) { + View.VISIBLE } else { - binding.searchContainer.visibility = View.GONE - binding.noSearchResult.visibility = View.VISIBLE + View.GONE } } nextPage = response.nextpage diff --git a/app/src/main/res/layout/fragment_search_result.xml b/app/src/main/res/layout/fragment_search_result.xml index 85aa8028b..536b4714f 100644 --- a/app/src/main/res/layout/fragment_search_result.xml +++ b/app/src/main/res/layout/fragment_search_result.xml @@ -1,5 +1,5 @@ - - + android:paddingHorizontal="10dp" + android:scrollbars="none" + app:layout_constraintBottom_toTopOf="@id/recycler_view" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> - + app:checkedChip="@id/chip_all" + app:selectionRequired="true" + app:singleLine="true" + app:singleSelection="true"> - + - + - + - + - + - + - + - + + + - - - - - - - + @@ -108,4 +102,4 @@ - \ No newline at end of file + \ No newline at end of file