Merge pull request #1298 from Bnyro/master

toast when instance unreachable
This commit is contained in:
Bnyro 2022-09-15 15:42:43 +02:00 committed by GitHub
commit 886c60c598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.GridLayoutManager
@ -51,6 +52,11 @@ class SubscriptionsFragment : BaseFragment() {
if (viewModel.videoFeed.value == null) viewModel.fetchFeed()
// listen for error responses
viewModel.errorResponse.observe(viewLifecycleOwner) {
if (it) Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show()
}
viewModel.videoFeed.observe(viewLifecycleOwner) {
if (!isShowingFeed()) return@observe
if (it == null) return@observe

View File

@ -13,10 +13,12 @@ import com.github.libretube.util.PreferenceHelper
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import retrofit2.HttpException
import java.io.IOException
class SubscriptionsViewModel : ViewModel() {
var errorResponse = MutableLiveData<Boolean>().apply {
value = false
}
var videoFeed = MutableLiveData<List<StreamItem>?>().apply {
value = null
}
@ -37,12 +39,9 @@ class SubscriptionsViewModel : ViewModel() {
SubscriptionHelper.getFormattedLocalSubscriptions()
)
}
} catch (e: IOException) {
} catch (e: Exception) {
errorResponse.postValue(true)
Log.e(TAG(), e.toString())
Log.e(TAG(), "IOException, you might not have internet connection")
return@launch
} catch (e: HttpException) {
Log.e(TAG(), "HttpException, unexpected response")
return@launch
}
this@SubscriptionsViewModel.videoFeed.postValue(videoFeed)
@ -65,12 +64,9 @@ class SubscriptionsViewModel : ViewModel() {
SubscriptionHelper.getFormattedLocalSubscriptions()
)
}
} catch (e: IOException) {
} catch (e: Exception) {
errorResponse.postValue(true)
Log.e(TAG(), e.toString())
Log.e(TAG(), "IOException, you might not have internet connection")
return@launch
} catch (e: HttpException) {
Log.e(TAG(), "HttpException, unexpected response")
return@launch
}
this@SubscriptionsViewModel.subscriptions.postValue(subscriptions)

View File

@ -201,7 +201,7 @@ class BackgroundMode : Service() {
* Listens for changed playbackStates (e.g. pause, end)
* Plays the next video when the current one ended
*/
player!!.addListener(object : Player.Listener {
player?.addListener(object : Player.Listener {
override fun onPlaybackStateChanged(@Player.State state: Int) {
when (state) {
Player.STATE_ENDED -> {