From 60755d0c26c55e8fa90406a973c00e0871c04723 Mon Sep 17 00:00:00 2001 From: Taco Date: Mon, 12 Oct 2020 16:46:25 -0400 Subject: [PATCH] Use some more KTX and Compat stuff (#3933) * Use more KTX extensions * Update Android Studio * Use more Compat classes --- .../tachiyomi/data/backup/BackupCreateService.kt | 8 ++------ .../data/backup/BackupRestoreService.kt | 8 ++------ .../tachiyomi/data/download/DownloadService.kt | 8 ++------ .../data/library/LibraryUpdateService.kt | 8 ++------ .../data/preference/PreferencesHelper.kt | 10 +++++----- .../tachiyomi/data/updater/UpdaterService.kt | 8 ++------ .../extension/util/ExtensionInstaller.kt | 2 +- .../tachiyomi/ui/browse/BrowseController.kt | 5 ++--- .../ui/browse/extension/ExtensionTrustDialog.kt | 9 +++++---- .../details/ExtensionDetailsController.kt | 5 ++--- .../details/SourcePreferencesController.kt | 5 ++--- .../migration/manga/MigrationMangaController.kt | 9 +++++---- .../source/latest/LatestUpdatesController.kt | 5 ++--- .../kanade/tachiyomi/ui/manga/MangaController.kt | 9 +++++---- .../chapter/DownloadCustomChaptersDialog.kt | 5 ++--- .../ui/manga/chapter/SetChapterSettingsDialog.kt | 5 ++--- .../ui/manga/track/SetTrackChaptersDialog.kt | 5 ++--- .../ui/manga/track/SetTrackReadingDatesDialog.kt | 5 ++--- .../ui/manga/track/SetTrackScoreDialog.kt | 5 ++--- .../ui/manga/track/SetTrackStatusDialog.kt | 5 ++--- .../tachiyomi/ui/manga/track/TrackController.kt | 5 ++--- .../ui/manga/track/TrackSearchDialog.kt | 5 ++--- .../kanade/tachiyomi/ui/more/AboutController.kt | 6 ++---- .../ui/setting/SettingsBackupController.kt | 5 ++--- .../ui/setting/track/TrackLoginDialog.kt | 3 ++- .../ui/setting/track/TrackLogoutDialog.kt | 3 ++- .../tachiyomi/util/system/ContextExtensions.kt | 2 +- .../kanade/tachiyomi/util/system/LocaleHelper.kt | 16 +++------------- buildSrc/src/main/kotlin/Dependencies.kt | 2 +- 29 files changed, 68 insertions(+), 108 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateService.kt index 4f6d329c0..a7c2100be 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateService.kt @@ -4,9 +4,9 @@ import android.app.Service import android.content.Context import android.content.Intent import android.net.Uri -import android.os.Build import android.os.IBinder import android.os.PowerManager +import androidx.core.content.ContextCompat import androidx.core.net.toUri import com.hippo.unifile.UniFile import eu.kanade.tachiyomi.data.notification.Notifications @@ -52,11 +52,7 @@ class BackupCreateService : Service() { putExtra(BackupConst.EXTRA_URI, uri) putExtra(BackupConst.EXTRA_FLAGS, flags) } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - context.startService(intent) - } else { - context.startForegroundService(intent) - } + ContextCompat.startForegroundService(context, intent) } } } 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 df51b1a99..318d09e07 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 @@ -4,9 +4,9 @@ import android.app.Service import android.content.Context import android.content.Intent import android.net.Uri -import android.os.Build import android.os.IBinder import android.os.PowerManager +import androidx.core.content.ContextCompat import com.github.salomonbrys.kotson.fromJson import com.google.gson.JsonArray import com.google.gson.JsonElement @@ -74,11 +74,7 @@ class BackupRestoreService : Service() { val intent = Intent(context, BackupRestoreService::class.java).apply { putExtra(BackupConst.EXTRA_URI, uri) } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - context.startService(intent) - } else { - context.startForegroundService(intent) - } + ContextCompat.startForegroundService(context, intent) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt index 403ccafc1..fa500d9c3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt @@ -7,9 +7,9 @@ import android.content.Intent import android.net.ConnectivityManager import android.net.NetworkInfo.State.CONNECTED import android.net.NetworkInfo.State.DISCONNECTED -import android.os.Build import android.os.IBinder import android.os.PowerManager +import androidx.core.content.ContextCompat import com.github.pwittchen.reactivenetwork.library.Connectivity import com.github.pwittchen.reactivenetwork.library.ReactiveNetwork import com.jakewharton.rxrelay.BehaviorRelay @@ -47,11 +47,7 @@ class DownloadService : Service() { */ fun start(context: Context) { val intent = Intent(context, DownloadService::class.java) - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - context.startService(intent) - } else { - context.startForegroundService(intent) - } + ContextCompat.startForegroundService(context, intent) } /** 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 49d64db7c..4884f87c0 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 @@ -3,9 +3,9 @@ package eu.kanade.tachiyomi.data.library import android.app.Service import android.content.Context import android.content.Intent -import android.os.Build import android.os.IBinder import android.os.PowerManager +import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper @@ -113,11 +113,7 @@ class LibraryUpdateService( putExtra(KEY_TARGET, target) category?.let { putExtra(KEY_CATEGORY, it.id) } } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - context.startService(intent) - } else { - context.startForegroundService(intent) - } + ContextCompat.startForegroundService(context, intent) return true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index a84b447dc..37cd602be 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -77,7 +77,7 @@ class PreferencesHelper(val context: Context) { fun showLibraryUpdateErrors() = prefs.getBoolean(Keys.showLibraryUpdateErrors, false) - fun clear() = prefs.edit().clear().apply() + fun clear() = prefs.edit { clear() } fun themeMode() = flowPrefs.getEnum(Keys.themeMode, Values.ThemeMode.system) @@ -164,10 +164,10 @@ class PreferencesHelper(val context: Context) { fun trackPassword(sync: TrackService) = prefs.getString(Keys.trackPassword(sync.id), "") fun setTrackCredentials(sync: TrackService, username: String, password: String) { - prefs.edit() - .putString(Keys.trackUsername(sync.id), username) - .putString(Keys.trackPassword(sync.id), password) - .apply() + prefs.edit { + putString(Keys.trackUsername(sync.id), username) + putString(Keys.trackPassword(sync.id), password) + } } fun trackToken(sync: TrackService) = flowPrefs.getString(Keys.trackToken(sync.id), "") diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterService.kt index 81103643e..089db2012 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterService.kt @@ -4,9 +4,9 @@ import android.app.PendingIntent import android.app.Service import android.content.Context import android.content.Intent -import android.os.Build import android.os.IBinder import android.os.PowerManager +import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.Notifications @@ -152,11 +152,7 @@ class UpdaterService : Service() { putExtra(EXTRA_DOWNLOAD_TITLE, title) putExtra(EXTRA_DOWNLOAD_URL, url) } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - context.startService(intent) - } else { - context.startForegroundService(intent) - } + ContextCompat.startForegroundService(context, intent) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt index 02ae9ae9f..488466391 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt @@ -29,7 +29,7 @@ internal class ExtensionInstaller(private val context: Context) { /** * The system's download manager */ - private val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager + private val downloadManager = context.getSystemService()!! /** * The broadcast receiver which listens to download completion events. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt index c1d60cd31..fe0682ca8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.os.bundleOf import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType @@ -31,9 +32,7 @@ class BrowseController : TabbedController { constructor(toExtensions: Boolean = false) : super( - Bundle().apply { - putBoolean(TO_EXTENSIONS_EXTRA, toExtensions) - } + bundleOf(TO_EXTENSIONS_EXTRA to toExtensions) ) @Suppress("unused") diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionTrustDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionTrustDialog.kt index 3a91724aa..1ee6db9d8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionTrustDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionTrustDialog.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.browse.extension import android.app.Dialog import android.os.Bundle +import androidx.core.os.bundleOf import com.afollestad.materialdialogs.MaterialDialog import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R @@ -11,10 +12,10 @@ class ExtensionTrustDialog(bundle: Bundle? = null) : DialogController(bundle) where T : Controller, T : ExtensionTrustDialog.Listener { constructor(target: T, signatureHash: String, pkgName: String) : this( - Bundle().apply { - putString(SIGNATURE_KEY, signatureHash) - putString(PKGNAME_KEY, pkgName) - } + bundleOf( + SIGNATURE_KEY to signatureHash, + PKGNAME_KEY to pkgName + ) ) { targetController = target } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt index b5ff00290..2921d439e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt @@ -14,6 +14,7 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.view.ContextThemeWrapper +import androidx.core.os.bundleOf import androidx.preference.Preference import androidx.preference.PreferenceGroupAdapter import androidx.preference.PreferenceManager @@ -55,9 +56,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : private var preferenceScreen: PreferenceScreen? = null constructor(pkgName: String) : this( - Bundle().apply { - putString(PKGNAME_KEY, pkgName) - } + bundleOf(PKGNAME_KEY to pkgName) ) init { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesController.kt index fa26cd208..844d956cc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesController.kt @@ -8,6 +8,7 @@ import android.view.ContextThemeWrapper import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.os.bundleOf import androidx.preference.DialogPreference import androidx.preference.EditTextPreference import androidx.preference.EditTextPreferenceDialogController @@ -41,9 +42,7 @@ class SourcePreferencesController(bundle: Bundle? = null) : private var preferenceScreen: PreferenceScreen? = null constructor(sourceId: Long) : this( - Bundle().apply { - putLong(SOURCE_ID, sourceId) - } + bundleOf(SOURCE_ID to sourceId) ) override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt index 62d8596ac..4e87121e5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.os.bundleOf import androidx.recyclerview.widget.LinearLayoutManager import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible @@ -19,10 +20,10 @@ class MigrationMangaController : private var adapter: FlexibleAdapter>? = null constructor(sourceId: Long, sourceName: String?) : super( - Bundle().apply { - putLong(SOURCE_ID_EXTRA, sourceId) - putString(SOURCE_NAME_EXTRA, sourceName) - } + bundleOf( + SOURCE_ID_EXTRA to sourceId, + SOURCE_NAME_EXTRA to sourceName + ) ) @Suppress("unused") diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/latest/LatestUpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/latest/LatestUpdatesController.kt index ba2e504a9..bc19f4c28 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/latest/LatestUpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/latest/LatestUpdatesController.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.browse.source.latest import android.os.Bundle import android.view.Menu +import androidx.core.os.bundleOf import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController @@ -13,9 +14,7 @@ import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter class LatestUpdatesController(bundle: Bundle) : BrowseSourceController(bundle) { constructor(source: CatalogueSource) : this( - Bundle().apply { - putLong(SOURCE_ID_KEY, source.id) - } + bundleOf(SOURCE_ID_KEY to source.id) ) override fun createPresenter(): BrowseSourcePresenter { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index 578a5b09d..09f1e588c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -17,6 +17,7 @@ import androidx.appcompat.view.ActionMode import androidx.core.graphics.blue import androidx.core.graphics.green import androidx.core.graphics.red +import androidx.core.os.bundleOf import androidx.core.view.isVisible import androidx.recyclerview.widget.ConcatAdapter import androidx.recyclerview.widget.LinearLayoutManager @@ -98,10 +99,10 @@ class MangaController : DeleteChaptersDialog.Listener { constructor(manga: Manga?, fromSource: Boolean = false) : super( - Bundle().apply { - putLong(MANGA_EXTRA, manga?.id ?: 0) - putBoolean(FROM_SOURCE_EXTRA, fromSource) - } + bundleOf( + MANGA_EXTRA to (manga?.id ?: 0), + FROM_SOURCE_EXTRA to fromSource + ) ) { this.manga = manga if (manga != null) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadCustomChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadCustomChaptersDialog.kt index 37b00d3a3..543b3d3b7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadCustomChaptersDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadCustomChaptersDialog.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.manga.chapter import android.app.Dialog import android.os.Bundle +import androidx.core.os.bundleOf import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.customview.customView import com.bluelinelabs.conductor.Controller @@ -25,10 +26,8 @@ class DownloadCustomChaptersDialog : DialogController * @param maxChapters maximal number of chapters that user can download. */ constructor(target: T, maxChapters: Int) : super( - Bundle().apply { // Add maximum number of chapters to download value to bundle. - putInt(KEY_ITEM_MAX, maxChapters) - } + bundleOf(KEY_ITEM_MAX to maxChapters) ) { targetController = target this.maxChapters = maxChapters 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 323034536..061e38ec1 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 @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.manga.chapter import android.app.Dialog import android.os.Bundle +import androidx.core.os.bundleOf import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.customview.customView import eu.kanade.tachiyomi.R @@ -14,9 +15,7 @@ import eu.kanade.tachiyomi.widget.DialogCheckboxView class SetChapterSettingsDialog(bundle: Bundle? = null) : DialogController(bundle) { constructor(manga: Manga) : this( - Bundle().apply { - putSerializable(MANGA_KEY, manga) - } + bundleOf(MANGA_KEY to manga) ) override fun onCreateDialog(savedViewState: Bundle?): Dialog { 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 311bab862..e2ebc7023 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 @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.track import android.app.Dialog import android.os.Bundle import android.widget.NumberPicker +import androidx.core.os.bundleOf import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.customview.customView import com.afollestad.materialdialogs.customview.getCustomView @@ -20,9 +21,7 @@ class SetTrackChaptersDialog : DialogController private val item: TrackItem constructor(target: T, item: TrackItem) : super( - Bundle().apply { - putSerializable(KEY_ITEM_TRACK, item.track) - } + bundleOf(KEY_ITEM_TRACK to item.track) ) { targetController = target this.item = item diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt index a5d60509a..6b64e1e00 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.manga.track import android.app.Dialog import android.os.Bundle +import androidx.core.os.bundleOf import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.datetime.datePicker import com.bluelinelabs.conductor.Controller @@ -21,9 +22,7 @@ class SetTrackReadingDatesDialog : DialogController private val dateToUpdate: ReadingDate constructor(target: T, dateToUpdate: ReadingDate, item: TrackItem) : super( - Bundle().apply { - putSerializable(SetTrackReadingDatesDialog.KEY_ITEM_TRACK, item.track) - } + bundleOf(KEY_ITEM_TRACK to item.track) ) { targetController = target this.item = item 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 266b49f9f..cc7569369 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 @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.track import android.app.Dialog import android.os.Bundle import android.widget.NumberPicker +import androidx.core.os.bundleOf import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.customview.customView import com.afollestad.materialdialogs.customview.getCustomView @@ -20,9 +21,7 @@ class SetTrackScoreDialog : DialogController private val item: TrackItem constructor(target: T, item: TrackItem) : super( - Bundle().apply { - putSerializable(KEY_ITEM_TRACK, item.track) - } + bundleOf(KEY_ITEM_TRACK to item.track) ) { targetController = target this.item = item 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 a7116362e..f20adb3d3 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 @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.manga.track import android.app.Dialog import android.os.Bundle +import androidx.core.os.bundleOf import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.bluelinelabs.conductor.Controller @@ -18,9 +19,7 @@ class SetTrackStatusDialog : DialogController private val item: TrackItem constructor(target: T, item: TrackItem) : super( - Bundle().apply { - putSerializable(KEY_ITEM_TRACK, item.track) - } + bundleOf(KEY_ITEM_TRACK to item.track) ) { targetController = target this.item = item diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackController.kt index f73b25036..7d158775a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackController.kt @@ -6,6 +6,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.core.net.toUri +import androidx.core.os.bundleOf import androidx.recyclerview.widget.LinearLayoutManager import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Manga @@ -30,9 +31,7 @@ class TrackController : SetTrackReadingDatesDialog.Listener { constructor(manga: Manga?) : super( - Bundle().apply { - putLong(MANGA_EXTRA, manga?.id ?: 0) - } + bundleOf(MANGA_EXTRA to (manga?.id ?: 0)) ) { this.manga = manga } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt index 2671042b5..59b366c86 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.track import android.app.Dialog import android.os.Bundle import android.view.View +import androidx.core.os.bundleOf import androidx.core.view.isInvisible import androidx.core.view.isVisible import com.afollestad.materialdialogs.MaterialDialog @@ -41,9 +42,7 @@ class TrackSearchDialog : DialogController { get() = targetController as TrackController constructor(target: TrackController, service: TrackService) : super( - Bundle().apply { - putInt(KEY_SERVICE, service.id) - } + bundleOf(KEY_SERVICE to service.id) ) { targetController = target this.service = service diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt index 75d0aa6e9..add12d656 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.os.Build import android.os.Bundle import androidx.core.net.toUri +import androidx.core.os.bundleOf import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog import com.mikepenz.aboutlibraries.LibsBuilder @@ -184,10 +185,7 @@ class AboutController : SettingsController() { class NewUpdateDialogController(bundle: Bundle? = null) : DialogController(bundle) { constructor(body: String, url: String) : this( - Bundle().apply { - putString(BODY_KEY, body) - putString(URL_KEY, url) - } + bundleOf(BODY_KEY to body, URL_KEY to url) ) override fun onCreateDialog(savedViewState: Bundle?): Dialog { 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 dd1ef0bf9..330b63bc4 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 @@ -9,6 +9,7 @@ import android.net.Uri import android.os.Bundle import android.view.View import androidx.core.net.toUri +import androidx.core.os.bundleOf import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.list.listItemsMultiChoice @@ -251,9 +252,7 @@ class SettingsBackupController : SettingsController() { class RestoreBackupDialog(bundle: Bundle? = null) : DialogController(bundle) { constructor(uri: Uri) : this( - Bundle().apply { - putParcelable(KEY_URI, uri) - } + bundleOf(KEY_URI to uri) ) override fun onCreateDialog(savedViewState: Bundle?): Dialog { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt index 63e152fe0..8d4ac2fbc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.setting.track import android.os.Bundle import android.view.View import androidx.annotation.StringRes +import androidx.core.os.bundleOf import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackService @@ -28,7 +29,7 @@ class TrackLoginDialog( constructor(service: TrackService) : this(service, null) constructor(service: TrackService, @StringRes usernameLabelRes: Int?) : - this(R.string.login_title, service.name, usernameLabelRes, Bundle().apply { putInt("key", service.id) }) + this(R.string.login_title, service.name, usernameLabelRes, bundleOf("key" to service.id)) override fun setCredentialsOnView(view: View) = with(view) { username.setText(service.getUsername()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt index 9bbbf6a02..187069bd9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.setting.track import android.app.Dialog import android.os.Bundle +import androidx.core.os.bundleOf import com.afollestad.materialdialogs.MaterialDialog import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.track.TrackManager @@ -15,7 +16,7 @@ class TrackLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) { private val service = Injekt.get().getService(args.getInt("key"))!! - constructor(service: TrackService) : this(Bundle().apply { putInt("key", service.id) }) + constructor(service: TrackService) : this(bundleOf("key" to service.id)) override fun onCreateDialog(savedViewState: Bundle?): Dialog { return MaterialDialog(activity!!) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 7ffc3a6d3..2a541c4b0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -64,7 +64,7 @@ fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT) { fun Context.copyToClipboard(label: String, content: String) { if (content.isBlank()) return - val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clipboard = getSystemService()!! clipboard.setPrimaryClip(ClipData.newPlainText(label, content)) toast(getString(R.string.copied_to_clipboard, content.truncateCenter(50))) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt index 059facb3a..d6ac453f8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt @@ -5,6 +5,7 @@ import android.content.Context import android.content.res.Configuration import android.os.Build import android.view.ContextThemeWrapper +import androidx.core.os.ConfigurationCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.browse.source.SourcePresenter @@ -110,10 +111,10 @@ object LocaleHelper { */ fun updateConfiguration(app: Application, config: Configuration, configChange: Boolean = false) { if (systemLocale == null) { - systemLocale = getConfigLocale(config) + systemLocale = ConfigurationCompat.getLocales(config)[0] } if (configChange) { - val configLocale = getConfigLocale(config) + val configLocale = ConfigurationCompat.getLocales(config)[0] if (currentLocale == configLocale) { return } @@ -127,17 +128,6 @@ object LocaleHelper { Locale.setDefault(currentLocale) } - /** - * Returns the locale applied in the given configuration. - */ - private fun getConfigLocale(config: Configuration): Locale { - return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { - config.locale - } else { - config.locales[0] - } - } - /** * Returns a new configuration with the given locale applied. */ diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index d622c3599..009dcdd42 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -1,5 +1,5 @@ object BuildPluginsVersion { - const val AGP = "4.0.1" + const val AGP = "4.0.2" const val KOTLIN = "1.4.10" const val KOTLINTER = "3.0.2" const val VERSIONS_PLUGIN = "0.33.0"