Merge branch 'devel' into feature/nextgen
This commit is contained in:
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.core.os
|
|||||||
|
|
||||||
import android.content.pm.ShortcutInfo
|
import android.content.pm.ShortcutInfo
|
||||||
import android.content.pm.ShortcutManager
|
import android.content.pm.ShortcutManager
|
||||||
|
import android.os.Build
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
@@ -32,6 +33,9 @@ class ShortcutsUpdaterTest : KoinTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testUpdateShortcuts() = runTest {
|
fun testUpdateShortcuts() = runTest {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
|
||||||
|
return@runTest
|
||||||
|
}
|
||||||
awaitUpdate()
|
awaitUpdate()
|
||||||
assertTrue(getShortcuts().isEmpty())
|
assertTrue(getShortcuts().isEmpty())
|
||||||
historyRepository.addOrUpdate(
|
historyRepository.addOrUpdate(
|
||||||
@@ -55,11 +59,7 @@ class ShortcutsUpdaterTest : KoinTest {
|
|||||||
|
|
||||||
private suspend fun awaitUpdate() {
|
private suspend fun awaitUpdate() {
|
||||||
val instrumentation = InstrumentationRegistry.getInstrumentation()
|
val instrumentation = InstrumentationRegistry.getInstrumentation()
|
||||||
while (true) {
|
instrumentation.awaitForIdle()
|
||||||
instrumentation.awaitForIdle()
|
shortcutsUpdater.await()
|
||||||
if (shortcutsUpdater.await()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,15 +158,21 @@ class TrackerTest : KoinTest {
|
|||||||
}
|
}
|
||||||
assertEquals(3, repository.getNewChaptersCount(mangaFirst.id))
|
assertEquals(3, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
|
||||||
val chapter = requireNotNull(mangaFull.chapters).run { get(lastIndex - 1) }
|
var chapter = requireNotNull(mangaFull.chapters).run { get(lastIndex - 1) }
|
||||||
repository.syncWithHistory(mangaFull, chapter.id)
|
repository.syncWithHistory(mangaFull, chapter.id)
|
||||||
|
|
||||||
assertEquals(1, repository.getNewChaptersCount(mangaFirst.id))
|
assertEquals(1, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
|
||||||
|
chapter = requireNotNull(mangaFull.chapters).run { get(lastIndex) }
|
||||||
|
repository.syncWithHistory(mangaFull, chapter.id)
|
||||||
|
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
|
||||||
tracker.checkUpdates(mangaFull, commit = true).apply {
|
tracker.checkUpdates(mangaFull, commit = true).apply {
|
||||||
assertTrue(isValid)
|
assertTrue(isValid)
|
||||||
assert(newChapters.isEmpty())
|
assert(newChapters.isEmpty())
|
||||||
}
|
}
|
||||||
assertEquals(1, repository.getNewChaptersCount(mangaFirst.id))
|
assertEquals(0, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun loadManga(name: String): Manga {
|
private suspend fun loadManga(name: String): Manga {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.koitharu.kotatsu.core.db.TABLE_HISTORY
|
|||||||
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
import org.koitharu.kotatsu.utils.ext.requireBitmap
|
import org.koitharu.kotatsu.utils.ext.requireBitmap
|
||||||
|
|
||||||
@@ -56,12 +57,14 @@ class ShortcutsUpdater(
|
|||||||
return shortcutsUpdateJob?.join() != null
|
return shortcutsUpdateJob?.join() != null
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun updateShortcutsImpl() {
|
private suspend fun updateShortcutsImpl() = runCatching {
|
||||||
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
||||||
val shortcuts = historyRepository.getList(0, manager.maxShortcutCountPerActivity)
|
val shortcuts = historyRepository.getList(0, manager.maxShortcutCountPerActivity)
|
||||||
.filter { x -> x.title.isNotEmpty() }
|
.filter { x -> x.title.isNotEmpty() }
|
||||||
.map { buildShortcutInfo(it).build().toShortcutInfo() }
|
.map { buildShortcutInfo(it).build().toShortcutInfo() }
|
||||||
manager.dynamicShortcuts = shortcuts
|
manager.dynamicShortcuts = shortcuts
|
||||||
|
}.onFailure {
|
||||||
|
it.printStackTraceDebug()
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun buildShortcutInfo(manga: Manga): ShortcutInfoCompat.Builder {
|
private suspend fun buildShortcutInfo(manga: Manga): ShortcutInfoCompat.Builder {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.koitharu.kotatsu.tracker.domain
|
|||||||
|
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import java.util.*
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
@@ -19,6 +18,7 @@ import org.koitharu.kotatsu.tracker.data.toTrackingLogItem
|
|||||||
import org.koitharu.kotatsu.tracker.domain.model.MangaTracking
|
import org.koitharu.kotatsu.tracker.domain.model.MangaTracking
|
||||||
import org.koitharu.kotatsu.tracker.domain.model.MangaUpdates
|
import org.koitharu.kotatsu.tracker.domain.model.MangaUpdates
|
||||||
import org.koitharu.kotatsu.tracker.domain.model.TrackingLogItem
|
import org.koitharu.kotatsu.tracker.domain.model.TrackingLogItem
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
private const val NO_ID = 0L
|
private const val NO_ID = 0L
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ class TrackingRepository(
|
|||||||
newChapters = when {
|
newChapters = when {
|
||||||
track.newChapters == 0 -> 0
|
track.newChapters == 0 -> 0
|
||||||
chapterIndex < 0 -> track.newChapters
|
chapterIndex < 0 -> track.newChapters
|
||||||
chapterIndex > lastNewChapterIndex -> chapters.lastIndex - chapterIndex
|
chapterIndex >= lastNewChapterIndex -> chapters.lastIndex - chapterIndex
|
||||||
else -> track.newChapters
|
else -> track.newChapters
|
||||||
},
|
},
|
||||||
lastCheck = System.currentTimeMillis(),
|
lastCheck = System.currentTimeMillis(),
|
||||||
|
|||||||
Reference in New Issue
Block a user