Parcourir la source

Minor code cleanup

arkon il y a 5 ans
Parent
commit
5cddb269d6
67 fichiers modifiés avec 185 ajouts et 185 suppressions
  1. 1 1
      app/src/main/java/eu/kanade/tachiyomi/App.kt
  2. 9 8
      app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt
  3. 2 4
      app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/ChapterTypeAdapter.kt
  4. 2 4
      app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/TrackTypeAdapter.kt
  5. 1 1
      app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt
  6. 2 2
      app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt
  7. 6 5
      app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt
  8. 1 1
      app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt
  9. 1 1
      app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/OAuth.kt
  10. 1 1
      app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt
  11. 4 4
      app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt
  12. 5 5
      app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListInterceptor.kt
  13. 2 1
      app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt
  14. 1 1
      app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt
  15. 1 1
      app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt
  16. 0 1
      app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt
  17. 1 1
      app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCataloguePresenter.kt
  18. 2 2
      app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/Pager.kt
  19. 0 1
      app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt
  20. 3 3
      app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt
  21. 3 3
      app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryCreateDialog.kt
  22. 3 3
      app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryRenameDialog.kt
  23. 3 3
      app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt
  24. 1 1
      app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt
  25. 1 1
      app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt
  26. 2 2
      app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt
  27. 19 16
      app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt
  28. 2 2
      app/src/main/java/eu/kanade/tachiyomi/ui/main/ChangelogDialogController.kt
  29. 2 2
      app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
  30. 3 2
      app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt
  31. 2 2
      app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DeletingChaptersDialog.kt
  32. 1 5
      app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt
  33. 4 4
      app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt
  34. 1 1
      app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt
  35. 2 2
      app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt
  36. 2 2
      app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationPresenter.kt
  37. 3 3
      app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt
  38. 11 6
      app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
  39. 7 5
      app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt
  40. 1 1
      app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterView.kt
  41. 1 1
      app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt
  42. 3 3
      app/src/main/java/eu/kanade/tachiyomi/ui/reader/SaveImageNotifier.kt
  43. 0 14
      app/src/main/java/eu/kanade/tachiyomi/ui/reader/model/ChapterTransition.kt
  44. 2 1
      app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/GestureDetectorWithLongTap.kt
  45. 2 1
      app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressBar.kt
  46. 3 2
      app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt
  47. 2 2
      app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/DeletingChaptersDialog.kt
  48. 3 2
      app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt
  49. 1 1
      app/src/main/java/eu/kanade/tachiyomi/ui/setting/AnilistLoginActivity.kt
  50. 4 2
      app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt
  51. 2 2
      app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt
  52. 2 2
      app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt
  53. 2 2
      app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt
  54. 5 5
      app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt
  55. 2 2
      app/src/main/java/eu/kanade/tachiyomi/util/ImageUtil.kt
  56. 2 2
      app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt
  57. 1 1
      app/src/main/java/eu/kanade/tachiyomi/util/SharedData.kt
  58. 2 2
      app/src/main/java/eu/kanade/tachiyomi/util/StringExtensions.kt
  59. 3 2
      app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt
  60. 3 2
      app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt
  61. 3 3
      app/src/main/java/eu/kanade/tachiyomi/widget/CustomLayoutPicker.kt
  62. 2 3
      app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt
  63. 1 0
      app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationBase.kt
  64. 6 5
      app/src/main/java/eu/kanade/tachiyomi/widget/NegativeSeekBar.kt
  65. 1 1
      app/src/main/java/eu/kanade/tachiyomi/widget/PTSansTextView.kt
  66. 8 7
      app/src/main/java/eu/kanade/tachiyomi/widget/SimpleNavigationView.kt
  67. 1 1
      app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/App.kt

@@ -22,7 +22,7 @@ import uy.kohesive.injekt.registry.default.DefaultRegistrar
         reportType = org.acra.sender.HttpSender.Type.JSON,
         httpMethod = org.acra.sender.HttpSender.Method.PUT,
         buildConfigClass = BuildConfig::class,
