Tracker notifications option in settings

remotes/weblate/feature/pagecrop
Koitharu 6 years ago
parent c4f712be3a
commit a2d4a63eb1

@ -52,6 +52,11 @@ class AppSettings private constructor(resources: Resources, private val prefs: S
0L 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)) private var sourcesOrderStr by NullableStringPreferenceDelegate(resources.getString(R.string.key_sources_order))
var sourcesOrder: List<Int> var sourcesOrder: List<Int>

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

@ -114,4 +114,5 @@
<string name="notifications">Уведомления</string> <string name="notifications">Уведомления</string>
<string name="enabled_d_from_d">Включено %1$d из %2$d</string> <string name="enabled_d_from_d">Включено %1$d из %2$d</string>
<string name="new_chapters">Новые главы</string> <string name="new_chapters">Новые главы</string>
<string name="show_notification_new_chapters">Уведомлять об обновлении манги, которую Вы читаете</string>
</resources> </resources>

@ -14,6 +14,7 @@
<string name="key_reader_switchers">reader_switchers</string> <string name="key_reader_switchers">reader_switchers</string>
<string name="key_app_update">app_update</string> <string name="key_app_update">app_update</string>
<string name="key_app_update_auto">app_update_auto</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 name="key_parser_domain">domain</string>
<string-array name="values_theme"> <string-array name="values_theme">

@ -115,4 +115,5 @@
<string name="notifications">Notifications</string> <string name="notifications">Notifications</string>
<string name="enabled_d_from_d">Enabled %1$d from %2$d</string> <string name="enabled_d_from_d">Enabled %1$d from %2$d</string>
<string name="new_chapters">New chapters</string> <string name="new_chapters">New chapters</string>
<string name="show_notification_new_chapters">Notify about updates of manga you are reading</string>
</resources> </resources>

@ -61,7 +61,13 @@
android:key="@string/key_app_update_auto" android:key="@string/key_app_update_auto"
android:summary="@string/show_notification_app_update" android:summary="@string/show_notification_app_update"
android:title="@string/application_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" /> app:iconSpaceReserved="false" />
</PreferenceCategory> </PreferenceCategory>

Loading…
Cancel
Save