0
0
mirror of https://github.com/mediathekview/zapp.git synced 2024-09-20 04:12:14 +02:00

Merge branch 'bugfix/global-scope-crashes' into develop-next

This commit is contained in:
Christine Coenen 2022-02-08 19:46:42 +01:00
commit 2f33877960
10 changed files with 40 additions and 30 deletions

View File

@ -22,6 +22,7 @@ import de.christinecoenen.code.zapp.persistence.Database
import de.christinecoenen.code.zapp.repositories.ChannelRepository
import de.christinecoenen.code.zapp.repositories.MediathekRepository
import de.christinecoenen.code.zapp.utils.api.UserAgentInterceptor
import kotlinx.coroutines.MainScope
import okhttp3.OkHttpClient
import org.koin.android.ext.koin.androidApplication
import org.koin.android.ext.koin.androidContext
@ -40,11 +41,13 @@ class KoinModules {
.build()
}
single { ChannelRepository(androidContext(), get()) }
single { MainScope() }
single { ChannelRepository(androidContext(), get(), get()) }
single { Database.getInstance(androidContext()) }
single { MediathekRepository(get()) }
single { PersistedPlaybackPositionRepository(get()) } bind IPlaybackPositionRepository::class
single { DownloadController(androidContext(), get()) } bind IDownloadController::class
single { DownloadController(androidContext(), get(), get()) } bind IDownloadController::class
single {
ZappBackendApiServiceFactory(androidContext(), get()).create()
} bind IZappBackendApiService::class

View File