-        excludeMatchingSharedPreferencesKeys = arrayOf(".*username.*", ".*password.*", ".*token.*")
+        excludeMatchingSharedPreferencesKeys = [".*username.*", ".*password.*", ".*token.*"]
 )
 open class App : Application() {
 

+ 9 - 8
app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt

@@ -35,6 +35,7 @@ import eu.kanade.tachiyomi.util.syncChaptersWithSource
 import rx.Observable
 import timber.log.Timber
 import uy.kohesive.injekt.injectLazy
+import kotlin.math.max
 
 class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
 
@@ -204,7 +205,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
         if (options and BACKUP_CHAPTER_MASK == BACKUP_CHAPTER) {
             // Backup all the chapters
             val chapters = databaseHelper.getChapters(manga).executeAsBlocking()
-            if (!chapters.isEmpty()) {
+            if (chapters.isNotEmpty()) {
                 val chaptersJson = parser.toJsonTree(chapters)
                 if (chaptersJson.asJsonArray.size() > 0) {
                     entry[CHAPTERS] = chaptersJson
@@ -216,7 +217,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
         if (options and BACKUP_CATEGORY_MASK == BACKUP_CATEGORY) {
             // Backup categories for this manga
             val categoriesForManga = databaseHelper.getCategoriesForManga(manga).executeAsBlocking()
-            if (!categoriesForManga.isEmpty()) {
+            if (categoriesForManga.isNotEmpty()) {
                 val categoriesNames = categoriesForManga.map { it.name }
                 entry[CATEGORIES] = parser.toJsonTree(categoriesNames)
             }
@@ -225,7 +226,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
         // Check if user wants track information in backup
         if (options and BACKUP_TRACK_MASK == BACKUP_TRACK) {
             val tracks = databaseHelper.getTracks(manga).executeAsBlocking()
-            if (!tracks.isEmpty()) {
+            if (tracks.isNotEmpty()) {
                 entry[TRACK] = parser.toJsonTree(tracks)
             }
         }
@@ -233,7 +234,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
         // Check if user wants history information in backup
         if (options and BACKUP_HISTORY_MASK == BACKUP_HISTORY) {
             val historyForManga = databaseHelper.getHistoryByMangaId(manga.id!!).executeAsBlocking()
-            if (!historyForManga.isEmpty()) {
+            if (historyForManga.isNotEmpty()) {
                 val historyData = historyForManga.mapNotNull { history ->
                     val url = databaseHelper.getChapter(history.chapter_id).executeAsBlocking()?.url
                     url?.let { DHistory(url, history.last_read) }
@@ -344,7 +345,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
         }
 
         // Update database
-        if (!mangaCategoriesToUpdate.isEmpty()) {
+        if (mangaCategoriesToUpdate.isNotEmpty()) {
             val mangaAsList = ArrayList<Manga>()
             mangaAsList.add(manga)
             databaseHelper.deleteOldMangasCategories(mangaAsList).executeAsBlocking()
@@ -365,7 +366,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
             // Check if history already in database and update
             if (dbHistory != null) {
                 dbHistory.apply {
-                    last_read = Math.max(lastRead, dbHistory.last_read)
+                    last_read = max(lastRead, dbHistory.last_read)
                 }
                 historyToBeUpdated.add(dbHistory)
             } else {
@@ -408,7 +409,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
                         if (track.library_id != dbTrack.library_id) {
                             dbTrack.library_id = track.library_id
                         }
-                        dbTrack.last_chapter_read = Math.max(dbTrack.last_chapter_read, track.last_chapter_read)
+                        dbTrack.last_chapter_read = max(dbTrack.last_chapter_read, track.last_chapter_read)
                         isInDatabase = true
                         trackToUpdate.add(dbTrack)
                         break
@@ -422,7 +423,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
             }
         }
         // Update database
-        if (!trackToUpdate.isEmpty()) {
+        if (trackToUpdate.isNotEmpty()) {
             databaseHelper.insertTracks(trackToUpdate).executeAsBlocking()
         }
     }

+ 2 - 4
app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/ChapterTypeAdapter.kt

@@ -43,9 +43,7 @@ object ChapterTypeAdapter {
                 beginObject()
                 while (hasNext()) {
                     if (peek() == JsonToken.NAME) {
-                        val name = nextName()
-
-                        when (name) {
+                        when (nextName()) {
                             URL -> chapter.url = nextString()
                             READ -> chapter.read = nextInt() == 1
                             BOOKMARK -> chapter.bookmark = nextInt() == 1
@@ -58,4 +56,4 @@ object ChapterTypeAdapter {
             }
         }
     }
-}
+}

+ 2 - 4
app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/TrackTypeAdapter.kt

@@ -42,9 +42,7 @@ object TrackTypeAdapter {
                 beginObject()
                 while (hasNext()) {
                     if (peek() == JsonToken.NAME) {
-                        val name = nextName()
-
-                        when (name) {
+                        when (nextName()) {
                             TITLE -> track.title = nextString()
                             SYNC -> track.sync_id = nextInt()
                             MEDIA -> track.media_id = nextInt()
@@ -59,4 +57,4 @@ object TrackTypeAdapter {
             }
         }
     }
-}
+}

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt

@@ -263,7 +263,7 @@ class DownloadCache(
         for (element in this) {
             val (key, value) = transform(element)
             if (key != null) {
-                destination.put(key, value)
+                destination[key] = value
             }
         }
         return destination

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt

@@ -57,8 +57,8 @@ abstract class TrackService(val id: Int) {
     }
 
     open val isLogged: Boolean
-        get() = !getUsername().isEmpty() &&
-                !getPassword().isEmpty()
+        get() = getUsername().isNotEmpty() &&
+                getPassword().isNotEmpty()
 
     fun getUsername() = preferences.trackUsername(this)!!
 

+ 6 - 5
app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt

@@ -16,6 +16,7 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
 import okhttp3.OkHttpClient
 import okhttp3.Request
 import okhttp3.RequestBody
+import okhttp3.RequestBody.Companion.toRequestBody
 import rx.Observable
 import java.util.Calendar
 
@@ -44,7 +45,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
                 "query" to query,
                 "variables" to variables
         )
-        val body = RequestBody.create(jsonMime, payload.toString())
+        val body = payload.toString().toRequestBody(jsonMime)
         val request = Request.Builder()
                 .url(apiUrl)
                 .post(body)
@@ -83,7 +84,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
                 "query" to query,
                 "variables" to variables
         )
-        val body = RequestBody.create(jsonMime, payload.toString())
+        val body = payload.toString().toRequestBody(jsonMime)
         val request = Request.Builder()
                 .url(apiUrl)
                 .post(body)
@@ -127,7 +128,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
                 "query" to query,
                 "variables" to variables
         )
-        val body = RequestBody.create(jsonMime, payload.toString())
+        val body = payload.toString().toRequestBody(jsonMime)
         val request = Request.Builder()
                 .url(apiUrl)
                 .post(body)
@@ -188,7 +189,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
                 "query" to query,
                 "variables" to variables
         )
-        val body = RequestBody.create(jsonMime, payload.toString())
+        val body = payload.toString().toRequestBody(jsonMime)
         val request = Request.Builder()
                 .url(apiUrl)
                 .post(body)
@@ -233,7 +234,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
         val payload = jsonObject(
                 "query" to query
         )
-        val body = RequestBody.create(jsonMime, payload.toString())
+        val body = payload.toString().toRequestBody(jsonMime)
         val request = Request.Builder()
                 .url(apiUrl)
                 .post(body)

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt

@@ -35,7 +35,7 @@ class BangumiInterceptor(val bangumi: Bangumi, val gson: Gson) : Interceptor {
       }
     }
 
-    var authRequest = if (originalRequest.method == "GET") originalRequest.newBuilder()
+    val authRequest = if (originalRequest.method == "GET") originalRequest.newBuilder()
       .header("User-Agent", "Tachiyomi")
       .url(originalRequest.url.newBuilder()
         .addQueryParameter("access_token", currAuth.access_token).build())

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/OAuth.kt

@@ -9,7 +9,7 @@ data class OAuth(
   val user_id: Long?
 ) {
 
-  // Access token refersh before expired
+  // Access token refresh before expired
   fun isExpired() = (System.currentTimeMillis() / 1000) > (created_at + expires_in - 3600)
 
 }

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt

@@ -29,7 +29,7 @@ class Myanimelist(private val context: Context, id: Int) : TrackService(id) {
     }
 
     private val interceptor by lazy { MyAnimeListInterceptor(this) }
-    private val api by lazy { MyanimelistApi(client, interceptor) }
+    private val api by lazy { MyAnimeListApi(client, interceptor) }
 
     override val name: String
         get() = "MyAnimeList"

+ 4 - 4
app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyanimelistApi.kt → app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt

@@ -14,6 +14,7 @@ import okhttp3.FormBody
 import okhttp3.MediaType.Companion.toMediaTypeOrNull
 import okhttp3.OkHttpClient
 import okhttp3.RequestBody
+import okhttp3.RequestBody.Companion.toRequestBody
 import okhttp3.Response
 import org.json.JSONObject
 import org.jsoup.Jsoup
@@ -26,7 +27,7 @@ import java.io.InputStreamReader
 import java.util.zip.GZIPInputStream
 
 
-class MyanimelistApi(private val client: OkHttpClient, interceptor: MyAnimeListInterceptor) {
+class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListInterceptor) {
 
     private val authClient = client.newBuilder().addInterceptor(interceptor).build()
 
@@ -37,8 +38,7 @@ class MyanimelistApi(private val client: OkHttpClient, interceptor: MyAnimeListI
                     .flatMap { Observable.from(it) }
                     .filter { it.title.contains(realQuery, true) }
                     .toList()
-        }
-        else {
+        } else {
             client.newCall(GET(searchUrl(query)))
                     .asObservable()
                     .flatMap { response ->
@@ -266,7 +266,7 @@ class MyanimelistApi(private val client: OkHttpClient, interceptor: MyAnimeListI
                     .put("score", track.score)
                     .put("num_read_chapters", track.last_chapter_read)
 
-            return RequestBody.create("application/json; charset=utf-8".toMediaTypeOrNull(), body.toString())
+            return body.toString().toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())
         }
 
         private fun Element.searchTitle() = select("strong").text()!!

+ 5 - 5
app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListInterceptor.kt

@@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.track.myanimelist
 import okhttp3.Interceptor
 import okhttp3.Request
 import okhttp3.RequestBody
+import okhttp3.RequestBody.Companion.toRequestBody
 import okhttp3.Response
 import okio.Buffer
 import org.json.JSONObject
@@ -15,7 +16,7 @@ class MyAnimeListInterceptor(private val myanimelist: Myanimelist): Interceptor
         val request = chain.request()
         var response = chain.proceed(updateRequest(request))
 
-        if (response.code == 400){
+        if (response.code == 400) {
             myanimelist.refreshLogin()
             response = chain.proceed(updateRequest(request))
         }
@@ -45,15 +46,14 @@ class MyAnimeListInterceptor(private val myanimelist: Myanimelist): Interceptor
     private fun updateFormBody(requestBody: RequestBody): RequestBody {
         val formString = bodyToString(requestBody)
 
-        return RequestBody.create(requestBody.contentType(),
-                "$formString${if (formString.isNotEmpty()) "&" else ""}${MyanimelistApi.CSRF}=${myanimelist.getCSRF()}")
+        return "$formString${if (formString.isNotEmpty()) "&" else ""}${MyAnimeListApi.CSRF}=${myanimelist.getCSRF()}".toRequestBody(requestBody.contentType())
     }
 
     private fun updateJsonBody(requestBody: RequestBody): RequestBody {
         val jsonString = bodyToString(requestBody)
         val newBody = JSONObject(jsonString)
-                .put(MyanimelistApi.CSRF, myanimelist.getCSRF())
+                .put(MyAnimeListApi.CSRF, myanimelist.getCSRF())
 
-        return RequestBody.create(requestBody.contentType(), newBody.toString())
+        return newBody.toString().toRequestBody(requestBody.contentType())
     }
 }

+ 2 - 1
app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt

@@ -19,6 +19,7 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
 import okhttp3.OkHttpClient
 import okhttp3.Request
 import okhttp3.RequestBody
+import okhttp3.RequestBody.Companion.toRequestBody
 import rx.Observable
 import uy.kohesive.injekt.injectLazy
 
@@ -40,7 +41,7 @@ class ShikimoriApi(private val client: OkHttpClient, interceptor: ShikimoriInter
                         "status" to track.toShikimoriStatus()
                 )
         )
-        val body = RequestBody.create(jsonime, payload.toString())
+        val body = payload.toString().toRequestBody(jsonime)
         val request = Request.Builder()
                 .url("$apiUrl/v2/user_rates")
                 .post(body)

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt

@@ -94,7 +94,7 @@ internal class ExtensionInstallReceiver(private val listener: Listener) :
     private suspend fun getExtensionFromIntent(context: Context, intent: Intent?): LoadResult {
         val pkgName = getPackageNameFromIntent(intent) ?:
                 return LoadResult.Error("Package name not found")
-        return GlobalScope.async(Dispatchers.Default, CoroutineStart.DEFAULT, { ExtensionLoader.loadExtensionFromPkgName(context, pkgName) }).await()
+        return GlobalScope.async(Dispatchers.Default, CoroutineStart.DEFAULT) { ExtensionLoader.loadExtensionFromPkgName(context, pkgName) }.await()
     }
 
     /**

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt

@@ -173,7 +173,7 @@ internal object ExtensionLoader {
      */
     private fun getSignatureHash(pkgInfo: PackageInfo): String? {
         val signatures = pkgInfo.signatures
-        return if (signatures != null && !signatures.isEmpty()) {
+        return if (signatures != null && signatures.isNotEmpty()) {
             Hash.sha256(signatures.first().toByteArray())
         } else {
             null

+ 0 - 1
app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt

@@ -37,7 +37,6 @@ open class Page(
     }
 
     companion object {
-
         const val QUEUE = 0
         const val LOAD_PAGE = 1
         const val DOWNLOAD_IMAGE = 2

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCataloguePresenter.kt

@@ -363,7 +363,7 @@ open class BrowseCataloguePresenter(
      * @param selectedCategories selected categories
      */
     fun updateMangaCategories(manga: Manga, selectedCategories: List<Category>) {
-        if (!selectedCategories.isEmpty()) {
+        if (selectedCategories.isNotEmpty()) {
             if (!manga.favorite)
                 changeMangaFavorite(manga)
 

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/Pager.kt

@@ -24,8 +24,8 @@ abstract class Pager(var currentPage: Int = 1) {
     fun onPageReceived(mangasPage: MangasPage) {
         val page = currentPage
         currentPage++
-        hasNextPage = mangasPage.hasNextPage && !mangasPage.mangas.isEmpty()
+        hasNextPage = mangasPage.hasNextPage && mangasPage.mangas.isNotEmpty()
         results.call(Pair(page, mangasPage.mangas))
     }
 
-}
+}

+ 0 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt

@@ -205,7 +205,6 @@ open class CatalogueSearchPresenter(
                             .map { Pair(source as CatalogueSource, it) }
 
                 }
-
                 .onBackpressureBuffer()
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe({ (source, manga) ->

+ 3 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt

@@ -207,11 +207,11 @@ class CategoryController : NucleusController<CategoryPresenter>(),
      */
     override fun onItemClick(view: View, position: Int): Boolean {
         // Check if action mode is initialized and selected item exist.
-        if (actionMode != null && position != RecyclerView.NO_POSITION) {
+        return if (actionMode != null && position != RecyclerView.NO_POSITION) {
             toggleSelection(position)
-            return true
+            true
         } else {
-            return false
+            false
         }
     }
 

+ 3 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryCreateDialog.kt

@@ -33,9 +33,9 @@ class CategoryCreateDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
                 .title(R.string.action_add_category)
                 .negativeText(android.R.string.cancel)
                 .alwaysCallInputCallback()
-                .input(resources?.getString(R.string.name), currentName, false, { _, input ->
+                .input(resources?.getString(R.string.name), currentName, false) { _, input ->
                     currentName = input.toString()
-                })
+                }
                 .onPositive { _, _ -> (targetController as? Listener)?.createCategory(currentName) }
                 .build()
     }
@@ -44,4 +44,4 @@ class CategoryCreateDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
         fun createCategory(name: String)
     }
 
-}
+}

+ 3 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryRenameDialog.kt

@@ -38,9 +38,9 @@ class CategoryRenameDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
                 .title(R.string.action_rename_category)
                 .negativeText(android.R.string.cancel)
                 .alwaysCallInputCallback()
-                .input(resources!!.getString(R.string.name), currentName, false, { _, input ->
+                .input(resources!!.getString(R.string.name), currentName, false) { _, input ->
                     currentName = input.toString()
-                })
+                }
                 .onPositive { _, _ -> onPositive() }
                 .build()
     }
@@ -83,4 +83,4 @@ class CategoryRenameDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
         const val CATEGORY_KEY = "CategoryRenameDialog.category"
     }
 
-}
+}

+ 3 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt

@@ -33,9 +33,9 @@ class DownloadPresenter : BasePresenter<DownloadController>() {
         downloadQueue.getUpdatedObservable()
                 .observeOn(AndroidSchedulers.mainThread())
                 .map { ArrayList(it) }
-                .subscribeLatestCache(DownloadController::onNextDownloads, { _, error ->
+                .subscribeLatestCache(DownloadController::onNextDownloads) { _, error ->
                     Timber.e(error)
-                })
+                }
     }
 
     fun getDownloadStatusObservable(): Observable<Download> {
@@ -62,4 +62,4 @@ class DownloadPresenter : BasePresenter<DownloadController>() {
         downloadManager.clearQueue()
     }
 
-}
+}

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt

@@ -99,7 +99,7 @@ open class ExtensionController : NucleusController<ExtensionPresenter>(),
         val searchView = searchItem.actionView as SearchView
         searchView.maxWidth = Int.MAX_VALUE
 
-        if (!query.isEmpty()) {
+        if (query.isNotEmpty()) {
             searchItem.expandActionView()
             searchView.setQuery(query, true)
             searchView.clearFocus()

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

@@ -178,7 +178,7 @@ class LibraryController(
     override fun createSecondaryDrawer(drawer: DrawerLayout): ViewGroup {
         val view = drawer.inflate(R.layout.library_drawer) as LibraryNavigationView
         navView = view
-        drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.END)
+        drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GravityCompat.END)
 
         navView?.onGroupClicked = { group ->
             when (group) {

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt

@@ -209,9 +209,9 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
             item.group.items.forEach { (it as Item.Radio).checked = false }
             item.checked = true
 
-            preferences.libraryAsList().set(if (item == list) true else false)
+            preferences.libraryAsList().set(item == list)
 
             item.group.items.forEach { adapter.notifyItemChanged(it) }
         }
     }
-}
+}

+ 19 - 16
app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt

@@ -89,12 +89,15 @@ class LibraryPresenter(
     fun subscribeLibrary() {
         if (librarySubscription.isNullOrUnsubscribed()) {
             librarySubscription = getLibraryObservable()
-                    .combineLatest(downloadTriggerRelay.observeOn(Schedulers.io()),
-                            { lib, _ -> lib.apply { setDownloadCount(mangaMap) } })
-                    .combineLatest(filterTriggerRelay.observeOn(Schedulers.io()),
-                            { lib, _ -> lib.copy(mangaMap = applyFilters(lib.mangaMap)) })
-                    .combineLatest(sortTriggerRelay.observeOn(Schedulers.io()),
-                            { lib, _ -> lib.copy(mangaMap = applySort(lib.mangaMap)) })
+                    .combineLatest(downloadTriggerRelay.observeOn(Schedulers.io())) {
+                        lib, _ -> lib.apply { setDownloadCount(mangaMap) }
+                    }
+                    .combineLatest(filterTriggerRelay.observeOn(Schedulers.io())) {
+                        lib, _ -> lib.copy(mangaMap = applyFilters(lib.mangaMap))
+                    }
+                    .combineLatest(sortTriggerRelay.observeOn(Schedulers.io())) {
+                        lib, _ -> lib.copy(mangaMap = applySort(lib.mangaMap))
+                    }
                     .observeOn(AndroidSchedulers.mainThread())
                     .subscribeLatestCache({ view, (categories, mangaMap) ->
                         view.onNextLibraryUpdate(categories, mangaMap)
@@ -222,16 +225,16 @@ class LibraryPresenter(
      * @return an observable of the categories and its manga.
      */
     private fun getLibraryObservable(): Observable<Library> {
-        return Observable.combineLatest(getCategoriesObservable(), getLibraryMangasObservable(),
-                { dbCategories, libraryManga ->
-                    val categories = if (libraryManga.containsKey(0))
-                        arrayListOf(Category.createDefault()) + dbCategories
-                    else
-                        dbCategories
-
-                    this.categories = categories
-                    Library(categories, libraryManga)
-                })
+        return Observable.combineLatest(getCategoriesObservable(), getLibraryMangasObservable()) {
+            dbCategories, libraryManga ->
+                val categories = if (libraryManga.containsKey(0))
+                    arrayListOf(Category.createDefault()) + dbCategories
+                else
+                    dbCategories
+
+                this.categories = categories
+                Library(categories, libraryManga)
+            }
     }
 
     /**

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

@@ -12,7 +12,7 @@ import it.gmariotti.changelibs.library.view.ChangeLogRecyclerView
 
 class ChangelogDialogController : DialogController() {
 
-    override fun onCreateDialog(savedState: Bundle?): Dialog {
+    override fun onCreateDialog(savedViewState: Bundle?): Dialog {
         val activity = activity!!
         val view = WhatsNewRecyclerView(activity)
         return MaterialDialog.Builder(activity)
@@ -29,4 +29,4 @@ class ChangelogDialogController : DialogController() {
             mChangeLogFileResourceId = if (BuildConfig.DEBUG) R.raw.changelog_debug else R.raw.changelog_release
         }
     }
-}
+}

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

@@ -170,7 +170,7 @@ class MainActivity : BaseActivity() {
 
                 //Get the search query provided in extras, and if not null, perform a global search with it.
                 val query = intent.getStringExtra(SearchManager.QUERY)
-                if (query != null && !query.isEmpty()) {
+                if (query != null && query.isNotEmpty()) {
                     if (router.backstackSize > 1) {
                         router.popToRoot()
                     }
@@ -180,7 +180,7 @@ class MainActivity : BaseActivity() {
             INTENT_SEARCH -> {
                 val query = intent.getStringExtra(INTENT_SEARCH_QUERY)
                 val filter = intent.getStringExtra(INTENT_SEARCH_FILTER)
-                if (query != null && !query.isEmpty()) {
+                if (query != null && query.isNotEmpty()) {
                     if (router.backstackSize > 1) {
                         router.popToRoot()
                     }

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

@@ -109,8 +109,9 @@ class ChaptersPresenter(
                 .observeOn(AndroidSchedulers.mainThread())
                 .filter { download -> download.manga.id == manga.id }
                 .doOnNext { onDownloadStatusChange(it) }
-                .subscribeLatestCache(ChaptersController::onChapterStatusChange,
-                        { _, error -> Timber.e(error) })
+                .subscribeLatestCache(ChaptersController::onChapterStatusChange) {
+                    _, error -> Timber.e(error)
+                }
     }
 
     /**

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DeletingChaptersDialog.kt

@@ -13,7 +13,7 @@ class DeletingChaptersDialog(bundle: Bundle? = null) : DialogController(bundle)
         const val TAG = "deleting_dialog"
     }
 
-    override fun onCreateDialog(savedState: Bundle?): Dialog {
+    override fun onCreateDialog(savedViewState: Bundle?): Dialog {
         return MaterialDialog.Builder(activity!!)
                 .progress(true, 0)
                 .content(R.string.deleting)
@@ -24,4 +24,4 @@ class DeletingChaptersDialog(bundle: Bundle? = null) : DialogController(bundle)
         showDialog(router, TAG)
     }
 
-}
+}

+ 1 - 5
app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt

@@ -195,11 +195,7 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
         }
 
         // If manga source is known update source TextView.
-        manga_source.text = if (source == null) {
-            view.context.getString(R.string.unknown)
-        } else {
-            source.toString()
-        }
+        manga_source.text = source?.toString() ?: view.context.getString(R.string.unknown)
 
         // Update genres list
         if (manga.genre.isNullOrBlank().not()) {

+ 4 - 4
app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt

@@ -32,7 +32,7 @@ class SetTrackStatusDialog<T> : DialogController
 
     override fun onCreateDialog(savedViewState: Bundle?): Dialog {
         val item = item
-        val statusList = item.service.getStatusList().orEmpty()
+        val statusList = item.service.getStatusList()
         val statusString = statusList.mapNotNull { item.service.getStatus(it) }
         val selectedIndex = statusList.indexOf(item.track?.status)
 
@@ -40,10 +40,10 @@ class SetTrackStatusDialog<T> : DialogController
                 .title(R.string.status)
                 .negativeText(android.R.string.cancel)
                 .items(statusString)
-                .itemsCallbackSingleChoice(selectedIndex, { _, _, i, _ ->
+                .itemsCallbackSingleChoice(selectedIndex) { _, _, i, _ ->
                     (targetController as? Listener)?.setStatus(item, i)
                     true
-                })
+                }
                 .build()
     }
 
@@ -55,4 +55,4 @@ class SetTrackStatusDialog<T> : DialogController
         const val KEY_ITEM_TRACK = "SetTrackStatusDialog.item.track"
     }
 
-}
+}

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

@@ -25,7 +25,7 @@ class TrackHolder(view: View, adapter: TrackAdapter) : BaseViewHolder(view) {
         logo_container.setBackgroundColor(item.service.getLogoColor())
         if (track != null) {
             track_title.setTextAppearance(itemView.context, R.style.TextAppearance_Regular_Body1_Secondary)
-            track_title.setAllCaps(false)
+            track_title.isAllCaps = false
             track_title.text = track.title
             track_chapters.text = "${track.last_chapter_read}/" +
                     if (track.total_chapters > 0) track.total_chapters else "-"

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

@@ -50,7 +50,7 @@ class TrackSearchDialog : DialogController {
         service = Injekt.get<TrackManager>().getService(bundle.getInt(KEY_SERVICE))!!
     }
 
-    override fun onCreateDialog(savedState: Bundle?): Dialog {
+    override fun onCreateDialog(savedViewState: Bundle?): Dialog {
         val dialog = MaterialDialog.Builder(activity!!)
                 .customView(R.layout.track_search_dialog, false)
                 .positiveText(android.R.string.ok)
@@ -63,7 +63,7 @@ class TrackSearchDialog : DialogController {
         }
 
         dialogView = dialog.view
-        onViewCreated(dialog.view, savedState)
+        onViewCreated(dialog.view, savedViewState)
 
         return dialog
     }

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationPresenter.kt

@@ -42,8 +42,8 @@ class MigrationPresenter(
                 .observeOn(AndroidSchedulers.mainThread())
                 .doOnNext { state = state.copy(sourcesWithManga = findSourcesWithManga(it)) }
                 .combineLatest(stateRelay.map { it.selectedSource }
-                        .distinctUntilChanged(),
-                        { library, source -> library to source })
+                        .distinctUntilChanged()
+                ) { library, source -> library to source }
                 .filter { (_, source) -> source != null }
                 .observeOn(Schedulers.io())
                 .map { (library, source) -> libraryToMigrationItem(library, source!!.id) }

+ 3 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt

@@ -77,13 +77,13 @@ class SearchController(
                     .content(R.string.migration_dialog_what_to_include)
                     .items(MigrationFlags.titles.map { resources?.getString(it) })
                     .alwaysCallMultiChoiceCallback()
-                    .itemsCallbackMultiChoice(preselected.toTypedArray(), { _, positions, _ ->
+                    .itemsCallbackMultiChoice(preselected.toTypedArray()) { _, positions, _ ->
                         // Save current settings for the next time
                         val newValue = MigrationFlags.getFlagsFromPositions(positions)
                         preferences.migrateFlags().set(newValue)
 
                         true
-                    })
+                    }
                     .positiveText(R.string.migrate)
                     .negativeText(R.string.copy)
                     .neutralText(android.R.string.cancel)
@@ -98,4 +98,4 @@ class SearchController(
 
     }
 
-}
+}

+ 11 - 6
app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt

@@ -43,6 +43,7 @@ import timber.log.Timber
 import uy.kohesive.injekt.injectLazy
 import java.io.File
 import java.util.concurrent.TimeUnit
+import kotlin.math.abs
 
 /**
  * Activity containing the reader of Tachiyomi. This activity is mostly a container of the
@@ -692,18 +693,22 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
          */
         private fun setCustomBrightnessValue(value: Int) {
             // Calculate and set reader brightness.
-            val readerBrightness = if (value > 0) {
-                value / 100f
-            } else if (value < 0) {
-                0.01f
-            } else WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
+            val readerBrightness = when {
+                value > 0 -> {
+                    value / 100f
+                }
+                value < 0 -> {
+                    0.01f
+                }
+                else -> WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
+            }
 
             window.attributes = window.attributes.apply { screenBrightness = readerBrightness }
 
             // Set black overlay visibility.
             if (value < 0) {
                 brightness_overlay.visibility = View.VISIBLE
-                val alpha = (Math.abs(value) * 2.56).toInt()
+                val alpha = (abs(value) * 2.56).toInt()
                 brightness_overlay.setBackgroundColor(Color.argb(alpha, 0, 0, 0))
             } else {
                 brightness_overlay.visibility = View.GONE

+ 7 - 5
app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt

@@ -1,12 +1,12 @@
 package eu.kanade.tachiyomi.ui.reader
 
 import android.graphics.Color
-import androidx.annotation.ColorInt
-import com.google.android.material.bottomsheet.BottomSheetBehavior
-import com.google.android.material.bottomsheet.BottomSheetDialog
 import android.view.View
 import android.view.ViewGroup
 import android.widget.SeekBar
+import androidx.annotation.ColorInt
+import com.google.android.material.bottomsheet.BottomSheetBehavior
+import com.google.android.material.bottomsheet.BottomSheetDialog
 import eu.kanade.tachiyomi.R
 import eu.kanade.tachiyomi.data.preference.PreferencesHelper
 import eu.kanade.tachiyomi.data.preference.getOrDefault
@@ -14,12 +14,14 @@ import eu.kanade.tachiyomi.util.plusAssign
 import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener
 import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
 import kotlinx.android.synthetic.main.reader_color_filter.*
-import kotlinx.android.synthetic.main.reader_color_filter_sheet.*
+import kotlinx.android.synthetic.main.reader_color_filter_sheet.brightness_overlay
+import kotlinx.android.synthetic.main.reader_color_filter_sheet.color_overlay
 import rx.Subscription
 import rx.android.schedulers.AndroidSchedulers
 import rx.subscriptions.CompositeSubscription
 import uy.kohesive.injekt.injectLazy
 import java.util.concurrent.TimeUnit
+import kotlin.math.abs
 
 /**
  * Color filter sheet to toggle custom filter and brightness overlay.
@@ -221,7 +223,7 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog(activ
         // Set black overlay visibility.
         if (value < 0) {
             brightness_overlay.visibility = View.VISIBLE
-            val alpha = (Math.abs(value) * 2.56).toInt()
+            val alpha = (abs(value) * 2.56).toInt()
             brightness_overlay.setBackgroundColor(Color.argb(alpha, 0, 0, 0))
         } else {
             brightness_overlay.visibility = View.GONE

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterView.kt

@@ -13,7 +13,7 @@ class ReaderColorFilterView(
     private val colorFilterPaint: Paint = Paint()
 
     fun setFilterColor(color: Int, filterMode: Int) {
-        colorFilterPaint.setColor(color)
+        colorFilterPaint.color = color
         colorFilterPaint.xfermode = PorterDuffXfermode(when (filterMode) {
             1 -> PorterDuff.Mode.MULTIPLY
             2 -> PorterDuff.Mode.SCREEN

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt

@@ -90,7 +90,7 @@ class ReaderPresenter(
 
         val chaptersForReader =
                 if (preferences.skipRead()) {
-                    var list = dbChapters.filter { it -> !it.read }.toMutableList()
+                    val list = dbChapters.filter { !it.read }.toMutableList()
                     val find = list.find { it.id == chapterId }
                     if (find == null) {
                         list.add(selectedChapter)

+ 3 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/reader/SaveImageNotifier.kt

@@ -57,8 +57,9 @@ class SaveImageNotifier(private val context: Context) {
             setStyle(NotificationCompat.BigPictureStyle().bigPicture(image))
             setLargeIcon(image)
             setAutoCancel(true)
+
             // Clear old actions if they exist
-            if (!mActions.isEmpty())
+            if (mActions.isNotEmpty())
                 mActions.clear()
 
             setContentIntent(NotificationHandler.openImagePendingActivity(context, file))
@@ -70,8 +71,8 @@ class SaveImageNotifier(private val context: Context) {
             addAction(R.drawable.ic_delete_grey_24dp,
                     context.getString(R.string.action_delete),
                     NotificationReceiver.deleteImagePendingBroadcast(context, file.absolutePath, notificationId))
-            updateNotification()
 
+            updateNotification()
         }
     }
 
@@ -87,7 +88,6 @@ class SaveImageNotifier(private val context: Context) {
         context.notificationManager.notify(notificationId, notificationBuilder.build())
     }
 
-
     /**
      * Called on error while downloading image.
      * @param error string containing error information.

+ 0 - 14
app/src/main/java/eu/kanade/tachiyomi/ui/reader/model/ChapterTransition.kt

@@ -12,20 +12,6 @@ sealed class ChapterTransition {
             override val from: ReaderChapter, override val to: ReaderChapter?
     ) : ChapterTransition()
 
-    override fun equals(other: Any?): Boolean {
-        if (this === other) return true
-        if (other !is ChapterTransition) return false
-        if (from == other.from && to == other.to) return true
-        if (from == other.to && to == other.from) return true
-        return false
-    }
-
-    override fun hashCode(): Int {
-        var result = from.hashCode()
-        result = 31 * result + (to?.hashCode() ?: 0)
-        return result
-    }
-
     override fun toString(): String {
         return "${javaClass.simpleName}(from=${from.chapter.url}, to=${to?.chapter?.url})"
     }

+ 2 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/GestureDetectorWithLongTap.kt

@@ -5,6 +5,7 @@ import android.os.Handler
 import android.view.GestureDetector
 import android.view.MotionEvent
 import android.view.ViewConfiguration
+import kotlin.math.abs
 
 /**
  * A custom gesture detector that also implements an on long tap confirmed, because the built-in
@@ -45,7 +46,7 @@ open class GestureDetectorWithLongTap(
                 }
             }
             MotionEvent.ACTION_MOVE -> {
-                if (Math.abs(ev.rawX - downX) > slop || Math.abs(ev.rawY - downY) > slop) {
+                if (abs(ev.rawX - downX) > slop || abs(ev.rawY - downY) > slop) {
                     handler.removeCallbacks(longTapFn)
                 }
             }

+ 2 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressBar.kt

@@ -16,6 +16,7 @@ import android.view.animation.LinearInterpolator
 import android.view.animation.RotateAnimation
 import eu.kanade.tachiyomi.R
 import eu.kanade.tachiyomi.util.getResourceColor
+import kotlin.math.min
 
 /**
  * A custom progress bar that always rotates while being determinate. By always rotating we give
@@ -75,7 +76,7 @@ class ReaderProgressBar @JvmOverloads constructor(
     override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
         super.onLayout(changed, left, top, right, bottom)
 
-        val diameter = Math.min(width, height)
+        val diameter = min(width, height)
         val thickness = diameter / 10f
         val pad = thickness / 2f
         ovalRect.set(pad, pad, diameter - pad, diameter - pad)

+ 3 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt

@@ -12,6 +12,7 @@ import android.view.animation.DecelerateInterpolator
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import eu.kanade.tachiyomi.ui.reader.viewer.GestureDetectorWithLongTap
+import kotlin.math.abs
 
 /**
  * Implementation of a [RecyclerView] used by the webtoon reader.
@@ -267,7 +268,7 @@ open class WebtoonRecyclerView @JvmOverloads constructor(
                     if (!isZoomDragging && currentScale > 1f) {
                         var startScroll = false
 
-                        if (Math.abs(dx) > touchSlop) {
+                        if (abs(dx) > touchSlop) {
                             if (dx < 0) {
                                 dx += touchSlop
                             } else {
@@ -275,7 +276,7 @@ open class WebtoonRecyclerView @JvmOverloads constructor(
                             }
                             startScroll = true
                         }
-                        if (Math.abs(dy) > touchSlop) {
+                        if (abs(dy) > touchSlop) {
                             if (dy < 0) {
                                 dy += touchSlop
                             } else {

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/DeletingChaptersDialog.kt

@@ -13,7 +13,7 @@ class DeletingChaptersDialog(bundle: Bundle? = null) : DialogController(bundle)
         const val TAG = "deleting_dialog"
     }
 
-    override fun onCreateDialog(savedState: Bundle?): Dialog {
+    override fun onCreateDialog(savedViewState: Bundle?): Dialog {
         return MaterialDialog.Builder(activity!!)
                 .progress(true, 0)
                 .content(R.string.deleting)
@@ -24,4 +24,4 @@ class DeletingChaptersDialog(bundle: Bundle? = null) : DialogController(bundle)
         showDialog(router, TAG)
     }
 
-}
+}

+ 3 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt

@@ -38,8 +38,9 @@ class RecentChaptersPresenter(
                 .subscribeLatestCache(RecentChaptersController::onNextRecentChapters)
 
         getChapterStatusObservable()
-                .subscribeLatestCache(RecentChaptersController::onChapterStatusChange,
-                        { _, error -> Timber.e(error) })
+                .subscribeLatestCache(RecentChaptersController::onChapterStatusChange) {
+                    _, error -> Timber.e(error)
+                }
     }
 
     /**

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/setting/AnilistLoginActivity.kt

@@ -31,7 +31,7 @@ class AnilistLoginActivity : AppCompatActivity() {
                     .observeOn(AndroidSchedulers.mainThread())
                     .subscribe({
                         returnToSettings()
-                    }, { _ ->
+                    }, {
                         returnToSettings()
                     })
         } else {

+ 4 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt

@@ -61,14 +61,16 @@ inline fun <P : Preference> PreferenceGroup.initThenAdd(p: P, block: P.() -> Uni
     return p.apply {
         block()
         this.isIconSpaceReserved  = false
-        addPreference(this) }
+        addPreference(this)
+    }
 }
 
 inline fun <P : Preference> PreferenceGroup.addThenInit(p: P, block: P.() -> Unit): P {
     return p.apply {
         this.isIconSpaceReserved  = false
         addPreference(this)
-        block() }
+        block()
+    }
 }
 
 inline fun Preference.onClick(crossinline block: () -> Unit) {

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt

@@ -206,7 +206,7 @@ class SettingsBackupController : SettingsController() {
                     .content(R.string.backup_choice)
                     .items(options)
                     .itemsDisabledIndices(0)
-                    .itemsCallbackMultiChoice(arrayOf(0, 1, 2, 3, 4), { _, positions, _ ->
+                    .itemsCallbackMultiChoice(arrayOf(0, 1, 2, 3, 4)) { _, positions, _ ->
                         var flags = 0
                         for (i in 1 until positions.size) {
                             when (positions[i]) {
@@ -219,7 +219,7 @@ class SettingsBackupController : SettingsController() {
 
                         (targetController as? SettingsBackupController)?.createBackup(flags)
                         true
-                    })
+                    }
                     .positiveText(R.string.action_create)
                     .negativeText(android.R.string.cancel)
                     .build()

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt

@@ -147,7 +147,7 @@ class SettingsDownloadController : SettingsController() {
 
             return MaterialDialog.Builder(activity)
                     .items(externalDirs)
-                    .itemsCallbackSingleChoice(selectedIndex, { _, _, which, text ->
+                    .itemsCallbackSingleChoice(selectedIndex) { _, _, which, text ->
                         val target = targetController as? SettingsDownloadController
                         if (which == externalDirs.lastIndex) {
                             target?.customDirectorySelected(currentDir)
@@ -155,7 +155,7 @@ class SettingsDownloadController : SettingsController() {
                             target?.predefinedDirectorySelected(text.toString())
                         }
                         true
-                    })
+                    }
                     .build()
         }
 

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt

@@ -79,8 +79,8 @@ class SettingsGeneralController : SettingsController() {
 
             Observable.combineLatest(
                     preferences.portraitColumns().asObservable(),
-                    preferences.landscapeColumns().asObservable(),
-                    { portraitCols, landscapeCols -> Pair(portraitCols, landscapeCols) })
+                    preferences.landscapeColumns().asObservable()
+            ) { portraitCols, landscapeCols -> Pair(portraitCols, landscapeCols) }
                     .subscribeUntilDestroy { (portraitCols, landscapeCols) ->
                         val portrait = getColumnValue(portraitCols)
                         val landscape = getColumnValue(landscapeCols)

+ 5 - 5
app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt

@@ -92,7 +92,7 @@ fun syncChaptersWithSource(db: DatabaseHelper,
     db.inTransaction {
         val deletedChapterNumbers = TreeSet<Float>()
         val deletedReadChapterNumbers = TreeSet<Float>()
-        if (!toDelete.isEmpty()) {
+        if (toDelete.isNotEmpty()) {
             for (c in toDelete) {
                 if (c.read) {
                     deletedReadChapterNumbers.add(c.chapter_number)
@@ -102,7 +102,7 @@ fun syncChaptersWithSource(db: DatabaseHelper,
             db.deleteChapters(toDelete).executeAsBlocking()
         }
 
-        if (!toAdd.isEmpty()) {
+        if (toAdd.isNotEmpty()) {
             // Set the date fetch for new items in reverse order to allow another sorting method.
             // Sources MUST return the chapters from most to less recent, which is common.
             var now = Date().time
@@ -121,7 +121,7 @@ fun syncChaptersWithSource(db: DatabaseHelper,
             db.insertChapters(toAdd).executeAsBlocking()
         }
 
-        if (!toChange.isEmpty()) {
+        if (toChange.isNotEmpty()) {
             db.insertChapters(toChange).executeAsBlocking()
         }
 
@@ -132,8 +132,8 @@ fun syncChaptersWithSource(db: DatabaseHelper,
         manga.last_update = Date().time
         db.updateLastUpdated(manga).executeAsBlocking()
     }
-    return Pair(toAdd.subtract(readded).toList(), toDelete.subtract(readded).toList())
 
+    return Pair(toAdd.subtract(readded).toList(), toDelete.subtract(readded).toList())
 }
 
 //checks if the chapter in db needs updated
@@ -141,4 +141,4 @@ private fun shouldUpdateDbChapter(dbChapter: Chapter, sourceChapter: SChapter):
     return dbChapter.scanlator != sourceChapter.scanlator || dbChapter.name != sourceChapter.name ||
             dbChapter.date_upload != sourceChapter.date_upload ||
             dbChapter.chapter_number != sourceChapter.chapter_number
-}
+}

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/util/ImageUtil.kt

@@ -50,7 +50,7 @@ object ImageUtil {
     }
 
     private fun ByteArray.compareWith(magic: ByteArray): Boolean {
-        for (i in 0 until magic.size) {
+        for (i in magic.indices) {
             if (this[i] != magic[i]) return false
         }
         return true
@@ -58,7 +58,7 @@ object ImageUtil {
 
     private fun charByteArrayOf(vararg bytes: Int): ByteArray {
         return ByteArray(bytes.size).apply {
-            for (i in 0 until bytes.size) {
+            for (i in bytes.indices) {
                 set(i, bytes[i].toByte())
             }
         }

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt

@@ -9,7 +9,7 @@ import android.view.ContextThemeWrapper
 import eu.kanade.tachiyomi.R
 import eu.kanade.tachiyomi.data.preference.PreferencesHelper
 import uy.kohesive.injekt.injectLazy
-import java.util.*
+import java.util.Locale
 
 /**
  * Utility class to change the application's language in runtime.
@@ -90,7 +90,7 @@ object LocaleHelper {
      * Updates the app's language to an activity.
      */
     fun updateConfiguration(wrapper: ContextThemeWrapper) {
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && appLocale != null) {
+        if (appLocale != null) {
             val config = Configuration(preferences.context.resources.configuration)
             config.setLocale(appLocale)
             wrapper.applyOverrideConfiguration(config)

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/util/SharedData.kt

@@ -22,7 +22,7 @@ object SharedData {
      * @param data the object to put.
      */
     fun <T : Any> put(data: T) {
-        map.put(data.javaClass, data)
+        map[data.javaClass] = data
     }
 
     /**

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/util/StringExtensions.kt

@@ -1,6 +1,6 @@
 package eu.kanade.tachiyomi.util
 
-import java.lang.Math.floor
+import kotlin.math.floor
 
 /**
  * Replaces the given string to have at most [count] characters using [replacement] at its end.
@@ -25,4 +25,4 @@ fun String.truncateCenter(count: Int, replacement: String = "..."): String{
     val pieceLength:Int = floor((count - replacement.length).div(2.0)).toInt()
 
     return "${ take(pieceLength) }$replacement${ takeLast(pieceLength) }"
-}
+}

+ 3 - 2
app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt

@@ -5,11 +5,12 @@ package eu.kanade.tachiyomi.util
 import android.graphics.Color
 import android.graphics.Point
 import android.graphics.Typeface
-import com.google.android.material.snackbar.Snackbar
 import android.view.View
 import android.widget.TextView
 import com.amulyakhare.textdrawable.TextDrawable
 import com.amulyakhare.textdrawable.util.ColorGenerator
+import com.google.android.material.snackbar.Snackbar
+import kotlin.math.min
 
 /**
  * Returns coordinates of view.
@@ -58,7 +59,7 @@ inline fun View.visibleIf(block: () -> Boolean) {
  * @param random random color
  */
 fun View.getRound(text: String, random : Boolean = true): TextDrawable {
-    val size = Math.min(this.width, this.height)
+    val size = min(this.width, this.height)
     return TextDrawable.builder()
             .beginConfig()
             .width(size)

+ 3 - 2
app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt

@@ -1,9 +1,10 @@
 package eu.kanade.tachiyomi.widget
 
 import android.content.Context
+import android.util.AttributeSet
 import androidx.recyclerview.widget.GridLayoutManager
 import androidx.recyclerview.widget.RecyclerView
-import android.util.AttributeSet
+import kotlin.math.max
 
 class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
         RecyclerView(context, attrs) {
@@ -37,7 +38,7 @@ class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: Att
     override fun onMeasure(widthSpec: Int, heightSpec: Int) {
         super.onMeasure(widthSpec, heightSpec)
         if (spanCount == 0 && columnWidth > 0) {
-            val count = Math.max(1, measuredWidth / columnWidth)
+            val count = max(1, measuredWidth / columnWidth)
             spanCount = count
         }
     }

+ 3 - 3
app/src/main/java/eu/kanade/tachiyomi/widget/CustomLayoutPicker.kt

@@ -22,12 +22,12 @@ class CustomLayoutPickerActivity : FilePickerActivity() {
 
 class CustomLayoutFilePickerFragment : FilePickerFragment() {
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
-        when (viewType) {
+        return when (viewType) {
             LogicHandler.VIEWTYPE_DIR -> {
                 val view = parent.inflate(R.layout.common_listitem_dir)
-                return DirViewHolder(view)
+                DirViewHolder(view)
             }
-            else -> return super.onCreateViewHolder(parent, viewType)
+            else -> super.onCreateViewHolder(parent, viewType)
         }
     }
 }

+ 2 - 3
app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt

@@ -13,7 +13,7 @@ import eu.kanade.tachiyomi.R
 import eu.kanade.tachiyomi.util.getResourceColor
 
 /**
- * An alternative implementation of [android.support.design.widget.NavigationView], without menu
+ * An alternative implementation of [com.google.android.material.navigation.NavigationView], without menu
  * inflation and allowing customizable items (multiple selections, custom views, etc).
  */
 open class ExtendedNavigationView @JvmOverloads constructor(
@@ -179,8 +179,7 @@ open class ExtendedNavigationView @JvmOverloads constructor(
 
         @CallSuper
         override fun getItemViewType(position: Int): Int {
-            val item = items[position]
-            return when (item) {
+            return when (items[position]) {
                 is Item.Header -> VIEW_TYPE_HEADER
                 is Item.Separator -> VIEW_TYPE_SEPARATOR
                 is Item.Radio -> VIEW_TYPE_RADIO

+ 1 - 0
app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationBase.kt

@@ -20,6 +20,7 @@ abstract class FABAnimationBase : FloatingActionButton.Behavior() {
                                 target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int,
                                 dyUnconsumed: Int, type: Int) {
         super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type)
+
         if (dyConsumed > 0 && !isAnimatingOut && child.visibility == View.VISIBLE) {
             // User scrolled down and the FAB is currently visible -> hide the FAB
             animateOut(child)

+ 6 - 5
app/src/main/java/eu/kanade/tachiyomi/widget/NegativeSeekBar.kt

@@ -5,6 +5,7 @@ import android.os.Parcelable
 import android.util.AttributeSet
 import android.widget.SeekBar
 import eu.kanade.tachiyomi.R
+import kotlin.math.abs
 
 
 class NegativeSeekBar @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
@@ -28,21 +29,21 @@ class NegativeSeekBar @JvmOverloads constructor(context: Context, attrs: Attribu
 
         super.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
             override fun onProgressChanged(seekBar: SeekBar?, value: Int, fromUser: Boolean) {
-                listener?.let { it.onProgressChanged(seekBar, minValue + value, fromUser) }
+                listener?.onProgressChanged(seekBar, minValue + value, fromUser)
             }
 
             override fun onStartTrackingTouch(p0: SeekBar?) {
-                listener?.let { it.onStartTrackingTouch(p0) }
+                listener?.onStartTrackingTouch(p0)
             }
 
             override fun onStopTrackingTouch(p0: SeekBar?) {
-                listener?.let { it.onStopTrackingTouch(p0) }
+                listener?.onStopTrackingTouch(p0)
             }
         })
     }
 
     override fun setProgress(progress: Int) {
-        super.setProgress(Math.abs(minValue) + progress)
+        super.setProgress(abs(minValue) + progress)
     }
 
     fun setMinSeek(minValue: Int) {
@@ -66,4 +67,4 @@ class NegativeSeekBar @JvmOverloads constructor(context: Context, attrs: Attribu
         super.setProgress(origProgress)
     }
 
-}
+}

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/widget/PTSansTextView.kt

@@ -30,7 +30,7 @@ class PTSansTextView @JvmOverloads constructor(context: Context, attrs: Attribut
                 Typeface.createFromAsset(context.assets, when (typeface) {
                     PTSANS_NARROW -> "fonts/PTSans-Narrow.ttf"
                     PTSANS_NARROW_BOLD -> "fonts/PTSans-NarrowBold.ttf"
-                    else -> throw IllegalArgumentException("Font not found " + typeface)
+                    else -> throw IllegalArgumentException("Font not found $typeface")
                 })
             })
 

+ 8 - 7
app/src/main/java/eu/kanade/tachiyomi/widget/SimpleNavigationView.kt

@@ -2,18 +2,19 @@ package eu.kanade.tachiyomi.widget
 
 import android.annotation.SuppressLint
 import android.content.Context
-import com.google.android.material.R
-import com.google.android.material.textfield.TextInputLayout
-import androidx.core.view.ViewCompat
-import androidx.recyclerview.widget.LinearLayoutManager
-import androidx.recyclerview.widget.RecyclerView
-import androidx.appcompat.widget.TintTypedArray
 import android.util.AttributeSet
 import android.view.View
 import android.view.ViewGroup
 import android.widget.*
+import androidx.appcompat.widget.TintTypedArray
+import androidx.core.view.ViewCompat
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+import com.google.android.material.R
 import com.google.android.material.internal.ScrimInsetsFrameLayout
+import com.google.android.material.textfield.TextInputLayout
 import eu.kanade.tachiyomi.util.inflate
+import kotlin.math.min
 import eu.kanade.tachiyomi.R as TR
 
 @Suppress("LeakingThis")
@@ -66,7 +67,7 @@ open class SimpleNavigationView @JvmOverloads constructor(
     override fun onMeasure(widthSpec: Int, heightSpec: Int) {
         val width = when (MeasureSpec.getMode(widthSpec)) {
             MeasureSpec.AT_MOST -> MeasureSpec.makeMeasureSpec(
-                    Math.min(MeasureSpec.getSize(widthSpec), maxWidth), MeasureSpec.EXACTLY)
+                    min(MeasureSpec.getSize(widthSpec), maxWidth), MeasureSpec.EXACTLY)
             MeasureSpec.UNSPECIFIED -> MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.EXACTLY)
             else -> widthSpec
         }

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt

@@ -25,7 +25,7 @@ abstract class LoginDialogPreference(bundle: Bundle? = null) : DialogController(
 
     var requestSubscription: Subscription? = null
 
-    override fun onCreateDialog(savedState: Bundle?): Dialog {
+    override fun onCreateDialog(savedViewState: Bundle?): Dialog {
         val dialog = MaterialDialog.Builder(activity!!)
                 .customView(R.layout.pref_account_login, false)
                 .negativeText(android.R.string.cancel)