diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt index f2aa054c36..95353f42a6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt @@ -350,7 +350,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) { */ internal fun restoreCategoriesForManga(manga: Manga, categories: List) { val dbCategories = databaseHelper.getCategories().executeAsBlocking() - val mangaCategoriesToUpdate = ArrayList() + val mangaCategoriesToUpdate = mutableListOf() for (backupCategoryStr in categories) { for (dbCategory in dbCategories) { if (backupCategoryStr.toLowerCase() == dbCategory.nameLower) { @@ -362,9 +362,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) { // Update database if (mangaCategoriesToUpdate.isNotEmpty()) { - val mangaAsList = ArrayList() - mangaAsList.add(manga) - databaseHelper.deleteOldMangasCategories(mangaAsList).executeAsBlocking() + databaseHelper.deleteOldMangasCategories(listOf(manga)).executeAsBlocking() databaseHelper.insertMangasCategories(mangaCategoriesToUpdate).executeAsBlocking() } } @@ -376,7 +374,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) { */ internal fun restoreHistoryForManga(history: List) { // List containing history to be updated - val historyToBeUpdated = ArrayList() + val historyToBeUpdated = mutableListOf() for ((url, lastRead) in history) { val dbHistory = databaseHelper.getHistoryByChapterUrl(url).executeAsBlocking() // Check if history already in database and update @@ -410,9 +408,9 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) { // Get tracks from database val dbTracks = databaseHelper.getTracks(manga).executeAsBlocking() - val trackToUpdate = ArrayList() + val trackToUpdate = mutableListOf() - for (track in tracks) { + tracks.forEach { track -> val service = trackManager.getService(track.sync_id) if (service != null && service.isLogged) { var isInDatabase = false 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 85ded01f8c..b937c7a2f0 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 @@ -207,7 +207,7 @@ class DownloadCache( fun removeChapters(chapters: List, manga: Manga) { val sourceDir = rootDir.files[manga.source] ?: return val mangaDir = sourceDir.files[provider.getMangaDirName(manga)] ?: return - for (chapter in chapters) { + chapters.forEach { chapter -> val chapterDirName = provider.getChapterDirName(chapter) if (chapterDirName in mangaDir.files) { mangaDir.files -= chapterDirName 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 3fa56fda89..0e35eb6205 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 @@ -28,7 +28,6 @@ import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.system.acquireWakeLock import eu.kanade.tachiyomi.util.system.isServiceRunning import java.io.File -import java.util.ArrayList import java.util.concurrent.atomic.AtomicInteger import rx.Observable import rx.Subscription @@ -254,9 +253,9 @@ class LibraryUpdateService( // Initialize the variables holding the progress of the updates. val count = AtomicInteger(0) // List containing new updates - val newUpdates = ArrayList>>() + val newUpdates = mutableListOf>>() // List containing failed updates - val failedUpdates = ArrayList>() + val failedUpdates = mutableListOf>() // Boolean to determine if DownloadManager has downloads var hasDownloads = false diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/AndroidCookieJar.kt b/app/src/main/java/eu/kanade/tachiyomi/network/AndroidCookieJar.kt index c93b217ee0..c436b0dbd8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/AndroidCookieJar.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/AndroidCookieJar.kt @@ -12,9 +12,7 @@ class AndroidCookieJar : CookieJar { override fun saveFromResponse(url: HttpUrl, cookies: List) { val urlString = url.toString() - for (cookie in cookies) { - manager.setCookie(urlString, cookie.toString()) - } + cookies.forEach { manager.setCookie(urlString, it.toString()) } } override fun loadForRequest(url: HttpUrl): List { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPreferencesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPreferencesController.kt index b0ca474ce8..a360994951 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPreferencesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPreferencesController.kt @@ -78,15 +78,15 @@ class ExtensionPreferencesController(bundle: Bundle? = null) : val multiSource = extension.sources.size > 1 - for (source in extension.sources) { - if (source is ConfigurableSource) { + extension.sources + .filterIsInstance() + .forEach { source -> try { addPreferencesForSource(screen, source, multiSource) } catch (e: AbstractMethodError) { Timber.e("Source did not implement [addPreferencesForSource]: ${source.name}") } } - } manager.setPreferences(screen) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt index cbbd91c98d..8e2ac55b58 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt @@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.databinding.DownloadControllerBinding import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight -import java.util.HashMap import java.util.concurrent.TimeUnit import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -39,7 +38,7 @@ class DownloadController : /** * Map of subscriptions for active downloads. */ - private val progressSubscriptions by lazy { HashMap() } + private val progressSubscriptions by lazy { mutableMapOf() } /** * Whether the download queue is running or not. 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 467e4f5eda..1e365a01e9 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 @@ -22,7 +22,6 @@ import eu.kanade.tachiyomi.util.lang.isNullOrUnsubscribed import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.removeCovers import eu.kanade.tachiyomi.util.updateCoverLastModified -import java.util.ArrayList import java.util.Collections import java.util.Comparator import rx.Observable @@ -348,7 +347,7 @@ class LibraryPresenter( * @param mangas the list of manga to move. */ fun moveMangasToCategories(categories: List, mangas: List) { - val mc = ArrayList() + val mc = mutableListOf() for (manga in mangas) { for (cat in categories) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt index e88ee02166..dda0d31d48 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt @@ -24,9 +24,6 @@ import timber.log.Timber import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -/** - * Presenter of [ChaptersController]. - */ class ChaptersPresenter( val manga: Manga, val source: Source, @@ -47,8 +44,9 @@ class ChaptersPresenter( /** * Subject of list of chapters to allow updating the view without going to DB. */ - val chaptersRelay: PublishRelay> - by lazy { PublishRelay.create>() } + private val chaptersRelay: PublishRelay> by lazy { + PublishRelay.create>() + } /** * Whether the chapter list has been requested to the source. @@ -144,11 +142,9 @@ class ChaptersPresenter( * @param chapters the list of chapter from the database. */ private fun setDownloadedChapters(chapters: List) { - for (chapter in chapters) { - if (downloadManager.isChapterDownloaded(chapter, manga)) { - chapter.status = Download.DOWNLOADED - } - } + chapters + .filter { downloadManager.isChapterDownloaded(it, manga) } + .forEach { it.status = Download.DOWNLOADED } } /** @@ -222,7 +218,7 @@ class ChaptersPresenter( * Called when a download for the active manga changes status. * @param download the download whose status changed. */ - fun onDownloadStatusChange(download: Download) { + private fun onDownloadStatusChange(download: Download) { // Assign the download to the model object. if (download.status == Download.QUEUE) { chapters.find { it.id == download.chapter.id }?.let { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt index 99c381a9bb..c7a37982f4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt @@ -10,7 +10,6 @@ import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.inflate -import java.util.ArrayList import kotlinx.android.synthetic.main.track_search_item.view.track_search_cover import kotlinx.android.synthetic.main.track_search_item.view.track_search_start import kotlinx.android.synthetic.main.track_search_item.view.track_search_start_result @@ -22,7 +21,7 @@ import kotlinx.android.synthetic.main.track_search_item.view.track_search_type import kotlinx.android.synthetic.main.track_search_item.view.track_search_type_result class TrackSearchAdapter(context: Context) : - ArrayAdapter(context, R.layout.track_search_item, ArrayList()) { + ArrayAdapter(context, R.layout.track_search_item, mutableListOf()) { override fun getView(position: Int, view: View?, parent: ViewGroup): View { var v = view diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/storage/EpubFile.kt b/app/src/main/java/eu/kanade/tachiyomi/util/storage/EpubFile.kt index 7f1e966f61..8d6c3a59b0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/storage/EpubFile.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/storage/EpubFile.kt @@ -150,7 +150,7 @@ class EpubFile(file: File) : Closeable { * Returns all the images contained in every page from the epub. */ private fun getImagesFromPages(pages: List, packageHref: String): List { - val result = ArrayList() + val result = mutableListOf() val basePath = getParentDirectory(packageHref) pages.forEach { page -> val entryPath = resolveZipPath(basePath, page) diff --git a/app/src/test/java/eu/kanade/tachiyomi/data/backup/BackupTest.kt b/app/src/test/java/eu/kanade/tachiyomi/data/backup/BackupTest.kt index 74f3b40173..5a41c08efe 100644 --- a/app/src/test/java/eu/kanade/tachiyomi/data/backup/BackupTest.kt +++ b/app/src/test/java/eu/kanade/tachiyomi/data/backup/BackupTest.kt @@ -236,7 +236,7 @@ class BackupTest { manga.id = backupManager.databaseHelper.insertManga(manga).executeAsBlocking().insertedId() // Create restore list - val chapters = ArrayList() + val chapters = mutableListOf() for (i in 1..8) { val chapter = getSingleChapter("Chapter $i") chapter.read = true @@ -249,7 +249,7 @@ class BackupTest { // Fetch chapters from upstream // Create list - val chaptersRemote = ArrayList() + val chaptersRemote = mutableListOf() (1..10).mapTo(chaptersRemote) { getSingleChapter("Chapter $it") } `when`(source.fetchChapterList(manga)).thenReturn(Observable.just(chaptersRemote)) @@ -284,7 +284,7 @@ class BackupTest { val historyJson = getSingleHistory(chapter) - val historyList = ArrayList() + val historyList = mutableListOf() historyList.add(historyJson) // Check parser diff --git a/app/src/test/java/eu/kanade/tachiyomi/data/library/LibraryUpdateServiceTest.kt b/app/src/test/java/eu/kanade/tachiyomi/data/library/LibraryUpdateServiceTest.kt index fa6c1ed9b9..044a57013f 100644 --- a/app/src/test/java/eu/kanade/tachiyomi/data/library/LibraryUpdateServiceTest.kt +++ b/app/src/test/java/eu/kanade/tachiyomi/data/library/LibraryUpdateServiceTest.kt @@ -11,7 +11,6 @@ import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.online.HttpSource -import java.util.ArrayList import org.assertj.core.api.Assertions.assertThat import org.junit.Before import org.junit.Test @@ -107,7 +106,7 @@ class LibraryUpdateServiceTest { } private fun createChapters(vararg urls: String): List { - val list = ArrayList() + val list = mutableListOf() for (url in urls) { val c = Chapter.create() c.url = url @@ -118,7 +117,7 @@ class LibraryUpdateServiceTest { } private fun createManga(vararg urls: String): List { - val list = ArrayList() + val list = mutableListOf() for (url in urls) { val m = LibraryManga() m.url = url