@ -34,7 +34,7 @@ class DownloadsFragment : Fragment(), DownloadListAdapter.Listener {
): View {
_binding = DownloadsFragmentBinding.inflate(inflater, container, false)
downloadAdapter = DownloadListAdapter(this, viewModel)
downloadAdapter = DownloadListAdapter(lifecycleScope, this, viewModel)
binding.list.adapter = downloadAdapter
downloadAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {

View File

@ -2,16 +2,17 @@ package de.christinecoenen.code.zapp.app.downloads.ui.list.adapter
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.paging.PagingDataAdapter
import de.christinecoenen.code.zapp.app.downloads.ui.list.DownloadsViewModel
import de.christinecoenen.code.zapp.databinding.DownloadsFragmentListItemBinding
import de.christinecoenen.code.zapp.models.shows.PersistedMediathekShow
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
class DownloadListAdapter(
private val scope: LifecycleCoroutineScope,
private val listener: Listener,
private val downloadsViewModel: DownloadsViewModel
) : PagingDataAdapter<PersistedMediathekShow, DownloadViewHolder>(DownloadDiffUtilCallback()) {
@ -34,7 +35,7 @@ class DownloadListAdapter(
getItem(position)?.let {
val showFlow = downloadsViewModel.getPersistedShow(it.id)
GlobalScope.launch(Dispatchers.Main) {
scope.launch(Dispatchers.Main) {
holder.bindItem(it, showFlow)
}
}

View File

@ -16,7 +16,7 @@ import de.christinecoenen.code.zapp.models.shows.DownloadStatus
import de.christinecoenen.code.zapp.models.shows.PersistedMediathekShow
import de.christinecoenen.code.zapp.models.shows.Quality
import de.christinecoenen.code.zapp.repositories.MediathekRepository
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import okhttp3.JavaNetCookieJar
@ -30,6 +30,7 @@ import kotlin.coroutines.suspendCoroutine
class DownloadController(
applicationContext: Context,
private val scope: CoroutineScope,
private val mediathekRepository: MediathekRepository
) : FetchListener, IDownloadController {
@ -56,7 +57,7 @@ class DownloadController(
val fetchConfiguration: FetchConfiguration = FetchConfiguration.Builder(applicationContext)
.setNotificationManager(object :
ZappNotificationManager(applicationContext, mediathekRepository) {
ZappNotificationManager(applicationContext, scope, mediathekRepository) {
override fun getFetchInstanceForNamespace(namespace: String): Fetch {
return fetch
}
@ -196,13 +197,13 @@ class DownloadController(
}
override fun onAdded(download: Download) {
GlobalScope.launch {
scope.launch {
updateDownloadStatus(download)
}
}
override fun onCancelled(download: Download) {
GlobalScope.launch {
scope.launch {
fetch.delete(download.id)
updateDownloadStatus(download)
updateDownloadProgress(download, 0)
@ -210,7 +211,7 @@ class DownloadController(
}
override fun onCompleted(download: Download) {
GlobalScope.launch {
scope.launch {
updateDownloadStatus(download)
mediathekRepository.updateDownloadedVideoPath(download.id, download.file)
downloadFileInfoManager.updateDownloadFileInMediaCollection(download)
@ -218,7 +219,7 @@ class DownloadController(
}
override fun onDeleted(download: Download) {
GlobalScope.launch {
scope.launch {
updateDownloadStatus(download)
updateDownloadProgress(download, 0)
downloadFileInfoManager.updateDownloadFileInMediaCollection(download)
@ -233,14 +234,14 @@ class DownloadController(
}
override fun onError(download: Download, error: Error, throwable: Throwable?) {
GlobalScope.launch {
scope.launch {
downloadFileInfoManager.deleteDownloadFile(download)
updateDownloadStatus(download)
}
}
override fun onPaused(download: Download) {
GlobalScope.launch {
scope.launch {
updateDownloadStatus(download)
}
}
@ -250,25 +251,25 @@ class DownloadController(
etaInMilliSeconds: Long,
downloadedBytesPerSecond: Long
) {
GlobalScope.launch {
scope.launch {
updateDownloadProgress(download, download.progress)
}
}
override fun onQueued(download: Download, waitingOnNetwork: Boolean) {
GlobalScope.launch {
scope.launch {
updateDownloadStatus(download)
}
}
override fun onRemoved(download: Download) {
GlobalScope.launch {
scope.launch {
updateDownloadStatus(download)
}
}
override fun onResumed(download: Download) {
GlobalScope.launch {
scope.launch {
updateDownloadStatus(download)
}
}
@ -278,13 +279,13 @@ class DownloadController(
downloadBlocks: List<DownloadBlock>,
totalBlocks: Int
) {
GlobalScope.launch {
scope.launch {
updateDownloadStatus(download)
}
}
override fun onWaitingNetwork(download: Download) {
GlobalScope.launch {
scope.launch {
updateDownloadStatus(download)
}
}

View File

@ -17,7 +17,7 @@ import de.christinecoenen.code.zapp.app.mediathek.controller.DownloadReceiver
import de.christinecoenen.code.zapp.models.shows.PersistedMediathekShow
import de.christinecoenen.code.zapp.repositories.MediathekRepository
import de.christinecoenen.code.zapp.utils.system.NotificationHelper
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
@ -25,6 +25,7 @@ const val ACTION_TYPE_REPORT_ERROR = 42
abstract class ZappNotificationManager(
context: Context,
private val scope: CoroutineScope,
private val mediathekRepository: MediathekRepository
) : FetchNotificationManager {
@ -346,7 +347,7 @@ abstract class ZappNotificationManager(
@SuppressLint("CheckResult")
override fun postDownloadUpdate(download: Download): Boolean {
GlobalScope.launch {
scope.launch {
val persistedShow = mediathekRepository
.getPersistedShowByDownloadId(download.id)
.first()

View File

@ -99,7 +99,8 @@ class MediathekListFragment : Fragment(), ListItemListener, OnRefreshListener {
viewmodel.isFilterApplied.observe(viewLifecycleOwner) { onIsFilterAppliedChanged() }
adapter = MediathekItemAdapter(MediathekShowComparator, this@MediathekListFragment)
adapter = MediathekItemAdapter(lifecycleScope, MediathekShowComparator, this@MediathekListFragment)
binding.list.adapter = adapter.withLoadStateFooter(FooterLoadStateAdapter(adapter::retry))

View File

@ -2,14 +2,16 @@ package de.christinecoenen.code.zapp.app.mediathek.ui.list.adapter
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import de.christinecoenen.code.zapp.databinding.FragmentMediathekListItemBinding
import de.christinecoenen.code.zapp.models.shows.MediathekShow
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class MediathekItemAdapter(
private val scope: LifecycleCoroutineScope,
diffCallback: DiffUtil.ItemCallback<MediathekShow>,
private val listener: ListItemListener?
) :
@ -24,7 +26,7 @@ class MediathekItemAdapter(
override fun onBindViewHolder(holder: MediathekItemViewHolder, position: Int) {
val show = getItem(position) ?: throw RuntimeException("null show not supported")
GlobalScope.launch {
scope.launch(Dispatchers.Main) {
holder.itemView.setOnClickListener { listener?.onShowClicked(show) }
holder.itemView.setOnLongClickListener { view ->

View File

@ -18,8 +18,6 @@ import com.google.android.exoplayer2.ui.PlayerNotificationManager.BitmapCallback
import com.google.android.exoplayer2.ui.PlayerNotificationManager.MediaDescriptionAdapter
import de.christinecoenen.code.zapp.R
import de.christinecoenen.code.zapp.utils.system.NotificationHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
@ -113,12 +111,13 @@ class BackgroundPlayerService : IntentService("BackgroundPlayerService"),
override fun onDestroy() {
movePlaybackToForeground()
GlobalScope.launch(Dispatchers.Main) {
lifecycleScope.launch {
player.destroy()
playerNotificationManager?.setPlayer(null)
lifecycleDispatcher.onServicePreSuperOnDestroy()
}
lifecycleDispatcher.onServicePreSuperOnDestroy()
super.onDestroy()
}

View File

@ -10,8 +10,8 @@ import de.christinecoenen.code.zapp.models.channels.ISortableChannelList
import de.christinecoenen.code.zapp.models.channels.json.SortableVisibleJsonChannelList
import de.christinecoenen.code.zapp.utils.io.IoUtils.readAllText
import de.christinecoenen.code.zapp.utils.io.IoUtils.writeAllText
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import timber.log.Timber
import java.io.IOException
@ -19,6 +19,7 @@ import java.io.IOException
@SuppressLint("CheckResult")
class ChannelRepository(
private val context: Context,
scope: CoroutineScope,
private val zappApi: IZappBackendApiService
) {
@ -94,7 +95,7 @@ class ChannelRepository(
init {
channelList = SortableVisibleJsonChannelList(context)
GlobalScope.launch(Dispatchers.IO) {
scope.launch(Dispatchers.IO) {
try {
// load fresh urls from api

View File

@ -2,6 +2,7 @@
* Video-Player-Interface verschwindet schneller automatisch
* Abspielfehler bei manchen Mediathek-Sendungen behoben
* Deaktivierter Download-Button bei manchen Mediathek-Sendungen behoben
* App-Absturz in der Mediathek-Liste behoben
# 6.0.1
* Absturz nach dem Bearbeiten der Senderliste behoben