mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 06:17:57 +01:00 
			
		
		
		
	JDK8, lint fixing (#2888)
* Use Kotlin JDK8 * Satisfy a ton of lints * Run res/layout files (and manifest) through reformatter
This commit is contained in:
		| @@ -128,7 +128,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) { | ||||
|         val categoryEntries = JsonArray() | ||||
|  | ||||
|         // Add value's to root | ||||
|         root[Backup.VERSION] = Backup.CURRENT_VERSION | ||||
|         root[Backup.VERSION] = CURRENT_VERSION | ||||
|         root[Backup.MANGAS] = mangaEntries | ||||
|         root[CATEGORIES] = categoryEntries | ||||
|  | ||||
| @@ -303,8 +303,8 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) { | ||||
|     fun restoreChapterFetchObservable(source: Source, manga: Manga, chapters: List<Chapter>): Observable<Pair<List<Chapter>, List<Chapter>>> { | ||||
|         return source.fetchChapterList(manga) | ||||
|                 .map { syncChaptersWithSource(databaseHelper, it, manga, source) } | ||||
|                 .doOnNext { | ||||
|                     if (it.first.isNotEmpty()) { | ||||
|                 .doOnNext { pair -> | ||||
|                     if (pair.first.isNotEmpty()) { | ||||
|                         chapters.forEach { it.manga_id = manga.id } | ||||
|                         insertChapters(chapters) | ||||
|                     } | ||||
|   | ||||
| @@ -164,7 +164,7 @@ class BackupRestoreService : Service() { | ||||
|      * @return the start value of the command. | ||||
|      */ | ||||
|     override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||||
|         if (intent == null) return Service.START_NOT_STICKY | ||||
|         if (intent == null) return START_NOT_STICKY | ||||
|  | ||||
|         val uri = intent.getParcelableExtra<Uri>(BackupConst.EXTRA_URI) | ||||
|  | ||||
| @@ -179,7 +179,7 @@ class BackupRestoreService : Service() { | ||||
|                 .subscribeOn(Schedulers.from(executor)) | ||||
|                 .subscribe() | ||||
|  | ||||
|         return Service.START_NOT_STICKY | ||||
|         return START_NOT_STICKY | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -80,13 +80,13 @@ class ChapterCache(private val context: Context) { | ||||
|         if (file == "journal" || file.startsWith("journal.")) | ||||
|             return false | ||||
|  | ||||
|         try { | ||||
|         return try { | ||||
|             // Remove the extension from the file to get the key of the cache | ||||
|             val key = file.substringBeforeLast(".") | ||||
|             // Remove file from cache. | ||||
|             return diskCache.remove(key) | ||||
|             diskCache.remove(key) | ||||
|         } catch (e: Exception) { | ||||
|             return false | ||||
|             false | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -149,10 +149,10 @@ class ChapterCache(private val context: Context) { | ||||
|      * @return true if in cache otherwise false. | ||||
|      */ | ||||
|     fun isImageInCache(imageUrl: String): Boolean { | ||||
|         try { | ||||
|             return diskCache.get(DiskUtil.hashKeyForDisk(imageUrl)) != null | ||||
|         return try { | ||||
|             diskCache.get(DiskUtil.hashKeyForDisk(imageUrl)) != null | ||||
|         } catch (e: IOException) { | ||||
|             return false | ||||
|             false | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -27,17 +27,15 @@ class HistoryLastReadPutResolver : HistoryPutResolver() { | ||||
|  | ||||
|         val putResult: PutResult | ||||
|  | ||||
|         try { | ||||
|             if (cursor.count == 0) { | ||||
|         putResult = cursor.use { putCursor -> | ||||
|             if (putCursor.count == 0) { | ||||
|                 val insertQuery = mapToInsertQuery(history) | ||||
|                 val insertedId = db.lowLevel().insert(insertQuery, mapToContentValues(history)) | ||||
|                 putResult = PutResult.newInsertResult(insertedId, insertQuery.table()) | ||||
|                 PutResult.newInsertResult(insertedId, insertQuery.table()) | ||||
|             } else { | ||||
|                 val numberOfRowsUpdated = db.lowLevel().update(updateQuery, mapToUpdateContentValues(history)) | ||||
|                 putResult = PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) | ||||
|                 PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) | ||||
|             } | ||||
|         } finally { | ||||
|             cursor.close() | ||||
|         } | ||||
|  | ||||
|         putResult | ||||
|   | ||||
| @@ -259,7 +259,7 @@ class DownloadCache( | ||||
|      */ | ||||
|     private inline fun <K, V, R> Map<out K, V>.mapNotNullKeys(transform: (Map.Entry<K?, V>) -> R?): Map<R, V> { | ||||
|         val destination = LinkedHashMap<R, V>() | ||||
|         forEach { element -> transform(element)?.let { destination.put(it, element.value) } } | ||||
|         forEach { element -> transform(element)?.let { destination[it] = element.value } } | ||||
|         return destination | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -106,7 +106,7 @@ class DownloadService : Service() { | ||||
|      * Not used. | ||||
|      */ | ||||
|     override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||||
|         return Service.START_NOT_STICKY | ||||
|         return START_NOT_STICKY | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -283,7 +283,7 @@ class Downloader( | ||||
|                 // Do when page is downloaded. | ||||
|                 .doOnNext { notifier.onProgressChange(download) } | ||||
|                 .toList() | ||||
|                 .map { _ -> download } | ||||
|                 .map { download } | ||||
|                 // Do after download completes | ||||
|                 .doOnNext { ensureSuccessfulDownload(download, mangaDir, tmpDir, chapterDirname) } | ||||
|                 // If the page list threw, it will resume here | ||||
|   | ||||
| @@ -5,6 +5,7 @@ import android.util.Log | ||||
| import com.bumptech.glide.Priority | ||||
| import com.bumptech.glide.load.DataSource | ||||
| import com.bumptech.glide.load.data.DataFetcher | ||||
| import timber.log.Timber | ||||
| import java.io.File | ||||
| import java.io.FileInputStream | ||||
| import java.io.FileNotFoundException | ||||
| @@ -24,7 +25,7 @@ open class FileFetcher(private val file: File) : DataFetcher<InputStream> { | ||||
|             data = FileInputStream(file) | ||||
|         } catch (e: FileNotFoundException) { | ||||
|             if (Log.isLoggable(TAG, Log.DEBUG)) { | ||||
|                 Log.d(TAG, "Failed to open file", e) | ||||
|                 Timber.d(e, "Failed to open file") | ||||
|             } | ||||
|             callback.onLoadFailed(e) | ||||
|             return | ||||
|   | ||||
| @@ -246,7 +246,7 @@ class LibraryUpdateService( | ||||
|                     stopSelf(startId) | ||||
|                 }) | ||||
|  | ||||
|         return Service.START_REDELIVER_INTENT | ||||
|         return START_REDELIVER_INTENT | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -97,13 +97,13 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { | ||||
|             // 100 point | ||||
|             POINT_100 -> index.toFloat() | ||||
|             // 5 stars | ||||
|             POINT_5 -> when { | ||||
|                 index == 0 -> 0f | ||||
|             POINT_5 -> when (index) { | ||||
|                 0 -> 0f | ||||
|                 else -> index * 20f - 10f | ||||
|             } | ||||
|             // Smiley | ||||
|             POINT_3 -> when { | ||||
|                 index == 0 -> 0f | ||||
|             POINT_3 -> when (index) { | ||||
|                 0 -> 0f | ||||
|                 else -> index * 25f + 10f | ||||
|             } | ||||
|             // 10 point decimal | ||||
| @@ -116,8 +116,8 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { | ||||
|         val score = track.score | ||||
|  | ||||
|         return when (scorePreference.getOrDefault()) { | ||||
|             POINT_5 -> when { | ||||
|                 score == 0f -> "0 ★" | ||||
|             POINT_5 -> when (score) { | ||||
|                 0f -> "0 ★" | ||||
|                 else -> "${((score + 10) / 20).toInt()} ★" | ||||
|             } | ||||
|             POINT_3 -> when { | ||||
|   | ||||
| @@ -38,7 +38,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) | ||||
|             .addConverterFactory(GsonConverterFactory.create(GsonBuilder().serializeNulls().create())) | ||||
|             .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) | ||||
|             .build() | ||||
|             .create(KitsuApi.Rest::class.java) | ||||
|             .create(Rest::class.java) | ||||
|  | ||||
|     private val searchRest = Retrofit.Builder() | ||||
|             .baseUrl(algoliaKeyUrl) | ||||
| @@ -46,7 +46,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) | ||||
|             .addConverterFactory(GsonConverterFactory.create()) | ||||
|             .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) | ||||
|             .build() | ||||
|             .create(KitsuApi.SearchKeyRest::class.java) | ||||
|             .create(SearchKeyRest::class.java) | ||||
|  | ||||
|     private val algoliaRest = Retrofit.Builder() | ||||
|             .baseUrl(algoliaUrl) | ||||
| @@ -54,7 +54,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) | ||||
|             .addConverterFactory(GsonConverterFactory.create()) | ||||
|             .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) | ||||
|             .build() | ||||
|             .create(KitsuApi.AgoliaSearchRest::class.java) | ||||
|             .create(AgoliaSearchRest::class.java) | ||||
|  | ||||
|     fun addLibManga(track: Track, userId: String): Observable<Track> { | ||||
|         return Observable.defer { | ||||
| @@ -162,7 +162,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) | ||||
|                 .addConverterFactory(GsonConverterFactory.create()) | ||||
|                 .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) | ||||
|                 .build() | ||||
|                 .create(KitsuApi.LoginRest::class.java) | ||||
|                 .create(LoginRest::class.java) | ||||
|                 .requestAccessToken(username, password) | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -36,10 +36,10 @@ class KitsuSearchManga(obj: JsonObject) { | ||||
|         cover_url = original ?: "" | ||||
|         summary = synopsis | ||||
|         tracking_url = KitsuApi.mangaUrl(media_id) | ||||
|         if (endDate == null) { | ||||
|             publishing_status = "Publishing" | ||||
|         publishing_status = if (endDate == null) { | ||||
|             "Publishing" | ||||
|         } else { | ||||
|             publishing_status = "Finished" | ||||
|             "Finished" | ||||
|         } | ||||
|         publishing_type = subType ?: "" | ||||
|         start_date = startDate ?: "" | ||||
|   | ||||
| @@ -49,8 +49,7 @@ internal class ExtensionInstallReceiver(private val listener: Listener) : | ||||
|         when (intent.action) { | ||||
|             Intent.ACTION_PACKAGE_ADDED -> { | ||||
|                 if (!isReplacing(intent)) launchNow { | ||||
|                     val result = getExtensionFromIntent(context, intent) | ||||
|                     when (result) { | ||||
|                     when (val result = getExtensionFromIntent(context, intent)) { | ||||
|                         is LoadResult.Success -> listener.onExtensionInstalled(result.extension) | ||||
|                         is LoadResult.Untrusted -> listener.onExtensionUntrusted(result.extension) | ||||
|                     } | ||||
| @@ -58,8 +57,7 @@ internal class ExtensionInstallReceiver(private val listener: Listener) : | ||||
|             } | ||||
|             Intent.ACTION_PACKAGE_REPLACED -> { | ||||
|                 launchNow { | ||||
|                     val result = getExtensionFromIntent(context, intent) | ||||
|                     when (result) { | ||||
|                     when (val result = getExtensionFromIntent(context, intent)) { | ||||
|                         is LoadResult.Success -> listener.onExtensionUpdated(result.extension) | ||||
|                         // Not needed as a package can't be upgraded if the signature is different | ||||
|                         is LoadResult.Untrusted -> { | ||||
|   | ||||
| @@ -94,8 +94,7 @@ internal object ExtensionLoader { | ||||
|             return LoadResult.Error(error) | ||||
|         } | ||||
|  | ||||
|         val extName = pkgManager.getApplicationLabel(appInfo).toString() | ||||
|                 .orEmpty().substringAfter("Tachiyomi: ") | ||||
|         val extName = pkgManager.getApplicationLabel(appInfo).toString().substringAfter("Tachiyomi: ") | ||||
|         val versionName = pkgInfo.versionName | ||||
|         val versionCode = pkgInfo.versionCode | ||||
|  | ||||
| @@ -137,8 +136,7 @@ internal object ExtensionLoader { | ||||
|                 } | ||||
|                 .flatMap { | ||||
|                     try { | ||||
|                         val obj = Class.forName(it, false, classLoader).newInstance() | ||||
|                         when (obj) { | ||||
|                         when (val obj = Class.forName(it, false, classLoader).newInstance()) { | ||||
|                             is Source -> listOf(obj) | ||||
|                             is SourceFactory -> obj.createSources() | ||||
|                             else -> throw Exception("Unknown source class type! ${obj.javaClass}") | ||||
|   | ||||
| @@ -81,16 +81,16 @@ class LocalSource(private val context: Context) : CatalogueSource { | ||||
|         val state = ((if (filters.isEmpty()) POPULAR_FILTERS else filters)[0] as OrderBy).state | ||||
|         when (state?.index) { | ||||
|             0 -> { | ||||
|                 if (state.ascending) | ||||
|                     mangaDirs = mangaDirs.sortedBy { it.name.toLowerCase(Locale.ENGLISH) } | ||||
|                 mangaDirs = if (state.ascending) | ||||
|                     mangaDirs.sortedBy { it.name.toLowerCase(Locale.ENGLISH) } | ||||
|                 else | ||||
|                     mangaDirs = mangaDirs.sortedByDescending { it.name.toLowerCase(Locale.ENGLISH) } | ||||
|                     mangaDirs.sortedByDescending { it.name.toLowerCase(Locale.ENGLISH) } | ||||
|             } | ||||
|             1 -> { | ||||
|                 if (state.ascending) | ||||
|                     mangaDirs = mangaDirs.sortedBy(File::lastModified) | ||||
|                 mangaDirs = if (state.ascending) | ||||
|                     mangaDirs.sortedBy(File::lastModified) | ||||
|                 else | ||||
|                     mangaDirs = mangaDirs.sortedByDescending(File::lastModified) | ||||
|                     mangaDirs.sortedByDescending(File::lastModified) | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @@ -131,17 +131,14 @@ class LocalSource(private val context: Context) : CatalogueSource { | ||||
|         getBaseDirectories(context) | ||||
|                 .mapNotNull { File(it, manga.url).listFiles()?.toList() } | ||||
|                 .flatten() | ||||
|                 .filter { it.extension.equals("json") } | ||||
|                 .firstOrNull() | ||||
|                 .firstOrNull { it.extension == "json" } | ||||
|                 ?.apply { | ||||
|                     val json = Gson().fromJson(Scanner(this).useDelimiter("\\Z").next(), JsonObject::class.java) | ||||
|                     manga.title = json["title"]?.asString ?: manga.title | ||||
|                     manga.author = json["author"]?.asString ?: manga.author | ||||
|                     manga.artist = json["artist"]?.asString ?: manga.artist | ||||
|                     manga.description = json["description"]?.asString ?: manga.description | ||||
|                     manga.genre = json["genre"]?.asJsonArray | ||||
|                             ?.map { it.asString } | ||||
|                             ?.joinToString(", ") | ||||
|                     manga.genre = json["genre"]?.asJsonArray?.joinToString(", ") { it.asString } | ||||
|                             ?: manga.genre | ||||
|                     manga.status = json["status"]?.asInt ?: manga.status | ||||
|                 } | ||||
| @@ -150,6 +147,7 @@ class LocalSource(private val context: Context) : CatalogueSource { | ||||
|  | ||||
|     override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> { | ||||
|         val chapters = getBaseDirectories(context) | ||||
|                 .asSequence() | ||||
|                 .mapNotNull { File(it, manga.url).listFiles()?.toList() } | ||||
|                 .flatten() | ||||
|                 .filter { it.isDirectory || isSupportedFile(it.extension) } | ||||
| @@ -171,6 +169,7 @@ class LocalSource(private val context: Context) : CatalogueSource { | ||||
|                     val c = c2.chapter_number.compareTo(c1.chapter_number) | ||||
|                     if (c == 0) c2.name.compareToCaseInsensitiveNaturalOrder(c1.name) else c | ||||
|                 }) | ||||
|                 .toList() | ||||
|  | ||||
|         return Observable.just(chapters) | ||||
|     } | ||||
| @@ -211,8 +210,7 @@ class LocalSource(private val context: Context) : CatalogueSource { | ||||
|     } | ||||
|  | ||||
|     private fun updateCover(chapter: SChapter, manga: SManga): File? { | ||||
|         val format = getFormat(chapter) | ||||
|         return when (format) { | ||||
|         return when (val format = getFormat(chapter)) { | ||||
|             is Format.Directory -> { | ||||
|                 val entry = format.file.listFiles() | ||||
|                         .sortedWith(Comparator<File> { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) }) | ||||
| @@ -250,7 +248,7 @@ class LocalSource(private val context: Context) : CatalogueSource { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private class OrderBy : Filter.Sort("Order by", arrayOf("Title", "Date"), Filter.Sort.Selection(0, true)) | ||||
|     private class OrderBy : Filter.Sort("Order by", arrayOf("Title", "Date"), Selection(0, true)) | ||||
|  | ||||
|     override fun getFilterList() = FilterList(OrderBy()) | ||||
|  | ||||
|   | ||||
| @@ -207,14 +207,14 @@ abstract class HttpSource : CatalogueSource { | ||||
|      * @param manga the manga to look for chapters. | ||||
|      */ | ||||
|     override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> { | ||||
|         if (manga.status != SManga.LICENSED) { | ||||
|             return client.newCall(chapterListRequest(manga)) | ||||
|         return if (manga.status != SManga.LICENSED) { | ||||
|             client.newCall(chapterListRequest(manga)) | ||||
|                     .asObservableSuccess() | ||||
|                     .map { response -> | ||||
|                         chapterListParse(response) | ||||
|                     } | ||||
|         } else { | ||||
|             return Observable.error(Exception("Licensed - No chapters to show")) | ||||
|             Observable.error(Exception("Licensed - No chapters to show")) | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -340,16 +340,16 @@ abstract class HttpSource : CatalogueSource { | ||||
|      * @param orig the full url. | ||||
|      */ | ||||
|     private fun getUrlWithoutDomain(orig: String): String { | ||||
|         try { | ||||
|         return try { | ||||
|             val uri = URI(orig) | ||||
|             var out = uri.path | ||||
|             if (uri.query != null) | ||||
|                 out += "?" + uri.query | ||||
|             if (uri.fragment != null) | ||||
|                 out += "#" + uri.fragment | ||||
|             return out | ||||
|             out | ||||
|         } catch (e: URISyntaxException) { | ||||
|             return orig | ||||
|             orig | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -31,13 +31,13 @@ interface SlicedHolder { | ||||
|  | ||||
|         when { | ||||
|             // Only one item in the card | ||||
|             count == 1 -> applySlice(2f, false, false, true, true) | ||||
|             count == 1 -> applySlice(2f, topRect = false, bottomRect = false, topShadow = true, bottomShadow = true) | ||||
|             // First item of the card | ||||
|             position == 0 -> applySlice(2f, false, true, true, false) | ||||
|             position == 0 -> applySlice(2f, topRect = false, bottomRect = true, topShadow = true, bottomShadow = false) | ||||
|             // Last item of the card | ||||
|             position == count - 1 -> applySlice(2f, true, false, false, true) | ||||
|             position == count - 1 -> applySlice(2f, topRect = true, bottomRect = false, topShadow = false, bottomShadow = true) | ||||
|             // Middle item | ||||
|             else -> applySlice(0f, false, false, false, false) | ||||
|             else -> applySlice(0f, topRect = false, bottomRect = false, topShadow = false, bottomShadow = false) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -22,7 +22,7 @@ class ExtensionAdapter(val controller: ExtensionController) : | ||||
|     /** | ||||
|      * Listener for browse item clicks. | ||||
|      */ | ||||
|     val buttonClickListener: ExtensionAdapter.OnButtonClickListener = controller | ||||
|     val buttonClickListener: OnButtonClickListener = controller | ||||
|  | ||||
|     interface OnButtonClickListener { | ||||
|         fun onButtonClick(position: Int) | ||||
|   | ||||
| @@ -229,13 +229,13 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att | ||||
|     override fun onItemClick(view: View?, position: Int): Boolean { | ||||
|         // If the action mode is created and the position is valid, toggle the selection. | ||||
|         val item = adapter.getItem(position) ?: return false | ||||
|         if (adapter.mode == SelectableAdapter.Mode.MULTI) { | ||||
|         return if (adapter.mode == SelectableAdapter.Mode.MULTI) { | ||||
|             lastClickPosition = position | ||||
|             toggleSelection(position) | ||||
|             return true | ||||
|             true | ||||
|         } else { | ||||
|             openManga(item.manga) | ||||
|             return false | ||||
|             false | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -303,7 +303,7 @@ class LibraryPresenter( | ||||
|         if (mangas.isEmpty()) return emptyList() | ||||
|         return mangas.toSet() | ||||
|                 .map { db.getCategoriesForManga(it).executeAsBlocking() } | ||||
|                 .reduce { set1: Iterable<Category>, set2 -> set1.intersect(set2) } | ||||
|                 .reduce { set1: Iterable<Category>, set2 -> set1.intersect(set2).toMutableList() } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -306,13 +306,13 @@ class ChaptersController : NucleusController<ChaptersControllerBinding, Chapters | ||||
|     override fun onItemClick(view: View?, position: Int): Boolean { | ||||
|         val adapter = adapter ?: return false | ||||
|         val item = adapter.getItem(position) ?: return false | ||||
|         if (actionMode != null && adapter.mode == SelectableAdapter.Mode.MULTI) { | ||||
|         return if (actionMode != null && adapter.mode == SelectableAdapter.Mode.MULTI) { | ||||
|             lastClickPosition = position | ||||
|             toggleSelection(position) | ||||
|             return true | ||||
|             true | ||||
|         } else { | ||||
|             openChapter(item.chapter) | ||||
|             return false | ||||
|             false | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -67,8 +67,8 @@ class ChaptersPresenter( | ||||
|         // Prepare the relay. | ||||
|         chaptersRelay.flatMap { applyChapterFilters(it) } | ||||
|                 .observeOn(AndroidSchedulers.mainThread()) | ||||
|                 .subscribeLatestCache(ChaptersController::onNextChapters, | ||||
|                         { _, error -> Timber.e(error) }) | ||||
|                 .subscribeLatestCache(ChaptersController::onNextChapters) | ||||
|                 { _, error -> Timber.e(error) } | ||||
|  | ||||
|         // Add the subscription that retrieves the chapters from the database, keeps subscribed to | ||||
|         // changes, and sends the list of chapters to the relay. | ||||
|   | ||||
| @@ -262,13 +262,11 @@ class MangaInfoController(private val fromSource: Boolean = false) : | ||||
|                     .centerCrop() | ||||
|                     .into(binding.mangaCover) | ||||
|  | ||||
|             if (binding.backdrop != null) { | ||||
|                 GlideApp.with(view.context) | ||||
|                         .load(manga) | ||||
|                         .diskCacheStrategy(DiskCacheStrategy.RESOURCE) | ||||
|                         .centerCrop() | ||||
|                         .into(binding.backdrop!!) | ||||
|             } | ||||
|             GlideApp.with(view.context) | ||||
|                     .load(manga) | ||||
|                     .diskCacheStrategy(DiskCacheStrategy.RESOURCE) | ||||
|                     .centerCrop() | ||||
|                     .into(binding.backdrop) | ||||
|         } | ||||
|  | ||||
|         // Manga info section | ||||
| @@ -618,8 +616,7 @@ class MangaInfoController(private val fromSource: Boolean = false) : | ||||
|             return | ||||
|         } | ||||
|  | ||||
|         val previousController = router.backstack[router.backstackSize - 2].controller() | ||||
|         when (previousController) { | ||||
|         when (val previousController = router.backstack[router.backstackSize - 2].controller()) { | ||||
|             is LibraryController -> { | ||||
|                 router.handleBack() | ||||
|                 previousController.search(query) | ||||
|   | ||||
| @@ -33,7 +33,7 @@ class SetTrackStatusDialog<T> : DialogController | ||||
|     override fun onCreateDialog(savedViewState: Bundle?): Dialog { | ||||
|         val item = item | ||||
|         val statusList = item.service.getStatusList() | ||||
|         val statusString = statusList.mapNotNull { item.service.getStatus(it) } | ||||
|         val statusString = statusList.map { item.service.getStatus(it) } | ||||
|         val selectedIndex = statusList.indexOf(item.track?.status) | ||||
|  | ||||
|         return MaterialDialog.Builder(activity!!) | ||||
|   | ||||
| @@ -90,7 +90,7 @@ class TrackController : NucleusController<TrackControllerBinding, TrackPresenter | ||||
|     override fun onLogoClick(position: Int) { | ||||
|         val track = adapter?.getItem(position)?.track ?: return | ||||
|  | ||||
|         if (track.tracking_url.isNullOrBlank()) { | ||||
|         if (track.tracking_url.isBlank()) { | ||||
|             activity?.toast(R.string.url_not_set) | ||||
|         } else { | ||||
|             activity?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(track.tracking_url))) | ||||
|   | ||||
| @@ -54,7 +54,7 @@ class TrackSearchAdapter(context: Context) : | ||||
|             view.track_search_title.text = track.title | ||||
|             view.track_search_summary.text = track.summary | ||||
|             GlideApp.with(view.context).clear(view.track_search_cover) | ||||
|             if (!track.cover_url.isNullOrEmpty()) { | ||||
|             if (!track.cover_url.isEmpty()) { | ||||
|                 GlideApp.with(view.context) | ||||
|                         .load(track.cover_url) | ||||
|                         .diskCacheStrategy(DiskCacheStrategy.RESOURCE) | ||||
| @@ -62,21 +62,21 @@ class TrackSearchAdapter(context: Context) : | ||||
|                         .into(view.track_search_cover) | ||||
|             } | ||||
|  | ||||
|             if (track.publishing_status.isNullOrBlank()) { | ||||
|             if (track.publishing_status.isBlank()) { | ||||
|                 view.track_search_status.gone() | ||||
|                 view.track_search_status_result.gone() | ||||
|             } else { | ||||
|                 view.track_search_status_result.text = track.publishing_status.capitalize() | ||||
|             } | ||||
|  | ||||
|             if (track.publishing_type.isNullOrBlank()) { | ||||
|             if (track.publishing_type.isBlank()) { | ||||
|                 view.track_search_type.gone() | ||||
|                 view.track_search_type_result.gone() | ||||
|             } else { | ||||
|                 view.track_search_type_result.text = track.publishing_type.capitalize() | ||||
|             } | ||||
|  | ||||
|             if (track.start_date.isNullOrBlank()) { | ||||
|             if (track.start_date.isBlank()) { | ||||
|                 view.track_search_start.gone() | ||||
|                 view.track_search_start_result.gone() | ||||
|             } else { | ||||
|   | ||||
| @@ -9,8 +9,8 @@ import kotlinx.android.synthetic.main.source_list_item.thumbnail | ||||
| import kotlinx.android.synthetic.main.source_list_item.title | ||||
|  | ||||
| class MangaHolder( | ||||
|     private val view: View, | ||||
|     private val adapter: FlexibleAdapter<*> | ||||
|     view: View, | ||||
|     adapter: FlexibleAdapter<*> | ||||
| ) : BaseFlexibleViewHolder(view, adapter) { | ||||
|  | ||||
|     fun bind(item: MangaItem) { | ||||
|   | ||||
| @@ -25,7 +25,7 @@ class SelectionHeader : AbstractHeaderItem<SelectionHeader.Holder>() { | ||||
|      * Creates a new view holder for this item. | ||||
|      */ | ||||
|     override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): Holder { | ||||
|         return SelectionHeader.Holder(view, adapter) | ||||
|         return Holder(view, adapter) | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -171,7 +171,7 @@ class AboutController : SettingsController() { | ||||
|     } | ||||
|  | ||||
|     private fun getFormattedBuildTime(): String { | ||||
|         try { | ||||
|         return try { | ||||
|             val inputDf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'", Locale.US) | ||||
|             inputDf.timeZone = TimeZone.getTimeZone("UTC") | ||||
|             val buildTime = inputDf.parse(BuildConfig.BUILD_TIME) | ||||
| @@ -180,9 +180,9 @@ class AboutController : SettingsController() { | ||||
|                     DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault()) | ||||
|             outputDf.timeZone = TimeZone.getDefault() | ||||
|  | ||||
|             return buildTime.toDateTimestampString(dateFormat) | ||||
|             buildTime.toDateTimestampString(dateFormat) | ||||
|         } catch (e: ParseException) { | ||||
|             return BuildConfig.BUILD_TIME | ||||
|             BuildConfig.BUILD_TIME | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -7,7 +7,6 @@ import android.text.Spannable | ||||
| import android.text.SpannableString | ||||
| import android.text.style.ScaleXSpan | ||||
| import android.util.AttributeSet | ||||
| import android.widget.TextView | ||||
| import androidx.appcompat.widget.AppCompatTextView | ||||
| import eu.kanade.tachiyomi.widget.OutlineSpan | ||||
|  | ||||
| @@ -39,7 +38,7 @@ class PageIndicatorTextView( | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         super.setText(finalText, TextView.BufferType.SPANNABLE) | ||||
|         super.setText(finalText, BufferType.SPANNABLE) | ||||
|     } | ||||
|  | ||||
|     private companion object { | ||||
|   | ||||
| @@ -361,7 +361,7 @@ class ReaderPresenter( | ||||
|  | ||||
|         if (selectedChapter != currentChapters.currChapter) { | ||||
|             Timber.d("Setting ${selectedChapter.chapter.url} as active") | ||||
|             onChapterChanged(currentChapters.currChapter, selectedChapter) | ||||
|             onChapterChanged(currentChapters.currChapter) | ||||
|             loadNewChapter(selectedChapter) | ||||
|         } | ||||
|     } | ||||
| @@ -370,7 +370,7 @@ class ReaderPresenter( | ||||
|      * Called when a chapter changed from [fromChapter] to [toChapter]. It updates [fromChapter] | ||||
|      * on the database. | ||||
|      */ | ||||
|     private fun onChapterChanged(fromChapter: ReaderChapter, toChapter: ReaderChapter) { | ||||
|     private fun onChapterChanged(fromChapter: ReaderChapter) { | ||||
|         saveChapterProgress(fromChapter) | ||||
|         saveChapterHistory(fromChapter) | ||||
|     } | ||||
|   | ||||
| @@ -33,10 +33,10 @@ class ChapterLoader( | ||||
|         return Observable.just(chapter) | ||||
|                 .doOnNext { chapter.state = ReaderChapter.State.Loading } | ||||
|                 .observeOn(Schedulers.io()) | ||||
|                 .flatMap { | ||||
|                 .flatMap { readerChapter -> | ||||
|                     Timber.d("Loading pages for ${chapter.chapter.name}") | ||||
|  | ||||
|                     val loader = getPageLoader(it) | ||||
|                     val loader = getPageLoader(readerChapter) | ||||
|                     chapter.pageLoader = loader | ||||
|  | ||||
|                     loader.getPages().take(1).doOnNext { pages -> | ||||
|   | ||||
| @@ -122,7 +122,7 @@ class ReaderProgressBar @JvmOverloads constructor( | ||||
|      */ | ||||
|     override fun setVisibility(visibility: Int) { | ||||
|         super.setVisibility(visibility) | ||||
|         val isVisible = visibility == View.VISIBLE | ||||
|         val isVisible = visibility == VISIBLE | ||||
|         if (isVisible) { | ||||
|             startAnimation() | ||||
|         } else { | ||||
| @@ -134,7 +134,7 @@ class ReaderProgressBar @JvmOverloads constructor( | ||||
|      * Starts the rotation animation if needed. | ||||
|      */ | ||||
|     private fun startAnimation() { | ||||
|         if (visibility != View.VISIBLE || windowVisibility != View.VISIBLE || animation != null) { | ||||
|         if (visibility != VISIBLE || windowVisibility != VISIBLE || animation != null) { | ||||
|             return | ||||
|         } | ||||
|  | ||||
| @@ -153,7 +153,7 @@ class ReaderProgressBar @JvmOverloads constructor( | ||||
|      * Hides this progress bar with an optional fade out if [animate] is true. | ||||
|      */ | ||||
|     fun hide(animate: Boolean = false) { | ||||
|         if (visibility == View.GONE) return | ||||
|         if (visibility == GONE) return | ||||
|  | ||||
|         if (!animate) { | ||||
|             gone() | ||||
|   | ||||
| @@ -285,7 +285,7 @@ class PagerPageHolder( | ||||
|         return ReaderProgressBar(context, null).apply { | ||||
|  | ||||
|             val size = 48.dpToPx | ||||
|             layoutParams = FrameLayout.LayoutParams(size, size).apply { | ||||
|             layoutParams = LayoutParams(size, size).apply { | ||||
|                 gravity = Gravity.CENTER | ||||
|             } | ||||
|         } | ||||
| @@ -300,7 +300,7 @@ class PagerPageHolder( | ||||
|         val config = viewer.config | ||||
|  | ||||
|         subsamplingImageView = SubsamplingScaleImageView(context).apply { | ||||
|             layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT) | ||||
|             layoutParams = LayoutParams(MATCH_PARENT, MATCH_PARENT) | ||||
|             setMaxTileSize(viewer.activity.maxBitmapSize) | ||||
|             setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER) | ||||
|             setDoubleTapZoomDuration(config.doubleTapAnimDuration) | ||||
| @@ -335,7 +335,7 @@ class PagerPageHolder( | ||||
|         if (imageView != null) return imageView!! | ||||
|  | ||||
|         imageView = PhotoView(context, null).apply { | ||||
|             layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT) | ||||
|             layoutParams = LayoutParams(MATCH_PARENT, MATCH_PARENT) | ||||
|             adjustViewBounds = true | ||||
|             setZoomTransitionDuration(viewer.config.doubleTapAnimDuration) | ||||
|             setScaleLevels(1f, 2f, 3f) | ||||
| @@ -362,7 +362,7 @@ class PagerPageHolder( | ||||
|         if (retryButton != null) return retryButton!! | ||||
|  | ||||
|         retryButton = PagerButton(context, viewer).apply { | ||||
|             layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { | ||||
|             layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { | ||||
|                 gravity = Gravity.CENTER | ||||
|             } | ||||
|             setText(R.string.action_retry) | ||||
| @@ -399,7 +399,7 @@ class PagerPageHolder( | ||||
|         } | ||||
|  | ||||
|         PagerButton(context, viewer).apply { | ||||
|             layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { | ||||
|             layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { | ||||
|                 setMargins(margins, margins, margins, margins) | ||||
|             } | ||||
|             setText(R.string.action_retry) | ||||
| @@ -413,7 +413,7 @@ class PagerPageHolder( | ||||
|         val imageUrl = page.imageUrl | ||||
|         if (imageUrl.orEmpty().startsWith("http")) { | ||||
|             PagerButton(context, viewer).apply { | ||||
|                 layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { | ||||
|                 layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { | ||||
|                     setMargins(margins, margins, margins, margins) | ||||
|                 } | ||||
|                 setText(R.string.action_open_in_web_view) | ||||
|   | ||||
| @@ -55,7 +55,7 @@ class PagerTransitionHolder( | ||||
|      * dynamically. | ||||
|      */ | ||||
|     private var pagesContainer = LinearLayout(context).apply { | ||||
|         layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT) | ||||
|         layoutParams = LayoutParams(MATCH_PARENT, WRAP_CONTENT) | ||||
|         orientation = VERTICAL | ||||
|         gravity = Gravity.CENTER | ||||
|     } | ||||
|   | ||||
| @@ -209,7 +209,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { | ||||
|      */ | ||||
|     private fun setChaptersInternal(chapters: ViewerChapters) { | ||||
|         Timber.d("setChaptersInternal") | ||||
|         var forceTransition = config.alwaysShowChapterTransition || adapter.items.getOrNull(pager.currentItem) is ChapterTransition | ||||
|         val forceTransition = config.alwaysShowChapterTransition || adapter.items.getOrNull(pager.currentItem) is ChapterTransition | ||||
|         adapter.setChapters(chapters, forceTransition) | ||||
|  | ||||
|         // Layout the pager once a chapter is being set | ||||
|   | ||||
| @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager | ||||
|  | ||||
| import android.view.View | ||||
| import android.view.ViewGroup | ||||
| import androidx.viewpager.widget.PagerAdapter | ||||
| import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition | ||||
| import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter | ||||
| import eu.kanade.tachiyomi.ui.reader.model.ReaderPage | ||||
| @@ -93,8 +92,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { | ||||
|      * Creates a new view for the item at the given [position]. | ||||
|      */ | ||||
|     override fun createView(container: ViewGroup, position: Int): View { | ||||
|         val item = items[position] | ||||
|         return when (item) { | ||||
|         return when (val item = items[position]) { | ||||
|             is ReaderPage -> PagerPageHolder(viewer, item) | ||||
|             is ChapterTransition -> PagerTransitionHolder(viewer, item) | ||||
|             else -> throw NotImplementedError("Holder for ${item.javaClass} not implemented") | ||||
| @@ -113,6 +111,6 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { | ||||
|                 Timber.d("Position for ${view.item} not found") | ||||
|             } | ||||
|         } | ||||
|         return PagerAdapter.POSITION_NONE | ||||
|         return POSITION_NONE | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -82,8 +82,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter<RecyclerV | ||||
|      * Returns the view type for the item at the given [position]. | ||||
|      */ | ||||
|     override fun getItemViewType(position: Int): Int { | ||||
|         val item = items[position] | ||||
|         return when (item) { | ||||
|         return when (val item = items[position]) { | ||||
|             is ReaderPage -> PAGE_VIEW | ||||
|             is ChapterTransition -> TRANSITION_VIEW | ||||
|             else -> error("Unknown view type for ${item.javaClass}") | ||||
|   | ||||
| @@ -202,7 +202,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr | ||||
|      */ | ||||
|     override fun setChapters(chapters: ViewerChapters) { | ||||
|         Timber.d("setChapters") | ||||
|         var forceTransition = config.alwaysShowChapterTransition || currentPage is ChapterTransition | ||||
|         val forceTransition = config.alwaysShowChapterTransition || currentPage is ChapterTransition | ||||
|         adapter.setChapters(chapters, forceTransition) | ||||
|  | ||||
|         if (recycler.visibility == View.GONE) { | ||||
|   | ||||
| @@ -53,9 +53,9 @@ class HistoryPresenter : BasePresenter<HistoryController>() { | ||||
|                     val map = TreeMap<Date, MutableList<MangaChapterHistory>> { d1, d2 -> d2.compareTo(d1) } | ||||
|                     val byDay = recents | ||||
|                             .groupByTo(map, { it.history.last_read.toDateKey() }) | ||||
|                     byDay.flatMap { | ||||
|                         val dateItem = DateSectionItem(it.key) | ||||
|                         it.value.map { HistoryItem(it, dateItem) } | ||||
|                     byDay.flatMap { entry -> | ||||
|                         val dateItem = DateSectionItem(entry.key) | ||||
|                         entry.value.map { HistoryItem(it, dateItem) } | ||||
|                     } | ||||
|                 } | ||||
|                 .observeOn(AndroidSchedulers.mainThread()) | ||||
| @@ -102,7 +102,7 @@ class HistoryPresenter : BasePresenter<HistoryController>() { | ||||
|         } | ||||
|  | ||||
|         val chapters = db.getChapters(manga).executeAsBlocking() | ||||
|                 .sortedWith(Comparator<Chapter> { c1, c2 -> sortFunction(c1, c2) }) | ||||
|                 .sortedWith(Comparator { c1, c2 -> sortFunction(c1, c2) }) | ||||
|  | ||||
|         val currChapterIndex = chapters.indexOfFirst { chapter.id == it.id } | ||||
|         return when (manga.sorting) { | ||||
|   | ||||
| @@ -156,12 +156,12 @@ class UpdatesController : NucleusController<UpdatesControllerBinding, UpdatesPre | ||||
|  | ||||
|         // Get item from position | ||||
|         val item = adapter.getItem(position) as? UpdatesItem ?: return false | ||||
|         if (actionMode != null && adapter.mode == SelectableAdapter.Mode.MULTI) { | ||||
|         return if (actionMode != null && adapter.mode == SelectableAdapter.Mode.MULTI) { | ||||
|             toggleSelection(position) | ||||
|             return true | ||||
|             true | ||||
|         } else { | ||||
|             openChapter(item) | ||||
|             return false | ||||
|             false | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -63,15 +63,15 @@ class UpdatesPresenter( | ||||
|                     val map = TreeMap<Date, MutableList<MangaChapter>> { d1, d2 -> d2.compareTo(d1) } | ||||
|                     val byDay = mangaChapters | ||||
|                             .groupByTo(map, { it.chapter.date_fetch.toDateKey() }) | ||||
|                     byDay.flatMap { | ||||
|                         val dateItem = DateSectionItem(it.key) | ||||
|                         it.value | ||||
|                     byDay.flatMap { entry -> | ||||
|                         val dateItem = DateSectionItem(entry.key) | ||||
|                         entry.value | ||||
|                                 .sortedWith(compareBy({ it.chapter.date_fetch }, { it.chapter.chapter_number })).asReversed() | ||||
|                                 .map { UpdatesItem(it.chapter, it.manga, dateItem) } | ||||
|                     } | ||||
|                 } | ||||
|                 .doOnNext { | ||||
|                     it.forEach { item -> | ||||
|                 .doOnNext { list -> | ||||
|                     list.forEach { item -> | ||||
|                         // Find an active download for this chapter. | ||||
|                         val download = downloadManager.queue.find { it.chapter.id == item.chapter.id } | ||||
|  | ||||
| @@ -81,8 +81,8 @@ class UpdatesPresenter( | ||||
|                             item.download = download | ||||
|                         } | ||||
|                     } | ||||
|                     setDownloadedChapters(it) | ||||
|                     chapters = it | ||||
|                     setDownloadedChapters(list) | ||||
|                     chapters = list | ||||
|                 } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -101,8 +101,8 @@ class SettingsDownloadController : SettingsController() { | ||||
|                         .subscribeUntilDestroy { isVisible = it } | ||||
|  | ||||
|                 preferences.downloadNewCategories().asObservable() | ||||
|                         .subscribeUntilDestroy { | ||||
|                             val selectedCategories = it | ||||
|                         .subscribeUntilDestroy { mutableSet -> | ||||
|                             val selectedCategories = mutableSet | ||||
|                                     .mapNotNull { id -> categories.find { it.id == id.toInt() } } | ||||
|                                     .sortedBy { it.order } | ||||
|  | ||||
|   | ||||
| @@ -118,8 +118,8 @@ class SettingsLibraryController : SettingsController() { | ||||
|                 entries = categories.map { it.name }.toTypedArray() | ||||
|                 entryValues = categories.map { it.id.toString() }.toTypedArray() | ||||
|                 preferences.libraryUpdateCategories().asObservable() | ||||
|                         .subscribeUntilDestroy { | ||||
|                             val selectedCategories = it | ||||
|                         .subscribeUntilDestroy { mutableSet -> | ||||
|                             val selectedCategories = mutableSet | ||||
|                                     .mapNotNull { id -> categories.find { it.id == id.toInt() } } | ||||
|                                     .sortedBy { it.order } | ||||
|  | ||||
|   | ||||
| @@ -87,7 +87,7 @@ class SourcePresenter( | ||||
|                 sharedObs.take(1), | ||||
|                 sharedObs.skip(1).delay(500, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())) | ||||
|                 .distinctUntilChanged() | ||||
|                 .map { (sourceManager.get(it) as? CatalogueSource)?.let { SourceItem(it) } } | ||||
|                 .map { item -> (sourceManager.get(item) as? CatalogueSource)?.let { SourceItem(it) } } | ||||
|                 .subscribeLatestCache(SourceController::setLastUsedSource) | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -149,9 +149,9 @@ open class BrowseSourcePresenter( | ||||
|         pagerSubscription?.let { remove(it) } | ||||
|         pagerSubscription = pager.results() | ||||
|                 .observeOn(Schedulers.io()) | ||||
|                 .map { it.first to it.second.map { networkToLocalManga(it, sourceId) } } | ||||
|                 .map { pair -> pair.first to pair.second.map { networkToLocalManga(it, sourceId) } } | ||||
|                 .doOnNext { initializeMangas(it.second) } | ||||
|                 .map { it.first to it.second.map { SourceItem(it, catalogueAsList) } } | ||||
|                 .map { pair -> pair.first to pair.second.map { SourceItem(it, catalogueAsList) } } | ||||
|                 .observeOn(AndroidSchedulers.mainThread()) | ||||
|                 .subscribeReplay({ view, (page, mangas) -> | ||||
|                     view.onAddPage(page, mangas) | ||||
| @@ -292,17 +292,17 @@ open class BrowseSourcePresenter( | ||||
|     } | ||||
|  | ||||
|     private fun FilterList.toItems(): List<IFlexible<*>> { | ||||
|         return mapNotNull { | ||||
|             when (it) { | ||||
|                 is Filter.Header -> HeaderItem(it) | ||||
|                 is Filter.Separator -> SeparatorItem(it) | ||||
|                 is Filter.CheckBox -> CheckboxItem(it) | ||||
|                 is Filter.TriState -> TriStateItem(it) | ||||
|                 is Filter.Text -> TextItem(it) | ||||
|                 is Filter.Select<*> -> SelectItem(it) | ||||
|         return mapNotNull { filter -> | ||||
|             when (filter) { | ||||
|                 is Filter.Header -> HeaderItem(filter) | ||||
|                 is Filter.Separator -> SeparatorItem(filter) | ||||
|                 is Filter.CheckBox -> CheckboxItem(filter) | ||||
|                 is Filter.TriState -> TriStateItem(filter) | ||||
|                 is Filter.Text -> TextItem(filter) | ||||
|                 is Filter.Select<*> -> SelectItem(filter) | ||||
|                 is Filter.Group<*> -> { | ||||
|                     val group = GroupItem(it) | ||||
|                     val subItems = it.state.mapNotNull { | ||||
|                     val group = GroupItem(filter) | ||||
|                     val subItems = filter.state.mapNotNull { | ||||
|                         when (it) { | ||||
|                             is Filter.CheckBox -> CheckboxSectionItem(it) | ||||
|                             is Filter.TriState -> TriStateSectionItem(it) | ||||
| @@ -316,8 +316,8 @@ open class BrowseSourcePresenter( | ||||
|                     group | ||||
|                 } | ||||
|                 is Filter.Sort -> { | ||||
|                     val group = SortGroup(it) | ||||
|                     val subItems = it.values.map { | ||||
|                     val group = SortGroup(filter) | ||||
|                     val subItems = filter.values.map { | ||||
|                         SortItem(it, group) | ||||
|                     } | ||||
|                     group.subItems = subItems | ||||
|   | ||||
| @@ -43,6 +43,10 @@ class ProgressItem : AbstractFlexibleItem<ProgressItem.Holder>() { | ||||
|         return this === other | ||||
|     } | ||||
|  | ||||
|     override fun hashCode(): Int { | ||||
|         return loadMore.hashCode() | ||||
|     } | ||||
|  | ||||
|     class Holder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter) { | ||||
|  | ||||
|         val progressBar: ProgressBar = view.findViewById(R.id.progress_bar) | ||||
|   | ||||
| @@ -163,9 +163,9 @@ open class GlobalSearchPresenter( | ||||
|                             .subscribeOn(Schedulers.io()) | ||||
|                             .onErrorReturn { MangasPage(emptyList(), false) } // Ignore timeouts or other exceptions | ||||
|                             .map { it.mangas.take(10) } // Get at most 10 manga from search result. | ||||
|                             .map { it.map { networkToLocalManga(it, source.id) } } // Convert to local manga. | ||||
|                             .map { list -> list.map { networkToLocalManga(it, source.id) } } // Convert to local manga. | ||||
|                             .doOnNext { fetchImage(it, source) } // Load manga covers. | ||||
|                             .map { createCatalogueSearchItem(source, it.map { GlobalSearchCardItem(it) }) } | ||||
|                             .map { list -> createCatalogueSearchItem(source, list.map { GlobalSearchCardItem(it) }) } | ||||
|                 }, 5) | ||||
|                 .observeOn(AndroidSchedulers.mainThread()) | ||||
|                 // Update matching source with the obtained results | ||||
| @@ -198,9 +198,9 @@ open class GlobalSearchPresenter( | ||||
|     private fun initializeFetchImageSubscription() { | ||||
|         fetchImageSubscription?.unsubscribe() | ||||
|         fetchImageSubscription = fetchImageSubject.observeOn(Schedulers.io()) | ||||
|                 .flatMap { | ||||
|                     val source = it.second | ||||
|                     Observable.from(it.first).filter { it.thumbnail_url == null && !it.initialized } | ||||
|                 .flatMap { pair -> | ||||
|                     val source = pair.second | ||||
|                     Observable.from(pair.first).filter { it.thumbnail_url == null && !it.initialized } | ||||
|                             .map { Pair(it, source) } | ||||
|                             .concatMap { getMangaDetailsObservable(it.first, it.second) } | ||||
|                             .map { Pair(source as CatalogueSource, it) } | ||||
|   | ||||
| @@ -123,11 +123,11 @@ object ChapterRecognition { | ||||
|             if (alpha.contains("special")) | ||||
|                 return .97f | ||||
|  | ||||
|             if (alpha[0] == '.') { | ||||
|             return if (alpha[0] == '.') { | ||||
|                 // Take value after (.) | ||||
|                 return parseAlphaPostFix(alpha[1]) | ||||
|                 parseAlphaPostFix(alpha[1]) | ||||
|             } else { | ||||
|                 return parseAlphaPostFix(alpha[0]) | ||||
|                 parseAlphaPostFix(alpha[0]) | ||||
|             } | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -85,7 +85,7 @@ object DiskUtil { | ||||
|      */ | ||||
|     fun buildValidFilename(origName: String): String { | ||||
|         val name = origName.trim('.', ' ') | ||||
|         if (name.isNullOrEmpty()) { | ||||
|         if (name.isEmpty()) { | ||||
|             return "(invalid)" | ||||
|         } | ||||
|         val sb = StringBuilder(name.length) | ||||
|   | ||||
| @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.widget | ||||
|  | ||||
| import android.content.Context | ||||
| import android.util.AttributeSet | ||||
| import android.view.View | ||||
| import android.widget.LinearLayout | ||||
| import android.widget.RelativeLayout | ||||
| import androidx.annotation.StringRes | ||||
| @@ -77,6 +76,6 @@ class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? | ||||
|  | ||||
|     data class Action( | ||||
|         @StringRes val resId: Int, | ||||
|         val listener: View.OnClickListener | ||||
|         val listener: OnClickListener | ||||
|     ) | ||||
| } | ||||
|   | ||||
| @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.widget | ||||
| import android.content.Context | ||||
| import android.graphics.drawable.Drawable | ||||
| import android.util.AttributeSet | ||||
| import android.view.View | ||||
| import android.view.ViewGroup | ||||
| import androidx.annotation.CallSuper | ||||
| import androidx.core.content.ContextCompat | ||||
| @@ -160,7 +159,7 @@ open class ExtendedNavigationView @JvmOverloads constructor( | ||||
|      */ | ||||
|     abstract inner class Adapter(private val items: List<Item>) : RecyclerView.Adapter<Holder>() { | ||||
|  | ||||
|         private val onClick = View.OnClickListener { | ||||
|         private val onClick = OnClickListener { | ||||
|             val pos = recycler.getChildAdapterPosition(it) | ||||
|             val item = items[pos] | ||||
|             onItemClicked(item) | ||||
|   | ||||
| @@ -76,7 +76,7 @@ open class SimpleNavigationView @JvmOverloads constructor( | ||||
|     /** | ||||
|      * Clickable view holder. | ||||
|      */ | ||||
|     abstract class ClickableHolder(view: View, listener: View.OnClickListener?) : Holder(view) { | ||||
|     abstract class ClickableHolder(view: View, listener: OnClickListener?) : Holder(view) { | ||||
|         init { | ||||
|             itemView.setOnClickListener(listener) | ||||
|         } | ||||
| @@ -85,7 +85,7 @@ open class SimpleNavigationView @JvmOverloads constructor( | ||||
|     /** | ||||
|      * Radio view holder. | ||||
|      */ | ||||
|     class RadioHolder(parent: ViewGroup, listener: View.OnClickListener?) : | ||||
|     class RadioHolder(parent: ViewGroup, listener: OnClickListener?) : | ||||
|         ClickableHolder(parent.inflate(TR.layout.navigation_view_radio), listener) { | ||||
|  | ||||
|         val radio: RadioButton = itemView.findViewById(TR.id.nav_view_item) | ||||
| @@ -94,7 +94,7 @@ open class SimpleNavigationView @JvmOverloads constructor( | ||||
|     /** | ||||
|      * Checkbox view holder. | ||||
|      */ | ||||
|     class CheckboxHolder(parent: ViewGroup, listener: View.OnClickListener?) : | ||||
|     class CheckboxHolder(parent: ViewGroup, listener: OnClickListener?) : | ||||
|         ClickableHolder(parent.inflate(TR.layout.navigation_view_checkbox), listener) { | ||||
|  | ||||
|         val check: CheckBox = itemView.findViewById(TR.id.nav_view_item) | ||||
| @@ -103,7 +103,7 @@ open class SimpleNavigationView @JvmOverloads constructor( | ||||
|     /** | ||||
|      * Multi state view holder. | ||||
|      */ | ||||
|     class MultiStateHolder(parent: ViewGroup, listener: View.OnClickListener?) : | ||||
|     class MultiStateHolder(parent: ViewGroup, listener: OnClickListener?) : | ||||
|         ClickableHolder(parent.inflate(TR.layout.navigation_view_checkedtext), listener) { | ||||
|  | ||||
|         val text: CheckedTextView = itemView.findViewById(TR.id.nav_view_item) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user