Address misc. build warnings

This commit is contained in:
arkon 2022-08-10 23:26:34 -04:00
parent 24e64f52e2
commit d6f1534ee8
29 changed files with 96 additions and 37 deletions

View File

@ -298,6 +298,8 @@ tasks {
"-opt-in=androidx.compose.foundation.ExperimentalFoundationApi", "-opt-in=androidx.compose.foundation.ExperimentalFoundationApi",
"-opt-in=androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi", "-opt-in=androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi",
"-opt-in=androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi", "-opt-in=androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=kotlinx.coroutines.FlowPreview",
"-opt-in=kotlinx.coroutines.InternalCoroutinesApi", "-opt-in=kotlinx.coroutines.InternalCoroutinesApi",
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi", "-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
) )

View File

@ -12,10 +12,10 @@ class CreateCategoryWithName(
private val categoryRepository: CategoryRepository, private val categoryRepository: CategoryRepository,
) { ) {
suspend fun await(name: String): Result = withContext(NonCancellable) await@{ suspend fun await(name: String): Result = withContext(NonCancellable) {
val categories = categoryRepository.getAll() val categories = categoryRepository.getAll()
if (categories.anyWithName(name)) { if (categories.anyWithName(name)) {
return@await Result.NameAlreadyExistsError return@withContext Result.NameAlreadyExistsError
} }
val nextOrder = categories.maxOfOrNull { it.order }?.plus(1) ?: 0 val nextOrder = categories.maxOfOrNull { it.order }?.plus(1) ?: 0

View File

@ -11,12 +11,12 @@ class DeleteCategory(
private val categoryRepository: CategoryRepository, private val categoryRepository: CategoryRepository,
) { ) {
suspend fun await(categoryId: Long) = withContext(NonCancellable) await@{ suspend fun await(categoryId: Long) = withContext(NonCancellable) {
try { try {
categoryRepository.delete(categoryId) categoryRepository.delete(categoryId)
} catch (e: Exception) { } catch (e: Exception) {
logcat(LogPriority.ERROR, e) logcat(LogPriority.ERROR, e)
return@await Result.InternalError(e) return@withContext Result.InternalError(e)
} }
val categories = categoryRepository.getAll() val categories = categoryRepository.getAll()

View File

@ -13,10 +13,10 @@ class RenameCategory(
private val categoryRepository: CategoryRepository, private val categoryRepository: CategoryRepository,
) { ) {
suspend fun await(categoryId: Long, name: String) = withContext(NonCancellable) await@{ suspend fun await(categoryId: Long, name: String) = withContext(NonCancellable) {
val categories = categoryRepository.getAll() val categories = categoryRepository.getAll()
if (categories.anyWithName(name)) { if (categories.anyWithName(name)) {
return@await Result.NameAlreadyExistsError return@withContext Result.NameAlreadyExistsError
} }
val update = CategoryUpdate( val update = CategoryUpdate(

View File

@ -12,12 +12,12 @@ class ReorderCategory(
private val categoryRepository: CategoryRepository, private val categoryRepository: CategoryRepository,
) { ) {
suspend fun await(categoryId: Long, newPosition: Int) = withContext(NonCancellable) await@{ suspend fun await(categoryId: Long, newPosition: Int) = withContext(NonCancellable) {
val categories = categoryRepository.getAll().filterNot(Category::isSystemCategory) val categories = categoryRepository.getAll().filterNot(Category::isSystemCategory)
val currentIndex = categories.indexOfFirst { it.id == categoryId } val currentIndex = categories.indexOfFirst { it.id == categoryId }
if (currentIndex == newPosition) { if (currentIndex == newPosition) {
return@await Result.Unchanged return@withContext Result.Unchanged
} }
val reorderedCategories = categories.toMutableList() val reorderedCategories = categories.toMutableList()

View File

@ -27,11 +27,11 @@ class SetReadStatus(
) )
} }
suspend fun await(read: Boolean, vararg values: Chapter): Result = withContext(NonCancellable) f@{ suspend fun await(read: Boolean, vararg values: Chapter): Result = withContext(NonCancellable) {
val chapters = values.filterNot { it.read == read } val chapters = values.filterNot { it.read == read }
if (chapters.isEmpty()) { if (chapters.isEmpty()) {
return@f Result.NoChapters return@withContext Result.NoChapters
} }
val manga = chapters.fold(mutableSetOf<Manga>()) { acc, chapter -> val manga = chapters.fold(mutableSetOf<Manga>()) { acc, chapter ->
@ -49,15 +49,15 @@ class SetReadStatus(
) )
} catch (e: Exception) { } catch (e: Exception) {
logcat(LogPriority.ERROR, e) logcat(LogPriority.ERROR, e)
return@f Result.InternalError(e) return@withContext Result.InternalError(e)
} }
if (read && preferences.removeAfterMarkedAsRead()) { if (read && preferences.removeAfterMarkedAsRead()) {
manga.forEach { manga -> manga.forEach {
deleteDownload.awaitAll( deleteDownload.awaitAll(
manga = manga, manga = it,
values = chapters values = chapters
.filter { manga.id == it.mangaId } .filter { chapter -> it.id == chapter.mangaId }
.toTypedArray(), .toTypedArray(),
) )
} }
@ -66,8 +66,8 @@ class SetReadStatus(
Result.Success Result.Success
} }
suspend fun await(mangaId: Long, read: Boolean): Result = withContext(NonCancellable) f@{ suspend fun await(mangaId: Long, read: Boolean): Result = withContext(NonCancellable) {
return@f await( await(
read = read, read = read,
values = chapterRepository values = chapterRepository
.getChapterByMangaId(mangaId) .getChapterByMangaId(mangaId)

View File

@ -198,6 +198,7 @@ object Migrations {
val oldSortingMode = prefs.getInt(PreferenceKeys.librarySortingMode, 0) val oldSortingMode = prefs.getInt(PreferenceKeys.librarySortingMode, 0)
val oldSortingDirection = prefs.getBoolean(PreferenceKeys.librarySortingDirection, true) val oldSortingDirection = prefs.getBoolean(PreferenceKeys.librarySortingDirection, true)
@Suppress("DEPRECATION")
val newSortingMode = when (oldSortingMode) { val newSortingMode = when (oldSortingMode) {
0 -> SortModeSetting.ALPHABETICAL 0 -> SortModeSetting.ALPHABETICAL
1 -> SortModeSetting.LAST_READ 1 -> SortModeSetting.LAST_READ

View File

@ -10,6 +10,7 @@ import androidx.core.content.ContextCompat
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.util.system.acquireWakeLock import eu.kanade.tachiyomi.util.system.acquireWakeLock
import eu.kanade.tachiyomi.util.system.getParcelableExtraCompat
import eu.kanade.tachiyomi.util.system.isServiceRunning import eu.kanade.tachiyomi.util.system.isServiceRunning
import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineExceptionHandler
@ -114,7 +115,7 @@ class BackupRestoreService : Service() {
* @return the start value of the command. * @return the start value of the command.
*/ */
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val uri = intent?.getParcelableExtra<Uri>(BackupConst.EXTRA_URI) ?: return START_NOT_STICKY val uri = intent?.getParcelableExtraCompat<Uri>(BackupConst.EXTRA_URI) ?: return START_NOT_STICKY
// Cancel any previous job if needed. // Cancel any previous job if needed.
restorer?.job?.cancel() restorer?.job?.cancel()

View File

@ -31,6 +31,7 @@ data class BackupTracking(
fun getTrackingImpl(): TrackImpl { fun getTrackingImpl(): TrackImpl {
return TrackImpl().apply { return TrackImpl().apply {
sync_id = this@BackupTracking.syncId sync_id = this@BackupTracking.syncId
@Suppress("DEPRECATION")
media_id = if (this@BackupTracking.mediaIdInt != 0) { media_id = if (this@BackupTracking.mediaIdInt != 0) {
this@BackupTracking.mediaIdInt.toLong() this@BackupTracking.mediaIdInt.toLong()
} else { } else {

View File

@ -49,7 +49,7 @@ class DownloadPendingDeleter(context: Context) {
// Last entry matches the manga, reuse it to avoid decoding json from preferences // Last entry matches the manga, reuse it to avoid decoding json from preferences
lastEntry.copy(chapters = newChapters) lastEntry.copy(chapters = newChapters)
} else { } else {
val existingEntry = preferences.getString(manga.id!!.toString(), null) val existingEntry = preferences.getString(manga.id.toString(), null)
if (existingEntry != null) { if (existingEntry != null) {
// Existing entry found on preferences, decode json and add the new chapter // Existing entry found on preferences, decode json and add the new chapter
val savedEntry = json.decodeFromString<Entry>(existingEntry) val savedEntry = json.decodeFromString<Entry>(existingEntry)

View File

@ -114,7 +114,7 @@ class DownloadStore(
* @param download the download to serialize. * @param download the download to serialize.
*/ */
private fun serialize(download: Download): String { private fun serialize(download: Download): String {
val obj = DownloadObject(download.manga.id!!, download.chapter.id!!, counter++) val obj = DownloadObject(download.manga.id, download.chapter.id!!, counter++)
return json.encodeToString(obj) return json.encodeToString(obj)
} }

View File

@ -52,6 +52,7 @@ import eu.kanade.tachiyomi.util.shouldDownloadNewChapters
import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.acquireWakeLock import eu.kanade.tachiyomi.util.system.acquireWakeLock
import eu.kanade.tachiyomi.util.system.createFileInCacheDir import eu.kanade.tachiyomi.util.system.createFileInCacheDir
import eu.kanade.tachiyomi.util.system.getSerializableExtraCompat
import eu.kanade.tachiyomi.util.system.isServiceRunning import eu.kanade.tachiyomi.util.system.isServiceRunning
import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineExceptionHandler
@ -223,7 +224,7 @@ class LibraryUpdateService(
*/ */
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (intent == null) return START_NOT_STICKY if (intent == null) return START_NOT_STICKY
val target = intent.getSerializableExtra(KEY_TARGET) as? Target val target = intent.getSerializableExtraCompat<Target>(KEY_TARGET)
?: return START_NOT_STICKY ?: return START_NOT_STICKY
instance = this instance = this

View File

@ -29,6 +29,7 @@ import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.storage.DiskUtil
import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.getParcelableExtraCompat
import eu.kanade.tachiyomi.util.system.notificationManager import eu.kanade.tachiyomi.util.system.notificationManager
import eu.kanade.tachiyomi.util.system.toShareIntent import eu.kanade.tachiyomi.util.system.toShareIntent
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
@ -82,7 +83,7 @@ class NotificationReceiver : BroadcastReceiver() {
ACTION_SHARE_BACKUP -> ACTION_SHARE_BACKUP ->
shareFile( shareFile(
context, context,
intent.getParcelableExtra(EXTRA_URI)!!, intent.getParcelableExtraCompat(EXTRA_URI)!!,
"application/x-protobuf+gzip", "application/x-protobuf+gzip",
intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1), intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1),
) )
@ -130,7 +131,7 @@ class NotificationReceiver : BroadcastReceiver() {
ACTION_SHARE_CRASH_LOG -> ACTION_SHARE_CRASH_LOG ->
shareFile( shareFile(
context, context,
intent.getParcelableExtra(EXTRA_URI)!!, intent.getParcelableExtraCompat(EXTRA_URI)!!,
"text/plain", "text/plain",
intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1), intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1),
) )

View File

@ -10,6 +10,7 @@ import android.content.pm.PackageInstaller
import android.os.Build import android.os.Build
import eu.kanade.tachiyomi.extension.model.InstallStep import eu.kanade.tachiyomi.extension.model.InstallStep
import eu.kanade.tachiyomi.util.lang.use import eu.kanade.tachiyomi.util.lang.use
import eu.kanade.tachiyomi.util.system.getParcelableExtraCompat
import eu.kanade.tachiyomi.util.system.getUriSize import eu.kanade.tachiyomi.util.system.getUriSize
import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.logcat
import logcat.LogPriority import logcat.LogPriority
@ -22,7 +23,7 @@ class PackageInstallerInstaller(private val service: Service) : Installer(servic
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE)) { when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE)) {
PackageInstaller.STATUS_PENDING_USER_ACTION -> { PackageInstaller.STATUS_PENDING_USER_ACTION -> {
val userAction = intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT) val userAction = intent.getParcelableExtraCompat<Intent>(Intent.EXTRA_INTENT)
if (userAction == null) { if (userAction == null) {
logcat(LogPriority.ERROR) { "Fatal error for $intent" } logcat(LogPriority.ERROR) { "Fatal error for $intent" }
continueQueue(InstallStep.Error) continueQueue(InstallStep.Error)

View File

@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.extension.installer.Installer
import eu.kanade.tachiyomi.extension.installer.PackageInstallerInstaller import eu.kanade.tachiyomi.extension.installer.PackageInstallerInstaller
import eu.kanade.tachiyomi.extension.installer.ShizukuInstaller import eu.kanade.tachiyomi.extension.installer.ShizukuInstaller
import eu.kanade.tachiyomi.extension.util.ExtensionInstaller.Companion.EXTRA_DOWNLOAD_ID import eu.kanade.tachiyomi.extension.util.ExtensionInstaller.Companion.EXTRA_DOWNLOAD_ID
import eu.kanade.tachiyomi.util.system.getSerializableExtraCompat
import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.logcat
import eu.kanade.tachiyomi.util.system.notificationBuilder import eu.kanade.tachiyomi.util.system.notificationBuilder
import logcat.LogPriority import logcat.LogPriority
@ -36,7 +37,7 @@ class ExtensionInstallService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val uri = intent?.data val uri = intent?.data
val id = intent?.getLongExtra(EXTRA_DOWNLOAD_ID, -1)?.takeIf { it != -1L } val id = intent?.getLongExtra(EXTRA_DOWNLOAD_ID, -1)?.takeIf { it != -1L }
val installerUsed = intent?.getSerializableExtra(EXTRA_INSTALLER) as? PreferenceValues.ExtensionInstaller val installerUsed = intent?.getSerializableExtraCompat<PreferenceValues.ExtensionInstaller>(EXTRA_INSTALLER)
if (uri == null || id == null || installerUsed == null) { if (uri == null || id == null || installerUsed == null) {
stopSelf() stopSelf()
return START_NOT_STICKY return START_NOT_STICKY

View File

@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.ui.browse.migration.MigrationFlags
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter
import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.util.system.getSerializableCompat
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -50,8 +51,8 @@ class SearchController(
override fun onRestoreInstanceState(savedInstanceState: Bundle) { override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState) super.onRestoreInstanceState(savedInstanceState)
manga = savedInstanceState.getSerializable(::manga.name) as? Manga manga = savedInstanceState.getSerializableCompat(::manga.name)
newManga = savedInstanceState.getSerializable(::newManga.name) as? Manga newManga = savedInstanceState.getSerializableCompat(::newManga.name)
} }
fun migrateManga(manga: Manga? = null, newManga: Manga?) { fun migrateManga(manga: Manga? = null, newManga: Manga?) {

View File

@ -6,6 +6,7 @@ import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController
import eu.kanade.tachiyomi.ui.browse.source.browse.SourceItem import eu.kanade.tachiyomi.ui.browse.source.browse.SourceItem
import eu.kanade.tachiyomi.util.system.getSerializableCompat
class SourceSearchController( class SourceSearchController(
bundle: Bundle, bundle: Bundle,
@ -20,7 +21,7 @@ class SourceSearchController(
} }
}, },
) )
private var oldManga: Manga? = args.getSerializable(MANGA_KEY) as Manga? private var oldManga: Manga? = args.getSerializableCompat(MANGA_KEY)
private var newManga: Manga? = null private var newManga: Manga? = null
override fun onItemClick(view: View, position: Int): Boolean { override fun onItemClick(view: View, position: Int): Boolean {

View File

@ -52,12 +52,12 @@ class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMo
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other is SourceItem) { if (other is SourceItem) {
return manga.id!! == other.manga.id!! return manga.id == other.manga.id
} }
return false return false
} }
override fun hashCode(): Int { override fun hashCode(): Int {
return manga.id!!.hashCode() return manga.id.hashCode()
} }
} }

View File

@ -40,7 +40,7 @@ class AddDuplicateMangaDialog(bundle: Bundle? = null) : DialogController(bundle)
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.setNeutralButton(activity?.getString(R.string.action_show_manga)) { _, _ -> .setNeutralButton(activity?.getString(R.string.action_show_manga)) { _, _ ->
dismissDialog() dismissDialog()
router.pushController(MangaController(libraryManga.id!!)) router.pushController(MangaController(libraryManga.id))
} }
.setCancelable(true) .setCancelable(true)
.create() .create()

View File

@ -8,6 +8,7 @@ import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.chapter.ChapterSettingsHelper import eu.kanade.tachiyomi.util.chapter.ChapterSettingsHelper
import eu.kanade.tachiyomi.util.system.getSerializableCompat
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.widget.DialogCheckboxView import eu.kanade.tachiyomi.widget.DialogCheckboxView
@ -27,7 +28,7 @@ class SetChapterSettingsDialog(bundle: Bundle? = null) : DialogController(bundle
.setTitle(R.string.chapter_settings) .setTitle(R.string.chapter_settings)
.setView(view) .setView(view)
.setPositiveButton(android.R.string.ok) { _, _ -> .setPositiveButton(android.R.string.ok) { _, _ ->
ChapterSettingsHelper.setGlobalSettings(args.getSerializable(MANGA_KEY)!! as Manga) ChapterSettingsHelper.setGlobalSettings(args.getSerializableCompat(MANGA_KEY)!!)
if (view.isChecked()) { if (view.isChecked()) {
ChapterSettingsHelper.updateAllMangasWithGlobalDefaults() ChapterSettingsHelper.updateAllMangasWithGlobalDefaults()
} }

View File

@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.databinding.TrackChaptersDialogBinding import eu.kanade.tachiyomi.databinding.TrackChaptersDialogBinding
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.system.getSerializableCompat
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -31,7 +32,7 @@ class SetTrackChaptersDialog<T> : DialogController
@Suppress("unused") @Suppress("unused")
constructor(bundle: Bundle) : super(bundle) { constructor(bundle: Bundle) : super(bundle) {
val track = bundle.getSerializable(KEY_ITEM_TRACK) as Track val track = bundle.getSerializableCompat<Track>(KEY_ITEM_TRACK)!!
val service = Injekt.get<TrackManager>().getService(track.sync_id.toLong())!! val service = Injekt.get<TrackManager>().getService(track.sync_id.toLong())!!
item = TrackItem(track, service) item = TrackItem(track, service)
} }

View File

@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.databinding.TrackScoreDialogBinding import eu.kanade.tachiyomi.databinding.TrackScoreDialogBinding
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.system.getSerializableCompat
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -31,7 +32,7 @@ class SetTrackScoreDialog<T> : DialogController
@Suppress("unused") @Suppress("unused")
constructor(bundle: Bundle) : super(bundle) { constructor(bundle: Bundle) : super(bundle) {
val track = bundle.getSerializable(KEY_ITEM_TRACK) as Track val track = bundle.getSerializableCompat<Track>(KEY_ITEM_TRACK)!!
val service = Injekt.get<TrackManager>().getService(track.sync_id.toLong())!! val service = Injekt.get<TrackManager>().getService(track.sync_id.toLong())!!
item = TrackItem(track, service) item = TrackItem(track, service)
} }

View File

@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.system.getSerializableCompat
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -29,7 +30,7 @@ class SetTrackStatusDialog<T> : DialogController
@Suppress("unused") @Suppress("unused")
constructor(bundle: Bundle) : super(bundle) { constructor(bundle: Bundle) : super(bundle) {
val track = bundle.getSerializable(KEY_ITEM_TRACK) as Track val track = bundle.getSerializableCompat<Track>(KEY_ITEM_TRACK)!!
val service = Injekt.get<TrackManager>().getService(track.sync_id.toLong())!! val service = Injekt.get<TrackManager>().getService(track.sync_id.toLong())!!
item = TrackItem(track, service) item = TrackItem(track, service)
} }

View File

@ -103,7 +103,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
} }
}, },
) )
pager.tapListener = f@{ event -> pager.tapListener = { event ->
val pos = PointF(event.rawX / pager.width, event.rawY / pager.height) val pos = PointF(event.rawX / pager.width, event.rawY / pager.height)
val navigator = config.navigator val navigator = config.navigator

View File

@ -116,7 +116,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
} }
}, },
) )
recycler.tapListener = f@{ event -> recycler.tapListener = { event ->
val pos = PointF(event.rawX / recycler.width, event.rawY / recycler.height) val pos = PointF(event.rawX / recycler.width, event.rawY / recycler.height)
val navigator = config.navigator val navigator = config.navigator

View File

@ -37,6 +37,7 @@ import eu.kanade.tachiyomi.util.preference.preferenceCategory
import eu.kanade.tachiyomi.util.preference.summaryRes import eu.kanade.tachiyomi.util.preference.summaryRes
import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.preference.titleRes
import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.util.system.DeviceUtil
import eu.kanade.tachiyomi.util.system.getParcelableCompat
import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.openInBrowser
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
@ -266,7 +267,7 @@ class SettingsBackupController : SettingsController() {
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val activity = activity!! val activity = activity!!
val uri: Uri = args.getParcelable(KEY_URI)!! val uri = args.getParcelableCompat<Uri>(KEY_URI)!!
return try { return try {
val results = BackupFileValidator().validate(activity, uri) val results = BackupFileValidator().validate(activity, uri)

View File

@ -1,3 +1,5 @@
@file:Suppress("NOTHING_TO_INLINE")
package eu.kanade.tachiyomi.util.preference package eu.kanade.tachiyomi.util.preference
import androidx.annotation.StringRes import androidx.annotation.StringRes

View File

@ -4,7 +4,10 @@ import android.content.ClipData
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Bundle
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import java.io.Serializable
fun Uri.toShareIntent(context: Context, type: String = "image/*", message: String? = null): Intent { fun Uri.toShareIntent(context: Context, type: String = "image/*", message: String? = null): Intent {
val uri = this val uri = this
@ -21,3 +24,39 @@ fun Uri.toShareIntent(context: Context, type: String = "image/*", message: Strin
flags = Intent.FLAG_ACTIVITY_NEW_TASK flags = Intent.FLAG_ACTIVITY_NEW_TASK
} }
} }
inline fun <reified T> Intent.getParcelableExtraCompat(name: String): T? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
getParcelableExtra(name, T::class.java)
} else {
@Suppress("DEPRECATION")
getParcelableExtra(name)
}
}
inline fun <reified T : Serializable> Intent.getSerializableExtraCompat(name: String): T? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
getSerializableExtra(name, T::class.java)
} else {
@Suppress("DEPRECATION")
getSerializableExtra(name) as? T
}
}
inline fun <reified T : Serializable> Bundle.getSerializableCompat(name: String): T? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
getSerializable(name, T::class.java)
} else {
@Suppress("DEPRECATION")
getSerializable(name) as? T
}
}
inline fun <reified T> Bundle.getParcelableCompat(name: String): T? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
getParcelable(name, T::class.java)
} else {
@Suppress("DEPRECATION")
getParcelable(name)
}
}

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.util.system package eu.kanade.tachiyomi.util.system
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.res.Resources import android.content.res.Resources
@ -20,6 +21,7 @@ object InternalResourceHelper {
* @param type resource type of [resName] to get * @param type resource type of [resName] to get
* @return 0 if not available * @return 0 if not available
*/ */
@SuppressLint("DiscouragedApi")
private fun getResourceId(resName: String, type: String): Int { private fun getResourceId(resName: String, type: String): Int {
return Resources.getSystem().getIdentifier(resName, type, "android") return Resources.getSystem().getIdentifier(resName, type, "android")
} }