Minor cleanup, remove some usages of ArrayList

This commit is contained in:
arkon 2020-05-30 23:34:58 -04:00
parent 3e837f8781
commit bf5065d16b
12 changed files with 28 additions and 41 deletions

View File

@ -350,7 +350,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
*/ */
internal fun restoreCategoriesForManga(manga: Manga, categories: List<String>) { internal fun restoreCategoriesForManga(manga: Manga, categories: List<String>) {
val dbCategories = databaseHelper.getCategories().executeAsBlocking() val dbCategories = databaseHelper.getCategories().executeAsBlocking()
val mangaCategoriesToUpdate = ArrayList<MangaCategory>() val mangaCategoriesToUpdate = mutableListOf<MangaCategory>()
for (backupCategoryStr in categories) { for (backupCategoryStr in categories) {
for (dbCategory in dbCategories) { for (dbCategory in dbCategories) {
if (backupCategoryStr.toLowerCase() == dbCategory.nameLower) { if (backupCategoryStr.toLowerCase() == dbCategory.nameLower) {
@ -362,9 +362,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
// Update database // Update database
if (mangaCategoriesToUpdate.isNotEmpty()) { if (mangaCategoriesToUpdate.isNotEmpty()) {
val mangaAsList = ArrayList<Manga>() databaseHelper.deleteOldMangasCategories(listOf(manga)).executeAsBlocking()
mangaAsList.add(manga)
databaseHelper.deleteOldMangasCategories(mangaAsList).executeAsBlocking()
databaseHelper.insertMangasCategories(mangaCategoriesToUpdate).executeAsBlocking() databaseHelper.insertMangasCategories(mangaCategoriesToUpdate).executeAsBlocking()
} }
} }
@ -376,7 +374,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
*/ */
internal fun restoreHistoryForManga(history: List<DHistory>) { internal fun restoreHistoryForManga(history: List<DHistory>) {
// List containing history to be updated // List containing history to be updated
val historyToBeUpdated = ArrayList<History>() val historyToBeUpdated = mutableListOf<History>()
for ((url, lastRead) in history) { for ((url, lastRead) in history) {
val dbHistory = databaseHelper.getHistoryByChapterUrl(url).executeAsBlocking() val dbHistory = databaseHelper.getHistoryByChapterUrl(url).executeAsBlocking()
// Check if history already in database and update // 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 // Get tracks from database
val dbTracks = databaseHelper.getTracks(manga).executeAsBlocking() val dbTracks = databaseHelper.getTracks(manga).executeAsBlocking()
val trackToUpdate = ArrayList<Track>() val trackToUpdate = mutableListOf<Track>()
for (track in tracks) { tracks.forEach { track ->
val service = trackManager.getService(track.sync_id) val service = trackManager.getService(track.sync_id)
if (service != null && service.isLogged) { if (service != null && service.isLogged) {
var isInDatabase = false var isInDatabase = false

View File

@ -207,7 +207,7 @@ class DownloadCache(
fun removeChapters(chapters: List<Chapter>, manga: Manga) { fun removeChapters(chapters: List<Chapter>, manga: Manga) {
val sourceDir = rootDir.files[manga.source] ?: return val sourceDir = rootDir.files[manga.source] ?: return
val mangaDir = sourceDir.files[provider.getMangaDirName(manga)] ?: return val mangaDir = sourceDir.files[provider.getMangaDirName(manga)] ?: return
for (chapter in chapters) { chapters.forEach { chapter ->
val chapterDirName = provider.getChapterDirName(chapter) val chapterDirName = provider.getChapterDirName(chapter)
if (chapterDirName in mangaDir.files) { if (chapterDirName in mangaDir.files) {
mangaDir.files -= chapterDirName mangaDir.files -= chapterDirName

View File

@ -28,7 +28,6 @@ import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.acquireWakeLock import eu.kanade.tachiyomi.util.system.acquireWakeLock
import eu.kanade.tachiyomi.util.system.isServiceRunning import eu.kanade.tachiyomi.util.system.isServiceRunning
import java.io.File import java.io.File
import java.util.ArrayList
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
import rx.Observable import rx.Observable
import rx.Subscription import rx.Subscription
@ -254,9 +253,9 @@ class LibraryUpdateService(
// Initialize the variables holding the progress of the updates. // Initialize the variables holding the progress of the updates.
val count = AtomicInteger(0) val count = AtomicInteger(0)
// List containing new updates // List containing new updates
val newUpdates = ArrayList<Pair<LibraryManga, Array<Chapter>>>() val newUpdates = mutableListOf<Pair<LibraryManga, Array<Chapter>>>()
// List containing failed updates // List containing failed updates
val failedUpdates = ArrayList<Pair<Manga, String?>>() val failedUpdates = mutableListOf<Pair<Manga, String?>>()
// Boolean to determine if DownloadManager has downloads // Boolean to determine if DownloadManager has downloads
var hasDownloads = false var hasDownloads = false

View File

@ -12,9 +12,7 @@ class AndroidCookieJar : CookieJar {
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) { override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
val urlString = url.toString() val urlString = url.toString()
for (cookie in cookies) { cookies.forEach { manager.setCookie(urlString, it.toString()) }
manager.setCookie(urlString, cookie.toString())
}
} }
override fun loadForRequest(url: HttpUrl): List<Cookie> { override fun loadForRequest(url: HttpUrl): List<Cookie> {

View File

@ -78,15 +78,15 @@ class ExtensionPreferencesController(bundle: Bundle? = null) :
val multiSource = extension.sources.size > 1 val multiSource = extension.sources.size > 1
for (source in extension.sources) { extension.sources
if (source is ConfigurableSource) { .filterIsInstance<ConfigurableSource>()
.forEach { source ->
try { try {
addPreferencesForSource(screen, source, multiSource) addPreferencesForSource(screen, source, multiSource)
} catch (e: AbstractMethodError) { } catch (e: AbstractMethodError) {
Timber.e("Source did not implement [addPreferencesForSource]: ${source.name}") Timber.e("Source did not implement [addPreferencesForSource]: ${source.name}")
} }
} }
}
manager.setPreferences(screen) manager.setPreferences(screen)

View File

@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.databinding.DownloadControllerBinding
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight
import java.util.HashMap
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
@ -39,7 +38,7 @@ class DownloadController :
/** /**
* Map of subscriptions for active downloads. * Map of subscriptions for active downloads.
*/ */
private val progressSubscriptions by lazy { HashMap<Download, Subscription>() } private val progressSubscriptions by lazy { mutableMapOf<Download, Subscription>() }
/** /**
* Whether the download queue is running or not. * Whether the download queue is running or not.

View File

@ -22,7 +22,6 @@ import eu.kanade.tachiyomi.util.lang.isNullOrUnsubscribed
import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.removeCovers import eu.kanade.tachiyomi.util.removeCovers
import eu.kanade.tachiyomi.util.updateCoverLastModified import eu.kanade.tachiyomi.util.updateCoverLastModified
import java.util.ArrayList
import java.util.Collections import java.util.Collections
import java.util.Comparator import java.util.Comparator
import rx.Observable import rx.Observable
@ -348,7 +347,7 @@ class LibraryPresenter(
* @param mangas the list of manga to move. * @param mangas the list of manga to move.
*/ */
fun moveMangasToCategories(categories: List<Category>, mangas: List<Manga>) { fun moveMangasToCategories(categories: List<Category>, mangas: List<Manga>) {
val mc = ArrayList<MangaCategory>() val mc = mutableListOf<MangaCategory>()
for (manga in mangas) { for (manga in mangas) {
for (cat in categories) { for (cat in categories) {

View File

@ -24,9 +24,6 @@ import timber.log.Timber
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
/**
* Presenter of [ChaptersController].
*/
class ChaptersPresenter( class ChaptersPresenter(
val manga: Manga, val manga: Manga,
val source: Source, val source: Source,
@ -47,8 +44,9 @@ class ChaptersPresenter(
/** /**
* Subject of list of chapters to allow updating the view without going to DB. * Subject of list of chapters to allow updating the view without going to DB.
*/ */
val chaptersRelay: PublishRelay<List<ChapterItem>> private val chaptersRelay: PublishRelay<List<ChapterItem>> by lazy {
by lazy { PublishRelay.create<List<ChapterItem>>() } PublishRelay.create<List<ChapterItem>>()
}
/** /**
* Whether the chapter list has been requested to the source. * 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. * @param chapters the list of chapter from the database.
*/ */
private fun setDownloadedChapters(chapters: List<ChapterItem>) { private fun setDownloadedChapters(chapters: List<ChapterItem>) {
for (chapter in chapters) { chapters
if (downloadManager.isChapterDownloaded(chapter, manga)) { .filter { downloadManager.isChapterDownloaded(it, manga) }
chapter.status = Download.DOWNLOADED .forEach { it.status = Download.DOWNLOADED }
}
}
} }
/** /**
@ -222,7 +218,7 @@ class ChaptersPresenter(
* Called when a download for the active manga changes status. * Called when a download for the active manga changes status.
* @param download the download whose status changed. * @param download the download whose status changed.
*/ */
fun onDownloadStatusChange(download: Download) { private fun onDownloadStatusChange(download: Download) {
// Assign the download to the model object. // Assign the download to the model object.
if (download.status == Download.QUEUE) { if (download.status == Download.QUEUE) {
chapters.find { it.id == download.chapter.id }?.let { chapters.find { it.id == download.chapter.id }?.let {

View File

@ -10,7 +10,6 @@ import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.data.track.model.TrackSearch
import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.inflate 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_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
import kotlinx.android.synthetic.main.track_search_item.view.track_search_start_result 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 import kotlinx.android.synthetic.main.track_search_item.view.track_search_type_result
class TrackSearchAdapter(context: Context) : class TrackSearchAdapter(context: Context) :
ArrayAdapter<TrackSearch>(context, R.layout.track_search_item, ArrayList<TrackSearch>()) { ArrayAdapter<TrackSearch>(context, R.layout.track_search_item, mutableListOf<TrackSearch>()) {
override fun getView(position: Int, view: View?, parent: ViewGroup): View { override fun getView(position: Int, view: View?, parent: ViewGroup): View {
var v = view var v = view

View File

@ -150,7 +150,7 @@ class EpubFile(file: File) : Closeable {
* Returns all the images contained in every page from the epub. * Returns all the images contained in every page from the epub.
*/ */
private fun getImagesFromPages(pages: List<String>, packageHref: String): List<String> { private fun getImagesFromPages(pages: List<String>, packageHref: String): List<String> {
val result = ArrayList<String>() val result = mutableListOf<String>()
val basePath = getParentDirectory(packageHref) val basePath = getParentDirectory(packageHref)
pages.forEach { page -> pages.forEach { page ->
val entryPath = resolveZipPath(basePath, page) val entryPath = resolveZipPath(basePath, page)

View File

@ -236,7 +236,7 @@ class BackupTest {
manga.id = backupManager.databaseHelper.insertManga(manga).executeAsBlocking().insertedId() manga.id = backupManager.databaseHelper.insertManga(manga).executeAsBlocking().insertedId()
// Create restore list // Create restore list
val chapters = ArrayList<Chapter>() val chapters = mutableListOf<Chapter>()
for (i in 1..8) { for (i in 1..8) {
val chapter = getSingleChapter("Chapter $i") val chapter = getSingleChapter("Chapter $i")
chapter.read = true chapter.read = true
@ -249,7 +249,7 @@ class BackupTest {
// Fetch chapters from upstream // Fetch chapters from upstream
// Create list // Create list
val chaptersRemote = ArrayList<Chapter>() val chaptersRemote = mutableListOf<Chapter>()
(1..10).mapTo(chaptersRemote) { getSingleChapter("Chapter $it") } (1..10).mapTo(chaptersRemote) { getSingleChapter("Chapter $it") }
`when`(source.fetchChapterList(manga)).thenReturn(Observable.just(chaptersRemote)) `when`(source.fetchChapterList(manga)).thenReturn(Observable.just(chaptersRemote))
@ -284,7 +284,7 @@ class BackupTest {
val historyJson = getSingleHistory(chapter) val historyJson = getSingleHistory(chapter)
val historyList = ArrayList<DHistory>() val historyList = mutableListOf<DHistory>()
historyList.add(historyJson) historyList.add(historyJson)
// Check parser // Check parser

View File

@ -11,7 +11,6 @@ import eu.kanade.tachiyomi.data.database.models.LibraryManga
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import java.util.ArrayList
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -107,7 +106,7 @@ class LibraryUpdateServiceTest {
} }
private fun createChapters(vararg urls: String): List<Chapter> { private fun createChapters(vararg urls: String): List<Chapter> {
val list = ArrayList<Chapter>() val list = mutableListOf<Chapter>()
for (url in urls) { for (url in urls) {
val c = Chapter.create() val c = Chapter.create()
c.url = url c.url = url
@ -118,7 +117,7 @@ class LibraryUpdateServiceTest {
} }
private fun createManga(vararg urls: String): List<LibraryManga> { private fun createManga(vararg urls: String): List<LibraryManga> {
val list = ArrayList<LibraryManga>() val list = mutableListOf<LibraryManga>()
for (url in urls) { for (url in urls) {
val m = LibraryManga() val m = LibraryManga()
m.url = url m.url = url