diff --git a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt index 9bc823f7a3..ee842500b7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt @@ -25,7 +25,6 @@ import uy.kohesive.injekt.api.get class AppModule(val app: Application) : InjektModule { override fun InjektRegistrar.registerInjectables() { - addSingleton(app) addSingletonFactory { PreferencesHelper(app) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index a44c199c3b..4c10eb9514 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -70,8 +70,9 @@ object Migrations { } } } - if (oldVersion < 54) + if (oldVersion < 54) { DownloadProvider(context).renameChapters() + } if (oldVersion < 62) { LibraryPresenter.updateDB() // Restore jobs after migrating from Evernote's job scheduler to WorkManager. 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 709f6d9d42..217ef14479 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 @@ -79,8 +79,9 @@ class ChapterCache(private val context: Context) { */ fun removeFileFromCache(file: String): Boolean { // Make sure we don't delete the journal file (keeps track of cache). - if (file == "journal" || file.startsWith("journal.")) + if (file == "journal" || file.startsWith("journal.")) { return false + } try { // Remove the extension from the file to get the key of the cache diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/CategoryTypeMapping.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/CategoryTypeMapping.kt index c05f95c220..7ff44191ce 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/CategoryTypeMapping.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/CategoryTypeMapping.kt @@ -41,9 +41,9 @@ class CategoryPutResolver : DefaultPutResolver() { put(COL_NAME, obj.name) put(COL_ORDER, obj.order) put(COL_FLAGS, obj.flags) - if (obj.mangaSort != null) + if (obj.mangaSort != null) { put(COL_MANGA_ORDER, obj.mangaSort.toString()) - else { + } else { val orderString = obj.mangaOrder.joinToString("/") put(COL_MANGA_ORDER, orderString) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt index e09ae08b39..fee19edae2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt @@ -105,17 +105,17 @@ interface Manga : SManga { { tag -> tag == "long strip" || tag == "manhwa" || tag.contains("webtoon") } == true || isWebtoonSource(sourceName) - ) + ) { ReaderActivity.WEBTOON - else if (currentTags?.any + } else if (currentTags?.any { tag -> tag == "chinese" || tag == "manhua" || tag.startsWith("english") || tag == "comic" } == true || (isComicSource(sourceName) && !sourceName.contains("tapas", true)) || sourceName.contains("manhua", true) - ) + ) { ReaderActivity.LEFT_TO_RIGHT - else 0 + } else 0 } fun isMangaTag(tag: String): Boolean { @@ -127,7 +127,7 @@ interface Manga : SManga { } fun isManhwaTag(tag: String): Boolean { - return tag in listOf("long strip", "manhwa", "манхва", "kr") || tag.startsWith("korean") + return tag in listOf("long strip", "manhwa", "манхва", "kr") || tag.startsWith("korean") } fun isComicTag(tag: String): Boolean { 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 33ccbb0fd7..d74003c159 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 @@ -90,7 +90,6 @@ class DownloadCache( checkRenew() if (forceCheckFolder) { - val source = sourceManager.get(manga.source) ?: return 0 val mangaDir = provider.findMangaDir(manga, source) @@ -173,7 +172,6 @@ class DownloadCache( */ @Synchronized fun addChapter(chapterDirName: String, mangaUniFile: UniFile, manga: Manga) { - val id = manga.id ?: return val files = mangaFiles[id] if (files == null) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index 4b4a8c6c20..71e72d424b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -110,10 +110,11 @@ class DownloadManager(val context: Context) { queue.add(0, download) reorderQueue(queue) if (isPaused()) { - if (DownloadService.isRunning(context)) + if (DownloadService.isRunning(context)) { downloader.start() - else + } else { DownloadService.start(context) + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt index 13fda6607f..fc6c2dac57 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt @@ -55,8 +55,9 @@ internal class DownloadNotifier(private val context: Context) { * Clear old actions if they exist. */ private fun clearActions() = with(notification) { - if (!mActions.isEmpty()) + if (!mActions.isEmpty()) { mActions.clear() + } } /** 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 f109a808a5..42e7f05bd2 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 @@ -201,10 +201,11 @@ class DownloadService : Service() { */ private fun listenDownloaderState() { subscriptions += downloadManager.runningRelay.subscribe { running -> - if (running) + if (running) { wakeLock.acquireIfNeeded() - else + } else { wakeLock.releaseIfNeeded() + } } } 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 8f9feedd81..4ed15d610f 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 @@ -469,7 +469,6 @@ class Downloader( tmpDir: UniFile, dirname: String ) { - // Ensure that the chapter folder has all the images. val downloadedImages = tmpDir.listFiles().orEmpty().filterNot { it.name!!.endsWith(".tmp") } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/Download.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/Download.kt index 6701d43a09..5359b86f68 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/Download.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/Download.kt @@ -11,11 +11,14 @@ class Download(val source: HttpSource, val manga: Manga, val chapter: Chapter) { var pages: List? = null - @Volatile @Transient var totalProgress: Int = 0 + @Volatile @Transient + var totalProgress: Int = 0 - @Volatile @Transient var downloadedImages: Int = 0 + @Volatile @Transient + var downloadedImages: Int = 0 - @Volatile @Transient var status: Int = 0 + @Volatile @Transient + var status: Int = 0 set(status) { field = status statusSubject?.onNext(this) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt index 585206c711..d7ce067d46 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt @@ -37,8 +37,9 @@ class DownloadQueue( store.remove(download) download.setStatusSubject(null) download.setStatusCallback(null) - if (download.status == Download.DOWNLOADING || download.status == Download.QUEUE) + if (download.status == Download.DOWNLOADING || download.status == Download.QUEUE) { download.status = Download.NOT_DOWNLOADED + } downloadListeners.forEach { it.updateDownload(download) } if (removed) { updatedRelay.call(Unit) @@ -65,8 +66,9 @@ class DownloadQueue( queue.forEach { download -> download.setStatusSubject(null) download.setStatusCallback(null) - if (download.status == Download.DOWNLOADING || download.status == Download.QUEUE) + if (download.status == Download.DOWNLOADING || download.status == Download.QUEUE) { download.status = Download.NOT_DOWNLOADED + } downloadListeners.forEach { it.updateDownload(download) } } queue.clear() @@ -85,11 +87,12 @@ class DownloadQueue( private fun setPagesFor(download: Download) { if (download.status == Download.DOWNLOADING) { - if (download.pages != null) + if (download.pages != null) { for (page in download.pages!!) page.setStatusCallback { callListeners(download) } + } downloadListeners.forEach { it.updateDownload(download) } } else if (download.status == Download.DOWNLOADED || download.status == Download.ERROR) { setPagesSubject(download.pages, null) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt index aaf6e8abb1..3587ddc189 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt @@ -31,10 +31,11 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet if (interval > 0) { val restrictions = preferences.libraryUpdateRestriction()!! val acRestriction = "ac" in restrictions - val wifiRestriction = if ("wifi" in restrictions) + val wifiRestriction = if ("wifi" in restrictions) { NetworkType.UNMETERED - else + } else { NetworkType.CONNECTED + } val constraints = Constraints.Builder() .setRequiredNetworkType(wifiRestriction) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt index 8258efe5f9..579b92d1a7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt @@ -195,7 +195,6 @@ class LibraryUpdateNotifier(private val context: Context) { } NotificationManagerCompat.from(context).apply { - notify( Notifications.ID_NEW_CHAPTERS, context.notification(Notifications.CHANNEL_NEW_CHAPTERS) { 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 91713e48bc..b9f53ded07 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 @@ -114,7 +114,9 @@ class LibraryUpdateService( enum class Target { CHAPTERS, // Manga chapters + DETAILS, // Manga metadata + TRACKING // Tracking metadata } @@ -172,8 +174,9 @@ class LibraryUpdateService( */ override fun onDestroy() { job?.cancel() - if (instance == this) + if (instance == this) { instance = null + } if (wakeLock.isHeld) { wakeLock.release() } @@ -380,47 +383,47 @@ class LibraryUpdateService( shouldDownload: Boolean ): Boolean { - try { - var hasDownloads = false - if (job?.isCancelled == true) { - return false - } - notifier.showProgressNotification(manga, progress, mangaToUpdate.size) - val source = sourceManager.get(manga.source) as? HttpSource ?: return false - val fetchedChapters = withContext(Dispatchers.IO) { - source.fetchChapterList(manga).toBlocking().single() - } ?: emptyList() - if (fetchedChapters.isNotEmpty()) { - val newChapters = syncChaptersWithSource(db, fetchedChapters, manga, source) - if (newChapters.first.isNotEmpty()) { - if (shouldDownload) { - downloadChapters(manga, newChapters.first.sortedBy { it.chapter_number }) - hasDownloads = true - } - newUpdates[manga] = - newChapters.first.sortedBy { it.chapter_number }.toTypedArray() - } - if (deleteRemoved && newChapters.second.isNotEmpty()) { - val removedChapters = newChapters.second.filter { - downloadManager.isChapterDownloaded(it, manga) - } - if (removedChapters.isNotEmpty()) { - downloadManager.deleteChapters(removedChapters, manga, source) - } - } - if (newChapters.first.size + newChapters.second.size > 0) listener?.onUpdateManga( - manga - ) - } - return hasDownloads - } catch (e: Exception) { - if (e !is CancellationException) { - failedUpdates[manga] = e.message - Timber.e("Failed updating: ${manga.title}: $e") - } + try { + var hasDownloads = false + if (job?.isCancelled == true) { return false } + notifier.showProgressNotification(manga, progress, mangaToUpdate.size) + val source = sourceManager.get(manga.source) as? HttpSource ?: return false + val fetchedChapters = withContext(Dispatchers.IO) { + source.fetchChapterList(manga).toBlocking().single() + } ?: emptyList() + if (fetchedChapters.isNotEmpty()) { + val newChapters = syncChaptersWithSource(db, fetchedChapters, manga, source) + if (newChapters.first.isNotEmpty()) { + if (shouldDownload) { + downloadChapters(manga, newChapters.first.sortedBy { it.chapter_number }) + hasDownloads = true + } + newUpdates[manga] = + newChapters.first.sortedBy { it.chapter_number }.toTypedArray() + } + if (deleteRemoved && newChapters.second.isNotEmpty()) { + val removedChapters = newChapters.second.filter { + downloadManager.isChapterDownloaded(it, manga) + } + if (removedChapters.isNotEmpty()) { + downloadManager.deleteChapters(removedChapters, manga, source) + } + } + if (newChapters.first.size + newChapters.second.size > 0) listener?.onUpdateManga( + manga + ) + } + return hasDownloads + } catch (e: Exception) { + if (e !is CancellationException) { + failedUpdates[manga] = e.message + Timber.e("Failed updating: ${manga.title}: $e") + } + return false } + } private fun downloadChapters(manga: Manga, chapters: List) { // We don't want to start downloading while the library is updating, because websites diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt index 6de223a8b2..148849531f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt @@ -448,19 +448,19 @@ class NotificationReceiver : BroadcastReceiver() { */ internal fun openChapterPendingActivity(context: Context, manga: Manga, groupId: Int): PendingIntent { - val newIntent = - Intent(context, MainActivity::class.java).setAction(MainActivity.SHORTCUT_MANGA) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP) - .putExtra(MangaDetailsController.MANGA_EXTRA, manga.id) - .putExtra("notificationId", manga.id.hashCode()) - .putExtra("groupId", groupId) - return PendingIntent.getActivity( - context, - manga.id.hashCode(), - newIntent, - PendingIntent.FLAG_UPDATE_CURRENT - ) - } + val newIntent = + Intent(context, MainActivity::class.java).setAction(MainActivity.SHORTCUT_MANGA) + .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP) + .putExtra(MangaDetailsController.MANGA_EXTRA, manga.id) + .putExtra("notificationId", manga.id.hashCode()) + .putExtra("groupId", groupId) + return PendingIntent.getActivity( + context, + manga.id.hashCode(), + newIntent, + PendingIntent.FLAG_UPDATE_CURRENT + ) + } /** * Returns [PendingIntent] that opens the error log file in an external viewer @@ -522,15 +522,15 @@ class NotificationReceiver : BroadcastReceiver() { groupId: Int ): PendingIntent { - val newIntent = Intent(context, NotificationReceiver::class.java).apply { - action = ACTION_MARK_AS_READ - putExtra(EXTRA_CHAPTER_URL, chapters.map { it.url }.toTypedArray()) - putExtra(EXTRA_MANGA_ID, manga.id) - putExtra(EXTRA_NOTIFICATION_ID, manga.id.hashCode()) - putExtra(EXTRA_GROUP_ID, groupId) - } - return PendingIntent.getBroadcast(context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT) + val newIntent = Intent(context, NotificationReceiver::class.java).apply { + action = ACTION_MARK_AS_READ + putExtra(EXTRA_CHAPTER_URL, chapters.map { it.url }.toTypedArray()) + putExtra(EXTRA_MANGA_ID, manga.id) + putExtra(EXTRA_NOTIFICATION_ID, manga.id.hashCode()) + putExtra(EXTRA_GROUP_ID, groupId) } + return PendingIntent.getBroadcast(context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT) + } /** * Returns [PendingIntent] that starts a service which stops the library update 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 717b44b4da..2018516574 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 @@ -6,11 +6,9 @@ import androidx.annotation.StringRes import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.track.anilist.Anilist import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.source.model.SManga -import eu.kanade.tachiyomi.ui.manga.track.SetTrackReadingDatesDialog import eu.kanade.tachiyomi.util.system.executeOnIO import okhttp3.OkHttpClient import uy.kohesive.injekt.injectLazy 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 6ccd635758..cbd0dd1b26 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 @@ -25,7 +25,6 @@ import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response import timber.log.Timber import java.util.Calendar -import java.util.Date import java.util.concurrent.TimeUnit class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { @@ -34,7 +33,6 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { suspend fun addLibManga(track: Track): Track { return withContext(Dispatchers.IO) { - val variables = jsonObject( "mangaId" to track.media_id, "progress" to track.last_chapter_read, @@ -105,7 +103,6 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { } suspend fun findLibManga(track: Track, userid: Int): Track? { - return withContext(Dispatchers.IO) { val variables = jsonObject( "id" to userid, @@ -141,7 +138,6 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { suspend fun remove(track: Track): Boolean { return withContext(Dispatchers.IO) { try { - val variables = jsonObject( "listId" to track.library_id ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt index 6a4cadb9ca..fb5dbb764e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt @@ -114,7 +114,6 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { suspend fun login(code: String): Boolean { try { - val oauth = api.accessToken(code) interceptor.newAuth(oauth) saveCredentials(oauth.user_id.toString(), oauth.access_token) 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 9990293e3c..e0050bb2d8 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 @@ -5,14 +5,12 @@ import android.graphics.Color import androidx.annotation.StringRes import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.data.track.updateNewTrackInfo import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json -import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import timber.log.Timber import uy.kohesive.injekt.injectLazy @@ -89,7 +87,6 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { // Set default fields if it's not found in the list add(track) } - } override fun canRemoveFromService(): Boolean = true 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 index e72c4f2aa5..bb7cb8c47b 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 @@ -8,17 +8,11 @@ import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.await -import eu.kanade.tachiyomi.network.consumeBody -import eu.kanade.tachiyomi.network.consumeXmlBody import eu.kanade.tachiyomi.network.parseAs import eu.kanade.tachiyomi.util.PkceUtil -import eu.kanade.tachiyomi.util.selectInt -import eu.kanade.tachiyomi.util.selectText import eu.kanade.tachiyomi.util.system.withIOContext -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll -import kotlinx.coroutines.withContext import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.boolean import kotlinx.serialization.json.contentOrNull @@ -27,17 +21,9 @@ import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive import okhttp3.FormBody -import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody -import okhttp3.RequestBody.Companion.toRequestBody -import org.json.JSONObject -import org.jsoup.Jsoup -import org.jsoup.nodes.Document -import org.jsoup.nodes.Element -import org.jsoup.parser.Parser -import retrofit2.http.DELETE import timber.log.Timber import java.text.SimpleDateFormat import java.util.* @@ -49,91 +35,90 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI suspend fun getAccessToken(authCode: String): OAuth { return withIOContext { val formBody: RequestBody = FormBody.Builder() - .add("client_id", clientId) - .add("code", authCode) - .add("code_verifier", codeVerifier) - .add("grant_type", "authorization_code") - .build() + .add("client_id", clientId) + .add("code", authCode) + .add("code_verifier", codeVerifier) + .add("grant_type", "authorization_code") + .build() client.newCall(POST("$baseOAuthUrl/token", body = formBody)) - .await() - .parseAs() + .await() + .parseAs() } } suspend fun getCurrentUser(): String { return withIOContext { val request = Request.Builder() - .url("$baseApiUrl/users/@me") - .get() - .build() + .url("$baseApiUrl/users/@me") + .get() + .build() authClient.newCall(request) - .await() - .parseAs() - .let { it["name"]!!.jsonPrimitive.content } + .await() + .parseAs() + .let { it["name"]!!.jsonPrimitive.content } } } suspend fun search(query: String): List { return withIOContext { val url = "$baseApiUrl/manga".toUri().buildUpon() - .appendQueryParameter("q", query) - .appendQueryParameter("nsfw", "true") - .build() + .appendQueryParameter("q", query) + .appendQueryParameter("nsfw", "true") + .build() authClient.newCall(GET(url.toString())) - .await() - .parseAs() - .let { - it["data"]!!.jsonArray - .map { data -> data.jsonObject["node"]!!.jsonObject } - .map { node -> - val id = node["id"]!!.jsonPrimitive.int - async { getMangaDetails(id) } - } - .awaitAll() - .filter { trackSearch -> trackSearch.publishing_type != "novel" } - } + .await() + .parseAs() + .let { + it["data"]!!.jsonArray + .map { data -> data.jsonObject["node"]!!.jsonObject } + .map { node -> + val id = node["id"]!!.jsonPrimitive.int + async { getMangaDetails(id) } + } + .awaitAll() + .filter { trackSearch -> trackSearch.publishing_type != "novel" } + } } } - suspend fun getMangaDetails(id: Int): TrackSearch { return withIOContext { val url = "$baseApiUrl/manga".toUri().buildUpon() - .appendPath(id.toString()) - .appendQueryParameter("fields", "id,title,synopsis,num_chapters,main_picture,status,media_type,start_date") - .build() + .appendPath(id.toString()) + .appendQueryParameter("fields", "id,title,synopsis,num_chapters,main_picture,status,media_type,start_date") + .build() authClient.newCall(GET(url.toString())) - .await() - .parseAs() - .let { - val obj = it.jsonObject - TrackSearch.create(TrackManager.MYANIMELIST).apply { - media_id = obj["id"]!!.jsonPrimitive.int - title = obj["title"]!!.jsonPrimitive.content - summary = obj["synopsis"]?.jsonPrimitive?.content ?: "" - total_chapters = obj["num_chapters"]!!.jsonPrimitive.int - cover_url = obj["main_picture"]?.jsonObject?.get("large")?.jsonPrimitive?.content ?: "" - tracking_url = "https://myanimelist.net/manga/$media_id" - publishing_status = obj["status"]!!.jsonPrimitive.content.replace("_", " ") - publishing_type = obj["media_type"]!!.jsonPrimitive.content.replace("_", " ") - start_date = try { - val outputDf = SimpleDateFormat("yyyy-MM-dd", Locale.US) - outputDf.format(obj["start_date"]!!) - } catch (e: Exception) { - "" - } + .await() + .parseAs() + .let { + val obj = it.jsonObject + TrackSearch.create(TrackManager.MYANIMELIST).apply { + media_id = obj["id"]!!.jsonPrimitive.int + title = obj["title"]!!.jsonPrimitive.content + summary = obj["synopsis"]?.jsonPrimitive?.content ?: "" + total_chapters = obj["num_chapters"]!!.jsonPrimitive.int + cover_url = obj["main_picture"]?.jsonObject?.get("large")?.jsonPrimitive?.content ?: "" + tracking_url = "https://myanimelist.net/manga/$media_id" + publishing_status = obj["status"]!!.jsonPrimitive.content.replace("_", " ") + publishing_type = obj["media_type"]!!.jsonPrimitive.content.replace("_", " ") + start_date = try { + val outputDf = SimpleDateFormat("yyyy-MM-dd", Locale.US) + outputDf.format(obj["start_date"]!!) + } catch (e: Exception) { + "" } } + } } } suspend fun updateItem(track: Track): Track { return withIOContext { val formBodyBuilder = FormBody.Builder() - .add("status", track.toMyAnimeListStatus() ?: "reading") - .add("is_rereading", (track.status == MyAnimeList.REREADING).toString()) - .add("score", track.score.toString()) - .add("num_chapters_read", track.last_chapter_read.toString()) + .add("status", track.toMyAnimeListStatus() ?: "reading") + .add("is_rereading", (track.status == MyAnimeList.REREADING).toString()) + .add("score", track.score.toString()) + .add("num_chapters_read", track.last_chapter_read.toString()) convertToIsoDate(track.started_reading_date)?.let { formBodyBuilder.add("start_date", it) } @@ -142,32 +127,31 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI } val request = Request.Builder() - .url(mangaUrl(track.media_id).toString()) - .put(formBodyBuilder.build()) - .build() + .url(mangaUrl(track.media_id).toString()) + .put(formBodyBuilder.build()) + .build() authClient.newCall(request) - .await() - .parseAs() - .let { parseMangaItem(it, track) } + .await() + .parseAs() + .let { parseMangaItem(it, track) } } } - suspend fun findListItem(track: Track): Track? { return withIOContext { val uri = "$baseApiUrl/manga".toUri().buildUpon() - .appendPath(track.media_id.toString()) - .appendQueryParameter("fields", "num_chapters,my_list_status{start_date,finish_date}") - .build() + .appendPath(track.media_id.toString()) + .appendQueryParameter("fields", "num_chapters,my_list_status{start_date,finish_date}") + .build() authClient.newCall(GET(uri.toString())) - .await() - .parseAs() - .let { obj -> - track.total_chapters = obj["num_chapters"]!!.jsonPrimitive.int - obj.jsonObject["my_list_status"]?.jsonObject?.let { - parseMangaItem(it, track) - } + .await() + .parseAs() + .let { obj -> + track.total_chapters = obj["num_chapters"]!!.jsonPrimitive.int + obj.jsonObject["my_list_status"]?.jsonObject?.let { + parseMangaItem(it, track) } + } } } @@ -177,17 +161,17 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI val obj = json.jsonObject val matches = obj["data"]!!.jsonArray - .filter { - it.jsonObject["node"]!!.jsonObject["title"]!!.jsonPrimitive.content.contains( - query, - ignoreCase = true - ) - } - .map { - val id = it.jsonObject["node"]!!.jsonObject["id"]!!.jsonPrimitive.int - async { getMangaDetails(id) } - } - .awaitAll() + .filter { + it.jsonObject["node"]!!.jsonObject["title"]!!.jsonPrimitive.content.contains( + query, + ignoreCase = true + ) + } + .map { + val id = it.jsonObject["node"]!!.jsonObject["id"]!!.jsonPrimitive.int + async { getMangaDetails(id) } + } + .awaitAll() // Check next page if there's more if (!obj["paging"]!!.jsonObject["next"]?.jsonPrimitive?.contentOrNull.isNullOrBlank()) { @@ -201,19 +185,19 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI private suspend fun getListPage(offset: Int): JsonObject { return withIOContext { val urlBuilder = "$baseApiUrl/users/@me/mangalist".toUri().buildUpon() - .appendQueryParameter("fields", "list_status{start_date,finish_date}") - .appendQueryParameter("limit", listPaginationAmount.toString()) + .appendQueryParameter("fields", "list_status{start_date,finish_date}") + .appendQueryParameter("limit", listPaginationAmount.toString()) if (offset > 0) { urlBuilder.appendQueryParameter("offset", offset.toString()) } val request = Request.Builder() - .url(urlBuilder.build().toString()) - .get() - .build() + .url(urlBuilder.build().toString()) + .get() + .build() authClient.newCall(request) - .await() - .parseAs() + .await() + .parseAs() } } @@ -251,7 +235,7 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI suspend fun remove(track: Track): Boolean { return withIOContext { - try { + try { val request = Request.Builder() .url(mangaUrl(track.media_id).toString()) .delete() @@ -277,22 +261,22 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI private var codeVerifier: String = "" fun authUrl(): Uri = "$baseOAuthUrl/authorize".toUri().buildUpon() - .appendQueryParameter("client_id", clientId) - .appendQueryParameter("code_challenge", getPkceChallengeCode()) - .appendQueryParameter("response_type", "code") - .build() + .appendQueryParameter("client_id", clientId) + .appendQueryParameter("code_challenge", getPkceChallengeCode()) + .appendQueryParameter("response_type", "code") + .build() fun mangaUrl(id: Int): Uri = "$baseApiUrl/manga".toUri().buildUpon() - .appendPath(id.toString()) - .appendPath("my_list_status") - .build() + .appendPath(id.toString()) + .appendPath("my_list_status") + .build() fun refreshTokenRequest(refreshToken: String): Request { val formBody: RequestBody = FormBody.Builder() - .add("client_id", clientId) - .add("refresh_token", refreshToken) - .add("grant_type", "refresh_token") - .build() + .add("client_id", clientId) + .add("refresh_token", refreshToken) + .add("grant_type", "refresh_token") + .build() return POST("$baseOAuthUrl/token", body = formBody) } 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 fb7038e9a6..9d8c1989b5 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,16 +3,10 @@ package eu.kanade.tachiyomi.data.track.myanimelist import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job -import kotlinx.coroutines.runBlocking import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import okhttp3.Interceptor -import okhttp3.Request -import okhttp3.RequestBody -import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response -import okio.Buffer -import org.json.JSONObject import uy.kohesive.injekt.injectLazy class MyAnimeListInterceptor(private val myanimelist: MyAnimeList, private var token: String?) : Interceptor { @@ -51,8 +45,8 @@ class MyAnimeListInterceptor(private val myanimelist: MyAnimeList, private var t // Add the authorization header to the original request. val authRequest = originalRequest.newBuilder() - .addHeader("Authorization", "Bearer ${oauth!!.access_token}") - .build() + .addHeader("Authorization", "Bearer ${oauth!!.access_token}") + .build() return chain.proceed(authRequest) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index 6c07f88411..92959414fd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -69,8 +69,9 @@ class ExtensionManager( } fun removeListener(listener: ExtensionsChangedListener) { - if (this.listener == listener) + if (this.listener == listener) { this.listener = null + } } fun getAppIconForSource(source: Source): Drawable? { diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt index 373e0a859c..a2ff814ce2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt @@ -62,17 +62,17 @@ internal class ExtensionGithubApi { libVersion >= ExtensionLoader.LIB_VERSION_MIN && libVersion <= ExtensionLoader.LIB_VERSION_MAX } .map { element -> - val name = element.jsonObject["name"]!!.jsonPrimitive.content.substringAfter("Tachiyomi: ") - val pkgName = element.jsonObject["pkg"]!!.jsonPrimitive.content - val apkName = element.jsonObject["apk"]!!.jsonPrimitive.content - val versionName = element.jsonObject["version"]!!.jsonPrimitive.content - val versionCode = element.jsonObject["code"]!!.jsonPrimitive.int - val lang = element.jsonObject["lang"]!!.jsonPrimitive.content - val nsfw = element.jsonObject["nsfw"]!!.jsonPrimitive.int == 1 - val icon = "${REPO_URL_PREFIX}icon/${apkName.replace(".apk", ".png")}" + val name = element.jsonObject["name"]!!.jsonPrimitive.content.substringAfter("Tachiyomi: ") + val pkgName = element.jsonObject["pkg"]!!.jsonPrimitive.content + val apkName = element.jsonObject["apk"]!!.jsonPrimitive.content + val versionName = element.jsonObject["version"]!!.jsonPrimitive.content + val versionCode = element.jsonObject["code"]!!.jsonPrimitive.int + val lang = element.jsonObject["lang"]!!.jsonPrimitive.content + val nsfw = element.jsonObject["nsfw"]!!.jsonPrimitive.int == 1 + val icon = "${REPO_URL_PREFIX}icon/${apkName.replace(".apk", ".png")}" - Extension.Available(name, pkgName, versionName, versionCode, lang, nsfw, apkName, icon) - } + Extension.Available(name, pkgName, versionName, versionCode, lang, nsfw, apkName, icon) + } } fun getApkUrl(extension: Extension.Available): String { 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 6a3b79ff9c..4a28751433 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 @@ -144,10 +144,11 @@ internal object ExtensionLoader { .split(";") .map { val sourceClass = it.trim() - if (sourceClass.startsWith(".")) + if (sourceClass.startsWith(".")) { pkgInfo.packageName + sourceClass - else + } else { sourceClass + } } .flatMap { try { diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/Requests.kt b/app/src/main/java/eu/kanade/tachiyomi/network/Requests.kt index f9ac33edbd..3d3b88b548 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/Requests.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/Requests.kt @@ -16,7 +16,6 @@ fun GET( headers: Headers = DEFAULT_HEADERS, cache: CacheControl = DEFAULT_CACHE_CONTROL ): Request { - return Request.Builder() .url(url) .headers(headers) @@ -30,7 +29,6 @@ fun POST( body: RequestBody = DEFAULT_BODY, cache: CacheControl = DEFAULT_CACHE_CONTROL ): Request { - return Request.Builder() .url(url) .post(body) diff --git a/app/src/main/java/eu/kanade/tachiyomi/smartsearch/SmartSearchEngine.kt b/app/src/main/java/eu/kanade/tachiyomi/smartsearch/SmartSearchEngine.kt index d133496a5a..8d50bc3519 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/smartsearch/SmartSearchEngine.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/smartsearch/SmartSearchEngine.kt @@ -61,8 +61,9 @@ class SmartSearchEngine( } else title val searchResults = source.fetchSearchManga(1, searchQuery, FilterList()).toSingle().await(Schedulers.io()) - if (searchResults.mangas.size == 1) + if (searchResults.mangas.size == 1) { return@supervisorScope listOf(SearchEntry(searchResults.mangas.first(), 0.0)) + } searchResults.mangas.map { val normalizedDistance = normalizedLevenshtein.similarity(title, it.title) 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 bbf9a36788..b50507ff5f 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 @@ -15,14 +15,16 @@ open class Page( val number: Int get() = index + 1 - @Transient @Volatile var status: Int = 0 + @Transient @Volatile + var status: Int = 0 set(value) { field = value statusSubject?.onNext(value) statusCallback?.invoke(this) } - @Transient @Volatile var progress: Int = 0 + @Transient @Volatile + var progress: Int = 0 set(value) { field = value statusCallback?.invoke(this) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt b/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt index 9141de9812..9805b13771 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt @@ -36,25 +36,31 @@ interface SManga : Serializable { get() = (this as? MangaImpl)?.ogGenre ?: genre fun copyFrom(other: SManga) { - if (other.author != null) + if (other.author != null) { author = other.originalAuthor + } - if (other.artist != null) + if (other.artist != null) { artist = other.originalArtist + } - if (other.description != null) + if (other.description != null) { description = other.originalDescription + } - if (other.genre != null) + if (other.genre != null) { genre = other.originalGenre + } - if (other.thumbnail_url != null) + if (other.thumbnail_url != null) { thumbnail_url = other.thumbnail_url + } status = other.status - if (!initialized) + if (!initialized) { initialized = other.initialized + } } companion object { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt index 369c201130..8c7023ae6d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt @@ -29,7 +29,8 @@ abstract class BaseActivity : AppCompatActivity() { override fun onResume() { super.onResume() - if (this !is BiometricActivity && this !is SearchActivity) + if (this !is BiometricActivity && this !is SearchActivity) { SecureActivityDelegate.promptLockIfNeeded(this) + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt index 1641b637f1..c09cd02f5e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt @@ -84,8 +84,9 @@ abstract class BaseController(bundle: Bundle? = null) : parentController = parentController.parentController } - if (router.backstack.lastOrNull()?.controller() == this) + if (router.backstack.lastOrNull()?.controller() == this) { (activity as? AppCompatActivity)?.supportActionBar?.title = getTitle() + } } private fun Controller.instance(): String { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/RxController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/RxController.kt index d227c1caf8..d72d44fb6d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/RxController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/RxController.kt @@ -43,12 +43,10 @@ abstract class RxController(bundle: Bundle? = null) : BaseController(bundle) { } fun Observable.subscribeUntilDetach(): Subscription { - return subscribe().also { untilDetachSubscriptions.add(it) } } fun Observable.subscribeUntilDetach(onNext: (T) -> Unit): Subscription { - return subscribe(onNext).also { untilDetachSubscriptions.add(it) } } @@ -56,7 +54,6 @@ abstract class RxController(bundle: Bundle? = null) : BaseController(bundle) { onNext: (T) -> Unit, onError: (Throwable) -> Unit ): Subscription { - return subscribe(onNext, onError).also { untilDetachSubscriptions.add(it) } } @@ -65,17 +62,14 @@ abstract class RxController(bundle: Bundle? = null) : BaseController(bundle) { onError: (Throwable) -> Unit, onCompleted: () -> Unit ): Subscription { - return subscribe(onNext, onError, onCompleted).also { untilDetachSubscriptions.add(it) } } fun Observable.subscribeUntilDestroy(): Subscription { - return subscribe().also { untilDestroySubscriptions.add(it) } } fun Observable.subscribeUntilDestroy(onNext: (T) -> Unit): Subscription { - return subscribe(onNext).also { untilDestroySubscriptions.add(it) } } @@ -83,7 +77,6 @@ abstract class RxController(bundle: Bundle? = null) : BaseController(bundle) { onNext: (T) -> Unit, onError: (Throwable) -> Unit ): Subscription { - return subscribe(onNext, onError).also { untilDestroySubscriptions.add(it) } } @@ -92,7 +85,6 @@ abstract class RxController(bundle: Bundle? = null) : BaseController(bundle) { onError: (Throwable) -> Unit, onCompleted: () -> Unit ): Subscription { - return subscribe(onNext, onError, onCompleted).also { untilDestroySubscriptions.add(it) } } } 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 06ea862f31..313b81513c 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 @@ -122,8 +122,9 @@ class CategoryController(bundle: Bundle? = null) : override fun onCategoryRename(position: Int, newName: String): Boolean { val category = adapter?.getItem(position)?.category ?: return false - if (category.order == CREATE_CATEGORY_ORDER) + if (category.order == CREATE_CATEGORY_ORDER) { return (presenter.createCategory(newName)) + } return (presenter.renameCategory(category, newName)) } @@ -185,6 +186,7 @@ class CategoryController(bundle: Bundle? = null) : override fun shouldMoveItem(fromPosition: Int, toPosition: Int): Boolean { return toPosition > 0 } + /** * Called from the presenter when a category with the given name already exists. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt index ca525c0b59..aed9a9a8df 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt @@ -121,8 +121,9 @@ class CategoryHolder(view: View, val adapter: CategoryAdapter) : BaseFlexibleVie ) { isEditing(false) edit_text.inputType = InputType.TYPE_NULL - if (!createCategory) + if (!createCategory) { title.text = edit_text.text.toString() + } } } else { itemView.performClick() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/ManageCategoryDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/ManageCategoryDialog.kt index 0eb2436992..482b72808e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/ManageCategoryDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/ManageCategoryDialog.kt @@ -105,10 +105,11 @@ class ManageCategoryDialog(bundle: Bundle? = null) : preferences.downloadNewCategories(), true ) - if (downloadNew && preferences.downloadNewCategories().get().isEmpty()) + if (downloadNew && preferences.downloadNewCategories().get().isEmpty()) { view.download_new.gone() - else if (!downloadNew) + } else if (!downloadNew) { view.download_new.visible() + } view.download_new.isChecked = preferences.downloadNew().get() && view.download_new.isChecked setCheckbox( @@ -132,9 +133,9 @@ class ManageCategoryDialog(bundle: Bundle? = null) : } private fun setCheckbox( - box: CompoundButton, - categories: Preference>, - shouldShow: Boolean + box: CompoundButton, + categories: Preference>, + shouldShow: Boolean ) { val updateCategories = categories.get() box.visibleIf(updateCategories.isNotEmpty() && shouldShow) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt index 94e7f8e732..1705d0d91a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt @@ -202,8 +202,9 @@ class DownloadBottomSheet @JvmOverloads constructor( val adapter = adapter ?: return false val items = adapter.currentItems.sortedBy { it.download.chapter.date_upload } .toMutableList() - if (item.itemId == R.id.newest) + if (item.itemId == R.id.newest) { items.reverse() + } adapter.updateDataSet(items) val downloads = items.mapNotNull { it.download } presenter.reorder(downloads) @@ -266,10 +267,11 @@ class DownloadBottomSheet @JvmOverloads constructor( val items = adapter?.currentItems?.toMutableList() ?: return val item = items[position] items.remove(item) - if (menuItem.itemId == R.id.move_to_top) + if (menuItem.itemId == R.id.move_to_top) { items.add(0, item) - else + } else { items.add(item) + } adapter?.updateDataSet(items) val downloads = items.mapNotNull { it.download } presenter.reorder(downloads) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadButton.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadButton.kt index b79e9876d4..19fad598d5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadButton.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadButton.kt @@ -59,8 +59,9 @@ class DownloadButton @JvmOverloads constructor(context: Context, attrs: Attribut isAnimating = false } download_icon.setImageDrawable( - if (state == Download.CHECKED) - checkDrawable else downloadDrawable + if (state == Download.CHECKED) { + checkDrawable + } else downloadDrawable ) when (state) { Download.CHECKED -> { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomPresenter.kt index 05bea5874a..59592825ba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomPresenter.kt @@ -15,7 +15,6 @@ import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.ui.migration.MangaItem import eu.kanade.tachiyomi.ui.migration.SelectionHeader import eu.kanade.tachiyomi.ui.migration.SourceItem -import eu.kanade.tachiyomi.util.lang.combineLatest import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.executeOnIO import kotlinx.coroutines.CoroutineScope @@ -26,8 +25,6 @@ import kotlinx.coroutines.awaitAll import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import rx.Observable -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -76,14 +73,15 @@ class ExtensionBottomPresenter( val migrationJob = async { val favs = db.getFavoriteMangas().executeOnIO() sourceItems = findSourcesWithManga(favs) - mangaItems = HashMap(sourceItems.associate { - it.source.id to this@ExtensionBottomPresenter.libraryToMigrationItem(favs, it.source.id) - }) + mangaItems = HashMap( + sourceItems.associate { + it.source.id to this@ExtensionBottomPresenter.libraryToMigrationItem(favs, it.source.id) + } + ) withContext(Dispatchers.Main) { if (selectedSource != null) { bottomSheet.setMigrationManga(mangaItems[selectedSource]) - } - else { + } else { bottomSheet.setMigrationSources(sourceItems) } } @@ -125,14 +123,15 @@ class ExtensionBottomPresenter( scope.launch { val favs = db.getFavoriteMangas().executeOnIO() sourceItems = findSourcesWithManga(favs) - mangaItems = HashMap(sourceItems.associate { - it.source.id to this@ExtensionBottomPresenter.libraryToMigrationItem(favs, it.source.id) - }) + mangaItems = HashMap( + sourceItems.associate { + it.source.id to this@ExtensionBottomPresenter.libraryToMigrationItem(favs, it.source.id) + } + ) withContext(Dispatchers.Main) { if (selectedSource != null) { bottomSheet.setMigrationManga(mangaItems[selectedSource]) - } - else { + } else { bottomSheet.setMigrationSources(sourceItems) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt index 1ec636ba4e..da9d582e7f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt @@ -308,10 +308,12 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At } override fun getPageTitle(position: Int): CharSequence { - return context.getString(when (position) { - 0 -> R.string.extensions - else -> R.string.migration - }) + return context.getString( + when (position) { + 0 -> R.string.extensions + else -> R.string.migration + } + ) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupItem.kt index 186ef930ca..8bd8fc78f4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupItem.kt @@ -38,7 +38,6 @@ data class ExtensionGroupItem(val name: String, val size: Int) : AbstractHeaderI position: Int, payloads: MutableList? ) { - holder.bind(this) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionItem.kt index be4abf80ef..dafe4eb0b1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionItem.kt @@ -46,7 +46,6 @@ data class ExtensionItem( position: Int, payloads: MutableList? ) { - if (payloads == null || payloads.isEmpty()) { holder.bind(this) } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/SettingsExtensionsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/SettingsExtensionsController.kt index 3c7ae356c0..cd57be7e13 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/SettingsExtensionsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/SettingsExtensionsController.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.extension import androidx.preference.PreferenceScreen import androidx.preference.SwitchPreference import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.ui.setting.onChange diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsController.kt index 334241c578..66aa13c508 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsController.kt @@ -125,7 +125,8 @@ class ExtensionDetailsController(bundle: Bundle? = null) : screen.setShouldUseGeneratedIds(true) val extHeaderAdapter = ExtensionDetailsHeaderAdapter(presenter) extHeaderAdapter.setHasStableIds(true) - extension_prefs_recycler.adapter = ConcatAdapter(concatAdapterConfig, + extension_prefs_recycler.adapter = ConcatAdapter( + concatAdapterConfig, extHeaderAdapter, PreferenceGroupAdapter(screen) ) @@ -151,7 +152,6 @@ class ExtensionDetailsController(bundle: Bundle? = null) : lastOpenPreferencePosition = savedInstanceState.get(LASTOPENPREFERENCE_KEY) as? Int } - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { inflater.inflate(R.menu.extension_details, menu) @@ -208,8 +208,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : toggleSource(source, checked) prefs.forEach { it.isVisible = checked } true - } - else { + } else { coordinator.snack(context.getString(R.string._must_be_enabled_first, title), Snackbar.LENGTH_LONG) { setAction(R.string.enable) { preferences.enabledLanguages() += source.lang @@ -308,7 +307,6 @@ class ExtensionDetailsController(bundle: Bundle? = null) : return id.toString() !in preferences.hiddenSources().get() && isLangEnabled() } - private fun Source.isLangEnabled(langs: Set? = null): Boolean { return (lang in langs ?: preferences.enabledLanguages().get()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsHeaderAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsHeaderAdapter.kt index 487c094a03..06a0b05a82 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsHeaderAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsHeaderAdapter.kt @@ -45,7 +45,7 @@ class ExtensionDetailsHeaderAdapter(private val presenter: ExtensionDetailsPrese view.extension_pkg.text = extension.pkgName view.extension_uninstall_button.setOnClickListener { - presenter.uninstallExtension() + presenter.uninstallExtension() } if (extension.isObsolete) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionSettingsDividerItemDecoration.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionSettingsDividerItemDecoration.kt index 37f399f8c5..f76fa0bd53 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionSettingsDividerItemDecoration.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionSettingsDividerItemDecoration.kt @@ -51,4 +51,4 @@ class ExtensionSettingsDividerItemDecoration(context: Context) : androidx.recycl ) { outRect.set(0, 0, 0, divider.intrinsicHeight) } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/AddToLibraryCategoriesDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/AddToLibraryCategoriesDialog.kt index 1a8739f2b0..564b316296 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/AddToLibraryCategoriesDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/AddToLibraryCategoriesDialog.kt @@ -41,7 +41,6 @@ class AddToLibraryCategoriesDialog(bundle: Bundle? = null) : } override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog(activity!!).title(R.string.add_to_library).message(R.string.add_to_categories) .listItemsMultiChoice( items = categories.map { it.name }, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt index 7809995b5d..2e3a62f799 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt @@ -29,6 +29,7 @@ class LibraryCategoryAdapter(val controller: LibraryController) : init { setDisplayHeadersAtStartUp(true) } + /** * The list of manga in this category. */ 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 887b3bc864..e2987bef9a 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 @@ -619,13 +619,12 @@ class LibraryController( (listOfYs.minOrNull() ?: filter_bottom_sheet.y) + hopperOffset if (view.height - insetBottom < category_hopper_frame.y) { - jumper_category_text.translationY = -(category_hopper_frame.y - (view.height - insetBottom)) + jumper_category_text.translationY = -(category_hopper_frame.y - (view.height - insetBottom)) } else { jumper_category_text.translationY = 0f } } - fun resetHopperY() { hopperOffset = 0f } @@ -821,10 +820,11 @@ class LibraryController( ) } adapter.setItems(mangaMap) - if (recycler.itemAnimator == null) + if (recycler.itemAnimator == null) { recycler.post { recycler.itemAnimator = DefaultItemAnimator() } + } singleCategory = presenter.categories.size <= 1 showDropdown() progress.gone() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index b41a6c1ddf..8a662cb165 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -70,8 +70,9 @@ class LibraryGridHolder( if (cover_thumbnail.height == 0) { val oldPos = adapterPosition adapter.recyclerView.post { - if (oldPos == adapterPosition) + if (oldPos == adapterPosition) { setCover(item.manga) + } } } else setCover(item.manga) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt index 8cac903330..4b5ee0a28d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt @@ -44,8 +44,9 @@ abstract class LibraryHolder( } fun setReadingButton(item: LibraryItem) { - play_layout?.visibility = if (item.manga.unread > 0 && item.unreadType > 0 && !item.hideReadingButton) - View.VISIBLE else View.GONE + play_layout?.visibility = if (item.manga.unread > 0 && item.unreadType > 0 && !item.hideReadingButton) { + View.VISIBLE + } else View.GONE } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index 13cdb045eb..0aa2683cb1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -46,10 +46,11 @@ class LibraryItem( get() = preferences.hideStartReadingButton().getOrDefault() override fun getLayoutRes(): Int { - return if (libraryLayout == 0 || manga.isBlank()) + return if (libraryLayout == 0 || manga.isBlank()) { R.layout.manga_list_item - else + } else { R.layout.manga_grid_item + } } override fun createViewHolder(view: View, adapter: FlexibleAdapter>): LibraryHolder { @@ -141,11 +142,13 @@ class LibraryItem( * @return true if the manga should be included, false otherwise. */ override fun filter(constraint: String): Boolean { - if (manga.isBlank() && manga.title.isBlank()) + if (manga.isBlank() && manga.title.isBlank()) { return constraint.isEmpty() + } val sourceManager by injectLazy() - val sourceName = if (manga.source == 0L) "Local" else + val sourceName = if (manga.source == 0L) "Local" else { sourceManager.getOrStub(manga.source).name + } return manga.title.contains(constraint, true) || (manga.author?.contains(constraint, true) ?: false) || (manga.artist?.contains(constraint, true) ?: false) || @@ -159,14 +162,15 @@ class LibraryItem( @SuppressLint("DefaultLocale") private fun containsGenre(tag: String, genres: List?): Boolean { if (tag.trim().isEmpty()) return true - return if (tag.startsWith("-")) + return if (tag.startsWith("-")) { genres?.find { it.trim().toLowerCase() == tag.substringAfter("-").toLowerCase() } == null - else + } else { genres?.find { it.trim().toLowerCase() == tag.toLowerCase() } != null + } } override fun equals(other: Any?): Boolean { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index 3c350acd98..b27fe4af73 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -36,7 +36,6 @@ class LibraryListHolder( * @param item the manga item to bind. */ override fun onSetValues(item: LibraryItem) { - title.visible() constraint_layout.minHeight = 56.dpToPx if (item.manga.isBlank()) { @@ -47,8 +46,9 @@ class LibraryListHolder( if (item.manga.status == -1) { title.text = null title.gone() - } else + } else { title.text = itemView.context.getString(R.string.category_is_empty) + } title.textAlignment = View.TEXT_ALIGNMENT_CENTER card.gone() badge_view.gone() 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 39d77cc429..56130d7630 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 @@ -729,8 +729,9 @@ class LibraryPresenter( db.resetMangaInfo(manga).executeOnIO() coverCache.deleteFromCache(manga) val source = sourceManager.get(manga.source) as? HttpSource - if (source != null) + if (source != null) { downloadManager.deleteManga(manga, source) + } } } } @@ -825,9 +826,10 @@ class LibraryPresenter( val mc = ArrayList() val categories = if (catId == 0) emptyList() - else + else { db.getCategoriesForManga(manga).executeOnIO() .filter { it.id != oldCatId } + listOf(category) + } for (cat in categories) { mc.add(MangaCategory.create(manga, cat)) @@ -858,10 +860,11 @@ class LibraryPresenter( val categoriesHidden = preferences.collapsedCategories().getOrDefault().mapNotNull { it.toIntOrNull() }.toMutableSet() - if (categoryId in categoriesHidden) + if (categoryId in categoriesHidden) { categoriesHidden.remove(categoryId) - else + } else { categoriesHidden.add(categoryId) + } preferences.collapsedCategories().set(categoriesHidden.map { it.toString() }.toMutableSet()) getLibrary() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryRecyclerView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryRecyclerView.kt index 46b5f8fd01..a87274d654 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryRecyclerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryRecyclerView.kt @@ -47,8 +47,9 @@ class CategoryRecyclerView @JvmOverloads constructor( } ) fastAdapter.onClickListener = { _, _, item, _ -> - if (item.category.id != -1) + if (item.category.id != -1) { onCategoryClicked(item.category.order) + } true } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt index 5629dc15e7..c23ad80032 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt @@ -20,4 +20,4 @@ class LibraryBadgesView @JvmOverloads constructor(context: Context, attrs: Attri controller.presenter.requestDownloadBadgesUpdate() } } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt index b9ed64cb8d..9ccf40d883 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt @@ -25,4 +25,4 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att controller.resetHopperY() } } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt index 065b94a020..770140f7e0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt @@ -20,4 +20,4 @@ class LibraryDisplayView @JvmOverloads constructor(context: Context, attrs: Attr controller.reattachAdapter() } } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/TabbedLibraryDisplaySheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/TabbedLibraryDisplaySheet.kt index 4917c89967..083459a486 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/TabbedLibraryDisplaySheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/TabbedLibraryDisplaySheet.kt @@ -11,7 +11,7 @@ import eu.kanade.tachiyomi.util.view.withFadeTransaction import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog import kotlinx.android.synthetic.main.tabbed_bottom_sheet.* -open class TabbedLibraryDisplaySheet(controller: LibraryController): +open class TabbedLibraryDisplaySheet(controller: LibraryController) : TabbedBottomSheetDialog(controller.activity!!) { private val displayView: LibraryDisplayView = inflate(controller.activity!!, R.layout.library_display_layout, null) as LibraryDisplayView @@ -26,10 +26,12 @@ open class TabbedLibraryDisplaySheet(controller: LibraryController): if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { menu.tooltipText = context.getString(R.string.more_library_settings) } - menu.setImageDrawable(ContextCompat.getDrawable( - context, - R.drawable.ic_settings_24dp - )) + menu.setImageDrawable( + ContextCompat.getDrawable( + context, + R.drawable.ic_settings_24dp + ) + ) menu.setOnClickListener { controller.router.pushController(SettingsLibraryController().withFadeTransaction()) dismiss() @@ -47,4 +49,4 @@ open class TabbedLibraryDisplaySheet(controller: LibraryController): R.string.badges, R.string.categories ) -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt index 99e9444b7c..9513677a59 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt @@ -90,8 +90,9 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri list.add(unread) list.add(downloaded) list.add(completed) - if (hasTracking) + if (hasTracking) { tracked?.let { list.add(it) } + } list } @@ -152,8 +153,9 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } val activeFilters = hasActiveFiltersFromPref() - if (activeFilters && sheetBehavior.isHidden() && sheetBehavior?.skipCollapsed == false) + if (activeFilters && sheetBehavior.isHidden() && sheetBehavior?.skipCollapsed == false) { sheetBehavior?.collapse() + } post { updateRootPadding( @@ -218,10 +220,11 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri ?: if (sheetBehavior.isExpanded()) 1f else 0f val percent = (trueProgress * 100).roundToInt() val value = (percent * (maxHeight - minHeight) / 100) + minHeight - if (trueProgress >= 0) + if (trueProgress >= 0) { libraryRecyler?.updatePaddingRelative(bottom = value + 10.dpToPx + bottomBarHeight) - else + } else { libraryRecyler?.updatePaddingRelative(bottom = (minHeight * (1 + trueProgress)).toInt() + bottomBarHeight) + } } fun hasActiveFilters() = filterItems.any { it.isActivated } @@ -235,7 +238,6 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } private fun createTags() { - downloaded = inflate(R.layout.filter_buttons) as FilterTagGroup downloaded.setup(this, R.string.downloaded, R.string.not_downloaded) @@ -372,8 +374,9 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri fun manageFilterPopup() { val recycler = RecyclerView(context) - if (filterOrder.count() != 6) + if (filterOrder.count() != 6) { filterOrder = "urdcmt" + } val adapter = FlexibleAdapter( filterOrder.toCharArray().map(::ManageFilterItem), this, @@ -493,8 +496,9 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri private fun reSortViews() { filter_layout.removeAllViews() - if (filterItems.any { it.isActivated }) + if (filterItems.any { it.isActivated }) { filter_layout.addView(clearButton) + } filterItems.filter { it.isActivated }.forEach { filter_layout.addView(it) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterTagGroup.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterTagGroup.kt index 31507c3972..99795e6e0b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterTagGroup.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterTagGroup.kt @@ -84,8 +84,9 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute private fun toggleButton(index: Int, callBack: Boolean = true) { if (index < 0 || itemCount == 0 || (isActivated && index != buttons.indexOfFirst { it.isActivated }) - ) + ) { return + } if (callBack) { val transition = androidx.transition.AutoTransition() transition.duration = 150 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 14aad42238..1a2f849569 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 @@ -268,7 +268,6 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { container: ViewGroup, handler: ControllerChangeHandler ) { - syncActivityViewWithController(to, from, isPush) appbar.y = 0f bottom_nav.translationY = 0f @@ -318,9 +317,9 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { window.navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1) { // basically if in landscape on a phone // For lollipop, draw opaque nav bar - if (insets.hasSideNavBar()) + if (insets.hasSideNavBar()) { Color.BLACK - else Color.argb(179, 0, 0, 0) + } else Color.argb(179, 0, 0, 0) } // if the android q+ device has gesture nav, transparent nav bar // this is here in case some crazy with a notch uses landscape @@ -515,10 +514,10 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { else !router.handleBack() ) { if (preferences.backReturnsToStart().get() && this !is SearchActivity && - startingTab() != bottom_nav?.selectedItemId) { + startingTab() != bottom_nav?.selectedItemId + ) { goToStartingTab() - } - else { + } else { if (!preferences.backReturnsToStart().get() && this !is SearchActivity) { setStartingTab() } @@ -529,13 +528,17 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { } private fun setStartingTab() { - if (bottom_nav?.selectedItemId != R.id.nav_browse - && bottom_nav?.selectedItemId != null - && preferences.startingTab().get() >= 0) - preferences.startingTab().set(when (bottom_nav?.selectedItemId) { - R.id.nav_library -> 0 - else -> 1 - }) + if (bottom_nav?.selectedItemId != R.id.nav_browse && + bottom_nav?.selectedItemId != null && + preferences.startingTab().get() >= 0 + ) { + preferences.startingTab().set( + when (bottom_nav?.selectedItemId) { + R.id.nav_library -> 0 + else -> 1 + } + ) + } } @IdRes diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/EditMangaDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/EditMangaDialog.kt index 99750859e4..46bdde08e6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/EditMangaDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/EditMangaDialog.kt @@ -69,8 +69,9 @@ class EditMangaDialog : DialogController { val isLocal = manga.source == LocalSource.ID if (isLocal) { - if (manga.title != manga.url) + if (manga.title != manga.url) { view.title.append(manga.title) + } view.title.hint = "${resources?.getString(R.string.title)}: ${manga.url}" view.manga_author.append(manga.author ?: "") view.manga_artist.append(manga.artist ?: "") diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index f2d8cbd1ee..7a6df689d0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -434,8 +434,9 @@ class MangaDetailsController : setActionBar(true) setStatusBarAndToolbar() } else if (type == ControllerChangeType.PUSH_EXIT || type == ControllerChangeType.POP_EXIT) { - if (router.backstack.lastOrNull()?.controller() is DialogController) + if (router.backstack.lastOrNull()?.controller() is DialogController) { return + } if (type == ControllerChangeType.POP_EXIT) { setActionBar(false) presenter.cancelScope() @@ -1042,10 +1043,11 @@ class MangaDetailsController : if (chapter.status != Download.NOT_DOWNLOADED && chapter.status != Download.ERROR) { presenter.deleteChapter(chapter) } else { - if (chapter.status == Download.ERROR) + if (chapter.status == Download.ERROR) { DownloadService.start(view.context) - else + } else { downloadChapters(listOf(chapter)) + } } } @@ -1279,8 +1281,9 @@ class MangaDetailsController : override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?): Boolean { mode?.title = view?.context?.getString( - if (startingDLChapterPos == null) - R.string.select_starting_chapter else R.string.select_ending_chapter + if (startingDLChapterPos == null) { + R.string.select_starting_chapter + } else R.string.select_ending_chapter ) return false } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt index ee2acfeea3..f68265ea30 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt @@ -4,7 +4,6 @@ import android.app.Application import android.graphics.Bitmap import android.net.Uri import android.os.Environment -import coil.Coil import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper @@ -88,7 +87,6 @@ class MangaDetailsPresenter( var headerItem = MangaHeaderItem(manga, controller.fromCatalogue) fun onCreate() { - isLockedFromSearch = SecureActivityDelegate.shouldBeLocked() headerItem.isLocked = isLockedFromSearch downloadManager.addListener(this) @@ -218,8 +216,9 @@ class MangaDetailsPresenter( * @return an observable of the list of chapters filtered and sorted. */ private fun applyChapterFilters(chapterList: List): List { - if (isLockedFromSearch) + if (isLockedFromSearch) { return chapterList + } val chapters = chapterFilter.filterChapters(chapterList, manga) @@ -357,8 +356,8 @@ class MangaDetailsPresenter( if (newChapters.first.isNotEmpty()) { if (manga.shouldDownloadNewChapters(db, preferences)) { downloadChapters( - newChapters.first.sortedBy { it.chapter_number } - .map { it.toModel() } + newChapters.first.sortedBy { it.chapter_number } + .map { it.toModel() } ) } } @@ -867,8 +866,9 @@ class MangaDetailsPresenter( fun setStatus(item: TrackItem, index: Int) { val track = item.track!! track.status = item.service.getStatusList()[index] - if (item.service.isCompletedStatus(index) && track.total_chapters > 0) + if (item.service.isCompletedStatus(index) && track.total_chapters > 0) { track.last_chapter_read = track.total_chapters + } updateRemote(track, item.service) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt index 4080f7bf28..16784104e1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt @@ -70,8 +70,8 @@ class MangaHeaderHolder( } if (event.actionMasked == MotionEvent.ACTION_UP) { hadSelection = manga_summary.hasSelection() - (adapter.delegate as MangaDetailsController).swipe_refresh.isEnabled = - true + (adapter.delegate as MangaDetailsController).swipe_refresh.isEnabled = + true } false } @@ -320,9 +320,9 @@ class MangaHeaderHolder( fun collapse() { sub_item_group.gone() start_reading_button.gone() - if (more_button.visibility == View.VISIBLE || more_button.visibility == View.INVISIBLE) + if (more_button.visibility == View.VISIBLE || more_button.visibility == View.INVISIBLE) { more_button_group.invisible() - else { + } else { less_button.gone() manga_genres_tags.gone() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt index 480e1ae1b1..8f4ed65c14 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt @@ -40,10 +40,11 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : BottomSheetD sheetBehavior.addBottomSheetCallback( object : BottomSheetBehavior.BottomSheetCallback() { override fun onSlide(bottomSheet: View, progress: Float) { - if (progress.isNaN()) + if (progress.isNaN()) { pill.alpha = 0f - else + } else { pill.alpha = (1 - max(0f, progress)) * 0.25f + } } override fun onStateChanged(p0: View, state: Int) { @@ -92,14 +93,16 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : BottomSheetD var defPref = presenter.globalSort() sort_group.check( - if (presenter.manga.sortDescending(defPref)) R.id.sort_newest else + if (presenter.manga.sortDescending(defPref)) R.id.sort_newest else { R.id.sort_oldest + } ) hide_titles.isChecked = presenter.manga.displayMode != Manga.DISPLAY_NAME sort_method_group.check( - if (presenter.manga.sorting == Manga.SORTING_SOURCE) R.id.sort_by_source else + if (presenter.manga.sorting == Manga.SORTING_SOURCE) R.id.sort_by_source else { R.id.sort_by_number + } ) set_as_default_sort.visInvisIf( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt index 63c01a552d..5dc315c4aa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt @@ -70,12 +70,14 @@ class SetTrackReadingDatesDialog : DialogController listener.setReadingDate(item, dateToUpdate, 0L) }.apply { getSuggestedDate()?.let { - message(text = it, - applySettings = { - messageTextView.setOnClickListener { - this@apply.setDate(suggestedDate ?: 0L) + message( + text = it, + applySettings = { + messageTextView.setOnClickListener { + this@apply.setDate(suggestedDate ?: 0L) + } } - }) + ) } } } @@ -93,9 +95,11 @@ class SetTrackReadingDatesDialog : DialogController val suggestedCalendar = Calendar.getInstance() suggestedCalendar.timeInMillis = suggestedDate return if (date > suggestedDate && - (suggestedCalendar.year != calendar.year || - suggestedCalendar.month != calendar.month || - suggestedCalendar.dayOfMonth != calendar.dayOfMonth) + ( + suggestedCalendar.year != calendar.year || + suggestedCalendar.month != calendar.month || + suggestedCalendar.dayOfMonth != calendar.dayOfMonth + ) ) { activity?.getString( R.string.suggested_date_, 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 d18e6b87c3..9f60159b58 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 @@ -72,9 +72,9 @@ class TrackHolder(view: View, adapter: TrackAdapter) : BaseViewHolder(view) { date_group.visibleIf(item.service.supportsReadingDates) if (item.service.supportsReadingDates) { track_start_date.text = - if (track.started_reading_date != 0L) dateFormat.format(track.started_reading_date) else "-" + if (track.started_reading_date != 0L) dateFormat.format(track.started_reading_date) else "-" track_finish_date.text = - if (track.finished_reading_date != 0L) dateFormat.format(track.finished_reading_date) else "-" + if (track.finished_reading_date != 0L) dateFormat.format(track.finished_reading_date) else "-" } else { } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackingBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackingBottomSheet.kt index f25767f64a..36d90e11b8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackingBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackingBottomSheet.kt @@ -1,8 +1,6 @@ package eu.kanade.tachiyomi.ui.manga.track import android.content.Intent -import android.graphics.Color -import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.view.View import android.view.ViewGroup @@ -190,11 +188,13 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) : if (item.track == null) return val suggestedDate = presenter.getSuggestedDate(SetTrackReadingDatesDialog.ReadingDate.Start) - SetTrackReadingDatesDialog(controller, + SetTrackReadingDatesDialog( + controller, this, SetTrackReadingDatesDialog.ReadingDate.Start, item, - suggestedDate) + suggestedDate + ) .showDialog(controller.router) } @@ -203,11 +203,13 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) : if (item.track == null) return val suggestedDate = presenter.getSuggestedDate(SetTrackReadingDatesDialog.ReadingDate.Finish) - SetTrackReadingDatesDialog(controller, + SetTrackReadingDatesDialog( + controller, this, SetTrackReadingDatesDialog.ReadingDate.Finish, item, - suggestedDate) + suggestedDate + ) .showDialog(controller.router) } @@ -257,5 +259,4 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) : private companion object { const val TAG_SEARCH_CONTROLLER = "track_search_controller" } - } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MangaItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MangaItem.kt index 68ff99c148..de332353b8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MangaItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MangaItem.kt @@ -24,7 +24,6 @@ class MangaItem(val manga: Manga) : AbstractFlexibleItem() { position: Int, payloads: MutableList? ) { - holder.bind(this) } 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 ca2825934b..47698a80dd 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 @@ -93,7 +93,6 @@ class MigrationPresenter( manga: Manga, replace: Boolean ) { - val flags = preferences.migrateFlags().getOrDefault() val migrateChapters = MigrationFlags.hasChapters(flags) val migrateCategories = MigrationFlags.hasCategories(flags) 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 6522af0536..2c81bd671d 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 @@ -42,8 +42,9 @@ class SearchController( override fun getTitle(): String? { if (totalProgress > 1) { return "($progress/$totalProgress) ${super.getTitle()}" - } else + } else { return super.getTitle() + } } override fun createPresenter(): GlobalSearchPresenter { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceItem.kt index 3c7c92bd3f..61a1e38e89 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceItem.kt @@ -40,7 +40,6 @@ data class SourceItem(val source: Source, val header: SelectionHeader? = null) : position: Int, payloads: MutableList? ) { - holder.bind(this) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt index 043dd98450..5e2b8f79be 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.migration.manga.design import android.graphics.Paint.STRIKE_THRU_TEXT_FLAG import android.view.View import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.icon import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt index ca93125655..289791b29e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt @@ -15,7 +15,6 @@ import com.google.android.material.bottomsheet.BottomSheetDialog import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.controller.BaseController diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt index 1f058bbd0a..c787d30421 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt @@ -54,7 +54,6 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Semaphore import kotlinx.coroutines.sync.withPermit import kotlinx.coroutines.withContext -import rx.schedulers.Schedulers import timber.log.Timber import uy.kohesive.injekt.injectLazy import java.util.concurrent.atomic.AtomicInteger @@ -99,7 +98,6 @@ class MigrationListController(bundle: Bundle? = null) : } override fun onViewCreated(view: View) { - super.onViewCreated(view) liftAppbarWith(recycler) setTitle() @@ -324,7 +322,6 @@ class MigrationListController(bundle: Bundle? = null) : } override fun onMenuItemClick(position: Int, item: MenuItem) { - when (item.itemId) { R.id.action_search_manually -> { launchUI { @@ -377,7 +374,7 @@ class MigrationListController(bundle: Bundle? = null) : try { val newManga = sourceManager.getOrStub(result.source).getMangaDetails(result.toMangaInfo()) - .toSManga() + .toSManga() result.copyFrom(newManga) db.insertManga(result).executeAsBlocking() 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 35bade127a..431ff05fef 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 @@ -33,7 +33,6 @@ import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.model.Page -import eu.kanade.tachiyomi.ui.base.MaterialMenuSheet import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.SearchActivity @@ -283,8 +282,10 @@ class ReaderActivity : override fun onPrepareOptionsMenu(menu: Menu?): Boolean { val detailsItem = menu?.findItem(R.id.action_manga_details) if (presenter.manga?.mangaType(this) != null) { - detailsItem?.title = getString(R.string._details, - presenter.manga?.mangaType(this)?.capitalize(Locale.ROOT) ?: "") + detailsItem?.title = getString( + R.string._details, + presenter.manga?.mangaType(this)?.capitalize(Locale.ROOT) ?: "" + ) } else { detailsItem?.title = getString(R.string.details) } @@ -798,7 +799,6 @@ class ReaderActivity : */ private fun setNotchCutoutMode() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - val currentOrientation = resources.configuration.orientation val params = window.attributes @@ -941,10 +941,11 @@ class ReaderActivity : * Sets the 32-bit color mode according to [enabled]. */ private fun setTrueColor(enabled: Boolean) { - if (enabled) + if (enabled) { SubsamplingScaleImageView.setPreferredBitmapConfig(Bitmap.Config.ARGB_8888) - else + } else { SubsamplingScaleImageView.setPreferredBitmapConfig(Bitmap.Config.RGB_565) + } } /** 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 88bba6e265..b1bbc0ca94 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 @@ -38,7 +38,6 @@ class SaveImageNotifier(private val context: Context) { * @param file image file containing downloaded page image. */ fun onComplete(file: File) { - val request = LoadRequest.Builder(context).memoryCachePolicy(CachePolicy.DISABLED).diskCachePolicy(CachePolicy.DISABLED) .data(file) .size(720, 1280) @@ -64,8 +63,9 @@ class SaveImageNotifier(private val context: Context) { setAutoCancel(true) color = ContextCompat.getColor(context, R.color.colorAccent) // Clear old actions if they exist - if (mActions.isNotEmpty()) + if (mActions.isNotEmpty()) { mActions.clear() + } setContentIntent(NotificationHandler.openImagePendingActivity(context, file)) // Share action diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt index b204647016..8d78cfeb64 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt @@ -192,10 +192,11 @@ class HttpPageLoader( * @param page the page whose source image has to be downloaded. */ private fun HttpSource.fetchImageFromCacheThenNet(page: ReaderPage): Observable { - return if (page.imageUrl.isNullOrEmpty()) + return if (page.imageUrl.isNullOrEmpty()) { getImageUrl(page).flatMap { getCachedImage(it) } - else + } else { getCachedImage(page) + } } private fun HttpSource.getImageUrl(page: ReaderPage): Observable { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderFilterView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderFilterView.kt index 054e52a33a..469ab1e3af 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderFilterView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderFilterView.kt @@ -5,9 +5,7 @@ import android.util.AttributeSet import android.widget.SeekBar import androidx.annotation.ColorInt import eu.kanade.tachiyomi.ui.reader.ReaderActivity -import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener import eu.kanade.tachiyomi.widget.BaseReaderSettingsView -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.view.* @@ -115,7 +113,6 @@ class ReaderFilterView @JvmOverloads constructor(context: Context, attrs: Attrib ) } - /** * Set enabled status of seekBars belonging to color filter * @param enabled determines if seekBar gets enabled @@ -202,7 +199,7 @@ class ReaderFilterView @JvmOverloads constructor(context: Context, attrs: Attrib * Sets the color filter overlay of the screen. Determined by HEX of integer * @param color hex of color. */ - private fun setColorFilterValue(@ColorInt color: Int) { + private fun setColorFilterValue(@ColorInt color: Int) { setValues(color) } @@ -267,4 +264,4 @@ class ReaderFilterView @JvmOverloads constructor(context: Context, attrs: Attrib */ fun ReaderFilterView.getGreenFromColor(color: Int): Int { return color shr 8 and 0xFF -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderGeneralView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderGeneralView.kt index 6c37bc6929..47f3626f54 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderGeneralView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderGeneralView.kt @@ -4,9 +4,7 @@ import android.content.Context import android.util.AttributeSet import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.bindToPreference -import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener import eu.kanade.tachiyomi.widget.BaseReaderSettingsView -import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener import kotlinx.android.synthetic.main.reader_general_layout.view.* class ReaderGeneralView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : @@ -43,4 +41,4 @@ class ReaderGeneralView @JvmOverloads constructor(context: Context, attrs: Attri private fun initPagerPreferences() { sheet.updateTabs(false) } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt index aec16c0689..42988d5650 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt @@ -44,4 +44,4 @@ class ReaderPagedView @JvmOverloads constructor(context: Context, attrs: Attribu listOf(scale_type, zoom_start, crop_borders, page_transitions, pager_nav, pager_invert).forEach { it.visibleIf(show) } listOf(crop_borders_webtoon, webtoon_side_padding, webtoon_enable_zoom_out, webtoon_nav, webtoon_invert).forEach { it.visibleIf(!show) } } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderSpinnerView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderSpinnerView.kt index 499fe78165..b70d4fbba6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderSpinnerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderSpinnerView.kt @@ -12,16 +12,14 @@ import com.tfcporciuncula.flow.Preference import eu.kanade.tachiyomi.R import kotlinx.android.synthetic.main.reader_preference.view.* - class ReaderSpinnerView @JvmOverloads constructor(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) { - private var entries = emptyList() private var selectedPosition = 0 private var pref: Preference? = null private var prefOffset = 0 - private var popup:PopupMenu? = null + private var popup: PopupMenu? = null var onItemSelectedListener: ((Int) -> Unit)? = null set(value) { @@ -159,11 +157,11 @@ class ReaderSpinnerView @JvmOverloads constructor(context: Context, attrs: Attri fun popup(): PopupMenu { val popup = PopupMenu(context, this, Gravity.END) - entries.forEachIndexed { index, entry -> + entries.forEachIndexed { index, entry -> popup.menu.add(0, index, 0, entry) } popup.menu[selectedPosition].isCheckable = true popup.menu[selectedPosition].isChecked = true return popup } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/TabbedReaderSettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/TabbedReaderSettingsSheet.kt index 404b3f0a17..e4788db572 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/TabbedReaderSettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/TabbedReaderSettingsSheet.kt @@ -1,22 +1,19 @@ package eu.kanade.tachiyomi.ui.reader.settings import android.view.View -import androidx.core.widget.NestedScrollView import com.google.android.material.tabs.TabLayout import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.library.display.LibraryBadgesView import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.visInvisIf import eu.kanade.tachiyomi.util.view.visible -import eu.kanade.tachiyomi.util.view.visibleIf import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog import kotlinx.android.synthetic.main.reader_activity.* import kotlinx.android.synthetic.main.reader_color_filter.view.* import kotlinx.android.synthetic.main.recycler_with_scroller.view.* import kotlinx.android.synthetic.main.tabbed_bottom_sheet.* -class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity): TabbedBottomSheetDialog( +class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) : TabbedBottomSheetDialog( readerActivity ) { private val generalView: ReaderGeneralView = View.inflate( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt index 21c0a0ce91..dd025d8cf3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt @@ -27,7 +27,6 @@ abstract class ViewerConfig(preferences: PreferencesHelper) { var volumeKeysInverted = false var alwaysShowChapterTransition = true - var navigationOverlayForNewUser = false var navigationMode = 0 protected set diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerNavigation.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerNavigation.kt index 2bd5d79848..8b04c947e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerNavigation.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerNavigation.kt @@ -17,8 +17,7 @@ abstract class ViewerNavigation { fun directionalRegion(LTR: Boolean): NavigationRegion { return if (this === LEFT || this === RIGHT) { if (if (LTR) this === LEFT else this === RIGHT) NEXT else PREV - } - else this + } else this } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt index d7ad37c8da..6577970b6f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt @@ -45,9 +45,12 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe .register({ navigationMode = it }, { updateNavigation(navigationMode) }) preferences.pagerNavInverted() - .register({ tappingInverted = it }, { - navigator.invertMode = it - }) + .register( + { tappingInverted = it }, + { + navigator.invertMode = it + } + ) preferences.pagerNavInverted().asFlow() .drop(1) 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 8df77e23ef..a54f4b2a79 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 @@ -340,7 +340,6 @@ class PagerPageHolder( @SuppressLint("PrivateResource") private fun createProgressBar(): ReaderProgressBar { return ReaderProgressBar(context, null).apply { - val size = 48.dpToPx layoutParams = LayoutParams(size, size).apply { gravity = Gravity.CENTER 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 30e568b97c..720171e4e7 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 @@ -24,6 +24,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { private set var currentChapter: ReaderChapter? = null + /** * Updates this adapter with the given [chapters]. It handles setting a few pages of the * next/previous chapter to allow seamless transitions and inverting the pages if the viewer 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..f6d28ff49f 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 @@ -22,6 +22,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter + recycler.tapListener = f@{ event -> if (!config.tappingEnabled) { activity.toggleMenu() return@f diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt index 81e61ee240..8293aa5eb3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt @@ -44,6 +44,7 @@ class RecentlyReadController(bundle: Bundle? = null) : init { setHasOptionsMenu(true) } + /** * Adapter containing the recent manga. */ @@ -85,8 +86,9 @@ class RecentlyReadController(bundle: Bundle? = null) : resetProgressItem() scrollViewWith(recycler, padBottom = true) - if (recentItems != null) + if (recentItems != null) { adapter?.updateDataSet(recentItems!!.toList()) + } launchUI { val manga = presenter.refresh(query) @@ -106,6 +108,7 @@ class RecentlyReadController(bundle: Bundle? = null) : observeLater = false } } + /** * Populate adapter with chapters * @@ -115,8 +118,9 @@ class RecentlyReadController(bundle: Bundle? = null) : val adapter = adapter ?: return adapter.updateDataSet(mangaHistory) adapter.onLoadMoreComplete(null) - if (recentItems == null) + if (recentItems == null) { resetProgressItem() + } recentItems = mangaHistory.toMutableList() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadItem.kt index 527a4f21bc..d08c40bf13 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadItem.kt @@ -24,7 +24,6 @@ class RecentlyReadItem(val mch: MangaChapterHistory) : AbstractFlexibleItem? ) { - holder.bind(mch) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt index 4bd543e306..694c7641ee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt @@ -40,7 +40,6 @@ import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.spToPx import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.expand -import eu.kanade.tachiyomi.util.view.isCollapsed import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.requestPermissionsSafe import eu.kanade.tachiyomi.util.view.scrollViewWith @@ -95,9 +94,9 @@ class RecentsController(bundle: Bundle? = null) : var headerHeight = 0 override fun getTitle(): String? { - return if (showingDownloads) + return if (showingDownloads) { resources?.getString(R.string.download_queue) - else resources?.getString(R.string.recents) + } else resources?.getString(R.string.recents) } override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { @@ -243,8 +242,9 @@ class RecentsController(bundle: Bundle? = null) : val pad = bottomBar.translationY - bottomBar.height val padding = max( (-pad).toInt(), - if (dl_bottom_sheet.sheetBehavior.isExpanded()) 0 else + if (dl_bottom_sheet.sheetBehavior.isExpanded()) 0 else { view?.rootWindowInsets?.systemWindowInsetBottom ?: 0 + } ) shadow2.translationY = pad dl_bottom_sheet.sheetBehavior?.peekHeight = 48.spToPx + padding @@ -303,8 +303,9 @@ class RecentsController(bundle: Bundle? = null) : swipe_refresh.isRefreshing = LibraryUpdateService.isRunning() adapter.updateItems(recents) adapter.removeAllScrollableHeaders() - if (presenter.viewType > 0) + if (presenter.viewType > 0) { adapter.addScrollableHeader(presenter.generalHeader) + } if (lastChapterId != null) { refreshItem(lastChapterId ?: 0L) lastChapterId = null @@ -380,8 +381,9 @@ class RecentsController(bundle: Bundle? = null) : val manga = item.mch.manga val history = item.mch.history val chapter = item.mch.chapter - if (history.id != null) + if (history.id != null) { RemoveHistoryDialog(this, manga, history, chapter).showDialog(router) + } } override fun removeHistory(manga: Manga, history: History, all: Boolean) { @@ -476,7 +478,7 @@ class RecentsController(bundle: Bundle? = null) : setBottomPadding() } - override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType ) { + override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) { super.onChangeEnded(handler, type) if (type == ControllerChangeType.POP_ENTER) setBottomPadding() } @@ -484,8 +486,9 @@ class RecentsController(bundle: Bundle? = null) : fun hasQueue() = presenter.downloadManager.hasQueue() override fun showSheet() { - if (dl_bottom_sheet.sheetBehavior?.isHideable == false || hasQueue()) + if (dl_bottom_sheet.sheetBehavior?.isHideable == false || hasQueue()) { dl_bottom_sheet.sheetBehavior?.expand() + } } override fun toggleSheet() { @@ -498,13 +501,15 @@ class RecentsController(bundle: Bundle? = null) : override fun expandSearch() { if (showingDownloads) { dl_bottom_sheet.dismiss() - } else + } else { activity?.toolbar?.menu?.findItem(R.id.action_search)?.expandActionView() + } } override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (showingDownloads) + if (showingDownloads) { return dl_bottom_sheet.onOptionsItemSelected(item) + } when (item.itemId) { R.id.action_group_all, R.id.action_ungroup_all, R.id.action_only_history, R.id.action_only_updates -> { @@ -516,8 +521,9 @@ class RecentsController(bundle: Bundle? = null) : else -> 0 } ) - if (item.itemId == R.id.action_only_history) + if (item.itemId == R.id.action_only_history) { activity?.toast(R.string.press_and_hold_to_reset_history, Toast.LENGTH_LONG) + } activity?.invalidateOptionsMenu() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt index 768f06bab2..bfcf57679f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt @@ -56,8 +56,9 @@ class RecentsPresenter( downloadManager.addListener(this) LibraryUpdateService.setListener(this) if (lastRecents != null) { - if (recentItems.isEmpty()) + if (recentItems.isEmpty()) { recentItems = lastRecents ?: emptyList() + } lastRecents = null } getRecents() @@ -95,14 +96,15 @@ class RecentsPresenter( } } - val cReading = if (viewType != 3) - if (query.isEmpty() && viewType != 2) + val cReading = if (viewType != 3) { + if (query.isEmpty() && viewType != 2) { db.getRecentsWithUnread(cal.time, query, isUngrouped).executeOnIO() - else db.getRecentMangaLimit( + } else db.getRecentMangaLimit( cal.time, if (viewType == 2) 200 else 8, query - ).executeOnIO() else emptyList() + ).executeOnIO() + } else emptyList() val rUpdates = when { viewType == 3 -> db.getRecentChapters(calWeek.time).executeOnIO().map { MangaChapterHistory(it.manga, it.chapter, HistoryImpl()) @@ -113,8 +115,9 @@ class RecentsPresenter( rUpdates.forEach { it.history.last_read = it.chapter.date_fetch } - val nAdditions = if (viewType < 2) - db.getRecentlyAdded(calDay.time, query, isUngrouped).executeOnIO() else emptyList() + val nAdditions = if (viewType < 2) { + db.getRecentlyAdded(calDay.time, query, isUngrouped).executeOnIO() + } else emptyList() nAdditions.forEach { it.history.last_read = it.manga.date_added } @@ -144,10 +147,11 @@ class RecentsPresenter( Comparator> { f1, f2 -> if (abs(f1.second.date_fetch - f2.second.date_fetch) <= TimeUnit.HOURS.toMillis(12) - ) + ) { f2.second.date_upload.compareTo(f1.second.date_upload) - else + } else { f2.second.date_fetch.compareTo(f1.second.date_fetch) + } } ) .take(4).map { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/AboutController.kt index 0e720e5856..5858bd67f2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/AboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/AboutController.kt @@ -10,7 +10,6 @@ import com.google.android.gms.oss.licenses.OssLicensesMenuActivity import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.updater.UpdateChecker import eu.kanade.tachiyomi.data.updater.UpdateResult import eu.kanade.tachiyomi.data.updater.UpdaterService 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 6078b631d2..c22d8419b9 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 @@ -46,8 +46,8 @@ inline fun PreferenceGroup.editTextPreference(block: (@DSL EditTextPreference).( inline fun PreferenceGroup.dropDownPreference(block: (@DSL DropDownPreference).() -> Unit): DropDownPreference { - return initThenAdd(DropDownPreference(context), block).also(::initDialog) - } + return initThenAdd(DropDownPreference(context), block).also(::initDialog) +} inline fun PreferenceGroup.listPreference( activity: Activity?, @@ -55,8 +55,8 @@ inline fun PreferenceGroup.listPreference( -> Unit ): ListMatPreference { - return initThenAdd(ListMatPreference(activity, context), block) - } + return initThenAdd(ListMatPreference(activity, context), block) +} inline fun PreferenceGroup.intListPreference( activity: Activity?, @@ -66,8 +66,8 @@ inline fun PreferenceGroup.intListPreference( ).() -> Unit ): IntListMatPreference { - return initThenAdd(IntListMatPreference(activity, context), block) - } + return initThenAdd(IntListMatPreference(activity, context), block) +} inline fun PreferenceGroup.multiSelectListPreferenceMat( activity: Activity?, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt index 45ab82ffae..8da020d7bc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt @@ -186,9 +186,7 @@ class SettingsAdvancedController : SettingsController() { class CleanupDownloadsDialogController() : DialogController() { override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog(activity!!).show { - title(R.string.clean_up_downloaded_chapters) .listItemsMultiChoice(R.array.clean_up_downloads, disabledIndices = intArrayOf(0), initialSelection = intArrayOf(0, 1, 2)) { dialog, selections, items -> val deleteRead = selections.contains(1) 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 2f4903b1e8..780a69c52a 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 @@ -151,7 +151,7 @@ class SettingsBackupController : SettingsController() { defaultValue = true preferences.backupInterval().asImmediateFlow { isVisible = it > 0 } - .launchIn(viewScope) + .launchIn(viewScope) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt index 1562903ed9..3a6bef597b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt @@ -9,7 +9,6 @@ import eu.kanade.tachiyomi.extension.ExtensionUpdateJob import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.migration.MigrationController -import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.withFadeTransaction import kotlinx.coroutines.flow.launchIn diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt index 91ca153fc7..4fab467f7f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt @@ -20,7 +20,6 @@ import com.bluelinelabs.conductor.ControllerChangeType import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.controller.BaseController -import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.view.scrollViewWith import kotlinx.coroutines.MainScope import rx.Observable 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 6910748ba8..f7dc58fea2 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 @@ -97,15 +97,16 @@ class SettingsDownloadController : SettingsController() { preferences.downloadNew().asImmediateFlow { isVisible = it } preferences.downloadNewCategories().asImmediateFlow { list -> - val selectedCategories = list - .mapNotNull { id -> dbCategories.find { it.id == id.toInt() } } - .sortedBy { it.order } + val selectedCategories = list + .mapNotNull { id -> dbCategories.find { it.id == id.toInt() } } + .sortedBy { it.order } - customSummary = if (selectedCategories.isEmpty()) - resources?.getString(R.string.all) - else - selectedCategories.joinToString { it.name } + customSummary = if (selectedCategories.isEmpty()) { + resources?.getString(R.string.all) + } else { + selectedCategories.joinToString { it.name } } + } } preferenceCategory { intListPreference(activity) { 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 a4b35de9a5..5924e5d264 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 @@ -137,7 +137,7 @@ class SettingsLibraryController : SettingsController() { preferences.libraryUpdateCategories().asImmediateFlow { list -> val selectedCategories = - list.mapNotNull { id -> dbCategories.find { it.id == id.toInt() } } + list.mapNotNull { id -> dbCategories.find { it.id == id.toInt() } } .sortedBy { it.order } customSummary = diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt index c837608383..222eebbec9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt @@ -7,8 +7,6 @@ import androidx.appcompat.widget.SearchView import androidx.preference.PreferenceScreen import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.RouterTransaction -import com.bluelinelabs.conductor.changehandler.FadeChangeHandler -import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.setting.search.SettingsSearchController import eu.kanade.tachiyomi.util.system.getResourceColor @@ -98,7 +96,8 @@ class SettingsMainController : SettingsController() { override fun onMenuItemActionExpand(item: MenuItem?): Boolean { SettingsSearchController.lastSearch = "" // reset saved search query router.pushController( - RouterTransaction.with(SettingsSearchController())) + RouterTransaction.with(SettingsSearchController()) + ) return true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt index c9b7043676..9ab700f6e2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt @@ -95,7 +95,6 @@ class SettingsSourcesController : SettingsController() { val hiddenCatalogues = preferences.hiddenSources().get() val selectAllPreference = CheckBoxPreference(group.context).apply { - title = "\t\t${context.getString(R.string.all_sources)}" key = "all_${sources.first().lang}" isPersistent = false @@ -105,10 +104,11 @@ class SettingsSourcesController : SettingsController() { onChange { newValue -> val checked = newValue as Boolean val current = preferences.hiddenSources().get().toMutableSet() - if (checked) + if (checked) { current.removeAll(sources.map { it.id.toString() }) - else + } else { current.addAll(sources.map { it.id.toString() }) + } preferences.hiddenSources().set(current) group.removeAll() addLanguageSources(group, sortedSources(sources)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt index e6dc13c654..4c55d167ce 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt @@ -1,9 +1,6 @@ package eu.kanade.tachiyomi.ui.setting import android.app.Activity -import android.content.Intent -import android.net.Uri -import androidx.browser.customtabs.CustomTabsIntent import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.track.TrackManager @@ -12,7 +9,6 @@ import eu.kanade.tachiyomi.data.track.anilist.AnilistApi import eu.kanade.tachiyomi.data.track.bangumi.BangumiApi import eu.kanade.tachiyomi.data.track.myanimelist.MyAnimeListApi import eu.kanade.tachiyomi.data.track.shikimori.ShikimoriApi -import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.widget.preference.LoginPreference import eu.kanade.tachiyomi.widget.preference.TrackLoginDialog @@ -63,21 +59,21 @@ class SettingsTrackingController : crossinline login: () -> Unit ): LoginPreference { return initThenAdd( - LoginPreference(context).apply { - key = Keys.trackUsername(service.id) - title = context.getString(service.nameRes()) - }, - { - onClick { - if (service.isLogged) { - val dialog = TrackLogoutDialog(service) - dialog.targetController = this@SettingsTrackingController - dialog.showDialog(router) - } else { - login() - } + LoginPreference(context).apply { + key = Keys.trackUsername(service.id) + title = context.getString(service.nameRes()) + }, + { + onClick { + if (service.isLogged) { + val dialog = TrackLogoutDialog(service) + dialog.targetController = this@SettingsTrackingController + dialog.showDialog(router) + } else { + login() } } + } ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchHolder.kt index 4bfe35562f..2c63bbe1a9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchHolder.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.ui.setting.search -import android.text.Html import android.view.View import androidx.core.content.ContextCompat import androidx.core.graphics.ColorUtils @@ -19,7 +18,6 @@ import kotlin.reflect.full.createInstance class SettingsSearchHolder(view: View, val adapter: SettingsSearchAdapter) : FlexibleViewHolder(view, adapter) { - init { view.title_wrapper.setOnClickListener { adapter.getItem(bindingAdapterPosition)?.let { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/AnilistLoginActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/AnilistLoginActivity.kt index e0c85741cb..0977906953 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/AnilistLoginActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/AnilistLoginActivity.kt @@ -1,23 +1,8 @@ package eu.kanade.tachiyomi.ui.setting.track -import android.content.Intent import android.net.Uri -import android.os.Bundle -import android.view.Gravity.CENTER -import android.view.ViewGroup.LayoutParams.WRAP_CONTENT -import android.widget.FrameLayout -import android.widget.ProgressBar -import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope -import eu.kanade.tachiyomi.data.track.TrackManager -import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.util.system.launchIO -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Job -import kotlinx.coroutines.cancel -import kotlinx.coroutines.launch -import uy.kohesive.injekt.injectLazy class AnilistLoginActivity : BaseOAuthLoginActivity() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/BangumiLoginActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/BangumiLoginActivity.kt index 90b1aca5df..bc2fbf7a08 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/BangumiLoginActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/BangumiLoginActivity.kt @@ -1,22 +1,8 @@ package eu.kanade.tachiyomi.ui.setting.track -import android.content.Intent import android.net.Uri -import android.os.Bundle -import android.view.Gravity.CENTER -import android.view.ViewGroup.LayoutParams.WRAP_CONTENT -import android.widget.FrameLayout -import android.widget.ProgressBar -import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope -import eu.kanade.tachiyomi.data.track.TrackManager -import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.util.system.launchIO -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Job -import kotlinx.coroutines.launch -import uy.kohesive.injekt.injectLazy class BangumiLoginActivity : BaseOAuthLoginActivity() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/ShikimoriLoginActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/ShikimoriLoginActivity.kt index ccbc444389..136d014ff8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/ShikimoriLoginActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/ShikimoriLoginActivity.kt @@ -1,22 +1,8 @@ package eu.kanade.tachiyomi.ui.setting.track -import android.content.Intent import android.net.Uri -import android.os.Bundle -import android.view.Gravity.CENTER -import android.view.ViewGroup.LayoutParams.WRAP_CONTENT -import android.widget.FrameLayout -import android.widget.ProgressBar -import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope -import eu.kanade.tachiyomi.data.track.TrackManager -import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.util.system.launchIO -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Job -import kotlinx.coroutines.launch -import uy.kohesive.injekt.injectLazy class ShikimoriLoginActivity : BaseOAuthLoginActivity() { override fun handleResult(data: Uri?) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt index 18c7400372..3cbcadd3c7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt @@ -38,7 +38,6 @@ import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController import eu.kanade.tachiyomi.ui.source.latest.LatestUpdatesController import eu.kanade.tachiyomi.util.system.dpToPx -import eu.kanade.tachiyomi.util.system.getBottomGestureInsets import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.spToPx @@ -110,14 +109,14 @@ class SourceController : } override fun getTitle(): String? { - return if (showingExtensions) + return if (showingExtensions) { view?.context?.getString( when (ext_bottom_sheet.tabs.selectedTabPosition) { 0 -> R.string.extensions else -> R.string.source_migration } ) - else view?.context?.getString(R.string.sources) + } else view?.context?.getString(R.string.sources) } override fun createPresenter(): SourcePresenter { @@ -203,14 +202,15 @@ class SourceController : ) { showingExtensions = state == BottomSheetBehavior.STATE_EXPANDED setTitle() - if (state == BottomSheetBehavior.STATE_EXPANDED) + if (state == BottomSheetBehavior.STATE_EXPANDED) { extBottomSheet.fetchOnlineExtensionsIfNeeded() - else extBottomSheet.shouldCallApi = true + } else extBottomSheet.shouldCallApi = true activity?.invalidateOptionsMenu() } - retainViewMode = if (state == BottomSheetBehavior.STATE_EXPANDED) - RetainViewMode.RETAIN_DETACH else RetainViewMode.RELEASE_DETACH + retainViewMode = if (state == BottomSheetBehavior.STATE_EXPANDED) { + RetainViewMode.RETAIN_DETACH + } else RetainViewMode.RELEASE_DETACH sheet_layout.isClickable = state == BottomSheetBehavior.STATE_COLLAPSED sheet_layout.isFocusable = state == BottomSheetBehavior.STATE_COLLAPSED setBottomSheetTabs(if (state == BottomSheetBehavior.STATE_COLLAPSED) 0f else 1f) @@ -249,18 +249,21 @@ class SourceController : ColorUtils.blendARGB( bottomSheet.context.getResourceColor(R.attr.actionBarTintColor), unselectedColor, - progress), + progress + ), ColorUtils.blendARGB( bottomSheet.context.getResourceColor(R.attr.actionBarTintColor), selectedColor, - progress) + progress + ) ) ext_bottom_sheet.sheet_layout.backgroundTintList = ColorStateList.valueOf( ColorUtils.blendARGB( bottomSheet.context.getResourceColor(R.attr.colorPrimaryVariant), bottomSheet.context.getResourceColor(R.attr.colorSecondary), - progress) + progress + ) ) } @@ -270,8 +273,9 @@ class SourceController : val pad = bottomBar.translationY - bottomBar.height val padding = max( (-pad).toInt(), - if (ext_bottom_sheet.sheetBehavior.isExpanded()) 0 else + if (ext_bottom_sheet.sheetBehavior.isExpanded()) 0 else { view?.rootWindowInsets?.systemWindowInsetBottom ?: 0 + } ) shadow2.translationY = pad ext_bottom_sheet.sheetBehavior?.peekHeight = 58.spToPx + padding @@ -479,9 +483,9 @@ class SourceController : // Initialize option to open catalogue settings. R.id.action_filter -> { val controller = - if (showingExtensions) + if (showingExtensions) { SettingsExtensionsController() - else SettingsSourcesController() + } else SettingsSourcesController() router.pushController( (RouterTransaction.with(controller)).popChangeHandler( SettingsSourcesFadeChangeHandler() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt index e7b0af4673..db0113c49f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt @@ -71,11 +71,13 @@ open class BrowseSourceController(bundle: Bundle) : Bundle().apply { putLong(SOURCE_ID_KEY, source.id) - if (searchQuery != null) + if (searchQuery != null) { putString(SEARCH_QUERY_KEY, searchQuery) + } - if (smartSearchConfig != null) + if (smartSearchConfig != null) { putParcelable(SMART_SEARCH_CONFIG_KEY, smartSearchConfig) + } } ) @@ -206,10 +208,11 @@ open class BrowseSourceController(bundle: Bundle) : recycler.addOnScrollListener( object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { - if (dy <= 0) + if (dy <= 0) { fab.extend() - else + } else { fab.shrink() + } } } ) @@ -260,10 +263,11 @@ open class BrowseSourceController(bundle: Bundle) : // Show next display mode menu.findItem(R.id.action_display_mode).apply { - val icon = if (presenter.isListMode) + val icon = if (presenter.isListMode) { R.drawable.ic_view_module_24dp - else + } else { R.drawable.ic_view_list_24dp + } setIcon(icon) } } @@ -367,8 +371,9 @@ open class BrowseSourceController(bundle: Bundle) : */ private fun searchWithQuery(newQuery: String) { // If text didn't change, do nothing - if (presenter.query == newQuery) + if (presenter.query == newQuery) { return + } showProgressBar() adapter?.clear() @@ -407,7 +412,6 @@ open class BrowseSourceController(bundle: Bundle) : val message = getErrorMessage(error) val retryAction = View.OnClickListener { - // If not the first page, show bottom progress bar. if (adapter.mainItemCount > 0 && progressItem != null) { adapter.addScrollableFooterWithDelay(progressItem!!, 0, true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceItem.kt index 8eaa6936c7..3460fd0411 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceItem.kt @@ -28,10 +28,11 @@ class BrowseSourceItem( AbstractFlexibleItem() { override fun getLayoutRes(): Int { - return if (catalogueAsList.getOrDefault()) + return if (catalogueAsList.getOrDefault()) { R.layout.manga_list_item - else + } else { R.layout.manga_grid_item + } } override fun createViewHolder(view: View, adapter: FlexibleAdapter>): BrowseSourceHolder { @@ -81,7 +82,6 @@ class BrowseSourceItem( position: Int, payloads: MutableList? ) { - holder.onSetValues(manga) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourcePager.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourcePager.kt index a28f38b6c1..2c7e4b60fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourcePager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourcePager.kt @@ -12,10 +12,11 @@ open class BrowseSourcePager(val source: CatalogueSource, val query: String, val override fun requestNext(): Observable { val page = currentPage - val observable = if (query.isBlank() && filters.isEmpty()) + val observable = if (query.isBlank() && filters.isEmpty()) { source.fetchPopularManga(page) - else + } else { source.fetchSearchManga(page, query, filters) + } return observable .subscribeOn(Schedulers.io()) 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 799107abcc..a1569d4ecb 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 @@ -406,13 +406,15 @@ open class BrowseSourcePresenter( */ fun updateMangaCategories(manga: Manga, selectedCategories: List) { if (selectedCategories.isNotEmpty()) { - if (!manga.favorite) + if (!manga.favorite) { changeMangaFavorite(manga) + } moveMangaToCategories(manga, selectedCategories.filter { it.id != 0 }) } else { - if (!manga.favorite) + if (!manga.favorite) { changeMangaFavorite(manga) + } } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt index 25d40d90df..3a27580a6d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt @@ -119,8 +119,9 @@ class SourceSearchSheet(activity: Activity) : override fun dismiss() { super.dismiss() - if (filterChanged) + if (filterChanged) { onSearchClicked() + } } fun setFilters(items: List>) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/filter/GroupItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/filter/GroupItem.kt index 50f4d6f983..67f49f0553 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/filter/GroupItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/filter/GroupItem.kt @@ -35,10 +35,11 @@ class GroupItem(val filter: Filter.Group<*>) : AbstractExpandableHeaderItem SharedPreferences.getItem(key: String, default: T): T { } } - /** * Binds a checkbox or switch view with a boolean preference. */ @@ -113,4 +111,4 @@ fun Spinner.bindToIntPreference(pref: com.tfcporciuncula.flow.Preference, @ pref.set(intValues[position] ?: 0) } setSelection(intValues.indexOf(pref.get()), false) -} \ No newline at end of file +} 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 469153412a..ba1360ba8c 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 @@ -39,8 +39,9 @@ object ChapterRecognition { fun parseChapterNumber(chapter: SChapter, manga: SManga) { // If chapter number is known return. - if (chapter.chapter_number == -2f || chapter.chapter_number > -1f) + if (chapter.chapter_number == -2f || chapter.chapter_number > -1f) { return + } // Get chapter title with lower case var name = chapter.name.toLowerCase() @@ -59,8 +60,9 @@ object ChapterRecognition { } // Check base case ch.xx - if (updateChapter(basic.find(name), chapter)) + if (updateChapter(basic.find(name), chapter)) { return + } // Check one number occurrence. val occurrences: MutableList = arrayListOf() @@ -69,20 +71,23 @@ object ChapterRecognition { } if (occurrences.size == 1) { - if (updateChapter(occurrences[0], chapter)) + if (updateChapter(occurrences[0], chapter)) { return + } } // Remove manga title from chapter title. val nameWithoutManga = name.replace(manga.originalTitle.toLowerCase(), "").trim() // Check if first value is number after title remove. - if (updateChapter(withoutManga.find(nameWithoutManga), chapter)) + if (updateChapter(withoutManga.find(nameWithoutManga), chapter)) { return + } // Take the first number encountered. - if (updateChapter(occurrence.find(nameWithoutManga), chapter)) + if (updateChapter(occurrence.find(nameWithoutManga), chapter)) { return + } } /** @@ -110,18 +115,22 @@ object ChapterRecognition { * @return decimal/alpha float value */ private fun checkForDecimal(decimal: String?, alpha: String?): Float { - if (!decimal.isNullOrEmpty()) + if (!decimal.isNullOrEmpty()) { return decimal.toFloat() + } if (!alpha.isNullOrEmpty()) { - if (alpha.contains("extra")) + if (alpha.contains("extra")) { return .99f + } - if (alpha.contains("omake")) + if (alpha.contains("omake")) { return .98f + } - if (alpha.contains("special")) + if (alpha.contains("special")) { return .97f + } if (alpha[0] == '.') { // Take value after (.) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt index 9f00d84db9..74850f6de5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt @@ -27,7 +27,6 @@ fun syncChaptersWithSource( manga: Manga, source: Source ): Pair, List> { - if (rawSourceChapters.isEmpty()) { throw Exception("No chapters found") } @@ -151,8 +150,9 @@ fun syncChaptersWithSource( val newestChapter = db.getChapters(manga).executeAsBlocking().maxBy { it.date_upload } val dateFetch = newestChapter?.date_upload ?: manga.last_update if (dateFetch == 0L) { - if (toAdd.isNotEmpty()) + if (toAdd.isNotEmpty()) { manga.last_update = Date().time + } } else manga.last_update = dateFetch db.updateLastUpdated(manga).executeAsBlocking() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt index 84b6200c68..4b09162dcc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt @@ -1,24 +1,22 @@ package eu.kanade.tachiyomi.util.lang -import android.graphics.Color import android.text.Spannable import android.text.SpannableString import android.text.Spanned import android.text.style.BackgroundColorSpan import androidx.annotation.ColorInt -import androidx.annotation.ColorRes import kotlin.math.floor - /** * Replaces the given string to have at most [count] characters using [replacement] at its end. * If [replacement] is longer than [count] an exception will be thrown when `length > count`. */ fun String.chop(count: Int, replacement: String = "..."): String { - return if (length > count) + return if (length > count) { take(count - replacement.length) + replacement - else + } else { this + } } fun String.removeArticles(): String { @@ -43,8 +41,9 @@ fun String.trimOrNull(): String? { * If [replacement] is longer than [count] an exception will be thrown when `length > count`. */ fun String.truncateCenter(count: Int, replacement: String = "..."): String { - if (length <= count) + if (length <= count) { return this + } val pieceLength: Int = floor((count - replacement.length).div(2.0)).toInt() @@ -76,11 +75,11 @@ fun String.indexesOf(substr: String, ignoreCase: Boolean = true): List { if (substr.isBlank()) return list var i = -1 - while(true) { + while (true) { i = indexOf(substr, i + 1, ignoreCase) when (i) { -1 -> return list else -> list.add(i) } } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/storage/FileExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/storage/FileExtensions.kt index 53523c6d4c..8482bd8f6f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/storage/FileExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/storage/FileExtensions.kt @@ -13,7 +13,7 @@ import java.io.File * @param context context of application */ fun File.getUriCompat(context: Context): Uri { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", this) - else Uri.fromFile(this) + } else Uri.fromFile(this) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index cd2bb232bf..cbe468f519 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -245,12 +245,12 @@ fun Context.openInBrowser(url: String, @ColorInt toolbarColor: Int? = null) { fun Context.openInBrowser(uri: Uri, @ColorInt toolbarColor: Int? = null) { try { val intent = CustomTabsIntent.Builder() - .setDefaultColorSchemeParams( - CustomTabColorSchemeParams.Builder() - .setToolbarColor(toolbarColor ?: getResourceColor(R.attr.colorPrimaryVariant)) - .build() - ) - .build() + .setDefaultColorSchemeParams( + CustomTabColorSchemeParams.Builder() + .setToolbarColor(toolbarColor ?: getResourceColor(R.attr.colorPrimaryVariant)) + .build() + ) + .build() intent.launchUrl(this, uri) } catch (e: Exception) { toast(e.message) @@ -264,11 +264,11 @@ fun Context.openInBrowser(url: String, forceBrowser: Boolean): Boolean { try { val parsedUrl = url.toUri() val intent = CustomTabsIntent.Builder() - .setDefaultColorSchemeParams( - CustomTabColorSchemeParams.Builder() - .setToolbarColor(getResourceColor(R.attr.colorPrimaryVariant)) - .build() - ) + .setDefaultColorSchemeParams( + CustomTabColorSchemeParams.Builder() + .setToolbarColor(getResourceColor(R.attr.colorPrimaryVariant)) + .build() + ) .build() if (forceBrowser) { val packages = getCustomTabsPackages().maxBy { it.preferredOrder } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/CoroutinesExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/CoroutinesExtensions.kt index b2ae8d5cc8..c019f99898 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/CoroutinesExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/CoroutinesExtensions.kt @@ -15,7 +15,7 @@ fun launchNow(block: suspend CoroutineScope.() -> Unit): Job = GlobalScope.launch(Dispatchers.Main, CoroutineStart.UNDISPATCHED, block) fun CoroutineScope.launchIO(block: suspend CoroutineScope.() -> Unit): Job = - launch(Dispatchers.IO, block = block) + launch(Dispatchers.IO, block = block) suspend fun withUIContext(block: suspend CoroutineScope.() -> T) = withContext(Dispatchers.Main, block) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt index caf0fd02dc..08f89550f3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt @@ -37,8 +37,9 @@ object ImageUtil { stream.read(bytes, 0, bytes.size) } - if (length == -1) + if (length == -1) { return null + } if (bytes.compareWith(charByteArrayOf(0xFF, 0xD8, 0xFF))) { return ImageType.JPG @@ -58,11 +59,13 @@ object ImageUtil { } fun autoSetBackground(image: Bitmap?, alwaysUseWhite: Boolean, context: Context): Drawable { - val backgroundColor = if (alwaysUseWhite) Color.WHITE else + val backgroundColor = if (alwaysUseWhite) Color.WHITE else { context.getResourceColor(R.attr.readerBackground) + } if (image == null) return ColorDrawable(backgroundColor) - if (image.width < 50 || image.height < 50) + if (image.width < 50 || image.height < 50) { return ColorDrawable(backgroundColor) + } val top = 5 val bot = image.height - 5 val left = (image.width * 0.0275).toInt() @@ -88,15 +91,17 @@ object ImageUtil { !isWhite(image.getPixel(right, bot)) && pixelIsClose(image.getPixel(right, bot), image.getPixel(midX, bot)) && !isWhite(image.getPixel(midX, bot)) && pixelIsClose(image.getPixel(midX, bot), image.getPixel(left, bot)) && !isWhite(image.getPixel(left, bot)) && pixelIsClose(image.getPixel(left, bot), image.getPixel(left, top)) - ) + ) { return ColorDrawable(image.getPixel(left, top)) + } if (isWhite(image.getPixel(left, top)).toInt() + isWhite(image.getPixel(right, top)).toInt() + isWhite(image.getPixel(left, bot)).toInt() + isWhite(image.getPixel(right, bot)).toInt() > 2 - ) + ) { darkBG = false + } var blackPixel = when { topLeftIsDark -> image.getPixel(left, top) @@ -126,52 +131,61 @@ object ImageUtil { if (isWhite(pixel)) { whitePixelsStreak++ whitePixels++ - if (notOffset) + if (notOffset) { overallWhitePixels++ - if (whitePixelsStreak > 14) + } + if (whitePixelsStreak > 14) { whiteStrak = true - if (whitePixelsStreak > 6 && whitePixelsStreak >= index - 1) + } + if (whitePixelsStreak > 6 && whitePixelsStreak >= index - 1) { topWhiteStreak = whitePixelsStreak + } } else { whitePixelsStreak = 0 if (isDark(pixel) && isDark(pixelOff)) { blackPixels++ - if (notOffset) + if (notOffset) { overallBlackPixels++ + } blackPixelsStreak++ - if (blackPixelsStreak >= 14) + if (blackPixelsStreak >= 14) { blackStreak = true + } continue } } - if (blackPixelsStreak > 6 && blackPixelsStreak >= index - 1) + if (blackPixelsStreak > 6 && blackPixelsStreak >= index - 1) { topBlackStreak = blackPixelsStreak + } blackPixelsStreak = 0 } - if (blackPixelsStreak > 6) + if (blackPixelsStreak > 6) { botBlackStreak = blackPixelsStreak - else if (whitePixelsStreak > 6) + } else if (whitePixelsStreak > 6) { botWhiteStreak = whitePixelsStreak + } when { blackPixels > 22 -> { - if (x == right || x == right + offsetX) + if (x == right || x == right + offsetX) { blackPixel = when { topRightIsDark -> image.getPixel(right, top) botRightIsDark -> image.getPixel(right, bot) else -> blackPixel } + } darkBG = true overallWhitePixels = 0 break@outer } blackStreak -> { darkBG = true - if (x == right || x == right + offsetX) + if (x == right || x == right + offsetX) { blackPixel = when { topRightIsDark -> image.getPixel(right, top) botRightIsDark -> image.getPixel(right, bot) else -> blackPixel } + } if (blackPixels > 18) { overallWhitePixels = 0 break@outer @@ -183,10 +197,12 @@ object ImageUtil { val topIsBlackStreak = topBlackStreak > topWhiteStreak val bottomIsBlackStreak = botBlackStreak > botWhiteStreak - if (overallWhitePixels > 9 && overallWhitePixels > overallBlackPixels) + if (overallWhitePixels > 9 && overallWhitePixels > overallBlackPixels) { darkBG = false - if (topIsBlackStreak && bottomIsBlackStreak) + } + if (topIsBlackStreak && bottomIsBlackStreak) { darkBG = true + } if (darkBG) { return if (isWhite(image.getPixel(left, bot)) && isWhite(image.getPixel(right, bot))) GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, @@ -203,21 +219,22 @@ object ImageUtil { isDark(image.getPixel(left - offsetX, top)) && isDark(image.getPixel(right + offsetX, top)) && (topMidIsDark || overallBlackPixels > 9) ) - ) + ) { return GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, intArrayOf(blackPixel, blackPixel, backgroundColor, backgroundColor) ) - else if (bottomIsBlackStreak || ( + } else if (bottomIsBlackStreak || ( botLeftIsDark && botRightIsDark && isDark(image.getPixel(left - offsetX, bot)) && isDark(image.getPixel(right + offsetX, bot)) && (isDark(image.getPixel(midX, bot)) || overallBlackPixels > 9) ) - ) + ) { return GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, intArrayOf(backgroundColor, backgroundColor, blackPixel, blackPixel) ) + } return ColorDrawable(backgroundColor) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/RxUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/RxUtil.kt index 80d9c0a649..bf8651af8d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/RxUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/RxUtil.kt @@ -17,8 +17,9 @@ suspend fun Single.await(subscribeOn: Scheduler? = null): T { } }, { - if (!continuation.isCancelled) + if (!continuation.isCancelled) { continuation.resumeWithException(it) + } } ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt index 61456c3c90..b43895339d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt @@ -312,4 +312,3 @@ fun Controller.openInBrowser(url: String) { activity?.toast(e.message) } } - diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index 90320ff093..44ad333b0a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -250,8 +250,9 @@ fun BottomSheetDialog.setEdgeToEdge( window?.navigationBarColor = activity.window.navigationBarColor val isLight = (activity.window?.decorView?.systemUiVisibility ?: 0) and View .SYSTEM_UI_FLAG_LIGHT_STATUS_BAR == View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isLight) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isLight) { window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + } window?.findViewById(com.google.android.material.R.id.container)?.fitsSystemWindows = false window?.findViewById(com.google.android.material.R.id.coordinator)?.fitsSystemWindows = 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 bc46cebf0b..11f054dbe1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt @@ -15,8 +15,9 @@ class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: Att var columnWidth = -1f set(value) { field = value - if (measuredWidth > 0) + if (measuredWidth > 0) { setSpan(true) + } } var spanCount = 0 diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/BaseTabbedScrollView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/BaseTabbedScrollView.kt index d26dd8c6e5..7d3d613733 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/BaseTabbedScrollView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/BaseTabbedScrollView.kt @@ -34,4 +34,4 @@ abstract class BaseLibraryDisplayView @JvmOverloads constructor(context: Context abstract class BaseReaderSettingsView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : BaseTabbedScrollView(context, attrs) { lateinit var activity: ReaderActivity -} \ No newline at end of file +} 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 40f7b8ba8a..f153ffc2c8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/CustomLayoutPicker.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/CustomLayoutPicker.kt @@ -14,10 +14,10 @@ class CustomLayoutPickerActivity : FilePickerActivity() { override fun getFragment(startPath: String?, mode: Int, allowMultiple: Boolean, allowCreateDir: Boolean): AbstractFilePickerFragment { - val fragment = CustomLayoutFilePickerFragment() - fragment.setArgs(startPath, mode, allowMultiple, allowCreateDir) - return fragment - } + val fragment = CustomLayoutFilePickerFragment() + fragment.setArgs(startPath, mode, allowMultiple, allowCreateDir) + return fragment + } } class CustomLayoutFilePickerFragment : FilePickerFragment() { 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 5bd0aa2003..d4a01a489c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt @@ -34,6 +34,7 @@ class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? fun show(@DrawableRes drawable: Int, @StringRes textResource: Int, actions: List? = null) { show(drawable, context.getString(textResource), actions) } + /** * Show the information view * @param drawable icon of information view diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheet.kt index 3f840d7468..ac8cefc483 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheet.kt @@ -16,10 +16,9 @@ import eu.kanade.tachiyomi.util.view.expand import eu.kanade.tachiyomi.util.view.setEdgeToEdge import kotlinx.android.synthetic.main.tabbed_bottom_sheet.* - abstract class TabbedBottomSheetDialog(private val activity: Activity) : BottomSheetDialog - (activity, R.style.BottomSheetDialogTheme) { + (activity, R.style.BottomSheetDialogTheme) { private var sheetBehavior: BottomSheetBehavior<*> @@ -33,7 +32,7 @@ abstract class TabbedBottomSheetDialog(private val activity: Activity) : setEdgeToEdge(activity, view) val height = activity.window.decorView.rootWindowInsets.systemWindowInsetTop - pager.maxHeight = activity.window.decorView.height - height - 125.dpToPx + pager.maxHeight = activity.window.decorView.height - height - 125.dpToPx val adapter = TabbedSheetAdapter() pager.offscreenPageLimit = 2 @@ -86,7 +85,7 @@ abstract class TabbedBottomSheetDialog(private val activity: Activity) : } } -class MeasuredViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null): ViewPager(context, attrs) { +class MeasuredViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ViewPager(context, attrs) { var maxHeight = 0 set(value) { @@ -100,7 +99,8 @@ class MeasuredViewPager @JvmOverloads constructor(context: Context, attrs: Attri var height = 0 val childWidthSpec = MeasureSpec.makeMeasureSpec( Math.max( - 0, MeasureSpec.getSize(widthMeasureSpec) - + 0, + MeasureSpec.getSize(widthMeasureSpec) - paddingLeft - paddingRight ), MeasureSpec.getMode(widthMeasureSpec) @@ -119,4 +119,4 @@ class MeasuredViewPager @JvmOverloads constructor(context: Context, attrs: Attri } super.onMeasure(widthMeasureSpec, heightMeasureSpec) } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/IntListMatPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/IntListMatPreference.kt index f33b372aa3..139c4ddb56 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/IntListMatPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/IntListMatPreference.kt @@ -47,8 +47,9 @@ class IntListMatPreference @JvmOverloads constructor( ) { _, pos, _ -> val value = entryValues[pos] - if (key != null) + if (key != null) { prefs.getInt(key, defValue).set(value) + } callChangeListener(value) this@IntListMatPreference.summary = this@IntListMatPreference.summary dismiss() 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 bb2753dc8a..ed8f976cbe 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 @@ -20,8 +20,8 @@ import rx.Subscription import uy.kohesive.injekt.injectLazy abstract class LoginDialogPreference( - @StringRes private val usernameLabelRes: Int? = null, - bundle: Bundle? = null + @StringRes private val usernameLabelRes: Int? = null, + bundle: Bundle? = null ) : DialogController(bundle) { @@ -48,7 +48,6 @@ abstract class LoginDialogPreference( fun onViewCreated(view: View) { v = view.apply { - if (usernameLabelRes != null) { username_input.hint = view.context.getString(usernameLabelRes) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/MatPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/MatPreference.kt index caecdd5e7e..0b0ac6ffdd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/MatPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/MatPreference.kt @@ -24,10 +24,11 @@ open class MatPreference @JvmOverloads constructor( var customSummary: String? = null override fun onClick() { - if (!isShowing) + if (!isShowing) { dialog().apply { onDismiss { this@MatPreference.isShowing = false } }.show() + } isShowing = true } @@ -37,8 +38,9 @@ open class MatPreference @JvmOverloads constructor( open fun dialog(): MaterialDialog { return MaterialDialog(activity ?: context).apply { - if (title != null) + if (title != null) { title(text = title.toString()) + } negativeButton(android.R.string.cancel) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/MultiListMatPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/MultiListMatPreference.kt index 16958610eb..cd569795a1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/MultiListMatPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/MultiListMatPreference.kt @@ -43,8 +43,9 @@ class MultiListMatPreference @JvmOverloads constructor( } .toIntArray() if (allSelectionRes != null && default.isEmpty()) default = intArrayOf(0) - val items = if (allSelectionRes != null) - (listOf(context.getString(allSelectionRes!!)) + entries) else entries + val items = if (allSelectionRes != null) { + (listOf(context.getString(allSelectionRes!!)) + entries) + } else entries positiveButton(android.R.string.ok) { val pos = mutableListOf() for (i in items.indices) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SwitchPreferenceCategory.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SwitchPreferenceCategory.kt index 9843d67216..91acacf6a2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SwitchPreferenceCategory.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SwitchPreferenceCategory.kt @@ -119,10 +119,11 @@ class SwitchPreferenceCategory @JvmOverloads constructor( override fun onSetInitialValue(restoreValue: Boolean, defaultValue: Any?) { setChecked( - if (restoreValue) + if (restoreValue) { getPersistedBoolean(mChecked) - else + } else { defaultValue as Boolean + } ) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/TrackLoginDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/TrackLoginDialog.kt index 3179650f5f..c51d32e722 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/TrackLoginDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/TrackLoginDialog.kt @@ -31,7 +31,6 @@ class TrackLoginDialog(@StringRes usernameLabelRes: Int? = null, bundle: Bundle? } override fun checkLogin() { - v?.apply { login.apply { progressType = ProgressType.INDETERMINATE