Address more coroutine scope leaks

This commit is contained in:
arkon
2021-01-07 18:15:57 -05:00
parent 36f81b4a62
commit 6fb7a85e8a
23 changed files with 85 additions and 83 deletions
@@ -9,9 +9,6 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.MangaChaptersHeaderBinding
import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.util.system.getResourceColor
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onEach
@@ -25,7 +22,6 @@ class MangaChaptersHeaderAdapter(
private var numChapters: Int? = null
private var hasActiveFilters: Boolean = false
private val scope = CoroutineScope(Job() + Dispatchers.Main)
private lateinit var binding: MangaChaptersHeaderBinding
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HeaderViewHolder {
@@ -68,7 +64,7 @@ class MangaChaptersHeaderAdapter(
merge(view.clicks(), binding.btnChaptersFilter.clicks())
.onEach { controller.showSettingsSheet() }
.launchIn(scope)
.launchIn(controller.viewScope)
}
}
}
@@ -23,9 +23,6 @@ import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.util.system.copyToClipboard
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.view.setChips
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onEach
@@ -47,7 +44,6 @@ class MangaInfoHeaderAdapter(
private var source: Source = controller.presenter.source
private var trackCount: Int = 0
private val scope = CoroutineScope(Job() + Dispatchers.Main)
private lateinit var binding: MangaInfoHeaderBinding
private var initialLoad: Boolean = true
@@ -90,12 +86,12 @@ class MangaInfoHeaderAdapter(
binding.btnFavorite.clicks()
.onEach { controller.onFavoriteClick() }
.launchIn(scope)
.launchIn(controller.viewScope)
if (controller.presenter.manga.favorite && controller.presenter.getCategories().isNotEmpty()) {
binding.btnFavorite.longClicks()
.onEach { controller.onCategoriesClick() }
.launchIn(scope)
.launchIn(controller.viewScope)
}
with(binding.btnTracking) {
@@ -118,7 +114,7 @@ class MangaInfoHeaderAdapter(
clicks()
.onEach { controller.onTrackingClick() }
.launchIn(scope)
.launchIn(controller.viewScope)
} else {
isVisible = false
}
@@ -128,7 +124,7 @@ class MangaInfoHeaderAdapter(
binding.btnWebview.isVisible = true
binding.btnWebview.clicks()
.onEach { controller.openMangaInWebView() }
.launchIn(scope)
.launchIn(controller.viewScope)
}
binding.mangaFullTitle.longClicks()
@@ -138,13 +134,13 @@ class MangaInfoHeaderAdapter(
binding.mangaFullTitle.text.toString()
)
}
.launchIn(scope)
.launchIn(controller.viewScope)
binding.mangaFullTitle.clicks()
.onEach {
controller.performGlobalSearch(binding.mangaFullTitle.text.toString())
}
.launchIn(scope)
.launchIn(controller.viewScope)
binding.mangaAuthor.longClicks()
.onEach {
@@ -153,13 +149,13 @@ class MangaInfoHeaderAdapter(
binding.mangaAuthor.text.toString()
)
}
.launchIn(scope)
.launchIn(controller.viewScope)
binding.mangaAuthor.clicks()
.onEach {
controller.performGlobalSearch(binding.mangaAuthor.text.toString())
}
.launchIn(scope)
.launchIn(controller.viewScope)
binding.mangaArtist.longClicks()
.onEach {
@@ -168,13 +164,13 @@ class MangaInfoHeaderAdapter(
binding.mangaArtist.text.toString()
)
}
.launchIn(scope)
.launchIn(controller.viewScope)
binding.mangaArtist.clicks()
.onEach {
controller.performGlobalSearch(binding.mangaArtist.text.toString())
}
.launchIn(scope)
.launchIn(controller.viewScope)
binding.mangaSummaryText.longClicks()
.onEach {
@@ -183,7 +179,7 @@ class MangaInfoHeaderAdapter(
binding.mangaSummaryText.text.toString()
)
}
.launchIn(scope)
.launchIn(controller.viewScope)
binding.mangaCover.longClicks()
.onEach {
@@ -192,7 +188,7 @@ class MangaInfoHeaderAdapter(
controller.presenter.manga.title
)
}
.launchIn(scope)
.launchIn(controller.viewScope)
setMangaInfo(manga, source)
}
@@ -300,7 +296,7 @@ class MangaInfoHeaderAdapter(
binding.mangaInfoToggleLess.clicks()
)
.onEach { toggleMangaInfo() }
.launchIn(scope)
.launchIn(controller.viewScope)
// Expand manga info if navigated from source listing
if (initialLoad && fromSource) {