From 5cddb269d6746969481ebf90ef2873d23790275a Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 7 Jan 2020 19:20:08 -0500 Subject: [PATCH] Minor code cleanup --- app/src/main/java/eu/kanade/tachiyomi/App.kt | 2 +- .../tachiyomi/data/backup/BackupManager.kt | 17 +++++----- .../backup/serializer/ChapterTypeAdapter.kt | 6 ++-- .../backup/serializer/TrackTypeAdapter.kt | 6 ++-- .../tachiyomi/data/download/DownloadCache.kt | 2 +- .../tachiyomi/data/track/TrackService.kt | 4 +-- .../data/track/anilist/AnilistApi.kt | 11 ++++--- .../data/track/bangumi/BangumiInterceptor.kt | 2 +- .../tachiyomi/data/track/bangumi/OAuth.kt | 2 +- .../data/track/myanimelist/MyAnimeList.kt | 2 +- .../{MyanimelistApi.kt => MyAnimeListApi.kt} | 8 ++--- .../myanimelist/MyAnimeListInterceptor.kt | 10 +++--- .../data/track/shikimori/ShikimoriApi.kt | 3 +- .../util/ExtensionInstallReceiver.kt | 2 +- .../extension/util/ExtensionLoader.kt | 2 +- .../eu/kanade/tachiyomi/source/model/Page.kt | 1 - .../browse/BrowseCataloguePresenter.kt | 2 +- .../tachiyomi/ui/catalogue/browse/Pager.kt | 4 +-- .../global_search/CatalogueSearchPresenter.kt | 1 - .../ui/category/CategoryController.kt | 6 ++-- .../ui/category/CategoryCreateDialog.kt | 6 ++-- .../ui/category/CategoryRenameDialog.kt | 6 ++-- .../ui/download/DownloadPresenter.kt | 6 ++-- .../ui/extension/ExtensionController.kt | 2 +- .../tachiyomi/ui/library/LibraryController.kt | 2 +- .../ui/library/LibraryNavigationView.kt | 4 +-- .../tachiyomi/ui/library/LibraryPresenter.kt | 33 ++++++++++--------- .../ui/main/ChangelogDialogController.kt | 4 +-- .../kanade/tachiyomi/ui/main/MainActivity.kt | 4 +-- .../ui/manga/chapter/ChaptersPresenter.kt | 5 +-- .../manga/chapter/DeletingChaptersDialog.kt | 4 +-- .../ui/manga/info/MangaInfoController.kt | 6 +--- .../ui/manga/track/SetTrackStatusDialog.kt | 8 ++--- .../tachiyomi/ui/manga/track/TrackHolder.kt | 2 +- .../ui/manga/track/TrackSearchDialog.kt | 4 +-- .../ui/migration/MigrationPresenter.kt | 4 +-- .../ui/migration/SearchController.kt | 6 ++-- .../tachiyomi/ui/reader/ReaderActivity.kt | 17 ++++++---- .../ui/reader/ReaderColorFilterSheet.kt | 12 ++++--- .../ui/reader/ReaderColorFilterView.kt | 2 +- .../tachiyomi/ui/reader/ReaderPresenter.kt | 2 +- .../tachiyomi/ui/reader/SaveImageNotifier.kt | 6 ++-- .../ui/reader/model/ChapterTransition.kt | 14 -------- .../viewer/GestureDetectorWithLongTap.kt | 3 +- .../ui/reader/viewer/ReaderProgressBar.kt | 3 +- .../viewer/webtoon/WebtoonRecyclerView.kt | 5 +-- .../recent_updates/DeletingChaptersDialog.kt | 4 +-- .../recent_updates/RecentChaptersPresenter.kt | 5 +-- .../ui/setting/AnilistLoginActivity.kt | 2 +- .../tachiyomi/ui/setting/PreferenceDSL.kt | 6 ++-- .../ui/setting/SettingsBackupController.kt | 4 +-- .../ui/setting/SettingsDownloadController.kt | 4 +-- .../ui/setting/SettingsGeneralController.kt | 4 +-- .../tachiyomi/util/ChapterSourceSync.kt | 10 +++--- .../eu/kanade/tachiyomi/util/ImageUtil.kt | 4 +-- .../eu/kanade/tachiyomi/util/LocaleHelper.kt | 4 +-- .../eu/kanade/tachiyomi/util/SharedData.kt | 2 +- .../kanade/tachiyomi/util/StringExtensions.kt | 4 +-- .../kanade/tachiyomi/util/ViewExtensions.kt | 5 +-- .../tachiyomi/widget/AutofitRecyclerView.kt | 5 +-- .../tachiyomi/widget/CustomLayoutPicker.kt | 6 ++-- .../widget/ExtendedNavigationView.kt | 5 ++- .../tachiyomi/widget/FABAnimationBase.kt | 1 + .../tachiyomi/widget/NegativeSeekBar.kt | 11 ++++--- .../kanade/tachiyomi/widget/PTSansTextView.kt | 2 +- .../tachiyomi/widget/SimpleNavigationView.kt | 15 +++++---- .../preference/LoginDialogPreference.kt | 2 +- 67 files changed, 184 insertions(+), 184 deletions(-) rename app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/{MyanimelistApi.kt => MyAnimeListApi.kt} (97%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index 7a2688b924..512c338d0e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/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() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt index c58b3e6033..b5a8e53a22 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt +++ b/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() 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() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/ChapterTypeAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/ChapterTypeAdapter.kt index 74002582de..9bd6e8e1e6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/ChapterTypeAdapter.kt +++ b/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 { } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/TrackTypeAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/TrackTypeAdapter.kt index d9f3b8cac3..0cc16d38e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/TrackTypeAdapter.kt +++ b/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 { } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt index bc6d6b42ee..b5c5d8c520 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt +++ b/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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt index 736b33cb93..f4bfcaeff4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt +++ b/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)!! diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt index 11ef51952f..055b7f89a1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt +++ b/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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt index b403daf8a9..d51c6d7862 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt +++ b/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()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/OAuth.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/OAuth.kt index 8674b6134b..b46276d167 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/OAuth.kt +++ b/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) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt index 0830600166..1cdb341085 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt +++ b/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" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyanimelistApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt similarity index 97% rename from app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyanimelistApi.kt rename to app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt index 3bc1b3f3b0..65c16d0e25 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyanimelistApi.kt +++ b/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()!! diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListInterceptor.kt index 9eae9f1370..9ef078983b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListInterceptor.kt +++ b/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()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt index 7441cf66d1..aa5cc21d71 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt +++ b/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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt index 2a55ccd7d9..2c7bf9ef78 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt +++ b/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() } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt index c4018f0461..1fa963419c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt b/app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt index c06a59a882..a0c0b1989e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt +++ b/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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCataloguePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCataloguePresenter.kt index 54c468e13d..d17cca5e0e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCataloguePresenter.kt +++ b/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) { - if (!selectedCategories.isEmpty()) { + if (selectedCategories.isNotEmpty()) { if (!manga.favorite) changeMangaFavorite(manga) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/Pager.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/Pager.kt index 1383fdfcc5..104e5887df 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/Pager.kt +++ b/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)) } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt index 14312da130..92f32fed9e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt +++ b/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) -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt index 6200d58ba8..f21014af57 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt @@ -207,11 +207,11 @@ class CategoryController : NucleusController(), */ 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 } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryCreateDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryCreateDialog.kt index dfa4bad32a..82306d0795 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryCreateDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryCreateDialog.kt @@ -33,9 +33,9 @@ class CategoryCreateDialog(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(bundle: Bundle? = null) : DialogController(bundle) fun createCategory(name: String) } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryRenameDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryRenameDialog.kt index 286093b06b..023333c833 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryRenameDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryRenameDialog.kt @@ -38,9 +38,9 @@ class CategoryRenameDialog(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(bundle: Bundle? = null) : DialogController(bundle) const val CATEGORY_KEY = "CategoryRenameDialog.category" } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt index 0577176e95..4ffc15f4bb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt @@ -33,9 +33,9 @@ class DownloadPresenter : BasePresenter() { downloadQueue.getUpdatedObservable() .observeOn(AndroidSchedulers.mainThread()) .map { ArrayList(it) } - .subscribeLatestCache(DownloadController::onNextDownloads, { _, error -> + .subscribeLatestCache(DownloadController::onNextDownloads) { _, error -> Timber.e(error) - }) + } } fun getDownloadStatusObservable(): Observable { @@ -62,4 +62,4 @@ class DownloadPresenter : BasePresenter() { downloadManager.clearQueue() } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt index 1a4dd6230f..823cd77873 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt @@ -99,7 +99,7 @@ open class ExtensionController : NucleusController(), 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() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 4ff8beb2b1..dd95147fd3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/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) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt index 2b8d57f8a7..febbceb06b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt +++ b/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) } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 4e8bf01a2a..967d35a123 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/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 { - return Observable.combineLatest(getCategoriesObservable(), getLibraryMangasObservable(), - { dbCategories, libraryManga -> - val categories = if (libraryManga.containsKey(0)) - arrayListOf(Category.createDefault()) + dbCategories - else - dbCategories + 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) - }) + this.categories = categories + Library(categories, libraryManga) + } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/ChangelogDialogController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/ChangelogDialogController.kt index 60627bee54..5e659c5b5e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/ChangelogDialogController.kt +++ b/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 } } -} \ No newline at end of file +} 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 397d2cb032..ad159b1eb9 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 @@ -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() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt index 271a58605e..f42c6c86a7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt +++ b/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) + } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DeletingChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DeletingChaptersDialog.kt index 8fa6df5862..07a3f318f8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DeletingChaptersDialog.kt +++ b/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) } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index 7e60dc30da..c3aae59212 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -195,11 +195,7 @@ class MangaInfoController : NucleusController(), } // 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()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt index ad2774c62b..8b2f929fcd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt @@ -32,7 +32,7 @@ class SetTrackStatusDialog : 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 : 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 : DialogController const val KEY_ITEM_TRACK = "SetTrackStatusDialog.item.track" } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt index 4a62c430b9..c8c9da6887 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt +++ b/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 "-" 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 215ef00b94..f93293812d 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 @@ -50,7 +50,7 @@ class TrackSearchDialog : DialogController { service = Injekt.get().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 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationPresenter.kt index 35b6bc06bd..e1a350c1ac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationPresenter.kt +++ b/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) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt index 275d3a911a..f6f82dad3f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt +++ b/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( } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index d72b993a3a..581593ca96 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -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() { */ 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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt index cffba4f8bc..a69c91e181 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt +++ b/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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterView.kt index 01d91a3b4a..4c833bbd08 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterView.kt +++ b/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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 243e5bb6e7..3211790a0d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/SaveImageNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/SaveImageNotifier.kt index d69ced1e2b..29cfe31a9f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/SaveImageNotifier.kt +++ b/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. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/model/ChapterTransition.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/model/ChapterTransition.kt index 892eceab04..d963371f21 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/model/ChapterTransition.kt +++ b/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})" } 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 d941d3bc42..a96392b52f 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 @@ -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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressBar.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressBar.kt index a251b0c8ab..16c0ae6343 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressBar.kt +++ b/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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt index b6597cba36..b5e55052fb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt +++ b/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 { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/DeletingChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/DeletingChaptersDialog.kt index 8bb9d57b99..4d310c7e30 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/DeletingChaptersDialog.kt +++ b/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) } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt index bcf418761d..b4e99693c3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt +++ b/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) + } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/AnilistLoginActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/AnilistLoginActivity.kt index 31c081a2b3..1cb43bed98 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/AnilistLoginActivity.kt +++ b/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 { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt index c551fd97cd..af694bd1f0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt @@ -61,14 +61,16 @@ inline fun

PreferenceGroup.initThenAdd(p: P, block: P.() -> Uni return p.apply { block() this.isIconSpaceReserved = false - addPreference(this) } + addPreference(this) + } } inline fun

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) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index 005ec1aaf1..536721c8cb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -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() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt index cd2b41a49f..42c19f7baa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt +++ b/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() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index f50b97d2fe..8698202381 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt index 60aff194a3..0b9bbd97fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt @@ -92,7 +92,7 @@ fun syncChaptersWithSource(db: DatabaseHelper, db.inTransaction { val deletedChapterNumbers = TreeSet() val deletedReadChapterNumbers = TreeSet() - 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 -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ImageUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ImageUtil.kt index fa879d4b4f..3e9344063a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ImageUtil.kt +++ b/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()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt index 14e6726e3a..94a8e3a6ef 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt +++ b/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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/SharedData.kt b/app/src/main/java/eu/kanade/tachiyomi/util/SharedData.kt index 98d10b2d47..5ac2f45ebb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/SharedData.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/SharedData.kt @@ -22,7 +22,7 @@ object SharedData { * @param data the object to put. */ fun put(data: T) { - map.put(data.javaClass, data) + map[data.javaClass] = data } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/StringExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/StringExtensions.kt index 862514e96d..1fb44d5aae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/StringExtensions.kt +++ b/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) }" -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt index e13f11e6c4..a0aebc4e32 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt +++ b/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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt index dbc694f520..b2d18e8237 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt +++ b/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 } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/CustomLayoutPicker.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/CustomLayoutPicker.kt index 53725afecb..bef33dc26e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/CustomLayoutPicker.kt +++ b/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) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt index de0e057904..d825b0d178 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt +++ b/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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationBase.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationBase.kt index 42babe98e5..b8586f0444 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationBase.kt +++ b/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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/NegativeSeekBar.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/NegativeSeekBar.kt index 807435b4e5..30e0eac7c5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/NegativeSeekBar.kt +++ b/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) } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/PTSansTextView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/PTSansTextView.kt index 4152f17670..8bbf4ad243 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/PTSansTextView.kt +++ b/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") }) }) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleNavigationView.kt index 4c6055cdf5..9035296ea6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleNavigationView.kt +++ b/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 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt index b27c77c62b..25e99ef286 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt +++ b/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)