From ead1999b99250c5115f00b83d7b5de0b6df65937 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 13:47:24 +0200 Subject: [PATCH] Fixed Search Items repeating lol --- .../main/java/com/github/libretube/SearchFragment.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index ff35ce9cb..2bf76c3ed 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -27,6 +27,7 @@ import com.github.libretube.adapters.SearchHistoryAdapter import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import org.chromium.base.ThreadUtils.runOnUiThread import retrofit2.HttpException import java.io.IOException @@ -37,6 +38,7 @@ class SearchFragment : Fragment() { private var nextPage : String? = null private lateinit var searchRecView : RecyclerView private var searchAdapter : SearchAdapter? = null + private var isLoading : Boolean = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -207,8 +209,14 @@ class SearchFragment : Fragment() { private fun fetchNextSearchItems(query: String){ lifecycleScope.launchWhenCreated { + if (!isLoading) { + isLoading = true val response = try { - RetrofitInstance.api.getSearchResultsNextPage(query!!, apiSearchFilter, nextPage!!) + RetrofitInstance.api.getSearchResultsNextPage( + query!!, + apiSearchFilter, + nextPage!! + ) } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection") @@ -219,8 +227,10 @@ class SearchFragment : Fragment() { } nextPage = response.nextpage searchAdapter?.updateItems(response.items!!) + isLoading = false } } + } private fun Fragment?.runOnUiThread(action: () -> Unit) { this ?: return