mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
toast when instance unreachable
This commit is contained in:
parent
efd95d95c3
commit
7c0b99f333
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 -> {
|
||||
|
Loading…
Reference in New Issue
Block a user