Tracker notifications option in settings
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -114,4 +114,5 @@
|
||||
<string name="notifications">Уведомления</string>
|
||||
<string name="enabled_d_from_d">Включено %1$d из %2$d</string>
|
||||
<string name="new_chapters">Новые главы</string>
|
||||
<string name="show_notification_new_chapters">Уведомлять об обновлении манги, которую Вы читаете</string>
|
||||
</resources>
|
||||
@@ -14,6 +14,7 @@
|
||||
<string name="key_reader_switchers">reader_switchers</string>
|
||||
<string name="key_app_update">app_update</string>
|
||||
<string name="key_app_update_auto">app_update_auto</string>
|
||||
<string name="key_tracker_notifications">tracker_notifications</string>
|
||||
|
||||
<string name="key_parser_domain">domain</string>
|
||||
<string-array name="values_theme">
|
||||
|
||||
@@ -115,4 +115,5 @@
|
||||
<string name="notifications">Notifications</string>
|
||||
<string name="enabled_d_from_d">Enabled %1$d from %2$d</string>
|
||||
<string name="new_chapters">New chapters</string>
|
||||
<string name="show_notification_new_chapters">Notify about updates of manga you are reading</string>
|
||||
</resources>
|
||||
@@ -61,7 +61,13 @@
|
||||
android:key="@string/key_app_update_auto"
|
||||
android:summary="@string/show_notification_app_update"
|
||||
android:title="@string/application_update"
|
||||
app:allowDividerBelow="true"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="@string/key_tracker_notifications"
|
||||
android:summary="@string/show_notification_new_chapters"
|
||||
android:title="@string/new_chapters"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
Reference in New Issue
Block a user