mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Minor cleanup, remove some usages of ArrayList
This commit is contained in:
		| @@ -350,7 +350,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) { | ||||
|      */ | ||||
|     internal fun restoreCategoriesForManga(manga: Manga, categories: List<String>) { | ||||
|         val dbCategories = databaseHelper.getCategories().executeAsBlocking() | ||||
|         val mangaCategoriesToUpdate = ArrayList<MangaCategory>() | ||||
|         val mangaCategoriesToUpdate = mutableListOf<MangaCategory>() | ||||
|         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<Manga>() | ||||
|             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<DHistory>) { | ||||
|         // List containing history to be updated | ||||
|         val historyToBeUpdated = ArrayList<History>() | ||||
|         val historyToBeUpdated = mutableListOf<History>() | ||||
|         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<Track>() | ||||
|         val trackToUpdate = mutableListOf<Track>() | ||||
|  | ||||
|         for (track in tracks) { | ||||
|         tracks.forEach { track -> | ||||
|             val service = trackManager.getService(track.sync_id) | ||||
|             if (service != null && service.isLogged) { | ||||
|                 var isInDatabase = false | ||||
|   | ||||
| @@ -207,7 +207,7 @@ class DownloadCache( | ||||
|     fun removeChapters(chapters: List<Chapter>, 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 | ||||
|   | ||||
| @@ -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<Pair<LibraryManga, Array<Chapter>>>() | ||||
|         val newUpdates = mutableListOf<Pair<LibraryManga, Array<Chapter>>>() | ||||
|         // List containing failed updates | ||||
|         val failedUpdates = ArrayList<Pair<Manga, String?>>() | ||||
|         val failedUpdates = mutableListOf<Pair<Manga, String?>>() | ||||
|         // Boolean to determine if DownloadManager has downloads | ||||
|         var hasDownloads = false | ||||
|  | ||||
|   | ||||
| @@ -12,9 +12,7 @@ class AndroidCookieJar : CookieJar { | ||||
|     override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) { | ||||
|         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<Cookie> { | ||||
|   | ||||
| @@ -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<ConfigurableSource>() | ||||
|             .forEach { source -> | ||||
|                 try { | ||||
|                     addPreferencesForSource(screen, source, multiSource) | ||||
|                 } catch (e: AbstractMethodError) { | ||||
|                     Timber.e("Source did not implement [addPreferencesForSource]: ${source.name}") | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         manager.setPreferences(screen) | ||||
|  | ||||
|   | ||||
| @@ -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<Download, Subscription>() } | ||||
|     private val progressSubscriptions by lazy { mutableMapOf<Download, Subscription>() } | ||||
|  | ||||
|     /** | ||||
|      * Whether the download queue is running or not. | ||||
|   | ||||
| @@ -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<Category>, mangas: List<Manga>) { | ||||
|         val mc = ArrayList<MangaCategory>() | ||||
|         val mc = mutableListOf<MangaCategory>() | ||||
|  | ||||
|         for (manga in mangas) { | ||||
|             for (cat in categories) { | ||||
|   | ||||
| @@ -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<List<ChapterItem>> | ||||
|     by lazy { PublishRelay.create<List<ChapterItem>>() } | ||||
|     private val chaptersRelay: PublishRelay<List<ChapterItem>> by lazy { | ||||
|         PublishRelay.create<List<ChapterItem>>() | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 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<ChapterItem>) { | ||||
|         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 { | ||||
|   | ||||
| @@ -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<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 { | ||||
|         var v = view | ||||
|   | ||||
| @@ -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<String>, packageHref: String): List<String> { | ||||
|         val result = ArrayList<String>() | ||||
|         val result = mutableListOf<String>() | ||||
|         val basePath = getParentDirectory(packageHref) | ||||
|         pages.forEach { page -> | ||||
|             val entryPath = resolveZipPath(basePath, page) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user