From cc7735e284d6084cca2ecc1eff61085ff9f8ff2f Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 28 Apr 2020 16:47:18 -0400 Subject: [PATCH] No longer using chapter url for new chapter notification's reader intent --- .../kanade/tachiyomi/ui/reader/ReaderActivity.kt | 8 ++------ .../kanade/tachiyomi/ui/reader/ReaderPresenter.kt | 15 --------------- .../tachiyomi/util/chapter/ChapterSourceSync.kt | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index ebfd55d593..d30bf879bf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -116,8 +116,6 @@ class ReaderActivity : BaseRxActivity() return Intent(context, ReaderActivity::class.java).apply { putExtra("manga", manga.id) putExtra("chapter", chapter.id) - // chapters just added from library updates don't have an id yet - putExtra("chapterUrl", chapter.url) addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) } } @@ -141,14 +139,12 @@ class ReaderActivity : BaseRxActivity() if (presenter.needsInit()) { val manga = intent.extras!!.getLong("manga", -1) val chapter = intent.extras!!.getLong("chapter", -1) - val chapterUrl = intent.extras!!.getString("chapterUrl", "") - if (manga == -1L || chapterUrl == "" && chapter == -1L) { + if (manga == -1L || chapter == -1L) { finish() return } NotificationReceiver.dismissNotification(this, manga.hashCode(), Notifications.ID_NEW_CHAPTERS) - if (chapter > -1) presenter.init(manga, chapter) - else presenter.init(manga, chapterUrl) + presenter.init(manga, chapter) } if (savedInstanceState != null) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index b6307bb083..7dc42d8e6f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -211,21 +211,6 @@ class ReaderPresenter( ) } - /** - * Initializes this presenter with the given [mangaId] and [chapterUrl]. This method will - * fetch the manga from the database and initialize the initial chapter. - */ - fun init(mangaId: Long, chapterUrl: String) { - if (!needsInit()) return - - val context = Injekt.get() - val db = DatabaseHelper(context) - val chapterId = db.getChapter(chapterUrl, mangaId).executeAsBlocking()?.id - if (chapterId != null) { - init(mangaId, chapterId) - } - } - /** * Initializes this presenter with the given [manga] and [initialChapterId]. This method will * set the chapter loader, view subscriptions and trigger an initial load. diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt index 5a2486642b..8090f940b3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt @@ -120,7 +120,10 @@ fun syncChaptersWithSource( readded.add(c) } } - db.insertChapters(toAdd).executeAsBlocking() + val chapters = db.insertChapters(toAdd).executeAsBlocking() + toAdd.forEach { chapter -> + chapter.id = chapters.results().getValue(chapter).insertedId() + } } if (toChange.isNotEmpty()) { @@ -131,7 +134,15 @@ fun syncChaptersWithSource( db.fixChaptersSourceOrder(sourceChapters).executeAsBlocking() // Set this manga as updated since chapters were changed - manga.last_update = Date().time + val newestChapter = db.getChapters(manga).executeAsBlocking().maxBy { it.date_upload } + val dateFetch = newestChapter?.date_upload ?: manga.last_update + if (dateFetch == 0L) { + if (toAdd.isNotEmpty()) { + manga.last_update = Date().time + } + } else { + manga.last_update = dateFetch + } db.updateLastUpdated(manga).executeAsBlocking() }