mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 02:51:47 +01:00
Minor cleanup
This commit is contained in:
parent
3b334c4230
commit
497fe1e68a
@ -5,7 +5,6 @@ import android.graphics.BitmapFactory
|
|||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
import eu.kanade.tachiyomi.data.download.model.DownloadQueue
|
|
||||||
import eu.kanade.tachiyomi.data.notification.NotificationHandler
|
import eu.kanade.tachiyomi.data.notification.NotificationHandler
|
||||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||||
@ -96,6 +95,7 @@ internal class DownloadNotifier(private val context: Context) {
|
|||||||
.format(download.downloadedImages, download.pages!!.size))
|
.format(download.downloadedImages, download.pages!!.size))
|
||||||
setProgress(download.pages!!.size, download.downloadedImages, false)
|
setProgress(download.pages!!.size, download.downloadedImages, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Displays the progress bar on notification
|
// Displays the progress bar on notification
|
||||||
notificationBuilder.show()
|
notificationBuilder.show()
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import android.os.PowerManager
|
|||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.app.NotificationCompat.GROUP_ALERT_SUMMARY
|
import androidx.core.app.NotificationCompat.GROUP_ALERT_SUMMARY
|
||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||||
@ -281,7 +280,7 @@ class LibraryUpdateService(
|
|||||||
val count = AtomicInteger(0)
|
val count = AtomicInteger(0)
|
||||||
// List containing new updates
|
// List containing new updates
|
||||||
val newUpdates = ArrayList<Pair<LibraryManga, Array<Chapter>>>()
|
val newUpdates = ArrayList<Pair<LibraryManga, Array<Chapter>>>()
|
||||||
// list containing failed updates
|
// List containing failed updates
|
||||||
val failedUpdates = ArrayList<Manga>()
|
val failedUpdates = ArrayList<Manga>()
|
||||||
// List containing categories that get included in downloads.
|
// List containing categories that get included in downloads.
|
||||||
val categoriesToDownload = preferences.downloadNewCategories().getOrDefault().map(String::toInt)
|
val categoriesToDownload = preferences.downloadNewCategories().getOrDefault().map(String::toInt)
|
||||||
@ -313,8 +312,12 @@ class LibraryUpdateService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Convert to the manga that contains new chapters.
|
// Convert to the manga that contains new chapters.
|
||||||
.map { Pair(manga, (it.first.sortedByDescending { ch -> ch
|
.map {
|
||||||
.source_order }.toTypedArray())) }
|
Pair(
|
||||||
|
manga,
|
||||||
|
(it.first.sortedByDescending { ch -> ch.source_order }.toTypedArray())
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Add manga with new chapters to the list.
|
// Add manga with new chapters to the list.
|
||||||
.doOnNext { manga ->
|
.doOnNext { manga ->
|
||||||
@ -491,7 +494,6 @@ class LibraryUpdateService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
NotificationManagerCompat.from(this).apply {
|
NotificationManagerCompat.from(this).apply {
|
||||||
|
|
||||||
notify(Notifications.ID_NEW_CHAPTERS, notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
notify(Notifications.ID_NEW_CHAPTERS, notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
||||||
setSmallIcon(R.drawable.ic_tachi)
|
setSmallIcon(R.drawable.ic_tachi)
|
||||||
setLargeIcon(notificationBitmap)
|
setLargeIcon(notificationBitmap)
|
||||||
@ -532,9 +534,10 @@ class LibraryUpdateService(
|
|||||||
* Returns an intent to open the main activity.
|
* Returns an intent to open the main activity.
|
||||||
*/
|
*/
|
||||||
private fun getNotificationIntent(): PendingIntent {
|
private fun getNotificationIntent(): PendingIntent {
|
||||||
val intent = Intent(this, MainActivity::class.java)
|
val intent = Intent(this, MainActivity::class.java).apply {
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
|
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||||
intent.action = MainActivity.SHORTCUT_RECENTLY_UPDATED
|
action = MainActivity.SHORTCUT_RECENTLY_UPDATED
|
||||||
|
}
|
||||||
return PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
return PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,9 +34,7 @@ import eu.kanade.tachiyomi.BuildConfig.APPLICATION_ID as ID
|
|||||||
* NOTE: Use local broadcasts if possible.
|
* NOTE: Use local broadcasts if possible.
|
||||||
*/
|
*/
|
||||||
class NotificationReceiver : BroadcastReceiver() {
|
class NotificationReceiver : BroadcastReceiver() {
|
||||||
/**
|
|
||||||
* Download manager.
|
|
||||||
*/
|
|
||||||
private val downloadManager: DownloadManager by injectLazy()
|
private val downloadManager: DownloadManager by injectLazy()
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
@ -67,17 +65,20 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
openChapter(context, intent.getLongExtra(EXTRA_MANGA_ID, -1),
|
openChapter(context, intent.getLongExtra(EXTRA_MANGA_ID, -1),
|
||||||
intent.getLongExtra(EXTRA_CHAPTER_ID, -1))
|
intent.getLongExtra(EXTRA_CHAPTER_ID, -1))
|
||||||
}
|
}
|
||||||
|
// Mark updated manga chapters as read
|
||||||
ACTION_MARK_AS_READ -> {
|
ACTION_MARK_AS_READ -> {
|
||||||
val notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1)
|
val notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1)
|
||||||
if (notificationId > -1) dismissNotification(
|
if (notificationId > -1) {
|
||||||
context, notificationId, intent.getIntExtra(EXTRA_GROUP_ID, 0)
|
dismissNotification(context, notificationId, intent.getIntExtra(EXTRA_GROUP_ID, 0))
|
||||||
)
|
}
|
||||||
val urls = intent.getStringArrayExtra(EXTRA_CHAPTER_URL) ?: return
|
val urls = intent.getStringArrayExtra(EXTRA_CHAPTER_URL) ?: return
|
||||||
val mangaId = intent.getLongExtra(EXTRA_MANGA_ID, -1)
|
val mangaId = intent.getLongExtra(EXTRA_MANGA_ID, -1)
|
||||||
|
if (mangaId > -1) {
|
||||||
markAsRead(urls, mangaId)
|
markAsRead(urls, mangaId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dismiss the notification
|
* Dismiss the notification
|
||||||
@ -159,10 +160,10 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method called when user wants to mark as read
|
* Method called when user wants to mark manga chapters as read
|
||||||
*
|
*
|
||||||
* @param context context of application
|
* @param chapterUrls URLs of chapter to mark as read
|
||||||
* @param notificationId id of notification
|
* @param mangaId id of manga
|
||||||
*/
|
*/
|
||||||
private fun markAsRead(chapterUrls: Array<String>, mangaId: Long) {
|
private fun markAsRead(chapterUrls: Array<String>, mangaId: Long) {
|
||||||
val db: DatabaseHelper = Injekt.get()
|
val db: DatabaseHelper = Injekt.get()
|
||||||
@ -192,10 +193,10 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
// Called to cancel library update.
|
// Called to cancel library update.
|
||||||
private const val ACTION_CANCEL_LIBRARY_UPDATE = "$ID.$NAME.CANCEL_LIBRARY_UPDATE"
|
private const val ACTION_CANCEL_LIBRARY_UPDATE = "$ID.$NAME.CANCEL_LIBRARY_UPDATE"
|
||||||
|
|
||||||
// Called to mark as read
|
// Called to mark manga chapters as read.
|
||||||
private const val ACTION_MARK_AS_READ = "$ID.$NAME.MARK_AS_READ"
|
private const val ACTION_MARK_AS_READ = "$ID.$NAME.MARK_AS_READ"
|
||||||
|
|
||||||
// Called to open chapter
|
// Called to open chapter.
|
||||||
private const val ACTION_OPEN_CHAPTER = "$ID.$NAME.ACTION_OPEN_CHAPTER"
|
private const val ACTION_OPEN_CHAPTER = "$ID.$NAME.ACTION_OPEN_CHAPTER"
|
||||||
|
|
||||||
// Value containing file location.
|
// Value containing file location.
|
||||||
@ -299,22 +300,24 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
* @param notificationId id of notification
|
* @param notificationId id of notification
|
||||||
* @return [PendingIntent]
|
* @return [PendingIntent]
|
||||||
*/
|
*/
|
||||||
internal fun dismissNotification(context: Context, notificationId: Int, groupId: Int? =
|
internal fun dismissNotification(context: Context, notificationId: Int, groupId: Int? = null) {
|
||||||
null) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
val groupKey = context.notificationManager.activeNotifications.find {
|
val groupKey = context.notificationManager.activeNotifications.find {
|
||||||
it.id == notificationId
|
it.id == notificationId
|
||||||
}?.groupKey
|
}?.groupKey
|
||||||
|
|
||||||
if (groupId != null && groupId != 0 && groupKey != null && groupKey.isNotEmpty()) {
|
if (groupId != null && groupId != 0 && groupKey != null && groupKey.isNotEmpty()) {
|
||||||
val notifications = context.notificationManager.activeNotifications.filter {
|
val notifications = context.notificationManager.activeNotifications.filter {
|
||||||
it.groupKey == groupKey
|
it.groupKey == groupKey
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notifications.size == 2) {
|
if (notifications.size == 2) {
|
||||||
context.notificationManager.cancel(groupId)
|
context.notificationManager.cancel(groupId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context.notificationManager.cancel(notificationId)
|
context.notificationManager.cancel(notificationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,11 +362,9 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
* @param manga manga of chapter
|
* @param manga manga of chapter
|
||||||
* @param chapter chapter that needs to be opened
|
* @param chapter chapter that needs to be opened
|
||||||
*/
|
*/
|
||||||
internal fun openChapterPendingActivity(context: Context, manga: Manga, chapter:
|
internal fun openChapterPendingActivity(context: Context, manga: Manga, chapter: Chapter): PendingIntent {
|
||||||
Chapter): PendingIntent {
|
|
||||||
val newIntent = ReaderActivity.newIntent(context, manga, chapter)
|
val newIntent = ReaderActivity.newIntent(context, manga, chapter)
|
||||||
return PendingIntent.getActivity(context, manga.id.hashCode(), newIntent, PendingIntent
|
return PendingIntent.getActivity(context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
.FLAG_UPDATE_CURRENT)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -372,17 +373,14 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
* @param context context of application
|
* @param context context of application
|
||||||
* @param manga manga of chapter
|
* @param manga manga of chapter
|
||||||
*/
|
*/
|
||||||
internal fun openChapterPendingActivity(context: Context, manga: Manga, groupId: Int):
|
internal fun openChapterPendingActivity(context: Context, manga: Manga, groupId: Int): PendingIntent {
|
||||||
PendingIntent {
|
|
||||||
val newIntent =
|
val newIntent =
|
||||||
Intent(context, MainActivity::class.java).setAction(MainActivity.SHORTCUT_MANGA)
|
Intent(context, MainActivity::class.java).setAction(MainActivity.SHORTCUT_MANGA)
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
.putExtra(MangaController.MANGA_EXTRA, manga.id)
|
.putExtra(MangaController.MANGA_EXTRA, manga.id)
|
||||||
.putExtra("notificationId", manga.id.hashCode())
|
.putExtra("notificationId", manga.id.hashCode())
|
||||||
.putExtra("groupId", groupId)
|
.putExtra("groupId", groupId)
|
||||||
return PendingIntent.getActivity(
|
return PendingIntent.getActivity(context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,9 +138,10 @@ class MainActivity : BaseActivity() {
|
|||||||
|
|
||||||
private fun handleIntentAction(intent: Intent): Boolean {
|
private fun handleIntentAction(intent: Intent): Boolean {
|
||||||
val notificationId = intent.getIntExtra("notificationId", -1)
|
val notificationId = intent.getIntExtra("notificationId", -1)
|
||||||
if (notificationId > -1) NotificationReceiver.dismissNotification(
|
if (notificationId > -1) {
|
||||||
applicationContext, notificationId, intent.getIntExtra("groupId", 0)
|
NotificationReceiver.dismissNotification(applicationContext, notificationId, intent.getIntExtra("groupId", 0))
|
||||||
)
|
}
|
||||||
|
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
SHORTCUT_LIBRARY -> setSelectedDrawerItem(R.id.nav_drawer_library)
|
SHORTCUT_LIBRARY -> setSelectedDrawerItem(R.id.nav_drawer_library)
|
||||||
SHORTCUT_RECENTLY_UPDATED -> setSelectedDrawerItem(R.id.nav_drawer_recent_updates)
|
SHORTCUT_RECENTLY_UPDATED -> setSelectedDrawerItem(R.id.nav_drawer_recent_updates)
|
||||||
|
@ -106,15 +106,14 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
const val VERTICAL = 3
|
const val VERTICAL = 3
|
||||||
const val WEBTOON = 4
|
const val WEBTOON = 4
|
||||||
|
|
||||||
fun newIntent(context: Context, manga: Manga, chapter: Chapter):
|
fun newIntent(context: Context, manga: Manga, chapter: Chapter): Intent {
|
||||||
Intent {
|
return Intent(context, ReaderActivity::class.java).apply {
|
||||||
val intent = Intent(context, ReaderActivity::class.java)
|
putExtra("manga", manga.id)
|
||||||
intent.putExtra("manga", manga.id)
|
putExtra("chapter", chapter.id)
|
||||||
intent.putExtra("chapter", chapter.id)
|
|
||||||
// chapters just added from library updates don't have an id yet
|
// chapters just added from library updates don't have an id yet
|
||||||
intent.putExtra("chapterUrl", chapter.url)
|
putExtra("chapterUrl", chapter.url)
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
return intent
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,12 +191,14 @@ class ReaderPresenter(
|
|||||||
*/
|
*/
|
||||||
fun init(mangaId: Long, chapterUrl: String) {
|
fun init(mangaId: Long, chapterUrl: String) {
|
||||||
if (!needsInit()) return
|
if (!needsInit()) return
|
||||||
|
|
||||||
val context = Injekt.get<Application>()
|
val context = Injekt.get<Application>()
|
||||||
val db = DatabaseHelper(context)
|
val db = DatabaseHelper(context)
|
||||||
val chapterId = db.getChapter(chapterUrl, mangaId).executeAsBlocking()?.id
|
val chapterId = db.getChapter(chapterUrl, mangaId).executeAsBlocking()?.id
|
||||||
if (chapterId != null)
|
if (chapterId != null) {
|
||||||
init(mangaId, chapterId)
|
init(mangaId, chapterId)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes this presenter with the given [manga] and [initialChapterId]. This method will
|
* Initializes this presenter with the given [manga] and [initialChapterId]. This method will
|
||||||
|
@ -542,8 +542,8 @@
|
|||||||
|
|
||||||
<!-- Notification channels -->
|
<!-- Notification channels -->
|
||||||
<string name="channel_common">Common</string>
|
<string name="channel_common">Common</string>
|
||||||
<string name="channel_library">Updating Library</string>
|
<string name="channel_library">Library</string>
|
||||||
<string name="channel_downloader">Downloader</string>
|
<string name="channel_downloader">Downloader</string>
|
||||||
<string name="channel_new_chapters">New Chapters</string>
|
<string name="channel_new_chapters">Chapter updates</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user