Group notifcations for Library updates (#2582)

This commit is contained in:
Jays2Kings
2020-02-17 07:56:23 -08:00
committed by GitHub
parent 12aa04be93
commit 7f115f2e83
12 changed files with 280 additions and 111 deletions

View File

@@ -12,6 +12,7 @@ import androidx.drawerlayout.widget.DrawerLayout
import com.bluelinelabs.conductor.*
import eu.kanade.tachiyomi.Migrations
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
import eu.kanade.tachiyomi.ui.base.controller.*
import eu.kanade.tachiyomi.ui.catalogue.CatalogueController
@@ -136,6 +137,10 @@ class MainActivity : BaseActivity() {
}
private fun handleIntentAction(intent: Intent): Boolean {
val notificationId = intent.getIntExtra("notificationId", -1)
if (notificationId > -1) NotificationReceiver.dismissNotification(
applicationContext, notificationId, intent.getIntExtra("groupId", 0)
)
when (intent.action) {
SHORTCUT_LIBRARY -> setSelectedDrawerItem(R.id.nav_drawer_library)
SHORTCUT_RECENTLY_UPDATED -> setSelectedDrawerItem(R.id.nav_drawer_recent_updates)

View File

@@ -19,6 +19,8 @@ import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
@@ -104,10 +106,14 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
const val VERTICAL = 3
const val WEBTOON = 4
fun newIntent(context: Context, manga: Manga, chapter: Chapter): Intent {
fun newIntent(context: Context, manga: Manga, chapter: Chapter):
Intent {
val intent = Intent(context, ReaderActivity::class.java)
intent.putExtra("manga", manga.id)
intent.putExtra("chapter", chapter.id)
// chapters just added from library updates don't have an id yet
intent.putExtra("chapterUrl", chapter.url)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
return intent
}
}
@@ -126,13 +132,14 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
if (presenter.needsInit()) {
val manga = intent.extras!!.getLong("manga", -1)
val chapter = intent.extras!!.getLong("chapter", -1)
if (manga == -1L || chapter == -1L) {
val chapterUrl = intent.extras!!.getString("chapterUrl", "")
if (manga == -1L || chapterUrl == "" && chapter == -1L) {
finish()
return
}
presenter.init(manga, chapter)
NotificationReceiver.dismissNotification(this, manga.hashCode(), Notifications.ID_NEW_CHAPTERS)
if (chapter > -1) presenter.init(manga, chapter)
else presenter.init(manga, chapterUrl)
}
if (savedState != null) {

View File

@@ -185,6 +185,19 @@ class ReaderPresenter(
}, ReaderActivity::setInitialChapterError)
}
/**
* 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<Application>()
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.

View File

@@ -13,12 +13,14 @@ import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.ui.base.controller.popControllerWithTag
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.util.system.notificationManager
import eu.kanade.tachiyomi.util.system.toast
import kotlinx.android.synthetic.main.recent_chapters_controller.empty_view
import kotlinx.android.synthetic.main.recent_chapters_controller.recycler
@@ -68,7 +70,7 @@ class RecentChaptersController : NucleusController<RecentChaptersPresenter>(),
*/
override fun onViewCreated(view: View) {
super.onViewCreated(view)
view.context.notificationManager.cancel(Notifications.ID_NEW_CHAPTERS)
// Init RecyclerView and adapter
val layoutManager = LinearLayoutManager(view.context)
recycler.layoutManager = layoutManager