@ -57,6 +57,7 @@ class TrackerJobService : BaseJobService() {
mangaId = track . manga . id ,
mangaId = track . manga . id ,
knownChaptersCount = chapters . size ,
knownChaptersCount = chapters . size ,
lastChapterId = chapters . lastOrNull ( ) ?. id ?: 0L ,
lastChapterId = chapters . lastOrNull ( ) ?. id ?: 0L ,
lastNotifiedChapterId = 0L ,
newChapters = 0
newChapters = 0
)
)
}
}
@ -65,6 +66,7 @@ class TrackerJobService : BaseJobService() {
mangaId = track . manga . id ,
mangaId = track . manga . id ,
knownChaptersCount = track . knownChaptersCount ,
knownChaptersCount = track . knownChaptersCount ,
lastChapterId = 0L ,
lastChapterId = 0L ,
lastNotifiedChapterId = chapters . lastOrNull ( ) ?. id ?: 0L ,
newChapters = chapters . size
newChapters = chapters . size
)
)
showNotification ( track . manga , chapters )
showNotification ( track . manga , chapters )
@ -82,6 +84,7 @@ class TrackerJobService : BaseJobService() {
mangaId = track . manga . id ,
mangaId = track . manga . id ,
knownChaptersCount = chapters . size ,
knownChaptersCount = chapters . size ,
lastChapterId = chapters . lastOrNull ( ) ?. id ?: 0L ,
lastChapterId = chapters . lastOrNull ( ) ?. id ?: 0L ,
lastNotifiedChapterId = chapters . lastOrNull ( ) ?. id ?: 0L ,
newChapters = 0
newChapters = 0
)
)
} else {
} else {
@ -90,23 +93,29 @@ class TrackerJobService : BaseJobService() {
mangaId = track . manga . id ,
mangaId = track . manga . id ,
knownChaptersCount = knownChapter + 1 ,
knownChaptersCount = knownChapter + 1 ,
lastChapterId = track . lastChapterId ,
lastChapterId = track . lastChapterId ,
lastNotifiedChapterId = chapters . lastOrNull ( ) ?. id ?: 0L ,
newChapters = newChapters
newChapters = newChapters
)
)
if ( chapters . lastOrNull ( ) ?. id != track . lastNotifiedChapterId ) {
showNotification ( track . manga , chapters . takeLast ( newChapters ) )
showNotification ( track . manga , chapters . takeLast ( newChapters ) )
}
}
}
}
}
}
}
else -> {
else -> {
val newChapters = chapters . size - track . knownChaptersCount
val newChapters = chapters . size - track . knownChaptersCount
repo . storeTrackResult (
repo . storeTrackResult (
mangaId = track . manga . id ,
mangaId = track . manga . id ,
knownChaptersCount = track . knownChaptersCount ,
knownChaptersCount = track . knownChaptersCount ,
lastChapterId = track . lastChapterId ,
lastChapterId = track . lastChapterId ,
lastNotifiedChapterId = chapters . lastOrNull ( ) ?. id ?: 0L ,
newChapters = newChapters
newChapters = newChapters
)
)
if ( chapters . lastOrNull ( ) ?. id != track . lastNotifiedChapterId ) {
showNotification ( track . manga , chapters . takeLast ( newChapters ) )
showNotification ( track . manga , chapters . takeLast ( newChapters ) )
}
}
}
}
}
success ++
success ++
}
}
if ( success == 0 ) {
if ( success == 0 ) {
@ -122,9 +131,10 @@ class TrackerJobService : BaseJobService() {
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 )
val summary = resources . getQuantityString ( R . plurals . new _chapters ,
newChapters . size , newChapters . size )
with ( builder ) {
with ( builder ) {
setContentText ( resources . getQuantityString ( R . plurals . new _chapters ,
setContentText ( summary )
newChapters . size , newChapters . size ) )
setContentText ( manga . title )
setContentText ( manga . title )
setNumber ( newChapters . size )
setNumber ( newChapters . size )
setLargeIcon ( safe {
setLargeIcon ( safe {
@ -136,6 +146,7 @@ class TrackerJobService : BaseJobService() {
style . addLine ( chapter . name )
style . addLine ( chapter . name )
}
}
style . setSummaryText ( manga . title )
style . setSummaryText ( manga . title )
style . setBigContentTitle ( summary )
setStyle ( style )
setStyle ( style )
val intent = MangaDetailsActivity . newIntent ( this @TrackerJobService , manga )
val intent = MangaDetailsActivity . newIntent ( this @TrackerJobService , manga )
setContentIntent ( PendingIntent . getActivity ( this @TrackerJobService , id ,
setContentIntent ( PendingIntent . getActivity ( this @TrackerJobService , id ,
@ -176,9 +187,9 @@ class TrackerJobService : BaseJobService() {
createNotificationChannel ( context )
createNotificationChannel ( context )
}
}
val scheduler = context . getSystemService ( Context . JOB _SCHEDULER _SERVICE ) as JobScheduler
val scheduler = context . getSystemService ( Context . JOB _SCHEDULER _SERVICE ) as JobScheduler
// if (scheduler.allPendingJobs != null) {
if ( scheduler . allPendingJobs . any { it . id == JOB _ID } ) {
// return
return
// }
}
val jobInfo =
val jobInfo =
JobInfo . Builder ( JOB _ID , ComponentName ( context , TrackerJobService :: class . java ) )
JobInfo . Builder ( JOB _ID , ComponentName ( context , TrackerJobService :: class . java ) )
if ( Build . VERSION . SDK _INT >= Build . VERSION_CODES . N ) {
if ( Build . VERSION . SDK _INT >= Build . VERSION_CODES . N ) {
@ -191,7 +202,7 @@ class TrackerJobService : BaseJobService() {
}
}
jobInfo . setRequiresDeviceIdle ( true )
jobInfo . setRequiresDeviceIdle ( true )
jobInfo . setPersisted ( true )
jobInfo . setPersisted ( true )
jobInfo . setPeriodic ( TimeUnit . HOURS . toMillis ( 6 ) )
jobInfo . setPeriodic ( TimeUnit . HOURS . toMillis ( 4 ) )
scheduler . schedule ( jobInfo . build ( ) )
scheduler . schedule ( jobInfo . build ( ) )
}
}
}
}