Tracker enhancements
This commit is contained in:
@@ -21,5 +21,6 @@ data class TrackEntity (
|
||||
@ColumnInfo(name = "chapters_total") val totalChapters: Int,
|
||||
@ColumnInfo(name = "last_chapter_id") val lastChapterId: Long,
|
||||
@ColumnInfo(name = "chapters_new") val newChapters: Int,
|
||||
@ColumnInfo(name = "last_check") val lastCheck: Long
|
||||
@ColumnInfo(name = "last_check") val lastCheck: Long,
|
||||
@ColumnInfo(name = "last_notified_id") val lastNotifiedChapterId: Long
|
||||
)
|
||||
@@ -6,6 +6,6 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
object Migration3To4 : Migration(3, 4) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS tracks (manga_id INTEGER NOT NULL, chapters_total INTEGER NOT NULL, last_chapter_id INTEGER NOT NULL, chapters_new INTEGER NOT NULL, last_check INTEGER NOT NULL, PRIMARY KEY(manga_id), FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )")
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS tracks (manga_id INTEGER NOT NULL, chapters_total INTEGER NOT NULL, last_chapter_id INTEGER NOT NULL, chapters_new INTEGER NOT NULL, last_check INTEGER NOT NULL, last_notified_id INTEGER NOT NULL, PRIMARY KEY(manga_id), FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )")
|
||||
}
|
||||
}
|
||||
@@ -9,5 +9,6 @@ data class MangaTracking (
|
||||
val manga: Manga,
|
||||
val knownChaptersCount: Int,
|
||||
val lastChapterId: Long,
|
||||
val lastNotifiedChapterId: Long,
|
||||
val lastCheck: Date?
|
||||
): Parcelable
|
||||
@@ -27,7 +27,8 @@ class TrackingRepository : KoinComponent {
|
||||
MangaTracking(
|
||||
manga = m.toManga(),
|
||||
knownChaptersCount = track?.totalChapters ?: -1,
|
||||
lastChapterId = track?.lastChapterId ?: 0,
|
||||
lastChapterId = track?.lastChapterId ?: 0L,
|
||||
lastNotifiedChapterId = track?.lastNotifiedChapterId ?: 0L,
|
||||
lastCheck = track?.lastCheck?.takeUnless { it == 0L }?.let(::Date)
|
||||
)
|
||||
}
|
||||
@@ -37,14 +38,16 @@ class TrackingRepository : KoinComponent {
|
||||
mangaId: Long,
|
||||
knownChaptersCount: Int,
|
||||
lastChapterId: Long,
|
||||
newChapters: Int
|
||||
newChapters: Int,
|
||||
lastNotifiedChapterId: Long
|
||||
) {
|
||||
val entity = TrackEntity(
|
||||
mangaId = mangaId,
|
||||
newChapters = newChapters,
|
||||
lastCheck = System.currentTimeMillis(),
|
||||
lastChapterId = lastChapterId,
|
||||
totalChapters = knownChaptersCount
|
||||
totalChapters = knownChaptersCount,
|
||||
lastNotifiedChapterId = lastNotifiedChapterId
|
||||
)
|
||||
db.tracksDao.upsert(entity)
|
||||
}
|
||||
@@ -56,7 +59,8 @@ class TrackingRepository : KoinComponent {
|
||||
totalChapters = chapters.size,
|
||||
lastChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
newChapters = 0,
|
||||
lastCheck = System.currentTimeMillis()
|
||||
lastCheck = System.currentTimeMillis(),
|
||||
lastNotifiedChapterId = 0L
|
||||
)
|
||||
db.tracksDao.insert(entity)
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ class TrackerJobService : BaseJobService() {
|
||||
mangaId = track.manga.id,
|
||||
knownChaptersCount = chapters.size,
|
||||
lastChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
lastNotifiedChapterId = 0L,
|
||||
newChapters = 0
|
||||
)
|
||||
}
|
||||
@@ -65,6 +66,7 @@ class TrackerJobService : BaseJobService() {
|
||||
mangaId = track.manga.id,
|
||||
knownChaptersCount = track.knownChaptersCount,
|
||||
lastChapterId = 0L,
|
||||
lastNotifiedChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
newChapters = chapters.size
|
||||
)
|
||||
showNotification(track.manga, chapters)
|
||||
@@ -82,6 +84,7 @@ class TrackerJobService : BaseJobService() {
|
||||
mangaId = track.manga.id,
|
||||
knownChaptersCount = chapters.size,
|
||||
lastChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
lastNotifiedChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
newChapters = 0
|
||||
)
|
||||
} else {
|
||||
@@ -90,9 +93,12 @@ class TrackerJobService : BaseJobService() {
|
||||
mangaId = track.manga.id,
|
||||
knownChaptersCount = knownChapter + 1,
|
||||
lastChapterId = track.lastChapterId,
|
||||
lastNotifiedChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
newChapters = newChapters
|
||||
)
|
||||
showNotification(track.manga, chapters.takeLast(newChapters))
|
||||
if (chapters.lastOrNull()?.id != track.lastNotifiedChapterId) {
|
||||
showNotification(track.manga, chapters.takeLast(newChapters))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,9 +108,12 @@ class TrackerJobService : BaseJobService() {
|
||||
mangaId = track.manga.id,
|
||||
knownChaptersCount = track.knownChaptersCount,
|
||||
lastChapterId = track.lastChapterId,
|
||||
lastNotifiedChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||
newChapters = newChapters
|
||||
)
|
||||
showNotification(track.manga, chapters.takeLast(newChapters))
|
||||
if (chapters.lastOrNull()?.id != track.lastNotifiedChapterId) {
|
||||
showNotification(track.manga, chapters.takeLast(newChapters))
|
||||
}
|
||||
}
|
||||
}
|
||||
success++
|
||||
@@ -122,9 +131,10 @@ class TrackerJobService : BaseJobService() {
|
||||
val id = manga.url.hashCode()
|
||||
val colorPrimary = ContextCompat.getColor(this@TrackerJobService, R.color.blue_primary)
|
||||
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
|
||||
val summary = resources.getQuantityString(R.plurals.new_chapters,
|
||||
newChapters.size, newChapters.size)
|
||||
with(builder) {
|
||||
setContentText(resources.getQuantityString(R.plurals.new_chapters,
|
||||
newChapters.size, newChapters.size))
|
||||
setContentText(summary)
|
||||
setContentText(manga.title)
|
||||
setNumber(newChapters.size)
|
||||
setLargeIcon(safe {
|
||||
@@ -136,6 +146,7 @@ class TrackerJobService : BaseJobService() {
|
||||
style.addLine(chapter.name)
|
||||
}
|
||||
style.setSummaryText(manga.title)
|
||||
style.setBigContentTitle(summary)
|
||||
setStyle(style)
|
||||
val intent = MangaDetailsActivity.newIntent(this@TrackerJobService, manga)
|
||||
setContentIntent(PendingIntent.getActivity(this@TrackerJobService, id,
|
||||
@@ -176,9 +187,9 @@ class TrackerJobService : BaseJobService() {
|
||||
createNotificationChannel(context)
|
||||
}
|
||||
val scheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
|
||||
// if (scheduler.allPendingJobs != null) {
|
||||
// return
|
||||
// }
|
||||
if (scheduler.allPendingJobs.any { it.id == JOB_ID }) {
|
||||
return
|
||||
}
|
||||
val jobInfo =
|
||||
JobInfo.Builder(JOB_ID, ComponentName(context, TrackerJobService::class.java))
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
@@ -191,7 +202,7 @@ class TrackerJobService : BaseJobService() {
|
||||
}
|
||||
jobInfo.setRequiresDeviceIdle(true)
|
||||
jobInfo.setPersisted(true)
|
||||
jobInfo.setPeriodic(TimeUnit.HOURS.toMillis(6))
|
||||
jobInfo.setPeriodic(TimeUnit.HOURS.toMillis(4))
|
||||
scheduler.schedule(jobInfo.build())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user