Tracker notifications option in settings

This commit is contained in:
Koitharu
2020-03-29 20:48:53 +03:00
parent c4f712be3a
commit a2d4a63eb1
6 changed files with 25 additions and 10 deletions

View File

@@ -52,6 +52,11 @@ class AppSettings private constructor(resources: Resources, private val prefs: S
0L
)
val trackerNotifications by BoolPreferenceDelegate(
resources.getString(R.string.key_tracker_notifications),
true
)
private var sourcesOrderStr by NullableStringPreferenceDelegate(resources.getString(R.string.key_sources_order))
var sourcesOrder: List<Int>

View File

@@ -17,9 +17,11 @@ import coil.Coil
import coil.api.get
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.koin.android.ext.android.inject
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.model.Manga
import org.koitharu.kotatsu.core.model.MangaChapter
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.domain.MangaProviderFactory
import org.koitharu.kotatsu.domain.tracking.TrackingRepository
import org.koitharu.kotatsu.ui.common.BaseJobService
@@ -33,6 +35,8 @@ class TrackerJobService : BaseJobService() {
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
}
private val settings by inject<AppSettings>()
override suspend fun doWork(params: JobParameters) {
withContext(Dispatchers.IO) {
val repo = TrackingRepository()
@@ -63,9 +67,7 @@ class TrackerJobService : BaseJobService() {
lastChapterId = 0L,
newChapters = chapters.size
)
if (chapters.isNotEmpty()) {
showNotification(track.manga, chapters)
}
showNotification(track.manga, chapters)
}
chapters.size == track.knownChaptersCount -> {
if (chapters.lastOrNull()?.id == track.lastChapterId) {
@@ -90,9 +92,7 @@ class TrackerJobService : BaseJobService() {
lastChapterId = track.lastChapterId,
newChapters = newChapters
)
if (newChapters != 0) {
showNotification(track.manga, chapters.takeLast(newChapters))
}
showNotification(track.manga, chapters.takeLast(newChapters))
}
}
}
@@ -104,9 +104,7 @@ class TrackerJobService : BaseJobService() {
lastChapterId = track.lastChapterId,
newChapters = newChapters
)
if (newChapters != 0) {
showNotification(track.manga, chapters.takeLast(newChapters))
}
showNotification(track.manga, chapters.takeLast(newChapters))
}
}
success++
@@ -118,6 +116,9 @@ class TrackerJobService : BaseJobService() {
}
private suspend fun showNotification(manga: Manga, newChapters: List<MangaChapter>) {
if (newChapters.isEmpty() || !settings.trackerNotifications) {
return
}
val id = manga.url.hashCode()
val colorPrimary = ContextCompat.getColor(this@TrackerJobService, R.color.blue_primary)
val builder = NotificationCompat.Builder(this, CHANNEL_ID)