Skip to content

Commit

Permalink
Merge pull request #3639 from Bnyro/master
Browse files Browse the repository at this point in the history
Fix various crashes caused by view bindings
  • Loading branch information
Bnyro authored Apr 27, 2023
2 parents 32d9abc + 7c08838 commit d7a8d9b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -240,6 +242,7 @@ class ChannelFragment : Fragment() {
} catch (e: Exception) {
return@launch
}
val binding = _binding ?: return@launch

val adapter = SearchAdapter()
binding.channelRecView.adapter = adapter
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d7a8d9b

Please sign in to comment.