mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-25 18:38:23 +01:00
Address misc. build warnings
This commit is contained in:
parent
24e64f52e2
commit
d6f1534ee8
@ -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",
|
||||
)
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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(
|
||||
|
@ -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()
|
||||
|
@ -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<Manga>()) { 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)
|
||||
|
@ -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
|
||||
|
@ -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<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.
|
||||
restorer?.job?.cancel()
|
||||
|
@ -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 {
|
||||
|
@ -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<Entry>(existingEntry)
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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<Target>(KEY_TARGET)
|
||||
?: return START_NOT_STICKY
|
||||
|
||||
instance = this
|
||||
|
@ -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),
|
||||
)
|
||||
|
@ -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>(Intent.EXTRA_INTENT)
|
||||
val userAction = intent.getParcelableExtraCompat<Intent>(Intent.EXTRA_INTENT)
|
||||
if (userAction == null) {
|
||||
logcat(LogPriority.ERROR) { "Fatal error for $intent" }
|
||||
continueQueue(InstallStep.Error)
|
||||
|
@ -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<PreferenceValues.ExtensionInstaller>(EXTRA_INSTALLER)
|
||||
if (uri == null || id == null || installerUsed == null) {
|
||||
stopSelf()
|
||||
return START_NOT_STICKY
|
||||
|
@ -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?) {
|
||||
|
@ -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 {
|
||||
|
@ -52,12 +52,12 @@ class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMo
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other is SourceItem) {
|
||||
return manga.id!! == other.manga.id!!
|
||||
return manga.id == other.manga.id
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return manga.id!!.hashCode()
|
||||
return manga.id.hashCode()
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class AddDuplicateMangaDialog(bundle: Bundle? = null) : DialogController(bundle)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setNeutralButton(activity?.getString(R.string.action_show_manga)) { _, _ ->
|
||||
dismissDialog()
|
||||
router.pushController(MangaController(libraryManga.id!!))
|
||||
router.pushController(MangaController(libraryManga.id))
|
||||
}
|
||||
.setCancelable(true)
|
||||
.create()
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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<T> : DialogController
|
||||
|
||||
@Suppress("unused")
|
||||
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())!!
|
||||
item = TrackItem(track, service)
|
||||
}
|
||||
|
@ -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<T> : DialogController
|
||||
|
||||
@Suppress("unused")
|
||||
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())!!
|
||||
item = TrackItem(track, service)
|
||||
}
|
||||
|
@ -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<T> : DialogController
|
||||
|
||||
@Suppress("unused")
|
||||
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())!!
|
||||
item = TrackItem(track, service)
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<Uri>(KEY_URI)!!
|
||||
|
||||
return try {
|
||||
val results = BackupFileValidator().validate(activity, uri)
|
||||
|
@ -1,3 +1,5 @@
|
||||
@file:Suppress("NOTHING_TO_INLINE")
|
||||
|
||||
package eu.kanade.tachiyomi.util.preference
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
|
@ -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 <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)
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user