Fix various crashes caused by view bindings

This commit is contained in:
Bnyro 2023-04-27 09:03:53 +02:00
parent 32d9abc5a7
commit 7c08838d1c
5 changed files with 18 additions and 9 deletions

View File

@ -118,14 +118,16 @@ class ChannelFragment : Fragment() {
}
}
} catch (e: IOException) {
binding.channelRefresh.isRefreshing = false
_binding?.channelRefresh?.isRefreshing = false
Log.e(TAG(), "IOException, you might not have internet connection")
return@repeatOnLifecycle
} catch (e: HttpException) {
binding.channelRefresh.isRefreshing = false
_binding?.channelRefresh?.isRefreshing = false
Log.e(TAG(), "HttpException, unexpected response")
return@repeatOnLifecycle
}
val binding = _binding ?: return@repeatOnLifecycle
// needed if the channel gets loaded by the ID
channelId = response.id
channelName = response.name
@ -240,6 +242,7 @@ class ChannelFragment : Fragment() {
} catch (e: Exception) {
return@launch
}
val binding = _binding ?: return@launch
val adapter = SearchAdapter()
binding.channelRecView.adapter = adapter
@ -268,14 +271,16 @@ class ChannelFragment : Fragment() {
RetrofitInstance.api.getChannelNextPage(channelId!!, nextPage!!)
}
} catch (e: IOException) {
binding.channelRefresh.isRefreshing = false
_binding?.channelRefresh?.isRefreshing = false
Log.e(TAG(), "IOException, you might not have internet connection")
return@repeatOnLifecycle
} catch (e: HttpException) {
binding.channelRefresh.isRefreshing = false
_binding?.channelRefresh?.isRefreshing = false
Log.e(TAG(), "HttpException, unexpected response," + e.response())
return@repeatOnLifecycle
}
val binding = _binding ?: return@repeatOnLifecycle
nextPage = response.nextpage
channelAdapter?.insertItems(response.relatedStreams)
isLoading = false

View File

@ -125,7 +125,7 @@ class LibraryFragment : Fragment() {
}
private fun fetchPlaylists() {
binding.playlistRefresh.isRefreshing = true
_binding?.playlistRefresh?.isRefreshing = true
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.CREATED) {
var playlists = try {

View File

@ -110,6 +110,10 @@ import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.upstream.DefaultDataSource
import com.google.android.exoplayer2.util.MimeTypes
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.io.IOException
import java.util.*
import java.util.concurrent.Executors
import kotlin.math.abs
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -118,10 +122,6 @@ import kotlinx.coroutines.withContext
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import retrofit2.HttpException
import java.io.IOException
import java.util.*
import java.util.concurrent.Executors
import kotlin.math.abs
class PlayerFragment : Fragment(), OnlinePlayerOptions {
private var _binding: FragmentPlayerBinding? = null

View File

@ -121,6 +121,8 @@ class PlaylistFragment : Fragment() {
Log.e(TAG(), e.toString())
return@repeatOnLifecycle
}
val binding = _binding ?: return@repeatOnLifecycle
playlistFeed = response.relatedStreams.toMutableList()
binding.playlistScrollview.visibility = View.VISIBLE
nextPage = response.nextpage

View File

@ -104,6 +104,8 @@ class SearchResultFragment : Fragment() {
Log.e(TAG(), "HttpException, unexpected response")
return@repeatOnLifecycle
}
val binding = _binding ?: return@repeatOnLifecycle
searchAdapter = SearchAdapter()
binding.searchRecycler.adapter = searchAdapter
searchAdapter.submitList(response.items)