mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-14 05:05:06 +01:00
Manga details tracking renaming + async
When refreshing tracking, all tracked services will be called async
This commit is contained in:
parent
4503d408df
commit
e69b51accb
@ -457,7 +457,7 @@ class MangaDetailsController : BaseController,
|
|||||||
presenter.fetchChapters(refreshTracker == null)
|
presenter.fetchChapters(refreshTracker == null)
|
||||||
if (refreshTracker != null) {
|
if (refreshTracker != null) {
|
||||||
trackingBottomSheet?.refreshItem(refreshTracker ?: 0)
|
trackingBottomSheet?.refreshItem(refreshTracker ?: 0)
|
||||||
presenter.refreshTrackers()
|
presenter.refreshTracking()
|
||||||
refreshTracker = null
|
refreshTracker = null
|
||||||
}
|
}
|
||||||
val isCurrentController = router?.backstack?.lastOrNull()?.controller() ==
|
val isCurrentController = router?.backstack?.lastOrNull()?.controller() ==
|
||||||
@ -839,7 +839,7 @@ class MangaDetailsController : BaseController,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
R.id.action_open_in_web_view -> openInWebView()
|
R.id.action_open_in_web_view -> openInWebView()
|
||||||
R.id.action_refresh_tracking -> presenter.refreshTrackers(true)
|
R.id.action_refresh_tracking -> presenter.refreshTracking(true)
|
||||||
R.id.action_migrate ->
|
R.id.action_migrate ->
|
||||||
if (!isNotOnline()) {
|
if (!isNotOnline()) {
|
||||||
PreMigrationController.navigateToMigration(
|
PreMigrationController.navigateToMigration(
|
||||||
|
@ -37,6 +37,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.awaitAll
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@ -92,8 +93,8 @@ class MangaDetailsPresenter(
|
|||||||
updateChapters()
|
updateChapters()
|
||||||
controller.updateChapters(this.chapters)
|
controller.updateChapters(this.chapters)
|
||||||
}
|
}
|
||||||
fetchTrackings()
|
setTrackItems()
|
||||||
refreshTrackers(false)
|
refreshTracking(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDestroy() {
|
fun onDestroy() {
|
||||||
@ -108,7 +109,7 @@ class MangaDetailsPresenter(
|
|||||||
fun fetchChapters(andTracking: Boolean = true) {
|
fun fetchChapters(andTracking: Boolean = true) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
getChapters()
|
getChapters()
|
||||||
if (andTracking) refreshTracking()
|
if (andTracking) fetchTracks()
|
||||||
withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
|
withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -749,7 +750,7 @@ class MangaDetailsPresenter(
|
|||||||
fun hasTrackers(): Boolean = loggedServices.isNotEmpty()
|
fun hasTrackers(): Boolean = loggedServices.isNotEmpty()
|
||||||
|
|
||||||
// Tracking
|
// Tracking
|
||||||
private fun fetchTrackings() {
|
private fun setTrackItems() {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
trackList = loggedServices.map { service ->
|
trackList = loggedServices.map { service ->
|
||||||
TrackItem(tracks.find { it.sync_id == service.id }, service)
|
TrackItem(tracks.find { it.sync_id == service.id }, service)
|
||||||
@ -757,7 +758,7 @@ class MangaDetailsPresenter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun refreshTracking() {
|
private suspend fun fetchTracks() {
|
||||||
tracks = withContext(Dispatchers.IO) { db.getTracks(manga).executeAsBlocking() }
|
tracks = withContext(Dispatchers.IO) { db.getTracks(manga).executeAsBlocking() }
|
||||||
trackList = loggedServices.map { service ->
|
trackList = loggedServices.map { service ->
|
||||||
TrackItem(tracks.find { it.sync_id == service.id }, service)
|
TrackItem(tracks.find { it.sync_id == service.id }, service)
|
||||||
@ -765,11 +766,11 @@ class MangaDetailsPresenter(
|
|||||||
withContext(Dispatchers.Main) { controller.refreshTracking(trackList) }
|
withContext(Dispatchers.Main) { controller.refreshTracking(trackList) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun refreshTrackers(showOfflineSnack: Boolean = false) {
|
fun refreshTracking(showOfflineSnack: Boolean = false) {
|
||||||
if (controller.isNotOnline(showOfflineSnack)) {
|
if (!controller.isNotOnline(showOfflineSnack)) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
trackList.filter { it.track != null }.map { item ->
|
val asyncList = trackList.filter { it.track != null }.map { item ->
|
||||||
withContext(Dispatchers.IO) {
|
async(Dispatchers.IO) {
|
||||||
val trackItem = try {
|
val trackItem = try {
|
||||||
item.service.refresh(item.track!!)
|
item.service.refresh(item.track!!)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -782,7 +783,8 @@ class MangaDetailsPresenter(
|
|||||||
} else item.track
|
} else item.track
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
refreshTracking()
|
asyncList.awaitAll()
|
||||||
|
fetchTracks()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -817,14 +819,14 @@ class MangaDetailsPresenter(
|
|||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (binding != null) db.insertTrack(binding).executeAsBlocking()
|
if (binding != null) db.insertTrack(binding).executeAsBlocking()
|
||||||
}
|
}
|
||||||
refreshTracking()
|
fetchTracks()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
db.deleteTrackForManga(manga, service).executeAsBlocking()
|
db.deleteTrackForManga(manga, service).executeAsBlocking()
|
||||||
}
|
}
|
||||||
refreshTracking()
|
fetchTracks()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -839,7 +841,7 @@ class MangaDetailsPresenter(
|
|||||||
}
|
}
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
withContext(Dispatchers.IO) { db.insertTrack(binding).executeAsBlocking() }
|
withContext(Dispatchers.IO) { db.insertTrack(binding).executeAsBlocking() }
|
||||||
refreshTracking()
|
fetchTracks()
|
||||||
} else trackRefreshDone()
|
} else trackRefreshDone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user