From c339bd49d01a88570ef9cbeedfef36add00b0c4c Mon Sep 17 00:00:00 2001 From: Eugene Date: Thu, 26 Dec 2019 17:48:39 -0500 Subject: [PATCH] Address minor Kotlin compiler warnings --- .../java/eu/kanade/tachiyomi/data/cache/CoverCache.kt | 2 +- .../data/preference/SharedPreferencesDataStore.kt | 4 ++-- .../kanade/tachiyomi/data/track/kitsu/KitsuModels.kt | 7 +++---- .../extension/util/ExtensionInstallActivity.kt | 2 +- .../kanade/tachiyomi/extension/util/ExtensionLoader.kt | 2 +- .../ui/catalogue/SourceDividerItemDecoration.kt | 2 +- .../ui/catalogue/browse/CatalogueNavigationView.kt | 4 ++-- .../catalogue/global_search/CatalogueSearchAdapter.kt | 2 +- .../ui/extension/ExtensionDetailsController.kt | 4 ++-- .../ui/extension/ExtensionDividerItemDecoration.kt | 2 +- .../tachiyomi/ui/extension/ExtensionTrustDialog.kt | 4 ++-- .../eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt | 4 ++-- .../eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt | 2 +- .../tachiyomi/ui/reader/loader/DownloadPageLoader.kt | 4 ++-- .../eu/kanade/tachiyomi/util/ChapterRecognition.kt | 10 +++++----- .../java/eu/kanade/tachiyomi/util/ContextExtensions.kt | 4 ++-- 16 files changed, 29 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt index 4586f8c18..c13492d9d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt @@ -60,7 +60,7 @@ class CoverCache(private val context: Context) { return false // Remove file. - val file = getCoverFile(thumbnailUrl!!) + val file = getCoverFile(thumbnailUrl) return file.exists() && file.delete() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/SharedPreferencesDataStore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/SharedPreferencesDataStore.kt index bb07bb0a5..8d02d1c77 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/SharedPreferencesDataStore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/SharedPreferencesDataStore.kt @@ -45,11 +45,11 @@ class SharedPreferencesDataStore(private val prefs: SharedPreferences) : Prefere prefs.edit().putString(key, value).apply() } - override fun getStringSet(key: String?, defValues: MutableSet?): MutableSet { + override fun getStringSet(key: String?, defValues: MutableSet?): MutableSet? { return prefs.getStringSet(key, defValues) } override fun putStringSet(key: String?, values: MutableSet?) { prefs.edit().putStringSet(key, values).apply() } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt index ca0de7d3d..b5e55d9d9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt @@ -18,13 +18,12 @@ class KitsuSearchManga(obj: JsonObject) { private val synopsis by obj.byString private var startDate = obj.get("startDate").nullString?.let { val outputDf = SimpleDateFormat("yyyy-MM-dd", Locale.US) - outputDf.format(Date(it!!.toLong() * 1000)) + outputDf.format(Date(it.toLong() * 1000)) } private val endDate = obj.get("endDate").nullString - @CallSuper - open fun toTrack() = TrackSearch.create(TrackManager.KITSU).apply { + fun toTrack() = TrackSearch.create(TrackManager.KITSU).apply { media_id = this@KitsuSearchManga.id title = canonicalTitle total_chapters = chapterCount ?: 0 @@ -55,7 +54,7 @@ class KitsuLibManga(obj: JsonObject, manga: JsonObject) { private val ratingTwenty = obj["attributes"].obj.get("ratingTwenty").nullString val progress by obj["attributes"].byInt - open fun toTrack() = TrackSearch.create(TrackManager.KITSU).apply { + fun toTrack() = TrackSearch.create(TrackManager.KITSU).apply { media_id = libraryId title = canonicalTitle total_chapters = chapterCount ?: 0 diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt index 421cfb191..5dcd6bb12 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt @@ -39,7 +39,7 @@ class ExtensionInstallActivity : Activity() { } private fun checkInstallationResult(resultCode: Int) { - val downloadId = intent.extras.getLong(ExtensionInstaller.EXTRA_DOWNLOAD_ID) + val downloadId = intent.extras!!.getLong(ExtensionInstaller.EXTRA_DOWNLOAD_ID) val success = resultCode == RESULT_OK val extensionManager = Injekt.get() diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt index f211d7d95..c4018f046 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt @@ -121,7 +121,7 @@ internal object ExtensionLoader { val classLoader = PathClassLoader(appInfo.sourceDir, null, context.classLoader) - val sources = appInfo.metaData.getString(METADATA_SOURCE_CLASS) + val sources = appInfo.metaData.getString(METADATA_SOURCE_CLASS)!! .split(";") .map { val sourceClass = it.trim() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceDividerItemDecoration.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceDividerItemDecoration.kt index a4c33beb7..e21b58124 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceDividerItemDecoration.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceDividerItemDecoration.kt @@ -13,7 +13,7 @@ class SourceDividerItemDecoration(context: Context) : RecyclerView.ItemDecoratio init { val a = context.obtainStyledAttributes(intArrayOf(android.R.attr.listDivider)) - divider = a.getDrawable(0) + divider = a.getDrawable(0)!! a.recycle() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueNavigationView.kt index 1f06fc407..d78d1fd7a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueNavigationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueNavigationView.kt @@ -28,7 +28,7 @@ class CatalogueNavigationView @JvmOverloads constructor(context: Context, attrs: val view = inflate(R.layout.catalogue_drawer_content) ((view as ViewGroup).getChildAt(1) as ViewGroup).addView(recycler) addView(view) - title.text = context?.getString(R.string.source_search_options) + title.text = context.getString(R.string.source_search_options) search_btn.setOnClickListener { onSearchClicked() } reset_btn.setOnClickListener { onResetClicked() } } @@ -37,4 +37,4 @@ class CatalogueNavigationView @JvmOverloads constructor(context: Context, attrs: adapter.updateDataSet(items) } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchAdapter.kt index f9ba52a02..441d575c8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchAdapter.kt @@ -38,7 +38,7 @@ class CatalogueSearchAdapter(val controller: CatalogueSearchController) : override fun onRestoreInstanceState(savedInstanceState: Bundle) { super.onRestoreInstanceState(savedInstanceState) - bundle = savedInstanceState.getBundle(HOLDER_BUNDLE_KEY) + bundle = savedInstanceState.getBundle(HOLDER_BUNDLE_KEY)!! } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt index 2005a9388..c851b81ad 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt @@ -47,7 +47,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : } override fun createPresenter(): ExtensionDetailsPresenter { - return ExtensionDetailsPresenter(args.getString(PKGNAME_KEY)) + return ExtensionDetailsPresenter(args.getString(PKGNAME_KEY)!!) } override fun getTitle(): String? { @@ -119,7 +119,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : private fun addPreferencesForSource(screen: PreferenceScreen, source: Source, multiSource: Boolean) { val context = screen.context - // TODO + // TODO val dataStore = SharedPreferencesDataStore(/*if (source is HttpSource) { source.preferences } else {*/ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDividerItemDecoration.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDividerItemDecoration.kt index 40fe44505..247206df7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDividerItemDecoration.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDividerItemDecoration.kt @@ -13,7 +13,7 @@ class ExtensionDividerItemDecoration(context: Context) : RecyclerView.ItemDecora init { val a = context.obtainStyledAttributes(intArrayOf(android.R.attr.listDivider)) - divider = a.getDrawable(0) + divider = a.getDrawable(0)!! a.recycle() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionTrustDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionTrustDialog.kt index 3094e9062..6c1f8bc0a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionTrustDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionTrustDialog.kt @@ -24,10 +24,10 @@ class ExtensionTrustDialog(bundle: Bundle? = null) : DialogController(bundle) .positiveText(R.string.ext_trust) .negativeText(R.string.ext_uninstall) .onPositive { _, _ -> - (targetController as? Listener)?.trustSignature(args.getString(SIGNATURE_KEY)) + (targetController as? Listener)?.trustSignature(args.getString(SIGNATURE_KEY)!!) } .onNegative { _, _ -> - (targetController as? Listener)?.uninstallExtension(args.getString(PKGNAME_KEY)) + (targetController as? Listener)?.uninstallExtension(args.getString(PKGNAME_KEY)!!) } .build() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index ee324e896..beb7783ff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -119,8 +119,8 @@ class ReaderActivity : BaseRxActivity() { setContentView(R.layout.reader_activity) if (presenter.needsInit()) { - val manga = intent.extras.getLong("manga", -1) - val chapter = intent.extras.getLong("chapter", -1) + val manga = intent.extras!!.getLong("manga", -1) + val chapter = intent.extras!!.getLong("chapter", -1) if (manga == -1L || chapter == -1L) { finish() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index b2aafa0a2..243e5bb6e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -498,7 +498,7 @@ class ReaderPresenter( .observeOn(AndroidSchedulers.mainThread()) .subscribeFirst( { view, file -> view.onShareImageResult(file) }, - { view, error -> /* Empty */ } + { _, _ -> /* Empty */ } ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt index af7d96930..6a207502a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt @@ -32,9 +32,9 @@ class DownloadPageLoader( return downloadManager.buildPageList(source, manga, chapter.chapter) .map { pages -> pages.map { page -> - ReaderPage(page.index, page.url, page.imageUrl, { + ReaderPage(page.index, page.url, page.imageUrl) { context.contentResolver.openInputStream(page.uri) - }).apply { + }.apply { status = Page.READY } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.kt index 9ee6774a7..742fa3e1a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.kt @@ -91,7 +91,7 @@ object ChapterRecognition { * @param chapter chapter object * @return true if volume is found */ - fun updateChapter(match: MatchResult?, chapter: SChapter): Boolean { + private fun updateChapter(match: MatchResult?, chapter: SChapter): Boolean { match?.let { val initial = it.groups[1]?.value?.toFloat()!! val subChapterDecimal = it.groups[2]?.value @@ -109,12 +109,12 @@ object ChapterRecognition { * @param alpha alpha value of regex * @return decimal/alpha float value */ - fun checkForDecimal(decimal: String?, alpha: String?): Float { + private fun checkForDecimal(decimal: String?, alpha: String?): Float { if (!decimal.isNullOrEmpty()) - return decimal?.toFloat()!! + return decimal.toFloat() if (!alpha.isNullOrEmpty()) { - if (alpha!!.contains("extra")) + if (alpha.contains("extra")) return .99f if (alpha.contains("omake")) @@ -138,7 +138,7 @@ object ChapterRecognition { * x.a -> x.1, x.b -> x.2, etc */ private fun parseAlphaPostFix(alpha: Char): Float { - return ("0." + Integer.toString(alpha.toInt() - 96)).toFloat() + return ("0." + (alpha.toInt() - 96).toString()).toFloat() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ContextExtensions.kt index 2c54b236c..ad3ec5c51 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ContextExtensions.kt @@ -172,11 +172,11 @@ fun Context.isServiceRunning(serviceClass: Class<*>): Boolean { */ fun Context.openInBrowser(url: String) { try { - val url = Uri.parse(url) + val parsedUrl = Uri.parse(url) val intent = CustomTabsIntent.Builder() .setToolbarColor(getResourceColor(R.attr.colorPrimary)) .build() - intent.launchUrl(this, url) + intent.launchUrl(this, parsedUrl) } catch (e: Exception) { toast(e.message) }