fix http 400

This commit is contained in:
Bnyro 2022-11-19 10:58:51 +01:00
parent 7211143398
commit 48564ed3c6
2 changed files with 10 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package com.github.libretube.ui.fragments package com.github.libretube.ui.fragments
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -60,16 +61,16 @@ class HomeFragment : BaseFragment() {
binding.refresh.setOnRefreshListener { binding.refresh.setOnRefreshListener {
binding.refresh.isRefreshing = true binding.refresh.isRefreshing = true
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
fetchHome(LocaleHelper.getTrendingRegion(requireContext())) fetchHome()
} }
} }
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
fetchHome(LocaleHelper.getTrendingRegion(requireContext())) fetchHome()
} }
} }
private suspend fun fetchHome(trendingRegion: String) { private suspend fun fetchHome() {
val token = PreferenceHelper.getToken() val token = PreferenceHelper.getToken()
runOrError { runOrError {
val feed = SubscriptionHelper.getFeed().withMaxSize(20) val feed = SubscriptionHelper.getFeed().withMaxSize(20)
@ -86,7 +87,9 @@ class HomeFragment : BaseFragment() {
} }
runOrError { runOrError {
val trending = RetrofitInstance.api.getTrending(trendingRegion).withMaxSize(10) val trending = RetrofitInstance.api.getTrending(
LocaleHelper.getTrendingRegion(requireContext())
).withMaxSize(10)
if (trending.isEmpty()) return@runOrError if (trending.isEmpty()) return@runOrError
runOnUiThread { runOnUiThread {
makeVisible(binding.trendingRV, binding.trendingTV) makeVisible(binding.trendingRV, binding.trendingTV)
@ -100,6 +103,7 @@ class HomeFragment : BaseFragment() {
} }
runOrError { runOrError {
if (token == "") return@runOrError
val playlists = RetrofitInstance.authApi.getUserPlaylists(token).withMaxSize(20) val playlists = RetrofitInstance.authApi.getUserPlaylists(token).withMaxSize(20)
if (playlists.isEmpty()) return@runOrError if (playlists.isEmpty()) return@runOrError
runOnUiThread { runOnUiThread {
@ -141,6 +145,7 @@ class HomeFragment : BaseFragment() {
action.invoke() action.invoke()
} catch (e: Exception) { } catch (e: Exception) {
e.localizedMessage?.let { context?.toastFromMainThread(it) } e.localizedMessage?.let { context?.toastFromMainThread(it) }
Log.e("fetching home tab", e.toString())
} }
} }
} }

View File

@ -61,7 +61,7 @@
<PreferenceCategory app:title="@string/bookmarks"> <PreferenceCategory app:title="@string/bookmarks">
<PreferenceCategory <Preference
android:title="@string/clear_bookmarks" android:title="@string/clear_bookmarks"
app:icon="@drawable/ic_bookmark" app:icon="@drawable/ic_bookmark"
app:key="clear_bookmarks" /> app:key="clear_bookmarks" />