From 415df2357c85d3f742547f99869ff8e84536678c Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Sat, 18 Apr 2020 14:47:22 -0400 Subject: [PATCH] JDK8, lint fixing (#2888) * Use Kotlin JDK8 * Satisfy a ton of lints * Run res/layout files (and manifest) through reformatter --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 35 +++++++++++-------- .../tachiyomi/data/backup/BackupManager.kt | 6 ++-- .../data/backup/BackupRestoreService.kt | 4 +-- .../tachiyomi/data/cache/ChapterCache.kt | 12 +++---- .../resolvers/HistoryLastReadPutResolver.kt | 10 +++--- .../tachiyomi/data/download/DownloadCache.kt | 2 +- .../data/download/DownloadService.kt | 2 +- .../tachiyomi/data/download/Downloader.kt | 2 +- .../tachiyomi/data/glide/FileFetcher.kt | 3 +- .../data/library/LibraryUpdateService.kt | 2 +- .../tachiyomi/data/track/anilist/Anilist.kt | 12 +++---- .../tachiyomi/data/track/kitsu/KitsuApi.kt | 8 ++--- .../tachiyomi/data/track/kitsu/KitsuModels.kt | 6 ++-- .../util/ExtensionInstallReceiver.kt | 6 ++-- .../extension/util/ExtensionLoader.kt | 6 ++-- .../eu/kanade/tachiyomi/source/LocalSource.kt | 26 +++++++------- .../tachiyomi/source/online/HttpSource.kt | 12 +++---- .../tachiyomi/ui/base/holder/SlicedHolder.kt | 8 ++--- .../ui/extension/ExtensionAdapter.kt | 2 +- .../ui/library/LibraryCategoryView.kt | 6 ++-- .../tachiyomi/ui/library/LibraryPresenter.kt | 2 +- .../ui/manga/chapter/ChaptersController.kt | 6 ++-- .../ui/manga/chapter/ChaptersPresenter.kt | 4 +-- .../ui/manga/info/MangaInfoController.kt | 15 ++++---- .../ui/manga/track/SetTrackStatusDialog.kt | 2 +- .../ui/manga/track/TrackController.kt | 2 +- .../ui/manga/track/TrackSearchAdapter.kt | 8 ++--- .../tachiyomi/ui/migration/MangaHolder.kt | 4 +-- .../tachiyomi/ui/migration/SelectionHeader.kt | 2 +- .../tachiyomi/ui/more/AboutController.kt | 6 ++-- .../ui/reader/PageIndicatorTextView.kt | 3 +- .../tachiyomi/ui/reader/ReaderPresenter.kt | 4 +-- .../ui/reader/loader/ChapterLoader.kt | 4 +-- .../ui/reader/viewer/ReaderProgressBar.kt | 6 ++-- .../ui/reader/viewer/pager/PagerPageHolder.kt | 12 +++---- .../viewer/pager/PagerTransitionHolder.kt | 2 +- .../ui/reader/viewer/pager/PagerViewer.kt | 2 +- .../reader/viewer/pager/PagerViewerAdapter.kt | 6 ++-- .../reader/viewer/webtoon/WebtoonAdapter.kt | 3 +- .../ui/reader/viewer/webtoon/WebtoonViewer.kt | 2 +- .../ui/recent/history/HistoryPresenter.kt | 8 ++--- .../ui/recent/updates/UpdatesController.kt | 6 ++-- .../ui/recent/updates/UpdatesPresenter.kt | 14 ++++---- .../ui/setting/SettingsDownloadController.kt | 4 +-- .../ui/setting/SettingsLibraryController.kt | 4 +-- .../tachiyomi/ui/source/SourcePresenter.kt | 2 +- .../ui/source/browse/BrowseSourcePresenter.kt | 28 +++++++-------- .../ui/source/browse/ProgressItem.kt | 4 +++ .../global_search/GlobalSearchPresenter.kt | 10 +++--- .../util/chapter/ChapterRecognition.kt | 6 ++-- .../kanade/tachiyomi/util/storage/DiskUtil.kt | 2 +- .../eu/kanade/tachiyomi/widget/EmptyView.kt | 3 +- .../widget/ExtendedNavigationView.kt | 3 +- .../tachiyomi/widget/SimpleNavigationView.kt | 8 ++--- app/src/main/res/layout/categories_item.xml | 4 +-- .../main/res/layout/chapters_controller.xml | 13 ++++--- app/src/main/res/layout/chapters_item.xml | 6 ++-- .../main/res/layout/common_action_toolbar.xml | 6 ++-- .../main/res/layout/common_listitem_dir.xml | 3 +- app/src/main/res/layout/download_item.xml | 4 +-- .../main/res/layout/extension_controller.xml | 4 +-- .../main/res/layout/manga_info_controller.xml | 2 +- .../res/layout/navigation_view_spinner.xml | 2 +- .../main/res/layout/navigation_view_text.xml | 1 + .../main/res/layout/pref_library_columns.xml | 1 + app/src/main/res/layout/reader_page_sheet.xml | 12 +++---- .../main/res/layout/reader_settings_sheet.xml | 6 ++-- .../main/res/layout/source_filter_sheet.xml | 4 +-- app/src/main/res/layout/source_grid_item.xml | 2 +- .../res/layout/source_main_controller.xml | 4 +-- .../main/res/layout/updates_controller.xml | 2 +- app/src/main/res/layout/updates_item.xml | 4 +-- .../tachiyomi/data/backup/BackupTest.kt | 2 +- .../tachiyomi/data/database/CategoryTest.kt | 2 +- 75 files changed, 224 insertions(+), 229 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1b19165ab1..8af52a047e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -254,7 +254,7 @@ dependencies { testImplementation "org.robolectric:shadows-multidex:$robolectric_version" testImplementation "org.robolectric:shadows-play-services:$robolectric_version" - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" final coroutines_version = '1.3.4' implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 463a8453f5..9acde10ed2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,15 +18,15 @@ android:name=".App" android:allowBackup="true" android:fullBackupContent="@xml/backup_rules" - android:hasFragileUserData="true" android:hardwareAccelerated="true" - android:usesCleartextTraffic="true" + android:hasFragileUserData="true" android:icon="@mipmap/ic_launcher" - android:requestLegacyExternalStorage="true" - android:roundIcon="@mipmap/ic_launcher_round" android:label="@string/app_name" android:largeHeap="true" - android:theme="@style/Theme.Tachiyomi.Light"> + android:requestLegacyExternalStorage="true" + android:roundIcon="@mipmap/ic_launcher_round" + android:theme="@style/Theme.Tachiyomi.Light" + android:usesCleartextTraffic="true"> - + - - + + + - + - + + - + @@ -110,7 +115,7 @@ + android:theme="@android:style/Theme.Translucent.NoTitleBar" /> + android:exported="false" /> + android:exported="false" /> 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 809a1344e1..82238578e7 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 @@ -128,7 +128,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) { val categoryEntries = JsonArray() // Add value's to root - root[Backup.VERSION] = Backup.CURRENT_VERSION + root[Backup.VERSION] = CURRENT_VERSION root[Backup.MANGAS] = mangaEntries root[CATEGORIES] = categoryEntries @@ -303,8 +303,8 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) { fun restoreChapterFetchObservable(source: Source, manga: Manga, chapters: List): Observable, List>> { return source.fetchChapterList(manga) .map { syncChaptersWithSource(databaseHelper, it, manga, source) } - .doOnNext { - if (it.first.isNotEmpty()) { + .doOnNext { pair -> + if (pair.first.isNotEmpty()) { chapters.forEach { it.manga_id = manga.id } insertChapters(chapters) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt index 0cd976ede5..a373adf79f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt @@ -164,7 +164,7 @@ class BackupRestoreService : Service() { * @return the start value of the command. */ override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { - if (intent == null) return Service.START_NOT_STICKY + if (intent == null) return START_NOT_STICKY val uri = intent.getParcelableExtra(BackupConst.EXTRA_URI) @@ -179,7 +179,7 @@ class BackupRestoreService : Service() { .subscribeOn(Schedulers.from(executor)) .subscribe() - return Service.START_NOT_STICKY + return START_NOT_STICKY } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt index b5a6841187..52b246f331 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt @@ -80,13 +80,13 @@ class ChapterCache(private val context: Context) { if (file == "journal" || file.startsWith("journal.")) return false - try { + return try { // Remove the extension from the file to get the key of the cache val key = file.substringBeforeLast(".") // Remove file from cache. - return diskCache.remove(key) + diskCache.remove(key) } catch (e: Exception) { - return false + false } } @@ -149,10 +149,10 @@ class ChapterCache(private val context: Context) { * @return true if in cache otherwise false. */ fun isImageInCache(imageUrl: String): Boolean { - try { - return diskCache.get(DiskUtil.hashKeyForDisk(imageUrl)) != null + return try { + diskCache.get(DiskUtil.hashKeyForDisk(imageUrl)) != null } catch (e: IOException) { - return false + false } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/HistoryLastReadPutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/HistoryLastReadPutResolver.kt index 98ec17cb4f..3834b710b8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/HistoryLastReadPutResolver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/HistoryLastReadPutResolver.kt @@ -27,17 +27,15 @@ class HistoryLastReadPutResolver : HistoryPutResolver() { val putResult: PutResult - try { - if (cursor.count == 0) { + putResult = cursor.use { putCursor -> + if (putCursor.count == 0) { val insertQuery = mapToInsertQuery(history) val insertedId = db.lowLevel().insert(insertQuery, mapToContentValues(history)) - putResult = PutResult.newInsertResult(insertedId, insertQuery.table()) + PutResult.newInsertResult(insertedId, insertQuery.table()) } else { val numberOfRowsUpdated = db.lowLevel().update(updateQuery, mapToUpdateContentValues(history)) - putResult = PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) + PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) } - } finally { - cursor.close() } putResult 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 f257bbc16b..aaa2d7c2b9 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 @@ -259,7 +259,7 @@ class DownloadCache( */ private inline fun Map.mapNotNullKeys(transform: (Map.Entry) -> R?): Map { val destination = LinkedHashMap() - forEach { element -> transform(element)?.let { destination.put(it, element.value) } } + forEach { element -> transform(element)?.let { destination[it] = element.value } } return destination } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt index ba37783f19..58b1acb394 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt @@ -106,7 +106,7 @@ class DownloadService : Service() { * Not used. */ override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { - return Service.START_NOT_STICKY + return START_NOT_STICKY } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt index d144073600..a8ed2cb82a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt @@ -283,7 +283,7 @@ class Downloader( // Do when page is downloaded. .doOnNext { notifier.onProgressChange(download) } .toList() - .map { _ -> download } + .map { download } // Do after download completes .doOnNext { ensureSuccessfulDownload(download, mangaDir, tmpDir, chapterDirname) } // If the page list threw, it will resume here diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/glide/FileFetcher.kt b/app/src/main/java/eu/kanade/tachiyomi/data/glide/FileFetcher.kt index 6f88ec722d..5397036426 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/glide/FileFetcher.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/glide/FileFetcher.kt @@ -5,6 +5,7 @@ import android.util.Log import com.bumptech.glide.Priority import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.data.DataFetcher +import timber.log.Timber import java.io.File import java.io.FileInputStream import java.io.FileNotFoundException @@ -24,7 +25,7 @@ open class FileFetcher(private val file: File) : DataFetcher { data = FileInputStream(file) } catch (e: FileNotFoundException) { if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, "Failed to open file", e) + Timber.d(e, "Failed to open file") } callback.onLoadFailed(e) return diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 8fb260d994..f7e4d32974 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -246,7 +246,7 @@ class LibraryUpdateService( stopSelf(startId) }) - return Service.START_REDELIVER_INTENT + return START_REDELIVER_INTENT } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt index 224547c4af..2cc10f8f62 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt @@ -97,13 +97,13 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { // 100 point POINT_100 -> index.toFloat() // 5 stars - POINT_5 -> when { - index == 0 -> 0f + POINT_5 -> when (index) { + 0 -> 0f else -> index * 20f - 10f } // Smiley - POINT_3 -> when { - index == 0 -> 0f + POINT_3 -> when (index) { + 0 -> 0f else -> index * 25f + 10f } // 10 point decimal @@ -116,8 +116,8 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { val score = track.score return when (scorePreference.getOrDefault()) { - POINT_5 -> when { - score == 0f -> "0 ★" + POINT_5 -> when (score) { + 0f -> "0 ★" else -> "${((score + 10) / 20).toInt()} ★" } POINT_3 -> when { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt index dcb759bccb..20ca7136c6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt @@ -38,7 +38,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) .addConverterFactory(GsonConverterFactory.create(GsonBuilder().serializeNulls().create())) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build() - .create(KitsuApi.Rest::class.java) + .create(Rest::class.java) private val searchRest = Retrofit.Builder() .baseUrl(algoliaKeyUrl) @@ -46,7 +46,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build() - .create(KitsuApi.SearchKeyRest::class.java) + .create(SearchKeyRest::class.java) private val algoliaRest = Retrofit.Builder() .baseUrl(algoliaUrl) @@ -54,7 +54,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build() - .create(KitsuApi.AgoliaSearchRest::class.java) + .create(AgoliaSearchRest::class.java) fun addLibManga(track: Track, userId: String): Observable { return Observable.defer { @@ -162,7 +162,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build() - .create(KitsuApi.LoginRest::class.java) + .create(LoginRest::class.java) .requestAccessToken(username, password) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt index 9664d87924..48e5d38714 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt @@ -36,10 +36,10 @@ class KitsuSearchManga(obj: JsonObject) { cover_url = original ?: "" summary = synopsis tracking_url = KitsuApi.mangaUrl(media_id) - if (endDate == null) { - publishing_status = "Publishing" + publishing_status = if (endDate == null) { + "Publishing" } else { - publishing_status = "Finished" + "Finished" } publishing_type = subType ?: "" start_date = startDate ?: "" 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 7cff793145..0cffad2d4f 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 @@ -49,8 +49,7 @@ internal class ExtensionInstallReceiver(private val listener: Listener) : when (intent.action) { Intent.ACTION_PACKAGE_ADDED -> { if (!isReplacing(intent)) launchNow { - val result = getExtensionFromIntent(context, intent) - when (result) { + when (val result = getExtensionFromIntent(context, intent)) { is LoadResult.Success -> listener.onExtensionInstalled(result.extension) is LoadResult.Untrusted -> listener.onExtensionUntrusted(result.extension) } @@ -58,8 +57,7 @@ internal class ExtensionInstallReceiver(private val listener: Listener) : } Intent.ACTION_PACKAGE_REPLACED -> { launchNow { - val result = getExtensionFromIntent(context, intent) - when (result) { + when (val result = getExtensionFromIntent(context, intent)) { is LoadResult.Success -> listener.onExtensionUpdated(result.extension) // Not needed as a package can't be upgraded if the signature is different is LoadResult.Untrusted -> { 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 1b22e3292c..2a7d53006c 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 @@ -94,8 +94,7 @@ internal object ExtensionLoader { return LoadResult.Error(error) } - val extName = pkgManager.getApplicationLabel(appInfo).toString() - .orEmpty().substringAfter("Tachiyomi: ") + val extName = pkgManager.getApplicationLabel(appInfo).toString().substringAfter("Tachiyomi: ") val versionName = pkgInfo.versionName val versionCode = pkgInfo.versionCode @@ -137,8 +136,7 @@ internal object ExtensionLoader { } .flatMap { try { - val obj = Class.forName(it, false, classLoader).newInstance() - when (obj) { + when (val obj = Class.forName(it, false, classLoader).newInstance()) { is Source -> listOf(obj) is SourceFactory -> obj.createSources() else -> throw Exception("Unknown source class type! ${obj.javaClass}") diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index 37bb0d8472..32a1e68763 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -81,16 +81,16 @@ class LocalSource(private val context: Context) : CatalogueSource { val state = ((if (filters.isEmpty()) POPULAR_FILTERS else filters)[0] as OrderBy).state when (state?.index) { 0 -> { - if (state.ascending) - mangaDirs = mangaDirs.sortedBy { it.name.toLowerCase(Locale.ENGLISH) } + mangaDirs = if (state.ascending) + mangaDirs.sortedBy { it.name.toLowerCase(Locale.ENGLISH) } else - mangaDirs = mangaDirs.sortedByDescending { it.name.toLowerCase(Locale.ENGLISH) } + mangaDirs.sortedByDescending { it.name.toLowerCase(Locale.ENGLISH) } } 1 -> { - if (state.ascending) - mangaDirs = mangaDirs.sortedBy(File::lastModified) + mangaDirs = if (state.ascending) + mangaDirs.sortedBy(File::lastModified) else - mangaDirs = mangaDirs.sortedByDescending(File::lastModified) + mangaDirs.sortedByDescending(File::lastModified) } } @@ -131,17 +131,14 @@ class LocalSource(private val context: Context) : CatalogueSource { getBaseDirectories(context) .mapNotNull { File(it, manga.url).listFiles()?.toList() } .flatten() - .filter { it.extension.equals("json") } - .firstOrNull() + .firstOrNull { it.extension == "json" } ?.apply { val json = Gson().fromJson(Scanner(this).useDelimiter("\\Z").next(), JsonObject::class.java) manga.title = json["title"]?.asString ?: manga.title manga.author = json["author"]?.asString ?: manga.author manga.artist = json["artist"]?.asString ?: manga.artist manga.description = json["description"]?.asString ?: manga.description - manga.genre = json["genre"]?.asJsonArray - ?.map { it.asString } - ?.joinToString(", ") + manga.genre = json["genre"]?.asJsonArray?.joinToString(", ") { it.asString } ?: manga.genre manga.status = json["status"]?.asInt ?: manga.status } @@ -150,6 +147,7 @@ class LocalSource(private val context: Context) : CatalogueSource { override fun fetchChapterList(manga: SManga): Observable> { val chapters = getBaseDirectories(context) + .asSequence() .mapNotNull { File(it, manga.url).listFiles()?.toList() } .flatten() .filter { it.isDirectory || isSupportedFile(it.extension) } @@ -171,6 +169,7 @@ class LocalSource(private val context: Context) : CatalogueSource { val c = c2.chapter_number.compareTo(c1.chapter_number) if (c == 0) c2.name.compareToCaseInsensitiveNaturalOrder(c1.name) else c }) + .toList() return Observable.just(chapters) } @@ -211,8 +210,7 @@ class LocalSource(private val context: Context) : CatalogueSource { } private fun updateCover(chapter: SChapter, manga: SManga): File? { - val format = getFormat(chapter) - return when (format) { + return when (val format = getFormat(chapter)) { is Format.Directory -> { val entry = format.file.listFiles() .sortedWith(Comparator { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) }) @@ -250,7 +248,7 @@ class LocalSource(private val context: Context) : CatalogueSource { } } - private class OrderBy : Filter.Sort("Order by", arrayOf("Title", "Date"), Filter.Sort.Selection(0, true)) + private class OrderBy : Filter.Sort("Order by", arrayOf("Title", "Date"), Selection(0, true)) override fun getFilterList() = FilterList(OrderBy()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt index 9b3ba6f20b..9e5e752ee1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt @@ -207,14 +207,14 @@ abstract class HttpSource : CatalogueSource { * @param manga the manga to look for chapters. */ override fun fetchChapterList(manga: SManga): Observable> { - if (manga.status != SManga.LICENSED) { - return client.newCall(chapterListRequest(manga)) + return if (manga.status != SManga.LICENSED) { + client.newCall(chapterListRequest(manga)) .asObservableSuccess() .map { response -> chapterListParse(response) } } else { - return Observable.error(Exception("Licensed - No chapters to show")) + Observable.error(Exception("Licensed - No chapters to show")) } } @@ -340,16 +340,16 @@ abstract class HttpSource : CatalogueSource { * @param orig the full url. */ private fun getUrlWithoutDomain(orig: String): String { - try { + return try { val uri = URI(orig) var out = uri.path if (uri.query != null) out += "?" + uri.query if (uri.fragment != null) out += "#" + uri.fragment - return out + out } catch (e: URISyntaxException) { - return orig + orig } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/SlicedHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/SlicedHolder.kt index d31e6062d1..3acb98558c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/SlicedHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/SlicedHolder.kt @@ -31,13 +31,13 @@ interface SlicedHolder { when { // Only one item in the card - count == 1 -> applySlice(2f, false, false, true, true) + count == 1 -> applySlice(2f, topRect = false, bottomRect = false, topShadow = true, bottomShadow = true) // First item of the card - position == 0 -> applySlice(2f, false, true, true, false) + position == 0 -> applySlice(2f, topRect = false, bottomRect = true, topShadow = true, bottomShadow = false) // Last item of the card - position == count - 1 -> applySlice(2f, true, false, false, true) + position == count - 1 -> applySlice(2f, topRect = true, bottomRect = false, topShadow = false, bottomShadow = true) // Middle item - else -> applySlice(0f, false, false, false, false) + else -> applySlice(0f, topRect = false, bottomRect = false, topShadow = false, bottomShadow = false) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionAdapter.kt index 7c071dbd74..09a439ff56 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionAdapter.kt @@ -22,7 +22,7 @@ class ExtensionAdapter(val controller: ExtensionController) : /** * Listener for browse item clicks. */ - val buttonClickListener: ExtensionAdapter.OnButtonClickListener = controller + val buttonClickListener: OnButtonClickListener = controller interface OnButtonClickListener { fun onButtonClick(position: Int) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index f73f14b155..657186bfed 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -229,13 +229,13 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att override fun onItemClick(view: View?, position: Int): Boolean { // If the action mode is created and the position is valid, toggle the selection. val item = adapter.getItem(position) ?: return false - if (adapter.mode == SelectableAdapter.Mode.MULTI) { + return if (adapter.mode == SelectableAdapter.Mode.MULTI) { lastClickPosition = position toggleSelection(position) - return true + true } else { openManga(item.manga) - return false + false } } 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 9d37972037..e4934d14ed 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 @@ -303,7 +303,7 @@ class LibraryPresenter( if (mangas.isEmpty()) return emptyList() return mangas.toSet() .map { db.getCategoriesForManga(it).executeAsBlocking() } - .reduce { set1: Iterable, set2 -> set1.intersect(set2) } + .reduce { set1: Iterable, set2 -> set1.intersect(set2).toMutableList() } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index cc36a7e4a5..575e3170fb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -306,13 +306,13 @@ class ChaptersController : NucleusController Timber.e(error) }) + .subscribeLatestCache(ChaptersController::onNextChapters) + { _, error -> Timber.e(error) } // Add the subscription that retrieves the chapters from the database, keeps subscribed to // changes, and sends the list of chapters to the relay. 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 22ee17cc19..f592619a4d 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 @@ -262,13 +262,11 @@ class MangaInfoController(private val fromSource: Boolean = false) : .centerCrop() .into(binding.mangaCover) - if (binding.backdrop != null) { - GlideApp.with(view.context) - .load(manga) - .diskCacheStrategy(DiskCacheStrategy.RESOURCE) - .centerCrop() - .into(binding.backdrop!!) - } + GlideApp.with(view.context) + .load(manga) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .centerCrop() + .into(binding.backdrop) } // Manga info section @@ -618,8 +616,7 @@ class MangaInfoController(private val fromSource: Boolean = false) : return } - val previousController = router.backstack[router.backstackSize - 2].controller() - when (previousController) { + when (val previousController = router.backstack[router.backstackSize - 2].controller()) { is LibraryController -> { router.handleBack() previousController.search(query) 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 b6e1aaf976..0a6892b2c8 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 @@ -33,7 +33,7 @@ class SetTrackStatusDialog : DialogController override fun onCreateDialog(savedViewState: Bundle?): Dialog { val item = item val statusList = item.service.getStatusList() - val statusString = statusList.mapNotNull { item.service.getStatus(it) } + val statusString = statusList.map { item.service.getStatus(it) } val selectedIndex = statusList.indexOf(item.track?.status) return MaterialDialog.Builder(activity!!) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackController.kt index a1524e9615..94d8f7a16d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackController.kt @@ -90,7 +90,7 @@ class TrackController : NucleusController + view: View, + adapter: FlexibleAdapter<*> ) : BaseFlexibleViewHolder(view, adapter) { fun bind(item: MangaItem) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SelectionHeader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SelectionHeader.kt index 3506aa7607..196cfb1ca2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SelectionHeader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SelectionHeader.kt @@ -25,7 +25,7 @@ class SelectionHeader : AbstractHeaderItem() { * Creates a new view holder for this item. */ override fun createViewHolder(view: View, adapter: FlexibleAdapter>): Holder { - return SelectionHeader.Holder(view, adapter) + return Holder(view, adapter) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt index 2efb8264b6..94782b5493 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt @@ -171,7 +171,7 @@ class AboutController : SettingsController() { } private fun getFormattedBuildTime(): String { - try { + return try { val inputDf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'", Locale.US) inputDf.timeZone = TimeZone.getTimeZone("UTC") val buildTime = inputDf.parse(BuildConfig.BUILD_TIME) @@ -180,9 +180,9 @@ class AboutController : SettingsController() { DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault()) outputDf.timeZone = TimeZone.getDefault() - return buildTime.toDateTimestampString(dateFormat) + buildTime.toDateTimestampString(dateFormat) } catch (e: ParseException) { - return BuildConfig.BUILD_TIME + BuildConfig.BUILD_TIME } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt index 6d85149411..06c4b76111 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt @@ -7,7 +7,6 @@ import android.text.Spannable import android.text.SpannableString import android.text.style.ScaleXSpan import android.util.AttributeSet -import android.widget.TextView import androidx.appcompat.widget.AppCompatTextView import eu.kanade.tachiyomi.widget.OutlineSpan @@ -39,7 +38,7 @@ class PageIndicatorTextView( } } - super.setText(finalText, TextView.BufferType.SPANNABLE) + super.setText(finalText, BufferType.SPANNABLE) } private companion object { 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 28420cf707..983fb7333e 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 @@ -361,7 +361,7 @@ class ReaderPresenter( if (selectedChapter != currentChapters.currChapter) { Timber.d("Setting ${selectedChapter.chapter.url} as active") - onChapterChanged(currentChapters.currChapter, selectedChapter) + onChapterChanged(currentChapters.currChapter) loadNewChapter(selectedChapter) } } @@ -370,7 +370,7 @@ class ReaderPresenter( * Called when a chapter changed from [fromChapter] to [toChapter]. It updates [fromChapter] * on the database. */ - private fun onChapterChanged(fromChapter: ReaderChapter, toChapter: ReaderChapter) { + private fun onChapterChanged(fromChapter: ReaderChapter) { saveChapterProgress(fromChapter) saveChapterHistory(fromChapter) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ChapterLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ChapterLoader.kt index be03beb16a..fc83952bfb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ChapterLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ChapterLoader.kt @@ -33,10 +33,10 @@ class ChapterLoader( return Observable.just(chapter) .doOnNext { chapter.state = ReaderChapter.State.Loading } .observeOn(Schedulers.io()) - .flatMap { + .flatMap { readerChapter -> Timber.d("Loading pages for ${chapter.chapter.name}") - val loader = getPageLoader(it) + val loader = getPageLoader(readerChapter) chapter.pageLoader = loader loader.getPages().take(1).doOnNext { pages -> 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 30c1aced66..1f58c25a1b 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 @@ -122,7 +122,7 @@ class ReaderProgressBar @JvmOverloads constructor( */ override fun setVisibility(visibility: Int) { super.setVisibility(visibility) - val isVisible = visibility == View.VISIBLE + val isVisible = visibility == VISIBLE if (isVisible) { startAnimation() } else { @@ -134,7 +134,7 @@ class ReaderProgressBar @JvmOverloads constructor( * Starts the rotation animation if needed. */ private fun startAnimation() { - if (visibility != View.VISIBLE || windowVisibility != View.VISIBLE || animation != null) { + if (visibility != VISIBLE || windowVisibility != VISIBLE || animation != null) { return } @@ -153,7 +153,7 @@ class ReaderProgressBar @JvmOverloads constructor( * Hides this progress bar with an optional fade out if [animate] is true. */ fun hide(animate: Boolean = false) { - if (visibility == View.GONE) return + if (visibility == GONE) return if (!animate) { gone() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt index 88304ffc74..3c68472086 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt @@ -285,7 +285,7 @@ class PagerPageHolder( return ReaderProgressBar(context, null).apply { val size = 48.dpToPx - layoutParams = FrameLayout.LayoutParams(size, size).apply { + layoutParams = LayoutParams(size, size).apply { gravity = Gravity.CENTER } } @@ -300,7 +300,7 @@ class PagerPageHolder( val config = viewer.config subsamplingImageView = SubsamplingScaleImageView(context).apply { - layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT) + layoutParams = LayoutParams(MATCH_PARENT, MATCH_PARENT) setMaxTileSize(viewer.activity.maxBitmapSize) setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER) setDoubleTapZoomDuration(config.doubleTapAnimDuration) @@ -335,7 +335,7 @@ class PagerPageHolder( if (imageView != null) return imageView!! imageView = PhotoView(context, null).apply { - layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT) + layoutParams = LayoutParams(MATCH_PARENT, MATCH_PARENT) adjustViewBounds = true setZoomTransitionDuration(viewer.config.doubleTapAnimDuration) setScaleLevels(1f, 2f, 3f) @@ -362,7 +362,7 @@ class PagerPageHolder( if (retryButton != null) return retryButton!! retryButton = PagerButton(context, viewer).apply { - layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { + layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { gravity = Gravity.CENTER } setText(R.string.action_retry) @@ -399,7 +399,7 @@ class PagerPageHolder( } PagerButton(context, viewer).apply { - layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { + layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { setMargins(margins, margins, margins, margins) } setText(R.string.action_retry) @@ -413,7 +413,7 @@ class PagerPageHolder( val imageUrl = page.imageUrl if (imageUrl.orEmpty().startsWith("http")) { PagerButton(context, viewer).apply { - layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { + layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { setMargins(margins, margins, margins, margins) } setText(R.string.action_open_in_web_view) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerTransitionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerTransitionHolder.kt index fb480f8a1c..8f63dc1aac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerTransitionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerTransitionHolder.kt @@ -55,7 +55,7 @@ class PagerTransitionHolder( * dynamically. */ private var pagesContainer = LinearLayout(context).apply { - layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT) + layoutParams = LayoutParams(MATCH_PARENT, WRAP_CONTENT) orientation = VERTICAL gravity = Gravity.CENTER } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt index 3028537673..8e968bcacd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt @@ -209,7 +209,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { */ private fun setChaptersInternal(chapters: ViewerChapters) { Timber.d("setChaptersInternal") - var forceTransition = config.alwaysShowChapterTransition || adapter.items.getOrNull(pager.currentItem) is ChapterTransition + val forceTransition = config.alwaysShowChapterTransition || adapter.items.getOrNull(pager.currentItem) is ChapterTransition adapter.setChapters(chapters, forceTransition) // Layout the pager once a chapter is being set diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt index ac8752628c..e32471e14f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager import android.view.View import android.view.ViewGroup -import androidx.viewpager.widget.PagerAdapter import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderPage @@ -93,8 +92,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { * Creates a new view for the item at the given [position]. */ override fun createView(container: ViewGroup, position: Int): View { - val item = items[position] - return when (item) { + return when (val item = items[position]) { is ReaderPage -> PagerPageHolder(viewer, item) is ChapterTransition -> PagerTransitionHolder(viewer, item) else -> throw NotImplementedError("Holder for ${item.javaClass} not implemented") @@ -113,6 +111,6 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { Timber.d("Position for ${view.item} not found") } } - return PagerAdapter.POSITION_NONE + return POSITION_NONE } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt index 409d9c71f1..92cb5192c7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt @@ -82,8 +82,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter PAGE_VIEW is ChapterTransition -> TRANSITION_VIEW else -> error("Unknown view type for ${item.javaClass}") diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt index 12052a91d3..b69be2d140 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt @@ -202,7 +202,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr */ override fun setChapters(chapters: ViewerChapters) { Timber.d("setChapters") - var forceTransition = config.alwaysShowChapterTransition || currentPage is ChapterTransition + val forceTransition = config.alwaysShowChapterTransition || currentPage is ChapterTransition adapter.setChapters(chapters, forceTransition) if (recycler.visibility == View.GONE) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt index a7867c89e5..3cd7ab593e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt @@ -53,9 +53,9 @@ class HistoryPresenter : BasePresenter() { val map = TreeMap> { d1, d2 -> d2.compareTo(d1) } val byDay = recents .groupByTo(map, { it.history.last_read.toDateKey() }) - byDay.flatMap { - val dateItem = DateSectionItem(it.key) - it.value.map { HistoryItem(it, dateItem) } + byDay.flatMap { entry -> + val dateItem = DateSectionItem(entry.key) + entry.value.map { HistoryItem(it, dateItem) } } } .observeOn(AndroidSchedulers.mainThread()) @@ -102,7 +102,7 @@ class HistoryPresenter : BasePresenter() { } val chapters = db.getChapters(manga).executeAsBlocking() - .sortedWith(Comparator { c1, c2 -> sortFunction(c1, c2) }) + .sortedWith(Comparator { c1, c2 -> sortFunction(c1, c2) }) val currChapterIndex = chapters.indexOfFirst { chapter.id == it.id } return when (manga.sorting) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index 9aafa9e08b..03e01cdd39 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -156,12 +156,12 @@ class UpdatesController : NucleusController> { d1, d2 -> d2.compareTo(d1) } val byDay = mangaChapters .groupByTo(map, { it.chapter.date_fetch.toDateKey() }) - byDay.flatMap { - val dateItem = DateSectionItem(it.key) - it.value + byDay.flatMap { entry -> + val dateItem = DateSectionItem(entry.key) + entry.value .sortedWith(compareBy({ it.chapter.date_fetch }, { it.chapter.chapter_number })).asReversed() .map { UpdatesItem(it.chapter, it.manga, dateItem) } } } - .doOnNext { - it.forEach { item -> + .doOnNext { list -> + list.forEach { item -> // Find an active download for this chapter. val download = downloadManager.queue.find { it.chapter.id == item.chapter.id } @@ -81,8 +81,8 @@ class UpdatesPresenter( item.download = download } } - setDownloadedChapters(it) - chapters = it + setDownloadedChapters(list) + chapters = list } } 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 dbcbc19665..4b6bea1464 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 @@ -101,8 +101,8 @@ class SettingsDownloadController : SettingsController() { .subscribeUntilDestroy { isVisible = it } preferences.downloadNewCategories().asObservable() - .subscribeUntilDestroy { - val selectedCategories = it + .subscribeUntilDestroy { mutableSet -> + val selectedCategories = mutableSet .mapNotNull { id -> categories.find { it.id == id.toInt() } } .sortedBy { it.order } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 1a8c23fa8e..8195e6b73c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -118,8 +118,8 @@ class SettingsLibraryController : SettingsController() { entries = categories.map { it.name }.toTypedArray() entryValues = categories.map { it.id.toString() }.toTypedArray() preferences.libraryUpdateCategories().asObservable() - .subscribeUntilDestroy { - val selectedCategories = it + .subscribeUntilDestroy { mutableSet -> + val selectedCategories = mutableSet .mapNotNull { id -> categories.find { it.id == id.toInt() } } .sortedBy { it.order } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourcePresenter.kt index 176493a291..44450fa4ed 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourcePresenter.kt @@ -87,7 +87,7 @@ class SourcePresenter( sharedObs.take(1), sharedObs.skip(1).delay(500, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())) .distinctUntilChanged() - .map { (sourceManager.get(it) as? CatalogueSource)?.let { SourceItem(it) } } + .map { item -> (sourceManager.get(item) as? CatalogueSource)?.let { SourceItem(it) } } .subscribeLatestCache(SourceController::setLastUsedSource) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourcePresenter.kt index ed2aac8e46..d382ed16c6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourcePresenter.kt @@ -149,9 +149,9 @@ open class BrowseSourcePresenter( pagerSubscription?.let { remove(it) } pagerSubscription = pager.results() .observeOn(Schedulers.io()) - .map { it.first to it.second.map { networkToLocalManga(it, sourceId) } } + .map { pair -> pair.first to pair.second.map { networkToLocalManga(it, sourceId) } } .doOnNext { initializeMangas(it.second) } - .map { it.first to it.second.map { SourceItem(it, catalogueAsList) } } + .map { pair -> pair.first to pair.second.map { SourceItem(it, catalogueAsList) } } .observeOn(AndroidSchedulers.mainThread()) .subscribeReplay({ view, (page, mangas) -> view.onAddPage(page, mangas) @@ -292,17 +292,17 @@ open class BrowseSourcePresenter( } private fun FilterList.toItems(): List> { - return mapNotNull { - when (it) { - is Filter.Header -> HeaderItem(it) - is Filter.Separator -> SeparatorItem(it) - is Filter.CheckBox -> CheckboxItem(it) - is Filter.TriState -> TriStateItem(it) - is Filter.Text -> TextItem(it) - is Filter.Select<*> -> SelectItem(it) + return mapNotNull { filter -> + when (filter) { + is Filter.Header -> HeaderItem(filter) + is Filter.Separator -> SeparatorItem(filter) + is Filter.CheckBox -> CheckboxItem(filter) + is Filter.TriState -> TriStateItem(filter) + is Filter.Text -> TextItem(filter) + is Filter.Select<*> -> SelectItem(filter) is Filter.Group<*> -> { - val group = GroupItem(it) - val subItems = it.state.mapNotNull { + val group = GroupItem(filter) + val subItems = filter.state.mapNotNull { when (it) { is Filter.CheckBox -> CheckboxSectionItem(it) is Filter.TriState -> TriStateSectionItem(it) @@ -316,8 +316,8 @@ open class BrowseSourcePresenter( group } is Filter.Sort -> { - val group = SortGroup(it) - val subItems = it.values.map { + val group = SortGroup(filter) + val subItems = filter.values.map { SortItem(it, group) } group.subItems = subItems diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/ProgressItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/ProgressItem.kt index 91f5d825ed..3d73b808a0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/ProgressItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/ProgressItem.kt @@ -43,6 +43,10 @@ class ProgressItem : AbstractFlexibleItem() { return this === other } + override fun hashCode(): Int { + return loadMore.hashCode() + } + class Holder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter) { val progressBar: ProgressBar = view.findViewById(R.id.progress_bar) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchPresenter.kt index 48de407256..17e30ad49b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchPresenter.kt @@ -163,9 +163,9 @@ open class GlobalSearchPresenter( .subscribeOn(Schedulers.io()) .onErrorReturn { MangasPage(emptyList(), false) } // Ignore timeouts or other exceptions .map { it.mangas.take(10) } // Get at most 10 manga from search result. - .map { it.map { networkToLocalManga(it, source.id) } } // Convert to local manga. + .map { list -> list.map { networkToLocalManga(it, source.id) } } // Convert to local manga. .doOnNext { fetchImage(it, source) } // Load manga covers. - .map { createCatalogueSearchItem(source, it.map { GlobalSearchCardItem(it) }) } + .map { list -> createCatalogueSearchItem(source, list.map { GlobalSearchCardItem(it) }) } }, 5) .observeOn(AndroidSchedulers.mainThread()) // Update matching source with the obtained results @@ -198,9 +198,9 @@ open class GlobalSearchPresenter( private fun initializeFetchImageSubscription() { fetchImageSubscription?.unsubscribe() fetchImageSubscription = fetchImageSubject.observeOn(Schedulers.io()) - .flatMap { - val source = it.second - Observable.from(it.first).filter { it.thumbnail_url == null && !it.initialized } + .flatMap { pair -> + val source = pair.second + Observable.from(pair.first).filter { it.thumbnail_url == null && !it.initialized } .map { Pair(it, source) } .concatMap { getMangaDetailsObservable(it.first, it.second) } .map { Pair(source as CatalogueSource, it) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterRecognition.kt b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterRecognition.kt index d0da5f6fb0..77254f6ce2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterRecognition.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterRecognition.kt @@ -123,11 +123,11 @@ object ChapterRecognition { if (alpha.contains("special")) return .97f - if (alpha[0] == '.') { + return if (alpha[0] == '.') { // Take value after (.) - return parseAlphaPostFix(alpha[1]) + parseAlphaPostFix(alpha[1]) } else { - return parseAlphaPostFix(alpha[0]) + parseAlphaPostFix(alpha[0]) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt index 4ad9f57b4c..d141421e07 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt @@ -85,7 +85,7 @@ object DiskUtil { */ fun buildValidFilename(origName: String): String { val name = origName.trim('.', ' ') - if (name.isNullOrEmpty()) { + if (name.isEmpty()) { return "(invalid)" } val sb = StringBuilder(name.length) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt index 4946f2e438..bc9e45b83d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.widget import android.content.Context import android.util.AttributeSet -import android.view.View import android.widget.LinearLayout import android.widget.RelativeLayout import androidx.annotation.StringRes @@ -77,6 +76,6 @@ class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? data class Action( @StringRes val resId: Int, - val listener: View.OnClickListener + val listener: OnClickListener ) } 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 286e14e6ef..3559ce1b86 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.widget import android.content.Context import android.graphics.drawable.Drawable import android.util.AttributeSet -import android.view.View import android.view.ViewGroup import androidx.annotation.CallSuper import androidx.core.content.ContextCompat @@ -160,7 +159,7 @@ open class ExtendedNavigationView @JvmOverloads constructor( */ abstract inner class Adapter(private val items: List) : RecyclerView.Adapter() { - private val onClick = View.OnClickListener { + private val onClick = OnClickListener { val pos = recycler.getChildAdapterPosition(it) val item = items[pos] onItemClicked(item) 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 49149e9973..04a0f255d7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleNavigationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleNavigationView.kt @@ -76,7 +76,7 @@ open class SimpleNavigationView @JvmOverloads constructor( /** * Clickable view holder. */ - abstract class ClickableHolder(view: View, listener: View.OnClickListener?) : Holder(view) { + abstract class ClickableHolder(view: View, listener: OnClickListener?) : Holder(view) { init { itemView.setOnClickListener(listener) } @@ -85,7 +85,7 @@ open class SimpleNavigationView @JvmOverloads constructor( /** * Radio view holder. */ - class RadioHolder(parent: ViewGroup, listener: View.OnClickListener?) : + class RadioHolder(parent: ViewGroup, listener: OnClickListener?) : ClickableHolder(parent.inflate(TR.layout.navigation_view_radio), listener) { val radio: RadioButton = itemView.findViewById(TR.id.nav_view_item) @@ -94,7 +94,7 @@ open class SimpleNavigationView @JvmOverloads constructor( /** * Checkbox view holder. */ - class CheckboxHolder(parent: ViewGroup, listener: View.OnClickListener?) : + class CheckboxHolder(parent: ViewGroup, listener: OnClickListener?) : ClickableHolder(parent.inflate(TR.layout.navigation_view_checkbox), listener) { val check: CheckBox = itemView.findViewById(TR.id.nav_view_item) @@ -103,7 +103,7 @@ open class SimpleNavigationView @JvmOverloads constructor( /** * Multi state view holder. */ - class MultiStateHolder(parent: ViewGroup, listener: View.OnClickListener?) : + class MultiStateHolder(parent: ViewGroup, listener: OnClickListener?) : ClickableHolder(parent.inflate(TR.layout.navigation_view_checkedtext), listener) { val text: CheckedTextView = itemView.findViewById(TR.id.nav_view_item) diff --git a/app/src/main/res/layout/categories_item.xml b/app/src/main/res/layout/categories_item.xml index b7c985e173..59e6c8b7d4 100644 --- a/app/src/main/res/layout/categories_item.xml +++ b/app/src/main/res/layout/categories_item.xml @@ -33,7 +33,7 @@ android:layout_height="@dimen/material_component_lists_single_line_with_avatar_height" android:layout_gravity="end" android:scaleType="center" - android:tint="?android:attr/textColorPrimary" - app:srcCompat="@drawable/ic_reorder_grey_24dp" /> + app:srcCompat="@drawable/ic_reorder_grey_24dp" + app:tint="?android:attr/textColorPrimary" /> diff --git a/app/src/main/res/layout/chapters_controller.xml b/app/src/main/res/layout/chapters_controller.xml index e2f2c817fb..6217ad42bb 100644 --- a/app/src/main/res/layout/chapters_controller.xml +++ b/app/src/main/res/layout/chapters_controller.xml @@ -1,6 +1,5 @@ - + android:visibility="invisible" /> @@ -42,7 +41,7 @@ android:layout_centerHorizontal="true" android:layout_gravity="end" app:fastScrollerBubbleEnabled="false" - tools:visibility="visible"/> + tools:visibility="visible" /> + app:icon="@drawable/ic_play_arrow_24dp" + app:layout_anchor="@id/recycler" /> diff --git a/app/src/main/res/layout/chapters_item.xml b/app/src/main/res/layout/chapters_item.xml index d74d89ab4e..a565d4c706 100644 --- a/app/src/main/res/layout/chapters_item.xml +++ b/app/src/main/res/layout/chapters_item.xml @@ -5,8 +5,8 @@ android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:background="@drawable/list_item_selector" - android:paddingEnd="16dp" - android:paddingStart="16dp"> + android:paddingStart="16dp" + android:paddingEnd="16dp"> diff --git a/app/src/main/res/layout/common_action_toolbar.xml b/app/src/main/res/layout/common_action_toolbar.xml index 4d9c8c3478..89164fe681 100644 --- a/app/src/main/res/layout/common_action_toolbar.xml +++ b/app/src/main/res/layout/common_action_toolbar.xml @@ -10,11 +10,11 @@ android:layout_height="?attr/actionBarSize" android:layout_gravity="bottom" android:background="?attr/colorPrimary" + android:elevation="2dp" android:theme="?attr/actionBarTheme" android:visibility="gone" - android:elevation="2dp" - app:contentInsetStart="8dp" - app:contentInsetEnd="8dp"> + app:contentInsetEnd="8dp" + app:contentInsetStart="8dp"> + app:srcCompat="@drawable/ic_reorder_grey_24dp" + app:tint="?android:attr/textColorPrimary" /> @@ -25,6 +25,6 @@ android:layout_centerHorizontal="true" android:layout_gravity="end" app:fastScrollerBubbleEnabled="false" - tools:visibility="visible"/> + tools:visibility="visible" /> diff --git a/app/src/main/res/layout/manga_info_controller.xml b/app/src/main/res/layout/manga_info_controller.xml index 957b66949a..b62ad91b57 100644 --- a/app/src/main/res/layout/manga_info_controller.xml +++ b/app/src/main/res/layout/manga_info_controller.xml @@ -80,8 +80,8 @@ style="@style/TextAppearance.Medium.Title" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:paddingBottom="8dp" android:maxLines="2" + android:paddingBottom="8dp" android:text="@string/manga_info_full_title_label" android:textIsSelectable="false" app:autoSizeMaxTextSize="20sp" diff --git a/app/src/main/res/layout/navigation_view_spinner.xml b/app/src/main/res/layout/navigation_view_spinner.xml index cbfb35eaa0..8f00ef57b5 100644 --- a/app/src/main/res/layout/navigation_view_spinner.xml +++ b/app/src/main/res/layout/navigation_view_spinner.xml @@ -1,8 +1,8 @@ diff --git a/app/src/main/res/layout/pref_library_columns.xml b/app/src/main/res/layout/pref_library_columns.xml index ee3ee35d5e..f31e978673 100644 --- a/app/src/main/res/layout/pref_library_columns.xml +++ b/app/src/main/res/layout/pref_library_columns.xml @@ -3,6 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" + android:baselineAligned="false" android:orientation="horizontal" android:paddingStart="@dimen/dialog_content_padding" android:paddingTop="@dimen/dialog_margin_top_content" diff --git a/app/src/main/res/layout/reader_page_sheet.xml b/app/src/main/res/layout/reader_page_sheet.xml index ba7e08e93d..7fba52a453 100644 --- a/app/src/main/res/layout/reader_page_sheet.xml +++ b/app/src/main/res/layout/reader_page_sheet.xml @@ -19,8 +19,8 @@ + app:srcCompat="@drawable/ic_photo_24dp" + app:tint="@color/md_white_1000_54" /> + app:srcCompat="@drawable/ic_share_24dp" + app:tint="@color/md_white_1000_54" /> + app:srcCompat="@drawable/ic_file_download_black_24dp" + app:tint="@color/md_white_1000_54" /> + app:layout_constraintRight_toLeftOf="@id/verticalcenter" /> + app:layout_constraintTop_toBottomOf="@id/crop_borders_webtoon" /> diff --git a/app/src/main/res/layout/source_filter_sheet.xml b/app/src/main/res/layout/source_filter_sheet.xml index 4cdfef0712..693865483b 100644 --- a/app/src/main/res/layout/source_filter_sheet.xml +++ b/app/src/main/res/layout/source_filter_sheet.xml @@ -21,10 +21,10 @@ android:alpha="0.5" android:scaleType="fitCenter" android:src="@drawable/ic_drag_pill_24dp" - android:tint="?attr/colorOnBackground" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" + app:tint="?attr/colorOnBackground" />