fix the search when no results were found

This commit is contained in:
Bnyro 2022-12-19 17:13:50 +01:00
parent 8345269179
commit 785180c64f
2 changed files with 67 additions and 72 deletions

View File

@ -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)
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

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -7,12 +7,6 @@
android:orientation="vertical"
tools:context=".ui.fragments.SearchFragment">
<LinearLayout
android:id="@+id/search_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<HorizontalScrollView
android:id="@+id/filter_bar"
android:layout_width="match_parent"
@ -81,13 +75,13 @@
android:layout_height="wrap_content"
android:layout_marginVertical="10dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/no_search_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:paddingTop="150dp"
android:orientation="vertical"
android:visibility="gone">
@ -108,4 +102,4 @@
</LinearLayout>
</FrameLayout>
</LinearLayout>