diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 2338e8f8b..47fd447dd 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -298,6 +298,8 @@ tasks { "-opt-in=androidx.compose.foundation.ExperimentalFoundationApi", "-opt-in=androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi", "-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.serialization.ExperimentalSerializationApi", ) diff --git a/app/src/main/java/eu/kanade/domain/category/interactor/CreateCategoryWithName.kt b/app/src/main/java/eu/kanade/domain/category/interactor/CreateCategoryWithName.kt index d835634ba..b4c035bc4 100644 --- a/app/src/main/java/eu/kanade/domain/category/interactor/CreateCategoryWithName.kt +++ b/app/src/main/java/eu/kanade/domain/category/interactor/CreateCategoryWithName.kt @@ -12,10 +12,10 @@ class CreateCategoryWithName( 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() if (categories.anyWithName(name)) { - return@await Result.NameAlreadyExistsError + return@withContext Result.NameAlreadyExistsError } val nextOrder = categories.maxOfOrNull { it.order }?.plus(1) ?: 0 diff --git a/app/src/main/java/eu/kanade/domain/category/interactor/DeleteCategory.kt b/app/src/main/java/eu/kanade/domain/category/interactor/DeleteCategory.kt index 52992fcf5..58e85bb3b 100644 --- a/app/src/main/java/eu/kanade/domain/category/interactor/DeleteCategory.kt +++ b/app/src/main/java/eu/kanade/domain/category/interactor/DeleteCategory.kt @@ -11,12 +11,12 @@ class DeleteCategory( private val categoryRepository: CategoryRepository, ) { - suspend fun await(categoryId: Long) = withContext(NonCancellable) await@{ + suspend fun await(categoryId: Long) = withContext(NonCancellable) { try { categoryRepository.delete(categoryId) } catch (e: Exception) { logcat(LogPriority.ERROR, e) - return@await Result.InternalError(e) + return@withContext Result.InternalError(e) } val categories = categoryRepository.getAll() diff --git a/app/src/main/java/eu/kanade/domain/category/interactor/RenameCategory.kt b/app/src/main/java/eu/kanade/domain/category/interactor/RenameCategory.kt index e2fbc4d7e..1552bd5fc 100644 --- a/app/src/main/java/eu/kanade/domain/category/interactor/RenameCategory.kt +++ b/app/src/main/java/eu/kanade/domain/category/interactor/RenameCategory.kt @@ -13,10 +13,10 @@ class RenameCategory( 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() if (categories.anyWithName(name)) { - return@await Result.NameAlreadyExistsError + return@withContext Result.NameAlreadyExistsError } val update = CategoryUpdate( diff --git a/app/src/main/java/eu/kanade/domain/category/interactor/ReorderCategory.kt b/app/src/main/java/eu/kanade/domain/category/interactor/ReorderCategory.kt index a286103a6..1afeecdf4 100644 --- a/app/src/main/java/eu/kanade/domain/category/interactor/ReorderCategory.kt +++ b/app/src/main/java/eu/kanade/domain/category/interactor/ReorderCategory.kt @@ -12,12 +12,12 @@ class ReorderCategory( 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 currentIndex = categories.indexOfFirst { it.id == categoryId } if (currentIndex == newPosition) { - return@await Result.Unchanged + return@withContext Result.Unchanged } val reorderedCategories = categories.toMutableList() diff --git a/app/src/main/java/eu/kanade/domain/chapter/interactor/SetReadStatus.kt b/app/src/main/java/eu/kanade/domain/chapter/interactor/SetReadStatus.kt index 2264f234b..69503cbae 100644 --- a/app/src/main/java/eu/kanade/domain/chapter/interactor/SetReadStatus.kt +++ b/app/src/main/java/eu/kanade/domain/chapter/interactor/SetReadStatus.kt @@ -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 } if (chapters.isEmpty()) { - return@f Result.NoChapters + return@withContext Result.NoChapters } val manga = chapters.fold(mutableSetOf()) { acc, chapter -> @@ -49,15 +49,15 @@ class SetReadStatus( ) } catch (e: Exception) { logcat(LogPriority.ERROR, e) - return@f Result.InternalError(e) + return@withContext Result.InternalError(e) } if (read && preferences.removeAfterMarkedAsRead()) { - manga.forEach { manga -> + manga.forEach { deleteDownload.awaitAll( - manga = manga, + manga = it, values = chapters - .filter { manga.id == it.mangaId } + .filter { chapter -> it.id == chapter.mangaId } .toTypedArray(), ) } @@ -66,8 +66,8 @@ class SetReadStatus( Result.Success } - suspend fun await(mangaId: Long, read: Boolean): Result = withContext(NonCancellable) f@{ - return@f await( + suspend fun await(mangaId: Long, read: Boolean): Result = withContext(NonCancellable) { + await( read = read, values = chapterRepository .getChapterByMangaId(mangaId) diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index 10bdd4ce4..867002d23 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -198,6 +198,7 @@ object Migrations { val oldSortingMode = prefs.getInt(PreferenceKeys.librarySortingMode, 0) val oldSortingDirection = prefs.getBoolean(PreferenceKeys.librarySortingDirection, true) + @Suppress("DEPRECATION") val newSortingMode = when (oldSortingMode) { 0 -> SortModeSetting.ALPHABETICAL 1 -> SortModeSetting.LAST_READ diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt index 53b2e7f56..e0cf8f2e6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt @@ -10,6 +10,7 @@ import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.Notifications 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.logcat import kotlinx.coroutines.CoroutineExceptionHandler @@ -114,7 +115,7 @@ class BackupRestoreService : Service() { * @return the start value of the command. */ override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { - val uri = intent?.getParcelableExtra(BackupConst.EXTRA_URI) ?: return START_NOT_STICKY + val uri = intent?.getParcelableExtraCompat(BackupConst.EXTRA_URI) ?: return START_NOT_STICKY // Cancel any previous job if needed. restorer?.job?.cancel() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/BackupTracking.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/BackupTracking.kt index 80c7d28a5..8a04f8796 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/BackupTracking.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/BackupTracking.kt @@ -31,6 +31,7 @@ data class BackupTracking( fun getTrackingImpl(): TrackImpl { return TrackImpl().apply { sync_id = this@BackupTracking.syncId + @Suppress("DEPRECATION") media_id = if (this@BackupTracking.mediaIdInt != 0) { this@BackupTracking.mediaIdInt.toLong() } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadPendingDeleter.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadPendingDeleter.kt index 945e57ca8..12301a5d1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadPendingDeleter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadPendingDeleter.kt @@ -49,7 +49,7 @@ class DownloadPendingDeleter(context: Context) { // Last entry matches the manga, reuse it to avoid decoding json from preferences lastEntry.copy(chapters = newChapters) } else { - val existingEntry = preferences.getString(manga.id!!.toString(), null) + val existingEntry = preferences.getString(manga.id.toString(), null) if (existingEntry != null) { // Existing entry found on preferences, decode json and add the new chapter val savedEntry = json.decodeFromString(existingEntry) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadStore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadStore.kt index 19a4f45c9..a275a1d4f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadStore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadStore.kt @@ -114,7 +114,7 @@ class DownloadStore( * @param download the download to serialize. */ 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) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index befe750c1..802bb77a8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -52,6 +52,7 @@ import eu.kanade.tachiyomi.util.shouldDownloadNewChapters import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.system.acquireWakeLock 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.logcat import kotlinx.coroutines.CoroutineExceptionHandler @@ -223,7 +224,7 @@ class LibraryUpdateService( */ override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { if (intent == null) return START_NOT_STICKY - val target = intent.getSerializableExtra(KEY_TARGET) as? Target + val target = intent.getSerializableExtraCompat(KEY_TARGET) ?: return START_NOT_STICKY instance = this diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt index 71c565b7c..db5bd65da 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt @@ -29,6 +29,7 @@ import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.storage.DiskUtil 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.toShareIntent import eu.kanade.tachiyomi.util.system.toast @@ -82,7 +83,7 @@ class NotificationReceiver : BroadcastReceiver() { ACTION_SHARE_BACKUP -> shareFile( context, - intent.getParcelableExtra(EXTRA_URI)!!, + intent.getParcelableExtraCompat(EXTRA_URI)!!, "application/x-protobuf+gzip", intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1), ) @@ -130,7 +131,7 @@ class NotificationReceiver : BroadcastReceiver() { ACTION_SHARE_CRASH_LOG -> shareFile( context, - intent.getParcelableExtra(EXTRA_URI)!!, + intent.getParcelableExtraCompat(EXTRA_URI)!!, "text/plain", intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1), ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/installer/PackageInstallerInstaller.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/installer/PackageInstallerInstaller.kt index ecaedf10c..c8ee92aab 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/installer/PackageInstallerInstaller.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/installer/PackageInstallerInstaller.kt @@ -10,6 +10,7 @@ import android.content.pm.PackageInstaller import android.os.Build import eu.kanade.tachiyomi.extension.model.InstallStep 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.logcat import logcat.LogPriority @@ -22,7 +23,7 @@ class PackageInstallerInstaller(private val service: Service) : Installer(servic override fun onReceive(context: Context, intent: Intent) { when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE)) { PackageInstaller.STATUS_PENDING_USER_ACTION -> { - val userAction = intent.getParcelableExtra(Intent.EXTRA_INTENT) + val userAction = intent.getParcelableExtraCompat(Intent.EXTRA_INTENT) if (userAction == null) { logcat(LogPriority.ERROR) { "Fatal error for $intent" } continueQueue(InstallStep.Error) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallService.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallService.kt index 2b8301fe9..8a787b548 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallService.kt @@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.extension.installer.Installer import eu.kanade.tachiyomi.extension.installer.PackageInstallerInstaller import eu.kanade.tachiyomi.extension.installer.ShizukuInstaller 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.notificationBuilder import logcat.LogPriority @@ -36,7 +37,7 @@ class ExtensionInstallService : Service() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { val uri = intent?.data val id = intent?.getLongExtra(EXTRA_DOWNLOAD_ID, -1)?.takeIf { it != -1L } - val installerUsed = intent?.getSerializableExtra(EXTRA_INSTALLER) as? PreferenceValues.ExtensionInstaller + val installerUsed = intent?.getSerializableExtraCompat(EXTRA_INSTALLER) if (uri == null || id == null || installerUsed == null) { stopSelf() return START_NOT_STICKY diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt index e49c58d7b..2b5245698 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt @@ -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.GlobalSearchPresenter import eu.kanade.tachiyomi.ui.manga.MangaController +import eu.kanade.tachiyomi.util.system.getSerializableCompat import kotlinx.coroutines.runBlocking import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -50,8 +51,8 @@ class SearchController( override fun onRestoreInstanceState(savedInstanceState: Bundle) { super.onRestoreInstanceState(savedInstanceState) - manga = savedInstanceState.getSerializable(::manga.name) as? Manga - newManga = savedInstanceState.getSerializable(::newManga.name) as? Manga + manga = savedInstanceState.getSerializableCompat(::manga.name) + newManga = savedInstanceState.getSerializableCompat(::newManga.name) } fun migrateManga(manga: Manga? = null, newManga: Manga?) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SourceSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SourceSearchController.kt index ce1e0198c..8df3a45a4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SourceSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SourceSearchController.kt @@ -6,6 +6,7 @@ import eu.kanade.domain.manga.model.Manga import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.browse.source.browse.SourceItem +import eu.kanade.tachiyomi.util.system.getSerializableCompat class SourceSearchController( 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 override fun onItemClick(view: View, position: Int): Boolean { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceItem.kt index 52472591b..d17c38b07 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceItem.kt @@ -52,12 +52,12 @@ class SourceItem(val manga: Manga, private val displayMode: Preference dismissDialog() - router.pushController(MangaController(libraryManga.id!!)) + router.pushController(MangaController(libraryManga.id)) } .setCancelable(true) .create() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetChapterSettingsDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetChapterSettingsDialog.kt index 2b82892d6..7403d2134 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetChapterSettingsDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetChapterSettingsDialog.kt @@ -8,6 +8,7 @@ import eu.kanade.domain.manga.model.Manga import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.controller.DialogController 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.widget.DialogCheckboxView @@ -27,7 +28,7 @@ class SetChapterSettingsDialog(bundle: Bundle? = null) : DialogController(bundle .setTitle(R.string.chapter_settings) .setView(view) .setPositiveButton(android.R.string.ok) { _, _ -> - ChapterSettingsHelper.setGlobalSettings(args.getSerializable(MANGA_KEY)!! as Manga) + ChapterSettingsHelper.setGlobalSettings(args.getSerializableCompat(MANGA_KEY)!!) if (view.isChecked()) { ChapterSettingsHelper.updateAllMangasWithGlobalDefaults() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackChaptersDialog.kt index 51407cb4a..bb21d7906 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackChaptersDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackChaptersDialog.kt @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.databinding.TrackChaptersDialogBinding import eu.kanade.tachiyomi.ui.base.controller.DialogController +import eu.kanade.tachiyomi.util.system.getSerializableCompat import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -31,7 +32,7 @@ class SetTrackChaptersDialog : DialogController @Suppress("unused") constructor(bundle: Bundle) : super(bundle) { - val track = bundle.getSerializable(KEY_ITEM_TRACK) as Track + val track = bundle.getSerializableCompat(KEY_ITEM_TRACK)!! val service = Injekt.get().getService(track.sync_id.toLong())!! item = TrackItem(track, service) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackScoreDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackScoreDialog.kt index cf7cf426f..341c2befa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackScoreDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackScoreDialog.kt @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.databinding.TrackScoreDialogBinding import eu.kanade.tachiyomi.ui.base.controller.DialogController +import eu.kanade.tachiyomi.util.system.getSerializableCompat import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -31,7 +32,7 @@ class SetTrackScoreDialog : DialogController @Suppress("unused") constructor(bundle: Bundle) : super(bundle) { - val track = bundle.getSerializable(KEY_ITEM_TRACK) as Track + val track = bundle.getSerializableCompat(KEY_ITEM_TRACK)!! val service = Injekt.get().getService(track.sync_id.toLong())!! item = TrackItem(track, service) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt index 128dc3b7f..3bc439fc6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt @@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.ui.base.controller.DialogController +import eu.kanade.tachiyomi.util.system.getSerializableCompat import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -29,7 +30,7 @@ class SetTrackStatusDialog : DialogController @Suppress("unused") constructor(bundle: Bundle) : super(bundle) { - val track = bundle.getSerializable(KEY_ITEM_TRACK) as Track + val track = bundle.getSerializableCompat(KEY_ITEM_TRACK)!! val service = Injekt.get().getService(track.sync_id.toLong())!! item = TrackItem(track, service) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt index 856789fd0..d8a04ad99 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt @@ -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 navigator = config.navigator diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt index 0f9f7cb0d..e6bf62d4e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt @@ -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 navigator = config.navigator diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index 4a5d1fa6b..1480a1618 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -37,6 +37,7 @@ import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.summaryRes import eu.kanade.tachiyomi.util.preference.titleRes 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.toast import kotlinx.coroutines.flow.launchIn @@ -266,7 +267,7 @@ class SettingsBackupController : SettingsController() { override fun onCreateDialog(savedViewState: Bundle?): Dialog { val activity = activity!! - val uri: Uri = args.getParcelable(KEY_URI)!! + val uri = args.getParcelableCompat(KEY_URI)!! return try { val results = BackupFileValidator().validate(activity, uri) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt index 70ce375e1..ef2ed1d91 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt @@ -1,3 +1,5 @@ +@file:Suppress("NOTHING_TO_INLINE") + package eu.kanade.tachiyomi.util.preference import androidx.annotation.StringRes diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/IntentExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/IntentExtensions.kt index ca5794479..38261857a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/IntentExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/IntentExtensions.kt @@ -4,7 +4,10 @@ import android.content.ClipData import android.content.Context import android.content.Intent import android.net.Uri +import android.os.Build +import android.os.Bundle import eu.kanade.tachiyomi.R +import java.io.Serializable fun Uri.toShareIntent(context: Context, type: String = "image/*", message: String? = null): Intent { val uri = this @@ -21,3 +24,39 @@ fun Uri.toShareIntent(context: Context, type: String = "image/*", message: Strin flags = Intent.FLAG_ACTIVITY_NEW_TASK } } + +inline fun 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 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 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 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) + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/InternalResourceHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/InternalResourceHelper.kt index 6570b7ffc..12529a19c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/InternalResourceHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/InternalResourceHelper.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.util.system +import android.annotation.SuppressLint import android.content.Context import android.content.res.Resources @@ -20,6 +21,7 @@ object InternalResourceHelper { * @param type resource type of [resName] to get * @return 0 if not available */ + @SuppressLint("DiscouragedApi") private fun getResourceId(resName: String, type: String): Int { return Resources.getSystem().getIdentifier(resName, type, "android") }