Browse Source

Address some build warnings

arkon 3 năm trước cách đây
mục cha
commit
71d225c562
19 tập tin đã thay đổi với 34 bổ sung26 xóa
  1. 2 2
      app/src/main/java/eu/kanade/tachiyomi/AppModule.kt
  2. 1 1
      app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt
  3. 4 4
      app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt
  4. 1 1
      app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt
  5. 4 5
      app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt
  6. 1 0
      app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt
  7. 1 0
      app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt
  8. 1 0
      app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCoverDialog.kt
  9. 2 1
      app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
  10. 1 0
      app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt
  11. 3 2
      app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt
  12. 1 0
      app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt
  13. 3 3
      app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DirectoryPageLoader.kt
  14. 2 1
      app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/GestureDetectorWithLongTap.kt
  15. 2 2
      app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt
  16. 1 0
      app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt
  17. 1 1
      app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt
  18. 1 1
      app/src/main/java/eu/kanade/tachiyomi/util/storage/OkioExtensions.kt
  19. 2 2
      app/src/main/java/eu/kanade/tachiyomi/util/system/IntentExtensions.kt

+ 2 - 2
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<PreferencesHelper>()
 
             get<NetworkHelper>()

+ 1 - 1
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()
         }

+ 4 - 4
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) }
     }
 
     /**

+ 1 - 1
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

+ 4 - 5
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
             }

+ 1 - 0
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()
 

+ 1 - 0
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 */ }
         }
     }
 

+ 1 - 0
app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCoverDialog.kt

@@ -18,6 +18,7 @@ class ChangeMangaCoverDialog<T>(bundle: Bundle? = null) :
         this.manga = manga
     }
 
+    @Suppress("DEPRECATION")
     override fun onCreateDialog(savedViewState: Bundle?): Dialog {
         return MaterialDialog(activity!!)
             .title(R.string.action_edit_cover)

+ 2 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt

@@ -357,11 +357,12 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
         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)
     }
 

+ 1 - 0
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))

+ 3 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt

@@ -40,6 +40,7 @@ class SetTrackReadingDatesDialog<T> : DialogController
         dateToUpdate = ReadingDate.Start
     }
 
+    @Suppress("DEPRECATION")
     override fun onCreateDialog(savedViewState: Bundle?): Dialog {
         return MaterialDialog(activity!!)
             .title(
@@ -49,10 +50,10 @@ class SetTrackReadingDatesDialog<T> : 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)
             }
     }
 

+ 1 - 0
app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt

@@ -51,6 +51,7 @@ class TrackSearchDialog : DialogController {
         service = Injekt.get<TrackManager>().getService(bundle.getInt(KEY_SERVICE))!!
     }
 
+    @Suppress("DEPRECATION")
     override fun onCreateDialog(savedViewState: Bundle?): Dialog {
         binding = TrackSearchDialogBinding.inflate(LayoutInflater.from(activity!!))
         val dialog = MaterialDialog(activity!!)

+ 3 - 3
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<List<ReaderPage>> {
         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

+ 2 - 1
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()

+ 2 - 2
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
                 }
 

+ 1 - 0
app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt

@@ -138,6 +138,7 @@ class WebViewActivity : BaseViewBindingActivity<WebviewActivityBinding>() {
         }
     }
 
+    @Suppress("UNNECESSARY_SAFE_CALL")
     override fun onDestroy() {
         super.onDestroy()
 

+ 1 - 1
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 {

+ 1 - 1
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())

+ 2 - 2
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
     }
 }