diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/animelib/AnimelibUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/animelib/AnimelibUpdateService.kt index 94c1210bc..312692883 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/animelib/AnimelibUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/animelib/AnimelibUpdateService.kt @@ -21,12 +21,14 @@ import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.TrackManager +import eu.kanade.tachiyomi.data.track.UnattendedTrackService import eu.kanade.tachiyomi.source.AnimeSourceManager import eu.kanade.tachiyomi.source.model.SAnime import eu.kanade.tachiyomi.source.model.toSAnime import eu.kanade.tachiyomi.source.model.toSEpisode import eu.kanade.tachiyomi.util.episode.NoEpisodesException import eu.kanade.tachiyomi.util.episode.syncEpisodesWithSource +import eu.kanade.tachiyomi.util.episode.syncEpisodesWithTrackServiceTwoWay import eu.kanade.tachiyomi.util.prepUpdateCover import eu.kanade.tachiyomi.util.shouldDownloadNewEpisodes import eu.kanade.tachiyomi.util.storage.getUriCompat @@ -413,8 +415,12 @@ class AnimelibUpdateService( val service = trackManager.getService(track.sync_id) if (service != null && service in loggedServices) { try { - val updatedTrack = service.refreshAnime(track) + val updatedTrack = service.refresh(track) db.insertTrack(updatedTrack).executeAsBlocking() + + if (service is UnattendedTrackService) { + syncEpisodesWithTrackServiceTwoWay(db, db.getEpisodes(anime).executeAsBlocking(), track, service) + } } catch (e: Throwable) { // Ignore errors and continue Timber.e(e) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt index 2cfbc41b3..1b83650b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt @@ -52,15 +52,15 @@ abstract class TrackService(val id: Int) { abstract suspend fun add(track: Track): Track - abstract suspend fun addAnime(track: AnimeTrack): AnimeTrack + abstract suspend fun add(track: AnimeTrack): AnimeTrack abstract suspend fun update(track: Track): Track - abstract suspend fun updateAnime(track: AnimeTrack): AnimeTrack + abstract suspend fun update(track: AnimeTrack): AnimeTrack abstract suspend fun bind(track: Track): Track - abstract suspend fun bindAnime(track: AnimeTrack): AnimeTrack + abstract suspend fun bind(track: AnimeTrack): AnimeTrack abstract suspend fun search(query: String): List @@ -68,7 +68,7 @@ abstract class TrackService(val id: Int) { abstract suspend fun refresh(track: Track): Track - abstract suspend fun refreshAnime(track: AnimeTrack): AnimeTrack + abstract suspend fun refresh(track: AnimeTrack): AnimeTrack abstract suspend fun login(username: String, password: String) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt index 9b8bcae61..db8f8fe27 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt @@ -155,7 +155,7 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { return api.addLibManga(track) } - override suspend fun addAnime(track: AnimeTrack): AnimeTrack { + override suspend fun add(track: AnimeTrack): AnimeTrack { return api.addLibAnime(track) } @@ -170,7 +170,7 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { return api.updateLibManga(track) } - override suspend fun updateAnime(track: AnimeTrack): AnimeTrack { + override suspend fun update(track: AnimeTrack): AnimeTrack { // If user was using API v1 fetch library_id if (track.library_id == null || track.library_id!! == 0L) { val libManga = api.findLibAnime(track, getUsername().toInt()) @@ -195,17 +195,17 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { } } - override suspend fun bindAnime(track: AnimeTrack): AnimeTrack { + override suspend fun bind(track: AnimeTrack): AnimeTrack { val remoteTrack = api.findLibAnime(track, getUsername().toInt()) return if (remoteTrack != null) { track.copyPersonalFrom(remoteTrack) track.library_id = remoteTrack.library_id - updateAnime(track) + update(track) } else { // Set default fields if it's not found in the list track.status = READING track.score = 0F - addAnime(track) + add(track) } } @@ -224,7 +224,7 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { return track } - override suspend fun refreshAnime(track: AnimeTrack): AnimeTrack { + override suspend fun refresh(track: AnimeTrack): AnimeTrack { val remoteTrack = api.getLibAnime(track, getUsername().toInt()) track.copyPersonalFrom(remoteTrack) track.total_episodes = remoteTrack.total_episodes diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt index 3cb95b89f..6dba7628b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt @@ -41,7 +41,7 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { return api.addLibManga(track) } - override suspend fun addAnime(track: AnimeTrack): AnimeTrack { + override suspend fun add(track: AnimeTrack): AnimeTrack { return api.addLibAnime(track) } @@ -49,7 +49,7 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { return api.updateLibManga(track) } - override suspend fun updateAnime(track: AnimeTrack): AnimeTrack { + override suspend fun update(track: AnimeTrack): AnimeTrack { return api.updateLibAnime(track) } @@ -73,7 +73,7 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { } } - override suspend fun bindAnime(track: AnimeTrack): AnimeTrack { + override suspend fun bind(track: AnimeTrack): AnimeTrack { val statusTrack = api.statusLibAnime(track) val remoteTrack = api.findLibAnime(track) return if (remoteTrack != null && statusTrack != null) { @@ -83,13 +83,13 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { track.score = statusTrack.score track.last_episode_seen = statusTrack.last_episode_seen track.total_episodes = remoteTrack.total_episodes - refreshAnime(track) + refresh(track) } else { // Set default fields if it's not found in the list track.status = READING track.score = 0F - addAnime(track) - updateAnime(track) + add(track) + update(track) } } @@ -110,7 +110,7 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { return track } - override suspend fun refreshAnime(track: AnimeTrack): AnimeTrack { + override suspend fun refresh(track: AnimeTrack): AnimeTrack { val remoteStatusTrack = api.statusLibAnime(track) track.copyPersonalFrom(remoteStatusTrack!!) api.findLibAnime(track)?.let { remoteTrack -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt index 20fe7e2eb..27780e4ce 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt @@ -78,7 +78,7 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { return api.addLibManga(track, getUserId()) } - override suspend fun addAnime(track: AnimeTrack): AnimeTrack { + override suspend fun add(track: AnimeTrack): AnimeTrack { return api.addLibAnime(track, getUserId()) } @@ -86,7 +86,7 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { return api.updateLibManga(track) } - override suspend fun updateAnime(track: AnimeTrack): AnimeTrack { + override suspend fun update(track: AnimeTrack): AnimeTrack { return api.updateLibAnime(track) } @@ -103,16 +103,16 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { } } - override suspend fun bindAnime(track: AnimeTrack): AnimeTrack { + override suspend fun bind(track: AnimeTrack): AnimeTrack { val remoteTrack = api.findLibAnime(track, getUserId()) return if (remoteTrack != null) { track.copyPersonalFrom(remoteTrack) track.media_id = remoteTrack.media_id - updateAnime(track) + update(track) } else { track.status = READING track.score = 0F - addAnime(track) + add(track) } } @@ -131,7 +131,7 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { return track } - override suspend fun refreshAnime(track: AnimeTrack): AnimeTrack { + override suspend fun refresh(track: AnimeTrack): AnimeTrack { val remoteTrack = api.getLibAnime(track) track.copyPersonalFrom(remoteTrack) track.total_episodes = remoteTrack.total_episodes diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt index 1886347cc..cb6cf140f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt @@ -62,19 +62,19 @@ class Komga(private val context: Context, id: Int) : TrackService(id), Unattende override suspend fun add(track: Track): Track = throw Exception("Not used") - override suspend fun addAnime(track: AnimeTrack): AnimeTrack = throw Exception("Not used") + override suspend fun add(track: AnimeTrack): AnimeTrack = throw Exception("Not used") override suspend fun update(track: Track): Track { return api.updateProgress(track) } - override suspend fun updateAnime(track: AnimeTrack): AnimeTrack = throw Exception("Not used") + override suspend fun update(track: AnimeTrack): AnimeTrack = throw Exception("Not used") override suspend fun bind(track: Track): Track { return track } - override suspend fun bindAnime(track: AnimeTrack): AnimeTrack = throw Exception("Not used") + override suspend fun bind(track: AnimeTrack): AnimeTrack = throw Exception("Not used") override suspend fun search(query: String): List = throw Exception("Not used") @@ -87,7 +87,7 @@ class Komga(private val context: Context, id: Int) : TrackService(id), Unattende return track } - override suspend fun refreshAnime(track: AnimeTrack): AnimeTrack { + override suspend fun refresh(track: AnimeTrack): AnimeTrack { TODO("Not yet implemented") } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt index 990989b2a..a4a4fcba9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt @@ -78,7 +78,7 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { return api.updateItem(track) } - override suspend fun addAnime(track: AnimeTrack): AnimeTrack { + override suspend fun add(track: AnimeTrack): AnimeTrack { track.status = READING track.score = 0F return api.updateItem(track) @@ -88,7 +88,7 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { return api.updateItem(track) } - override suspend fun updateAnime(track: AnimeTrack): AnimeTrack { + override suspend fun update(track: AnimeTrack): AnimeTrack { return api.updateItem(track) } @@ -103,14 +103,14 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { } } - override suspend fun bindAnime(track: AnimeTrack): AnimeTrack { + override suspend fun bind(track: AnimeTrack): AnimeTrack { val remoteTrack = api.findListItem(track) return if (remoteTrack != null) { track.copyPersonalFrom(remoteTrack) track.media_id = remoteTrack.media_id - updateAnime(track) + update(track) } else { - addAnime(track) + add(track) } } @@ -150,8 +150,8 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { return api.findListItem(track) ?: add(track) } - override suspend fun refreshAnime(track: AnimeTrack): AnimeTrack { - return api.findListItem(track) ?: addAnime(track) + override suspend fun refresh(track: AnimeTrack): AnimeTrack { + return api.findListItem(track) ?: add(track) } override suspend fun login(username: String, password: String) = login(password) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt index ea8a8a02b..9cc95ef66 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt @@ -50,7 +50,7 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { return api.addLibManga(track, getUsername()) } - override suspend fun addAnime(track: AnimeTrack): AnimeTrack { + override suspend fun add(track: AnimeTrack): AnimeTrack { return api.addLibAnime(track, getUsername()) } @@ -58,7 +58,7 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { return api.updateLibManga(track, getUsername()) } - override suspend fun updateAnime(track: AnimeTrack): AnimeTrack { + override suspend fun update(track: AnimeTrack): AnimeTrack { return api.updateLibAnime(track, getUsername()) } @@ -76,17 +76,17 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { } } - override suspend fun bindAnime(track: AnimeTrack): AnimeTrack { + override suspend fun bind(track: AnimeTrack): AnimeTrack { val remoteTrack = api.findLibAnime(track, getUsername()) return if (remoteTrack != null) { track.copyPersonalFrom(remoteTrack) track.library_id = remoteTrack.library_id - updateAnime(track) + update(track) } else { // Set default fields if it's not found in the list track.status = READING track.score = 0F - addAnime(track) + add(track) } } @@ -106,7 +106,7 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { return track } - override suspend fun refreshAnime(track: AnimeTrack): AnimeTrack { + override suspend fun refresh(track: AnimeTrack): AnimeTrack { api.findLibAnime(track, getUsername())?.let { remoteTrack -> track.copyPersonalFrom(remoteTrack) track.total_episodes = remoteTrack.total_episodes diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimeController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimeController.kt index 6e5e99230..319b4cfb6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimeController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimeController.kt @@ -36,6 +36,8 @@ import eu.kanade.tachiyomi.data.database.models.Episode import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.download.model.AnimeDownload import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.track.TrackService +import eu.kanade.tachiyomi.data.track.UnattendedTrackService import eu.kanade.tachiyomi.data.track.model.AnimeTrackSearch import eu.kanade.tachiyomi.databinding.AnimeControllerBinding import eu.kanade.tachiyomi.source.AnimeSource @@ -71,6 +73,7 @@ import eu.kanade.tachiyomi.ui.watcher.WatcherActivity import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.util.episode.NoEpisodesException import eu.kanade.tachiyomi.util.hasCustomCover +import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.toast @@ -504,6 +507,24 @@ class AnimeController : .showDialog(router) } } + + if (source != null && preferences.autoAddTrack()) { + presenter.trackList + .map { it.service } + .filterIsInstance() + .filter { it.accept(source!!) } + .forEach { service -> + launchIO { + try { + service.match(anime)?.let { track -> + presenter.registerTracking(track, service as TrackService) + } + } catch (e: Exception) { + Timber.w(e, "Could not match manga: ${anime.title} with service $service") + } + } + } + } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimePresenter.kt index f93cf6512..a5701af76 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimePresenter.kt @@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.data.download.model.AnimeDownload import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackService +import eu.kanade.tachiyomi.data.track.UnattendedTrackService import eu.kanade.tachiyomi.source.AnimeSource import eu.kanade.tachiyomi.source.LocalAnimeSource import eu.kanade.tachiyomi.source.model.toEpisodeInfo @@ -27,6 +28,7 @@ import eu.kanade.tachiyomi.ui.anime.track.TrackItem import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.episode.EpisodeSettingsHelper import eu.kanade.tachiyomi.util.episode.syncEpisodesWithSource +import eu.kanade.tachiyomi.util.episode.syncEpisodesWithTrackServiceTwoWay import eu.kanade.tachiyomi.util.isLocal import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.withUIContext @@ -752,8 +754,12 @@ class AnimePresenter( .filter { it.track != null } .map { async { - val track = it.service.refreshAnime(it.track!!) + val track = it.service.refresh(it.track!!) db.insertTrack(track).executeAsBlocking() + + if (it.service is UnattendedTrackService) { + syncEpisodesWithTrackServiceTwoWay(db, episodes, track, it.service) + } } } .awaitAll() @@ -783,7 +789,7 @@ class AnimePresenter( item.anime_id = anime.id!! launchIO { try { - service.bindAnime(item) + service.bind(item) db.insertTrack(item).executeAsBlocking() } catch (e: Throwable) { withUIContext { view?.applicationContext?.toast(e.message) } @@ -801,7 +807,7 @@ class AnimePresenter( private fun updateRemote(track: AnimeTrack, service: TrackService) { launchIO { try { - service.updateAnime(track) + service.update(track) db.insertTrack(track).executeAsBlocking() withUIContext { view?.onTrackingRefreshDone() } } catch (e: Throwable) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/track/TrackHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/track/TrackHolder.kt index 49ff6aaae..6c7ecb334 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/track/TrackHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/track/TrackHolder.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.anime.track import android.annotation.SuppressLint import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView +import eu.kanade.tachiyomi.R.string import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.TrackItemBinding import uy.kohesive.injekt.injectLazy @@ -49,6 +50,12 @@ class TrackHolder(private val binding: TrackItemBinding, adapter: TrackAdapter) if (track.total_episodes > 0) track.total_episodes else "-" binding.trackStatus.text = item.service.getStatus(track.status) binding.trackScore.text = if (track.score == 0f) "-" else item.service.displayScore(track) + if (item.service.getScoreList().isEmpty()) { + with(binding.trackScore) { + text = context.getString(string.score_unsupported) + isEnabled = false + } + } if (item.service.supportsReadingDates) { binding.trackStartDate.text = diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/track/TrackSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/track/TrackSheet.kt index f5aefb4b3..3b91f51a8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/track/TrackSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/track/TrackSheet.kt @@ -5,16 +5,25 @@ import android.view.LayoutInflater import android.view.View import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.bottomsheet.BottomSheetBehavior +import eu.kanade.tachiyomi.R.string import eu.kanade.tachiyomi.data.database.models.Anime +import eu.kanade.tachiyomi.data.track.UnattendedTrackService import eu.kanade.tachiyomi.databinding.TrackControllerBinding +import eu.kanade.tachiyomi.source.AnimeSourceManager import eu.kanade.tachiyomi.ui.anime.AnimeController import eu.kanade.tachiyomi.ui.base.controller.openInBrowser +import eu.kanade.tachiyomi.util.lang.launchIO +import eu.kanade.tachiyomi.util.lang.withUIContext import eu.kanade.tachiyomi.util.system.copyToClipboard +import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.widget.sheet.BaseBottomSheetDialog +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get class TrackSheet( val controller: AnimeController, - val anime: Anime + val anime: Anime, + private val sourceManager: AnimeSourceManager = Injekt.get() ) : BaseBottomSheetDialog(controller.activity!!), TrackAdapter.OnClickListener, SetTrackStatusDialog.Listener, @@ -41,15 +50,10 @@ class TrackSheet( adapter.items = controller.presenter.trackList } - override fun onStart() { - super.onStart() - sheetBehavior.skipCollapsed = true - } - override fun show() { super.show() controller.presenter.refreshTrackers() - sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED + sheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED } fun onNextTrackers(trackers: List) { @@ -69,7 +73,31 @@ class TrackSheet( override fun onSetClick(position: Int) { val item = adapter.getItem(position) ?: return - TrackSearchDialog(controller, item.service).showDialog(controller.router, TAG_SEARCH_CONTROLLER) + + if (item.service is UnattendedTrackService) { + if (item.track != null) { + controller.presenter.unregisterTracking(item.service) + return + } + + if (!item.service.accept(sourceManager.getOrStub(anime.source))) { + controller.presenter.view?.applicationContext?.toast(string.source_unsupported) + return + } + + launchIO { + try { + item.service.match(anime)?.let { track -> + controller.presenter.registerTracking(track, item.service) + } + ?: withUIContext { controller.presenter.view?.applicationContext?.toast(string.error_no_match) } + } catch (e: Exception) { + withUIContext { controller.presenter.view?.applicationContext?.toast(string.error_no_match) } + } + } + } else { + TrackSearchDialog(controller, item.service).showDialog(controller.router, TAG_SEARCH_CONTROLLER) + } } override fun onTitleLongClick(position: Int) { @@ -94,7 +122,7 @@ class TrackSheet( override fun onScoreClick(position: Int) { val item = adapter.getItem(position) ?: return - if (item.track == null) return + if (item.track == null || item.service.getScoreList().isEmpty()) return SetTrackScoreDialog(controller, this, item).showDialog(controller.router) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/browse/BrowseAnimeSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/browse/BrowseAnimeSourcePresenter.kt index 2a3fae808..1f7a822f4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/browse/BrowseAnimeSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/browse/BrowseAnimeSourcePresenter.kt @@ -9,6 +9,9 @@ import eu.kanade.tachiyomi.data.database.models.AnimeCategory import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.toAnimeInfo import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.track.TrackManager +import eu.kanade.tachiyomi.data.track.TrackService +import eu.kanade.tachiyomi.data.track.UnattendedTrackService import eu.kanade.tachiyomi.source.AnimeCatalogueSource import eu.kanade.tachiyomi.source.AnimeSourceManager import eu.kanade.tachiyomi.source.model.Filter @@ -30,6 +33,7 @@ import eu.kanade.tachiyomi.ui.browse.animesource.filter.TextSectionItem import eu.kanade.tachiyomi.ui.browse.animesource.filter.TriStateItem import eu.kanade.tachiyomi.ui.browse.animesource.filter.TriStateSectionItem import eu.kanade.tachiyomi.util.episode.EpisodeSettingsHelper +import eu.kanade.tachiyomi.util.episode.syncEpisodesWithTrackServiceTwoWay import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.withUIContext import eu.kanade.tachiyomi.util.removeCovers @@ -102,6 +106,8 @@ open class BrowseAnimeSourcePresenter( */ private var pageSubscription: Subscription? = null + private val loggedServices by lazy { Injekt.get().services.filter { it.isLogged } } + init { query = searchQuery ?: "" } @@ -260,11 +266,36 @@ open class BrowseAnimeSourcePresenter( anime.removeCovers(coverCache) } else { EpisodeSettingsHelper.applySettingDefaults(anime) + + if (prefs.autoAddTrack()) { + autoAddTrack(anime) + } } db.insertAnime(anime).executeAsBlocking() } + private fun autoAddTrack(anime: Anime) { + loggedServices + .filterIsInstance() + .filter { it.accept(source) } + .forEach { service -> + launchIO { + try { + service.match(anime)?.let { track -> + track.anime_id = anime.id!! + (service as TrackService).bind(track) + db.insertTrack(track).executeAsBlocking() + + syncEpisodesWithTrackServiceTwoWay(db, db.getEpisodes(anime).executeAsBlocking(), track, service as TrackService) + } + } catch (e: Exception) { + Timber.w(e, "Could not match anime: ${anime.title} with service $service") + } + } + } + } + /** * Set the filter states for the current source. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/episode/EpisodeTrackSync.kt b/app/src/main/java/eu/kanade/tachiyomi/util/episode/EpisodeTrackSync.kt index be02ab75f..b88ae811f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/episode/EpisodeTrackSync.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/episode/EpisodeTrackSync.kt @@ -33,7 +33,7 @@ fun syncEpisodesWithTrackServiceTwoWay(db: AnimeDatabaseHelper, episodes: List -======= android:pathData="M14.5,7L86.5,7A7,7 0,0 1,93.5 14L93.5,95A7,7 0,0 1,86.5 102L14.5,102A7,7 0,0 1,7.5 95L7.5,14A7,7 0,0 1,14.5 7z" /> ->>>>>>> pr17 -======= android:pathData="M7.5,12.01C7.5,9.24 9.74,7 12.5,7L17.5,7L17.5,102L12.5,102C9.74,102 7.5,99.77 7.5,96.99L7.5,12.01Z" /> ->>>>>>> pr17 >>>>>> pr17 android:fillType="evenOdd" - android:pathData="M52.04,46.3L47.42,46.3C46.14,46.3 44.93,46.23 44.2,46.14L44.2,49.76C45,49.65 46.16,49.6 47.42,49.6L60.58,49.6C61.86,49.6 63.02,49.65 63.82,49.76L63.82,46.14C63.09,46.23 61.86,46.3 60.58,46.3L55.69,46.3L55.69,45.07C55.69,44.43 55.73,43.95 55.82,43.45L51.9,43.45C51.99,44 52.04,44.43 52.04,45.07L52.04,46.3ZM46.78,60.68C45.46,60.68 44.29,60.63 43.45,60.52L43.45,64.14C44.34,64.03 45.46,63.98 46.78,63.98L61.29,63.98C62.57,63.98 63.71,64.03 64.57,64.14L64.57,60.52C63.73,60.63 62.57,60.68 61.29,60.68L58.24,60.68C59.33,58.06 59.99,56.23 60.7,53.91C61.34,51.81 61.34,51.81 61.56,51.13L57.58,50.06C57.51,50.93 57.37,51.52 56.89,53.41C56.19,56.14 55.32,58.74 54.5,60.68L46.78,60.68ZM46.48,51.36C47.55,54.02 48.28,56.53 49.03,60.15L52.66,58.9C51.65,54.98 50.92,52.66 49.94,50.11L46.48,51.36Z" /> + android:pathData="M47,41v28l22,-14z" /> diff --git a/app/src/main/res/layout/anime_episodes_header.xml b/app/src/main/res/layout/anime_episodes_header.xml index 2e2ea6ef8..881ff7ac2 100644 --- a/app/src/main/res/layout/anime_episodes_header.xml +++ b/app/src/main/res/layout/anime_episodes_header.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/selectableItemBackground" + android:background="@drawable/selectable_item_background" android:paddingStart="16dp" android:paddingTop="4dp" android:paddingEnd="12dp" @@ -28,7 +28,7 @@ android:id="@+id/btn_episodes_filter" android:layout_width="28dp" android:layout_height="28dp" - android:background="?selectableItemBackgroundBorderless" + android:background="@drawable/ripple_regular" android:contentDescription="@string/action_filter" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/main/res/layout/anime_history_controller.xml b/app/src/main/res/layout/anime_history_controller.xml index 13c41c4c2..d33aa20ed 100644 --- a/app/src/main/res/layout/anime_history_controller.xml +++ b/app/src/main/res/layout/anime_history_controller.xml @@ -11,6 +11,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:clipToPadding="false" + android:paddingTop="4dp" android:paddingBottom="@dimen/action_toolbar_list_padding" tools:listitem="@layout/history_item" /> diff --git a/app/src/main/res/layout/anime_history_item.xml b/app/src/main/res/layout/anime_history_item.xml index 3728fc6b7..c40a35462 100644 --- a/app/src/main/res/layout/anime_history_item.xml +++ b/app/src/main/res/layout/anime_history_item.xml @@ -56,7 +56,7 @@ android:id="@+id/remove" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="?selectableItemBackgroundBorderless" + android:background="@drawable/ripple_regular" android:contentDescription="@string/action_remove" android:padding="8dp" app:layout_constraintBottom_toBottomOf="parent" @@ -69,7 +69,7 @@ android:id="@+id/resume" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="?selectableItemBackgroundBorderless" + android:background="@drawable/ripple_regular" android:contentDescription="@string/action_resume" android:padding="8dp" app:layout_constraintBottom_toBottomOf="parent" diff --git a/app/src/main/res/layout/anime_info_header.xml b/app/src/main/res/layout/anime_info_header.xml index be19f383f..6ecc03a8a 100644 --- a/app/src/main/res/layout/anime_info_header.xml +++ b/app/src/main/res/layout/anime_info_header.xml @@ -142,7 +142,8 @@ app:icon="@drawable/ic_favorite_border_24dp" app:layout_constraintEnd_toStartOf="@+id/btn_tracking" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/anime_info" /> + app:layout_constraintTop_toBottomOf="@+id/anime_info" + app:rippleColor="?attr/rippleColor" /> diff --git a/app/src/main/res/layout/anime_source_filter_sheet.xml b/app/src/main/res/layout/anime_source_filter_sheet.xml index 2bef6300c..044075429 100644 --- a/app/src/main/res/layout/anime_source_filter_sheet.xml +++ b/app/src/main/res/layout/anime_source_filter_sheet.xml @@ -42,8 +42,8 @@ android:layout_height="0dp" android:layout_gravity="top" android:layout_weight="1" - android:paddingBottom="8dp" android:clipChildren="false" - android:clipToPadding="false" /> + android:clipToPadding="false" + android:paddingBottom="8dp" /> diff --git a/app/src/main/res/layout/anime_source_list_item.xml b/app/src/main/res/layout/anime_source_list_item.xml index 63c1272db..e25d6019d 100644 --- a/app/src/main/res/layout/anime_source_list_item.xml +++ b/app/src/main/res/layout/anime_source_list_item.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="@dimen/material_component_lists_single_line_with_avatar_height" + android:layout_height="56dp" android:layout_gravity="center_vertical" android:background="@drawable/list_item_selector_background" android:paddingStart="8dp" @@ -11,8 +11,8 @@ diff --git a/app/src/main/res/layout/anime_updates_item.xml b/app/src/main/res/layout/anime_updates_item.xml index bf23d09b5..83cb6e091 100644 --- a/app/src/main/res/layout/anime_updates_item.xml +++ b/app/src/main/res/layout/anime_updates_item.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="@dimen/material_component_lists_two_line_height" + android:layout_height="56dp" android:background="@drawable/list_item_selector_background" android:paddingEnd="4dp"> @@ -55,8 +55,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingStart="4dp" - app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/episode_download_view.xml b/app/src/main/res/layout/episode_download_view.xml index 8b52c2e7f..a11f19441 100644 --- a/app/src/main/res/layout/episode_download_view.xml +++ b/app/src/main/res/layout/episode_download_view.xml @@ -4,8 +4,8 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="42dp" android:layout_height="42dp" - android:padding="8dp" - android:background="?selectableItemBackgroundBorderless"> + android:background="@drawable/ripple_regular" + android:padding="8dp"> + android:background="@drawable/selectable_item_background"> diff --git a/app/src/main/res/layout/history_item.xml b/app/src/main/res/layout/history_item.xml index c3e012700..579b45ffc 100644 --- a/app/src/main/res/layout/history_item.xml +++ b/app/src/main/res/layout/history_item.xml @@ -56,13 +56,8 @@ android:id="@+id/remove" android:layout_width="wrap_content" android:layout_height="wrap_content" -<<<<<<< HEAD - android:background="?selectableItemBackgroundBorderless" - android:contentDescription="@string/action_remove" -======= android:background="@drawable/ripple_regular" - android:contentDescription="@string/action_resume" ->>>>>>> pr17 + android:contentDescription="@string/action_remove" android:padding="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/resume"