|
|
|
@ -21,6 +21,7 @@ import kotlinx.coroutines.launch
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.core.db.TABLE_HISTORY
|
|
|
|
import org.koitharu.kotatsu.core.db.TABLE_HISTORY
|
|
|
|
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
|
|
|
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.parser.favicon.faviconUri
|
|
|
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
|
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
|
|
import org.koitharu.kotatsu.core.ui.image.ThumbnailTransformation
|
|
|
|
import org.koitharu.kotatsu.core.ui.image.ThumbnailTransformation
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.getDrawableOrThrow
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.getDrawableOrThrow
|
|
|
|
@ -29,8 +30,10 @@ import org.koitharu.kotatsu.core.util.ext.processLifecycleScope
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.source
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.source
|
|
|
|
import org.koitharu.kotatsu.history.data.HistoryRepository
|
|
|
|
import org.koitharu.kotatsu.history.data.HistoryRepository
|
|
|
|
import org.koitharu.kotatsu.parsers.model.Manga
|
|
|
|
import org.koitharu.kotatsu.parsers.model.Manga
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
|
|
|
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
|
|
|
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
|
|
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
|
|
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
|
|
|
import javax.inject.Inject
|
|
|
|
import javax.inject.Inject
|
|
|
|
import javax.inject.Singleton
|
|
|
|
import javax.inject.Singleton
|
|
|
|
|
|
|
|
|
|
|
|
@ -77,6 +80,10 @@ class AppShortcutManager @Inject constructor(
|
|
|
|
return ShortcutManagerCompat.requestPinShortcut(context, buildShortcutInfo(manga), null)
|
|
|
|
return ShortcutManagerCompat.requestPinShortcut(context, buildShortcutInfo(manga), null)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
suspend fun requestPinShortcut(source: MangaSource): Boolean {
|
|
|
|
|
|
|
|
return ShortcutManagerCompat.requestPinShortcut(context, buildShortcutInfo(source), null)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
@VisibleForTesting
|
|
|
|
suspend fun await(): Boolean {
|
|
|
|
suspend fun await(): Boolean {
|
|
|
|
return shortcutsUpdateJob?.join() != null
|
|
|
|
return shortcutsUpdateJob?.join() != null
|
|
|
|
@ -86,6 +93,11 @@ class AppShortcutManager @Inject constructor(
|
|
|
|
ShortcutManagerCompat.reportShortcutUsed(context, mangaId.toString())
|
|
|
|
ShortcutManagerCompat.reportShortcutUsed(context, mangaId.toString())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun isDynamicShortcutsAvailable(): Boolean {
|
|
|
|
|
|
|
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 &&
|
|
|
|
|
|
|
|
context.getSystemService(ShortcutManager::class.java).maxShortcutCountPerActivity > 0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private suspend fun updateShortcutsImpl() = runCatchingCancellable {
|
|
|
|
private suspend fun updateShortcutsImpl() = runCatchingCancellable {
|
|
|
|
val maxShortcuts = ShortcutManagerCompat.getMaxShortcutCountPerActivity(context).coerceAtLeast(5)
|
|
|
|
val maxShortcuts = ShortcutManagerCompat.getMaxShortcutCountPerActivity(context).coerceAtLeast(5)
|
|
|
|
val shortcuts = historyRepository.getList(0, maxShortcuts)
|
|
|
|
val shortcuts = historyRepository.getList(0, maxShortcuts)
|
|
|
|
@ -132,8 +144,25 @@ class AppShortcutManager @Inject constructor(
|
|
|
|
.build()
|
|
|
|
.build()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun isDynamicShortcutsAvailable(): Boolean {
|
|
|
|
private suspend fun buildShortcutInfo(source: MangaSource): ShortcutInfoCompat {
|
|
|
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 &&
|
|
|
|
val icon = runCatchingCancellable {
|
|
|
|
context.getSystemService(ShortcutManager::class.java).maxShortcutCountPerActivity > 0
|
|
|
|
coil.execute(
|
|
|
|
|
|
|
|
ImageRequest.Builder(context)
|
|
|
|
|
|
|
|
.data(source.faviconUri())
|
|
|
|
|
|
|
|
.size(iconSize)
|
|
|
|
|
|
|
|
.scale(Scale.FIT)
|
|
|
|
|
|
|
|
.build(),
|
|
|
|
|
|
|
|
).getDrawableOrThrow().toBitmap()
|
|
|
|
|
|
|
|
}.fold(
|
|
|
|
|
|
|
|
onSuccess = { IconCompat.createWithAdaptiveBitmap(it) },
|
|
|
|
|
|
|
|
onFailure = { IconCompat.createWithResource(context, R.drawable.ic_shortcut_default) },
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return ShortcutInfoCompat.Builder(context, source.name)
|
|
|
|
|
|
|
|
.setShortLabel(source.title)
|
|
|
|
|
|
|
|
.setLongLabel(source.title)
|
|
|
|
|
|
|
|
.setIcon(icon)
|
|
|
|
|
|
|
|
.setLongLived(true)
|
|
|
|
|
|
|
|
.setIntent(MangaListActivity.newIntent(context, source))
|
|
|
|
|
|
|
|
.build()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|