From 71d225c56286d4b868c1634316a4748a494037ea Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 5 Jun 2021 17:49:20 -0400 Subject: [PATCH] Address some build warnings --- app/src/main/java/eu/kanade/tachiyomi/AppModule.kt | 4 ++-- .../kanade/tachiyomi/data/backup/BackupRestoreService.kt | 2 +- .../tachiyomi/data/notification/NotificationReceiver.kt | 8 ++++---- .../java/eu/kanade/tachiyomi/data/track/komga/Komga.kt | 2 +- .../network/interceptor/CloudflareInterceptor.kt | 9 ++++----- .../ui/browse/migration/search/SearchController.kt | 1 + .../kanade/tachiyomi/ui/download/DownloadController.kt | 1 + .../tachiyomi/ui/library/ChangeMangaCoverDialog.kt | 1 + .../java/eu/kanade/tachiyomi/ui/main/MainActivity.kt | 3 ++- .../kanade/tachiyomi/ui/main/WhatsNewDialogController.kt | 1 + .../ui/manga/track/SetTrackReadingDatesDialog.kt | 5 +++-- .../kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt | 1 + .../tachiyomi/ui/reader/loader/DirectoryPageLoader.kt | 6 +++--- .../ui/reader/viewer/GestureDetectorWithLongTap.kt | 3 ++- .../tachiyomi/ui/setting/SettingsLibraryController.kt | 4 ++-- .../eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt | 1 + .../java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt | 2 +- .../eu/kanade/tachiyomi/util/storage/OkioExtensions.kt | 2 +- .../eu/kanade/tachiyomi/util/system/IntentExtensions.kt | 4 ++-- 19 files changed, 34 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt index ab1e75f67..25b8d6987 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt @@ -1,7 +1,7 @@ package eu.kanade.tachiyomi import android.app.Application -import android.os.Handler +import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper @@ -44,7 +44,7 @@ class AppModule(val app: Application) : InjektModule { addSingletonFactory { Json { ignoreUnknownKeys = true } } // Asynchronously init expensive components for a faster cold start - Handler().post { + ContextCompat.getMainExecutor(app).execute { get() get() 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 dcae87dbc..f48853f30 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 @@ -96,7 +96,7 @@ class BackupRestoreService : Service() { private fun destroyJob() { backupRestore?.job?.cancel() - ioScope?.cancel() + ioScope.cancel() if (wakeLock.isHeld) { wakeLock.release() } 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 53b3be48d..1d6cadb86 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 @@ -6,7 +6,7 @@ import android.content.Context import android.content.Intent import android.net.Uri import android.os.Build -import android.os.Handler +import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.backup.BackupRestoreService import eu.kanade.tachiyomi.data.database.DatabaseHelper @@ -143,7 +143,7 @@ class NotificationReceiver : BroadcastReceiver() { */ private fun shareFile(context: Context, uri: Uri, fileMimeType: String, notificationId: Int) { dismissNotification(context, notificationId) - context.startActivity(uri.toShareIntent()) + context.startActivity(uri.toShareIntent(fileMimeType)) } /** @@ -192,7 +192,7 @@ class NotificationReceiver : BroadcastReceiver() { */ private fun cancelRestore(context: Context, notificationId: Int) { BackupRestoreService.stop(context) - Handler().post { dismissNotification(context, notificationId) } + ContextCompat.getMainExecutor(context).execute { dismissNotification(context, notificationId) } } /** @@ -203,7 +203,7 @@ class NotificationReceiver : BroadcastReceiver() { */ private fun cancelLibraryUpdate(context: Context, notificationId: Int) { LibraryUpdateService.stop(context) - Handler().post { dismissNotification(context, notificationId) } + ContextCompat.getMainExecutor(context).execute { dismissNotification(context, notificationId) } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt index bc1511c9b..75d90219d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt @@ -68,7 +68,7 @@ class Komga(private val context: Context, id: Int) : TrackService(id), Unattende } override suspend fun refresh(track: Track): Track { - val remoteTrack = api.getTrackSearch(track.tracking_url)!! + val remoteTrack = api.getTrackSearch(track.tracking_url) track.copyPersonalFrom(remoteTrack) track.total_chapters = remoteTrack.total_chapters return track diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt index 2849d3ed2..05ee87a78 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt @@ -2,11 +2,10 @@ package eu.kanade.tachiyomi.network.interceptor import android.annotation.SuppressLint import android.content.Context -import android.os.Handler -import android.os.Looper import android.webkit.WebSettings import android.webkit.WebView import android.widget.Toast +import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.source.online.HttpSource @@ -28,7 +27,7 @@ import java.util.concurrent.TimeUnit class CloudflareInterceptor(private val context: Context) : Interceptor { - private val handler = Handler(Looper.getMainLooper()) + private val executor = ContextCompat.getMainExecutor(context) private val networkHelper: NetworkHelper by injectLazy() @@ -92,7 +91,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor { val headers = request.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap() headers["X-Requested-With"] = WebViewUtil.REQUESTED_WITH - handler.post { + executor.execute { val webview = WebView(context) webView = webview webview.setDefaultSettings() @@ -146,7 +145,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor { // around 4 seconds but it can take more due to slow networks or server issues. latch.await(12, TimeUnit.SECONDS) - handler.post { + executor.execute { if (!cloudflareBypassed) { isWebViewOutdated = webView?.isOutdated() == true } 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 c97cf93a7..cd8912f8e 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 @@ -86,6 +86,7 @@ class SearchController( private val preferences: PreferencesHelper by injectLazy() + @Suppress("DEPRECATION") override fun onCreateDialog(savedViewState: Bundle?): Dialog { val prefValue = preferences.migrateFlags().get() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt index a47b1c54b..dd861f8a2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt @@ -188,6 +188,7 @@ class DownloadController : onUpdateDownloadedPages(download) } Download.State.ERROR -> unsubscribeProgress(download) + else -> { /* unused */ } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCoverDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCoverDialog.kt index c12b0f13f..68485a4da 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCoverDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCoverDialog.kt @@ -18,6 +18,7 @@ class ChangeMangaCoverDialog(bundle: Bundle? = null) : this.manga = manga } + @Suppress("DEPRECATION") override fun onCreateDialog(savedViewState: Bundle?): Dialog { return MaterialDialog(activity!!) .title(R.string.action_edit_cover) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 2427fc679..f4cac0a9c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -357,11 +357,12 @@ class MainActivity : BaseViewBindingActivity() { return true } + @Suppress("UNNECESSARY_SAFE_CALL") override fun onDestroy() { super.onDestroy() // Binding sometimes isn't actually instantiated yet somehow - nav.setOnItemSelectedListener(null) + nav?.setOnItemSelectedListener(null) binding?.toolbar.setNavigationOnClickListener(null) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt index b1b5dd335..23e56b89b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt @@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.ui.base.controller.openInBrowser class WhatsNewDialogController(bundle: Bundle? = null) : DialogController(bundle) { + @Suppress("DEPRECATION") override fun onCreateDialog(savedViewState: Bundle?): Dialog { return MaterialDialog(activity!!) .title(text = activity!!.getString(R.string.updated_version, BuildConfig.VERSION_NAME)) 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 a0331c952..34e1cfeba 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 @@ -40,6 +40,7 @@ class SetTrackReadingDatesDialog : DialogController dateToUpdate = ReadingDate.Start } + @Suppress("DEPRECATION") override fun onCreateDialog(savedViewState: Bundle?): Dialog { return MaterialDialog(activity!!) .title( @@ -49,10 +50,10 @@ class SetTrackReadingDatesDialog : DialogController } ) .datePicker(currentDate = getCurrentDate()) { _, date -> - listener?.setReadingDate(item, dateToUpdate, date.timeInMillis) + listener.setReadingDate(item, dateToUpdate, date.timeInMillis) } .neutralButton(R.string.action_remove) { - listener?.setReadingDate(item, dateToUpdate, 0L) + listener.setReadingDate(item, dateToUpdate, 0L) } } 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 d02e4015c..11ee42b58 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 @@ -51,6 +51,7 @@ class TrackSearchDialog : DialogController { service = Injekt.get().getService(bundle.getInt(KEY_SERVICE))!! } + @Suppress("DEPRECATION") override fun onCreateDialog(savedViewState: Bundle?): Dialog { binding = TrackSearchDialogBinding.inflate(LayoutInflater.from(activity!!)) val dialog = MaterialDialog(activity!!) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DirectoryPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DirectoryPageLoader.kt index d836cc0c3..aba79147f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DirectoryPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DirectoryPageLoader.kt @@ -19,9 +19,9 @@ class DirectoryPageLoader(val file: File) : PageLoader() { */ override fun getPages(): Observable> { return file.listFiles() - .filter { !it.isDirectory && ImageUtil.isImage(it.name) { FileInputStream(it) } } - .sortedWith { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) } - .mapIndexed { i, file -> + ?.filter { !it.isDirectory && ImageUtil.isImage(it.name) { FileInputStream(it) } } + ?.sortedWith { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) } + ?.mapIndexed { i, file -> val streamFn = { FileInputStream(file) } ReaderPage(i).apply { stream = streamFn diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/GestureDetectorWithLongTap.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/GestureDetectorWithLongTap.kt index 52e1ab9bc..e53ee8b72 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/GestureDetectorWithLongTap.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/GestureDetectorWithLongTap.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.reader.viewer import android.content.Context import android.os.Handler +import android.os.Looper import android.view.GestureDetector import android.view.MotionEvent import android.view.ViewConfiguration @@ -16,7 +17,7 @@ open class GestureDetectorWithLongTap( listener: Listener ) : GestureDetector(context, listener) { - private val handler = Handler() + private val handler = Handler(Looper.getMainLooper()) private val slop = ViewConfiguration.get(context).scaledTouchSlop private val longTapTime = ViewConfiguration.getLongPressTimeout().toLong() private val doubleTapTime = ViewConfiguration.getDoubleTapTimeout().toLong() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 3045e25e9..e0ffc7ad2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -2,8 +2,8 @@ package eu.kanade.tachiyomi.ui.setting import android.app.Dialog import android.os.Bundle -import android.os.Handler import android.view.View +import androidx.core.content.ContextCompat import androidx.core.text.buildSpannedString import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog @@ -171,7 +171,7 @@ class SettingsLibraryController : SettingsController() { onChange { // Post to event looper to allow the preference to be updated. - Handler().post { LibraryUpdateJob.setupTask(context) } + ContextCompat.getMainExecutor(context).execute { LibraryUpdateJob.setupTask(context) } true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt index a66824e57..b1a7e79bf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt @@ -138,6 +138,7 @@ class WebViewActivity : BaseViewBindingActivity() { } } + @Suppress("UNNECESSARY_SAFE_CALL") override fun onDestroy() { super.onDestroy() diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt index 9a2600aba..bc4f7e964 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt @@ -21,7 +21,7 @@ object DiskUtil { fun getDirectorySize(f: File): Long { var size: Long = 0 if (f.isDirectory) { - for (file in f.listFiles()) { + for (file in f.listFiles().orEmpty()) { size += getDirectorySize(file) } } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/storage/OkioExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/storage/OkioExtensions.kt index c3f72c866..a4301d9b9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/storage/OkioExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/storage/OkioExtensions.kt @@ -14,7 +14,7 @@ import java.io.OutputStream fun BufferedSource.saveTo(file: File) { try { // Create parent dirs if needed - file.parentFile.mkdirs() + file.parentFile?.mkdirs() // Copy to destination saveTo(file.outputStream()) 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 f5a3abf8f..84513930a 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,12 +4,12 @@ import android.content.ClipData import android.content.Intent import android.net.Uri -fun Uri.toShareIntent(): Intent { +fun Uri.toShareIntent(type: String = "image/*"): Intent { val uri = this return Intent(Intent.ACTION_SEND).apply { putExtra(Intent.EXTRA_STREAM, uri) clipData = ClipData.newRawUri(null, uri) - type = "image/*" + setType(type) flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION } }