From f63142841cd95bc269eda814dd07aed776c27b10 Mon Sep 17 00:00:00 2001 From: jmir1 Date: Wed, 2 Jun 2021 11:23:27 +0200 Subject: [PATCH] fix unnecessary duplicate layouts and deprecated.. ...functions --- .../tachiyomi/animesource/LocalAnimeSource.kt | 6 +- .../animesource/online/AnimeHttpSource.kt | 4 +- .../ui/anime/info/AnimeInfoHeaderAdapter.kt | 89 +++--- .../animeextension/AnimeExtensionHolder.kt | 2 +- .../AnimeExtensionDetailsController.kt | 2 +- .../AnimeSourceFilterController.kt | 2 +- .../animesource/AnimeSourcePresenter.kt | 2 +- .../GlobalAnimeSearchPresenter.kt | 4 +- .../search/AnimeSourceSearchController.kt | 5 + .../sources/MigrationSourcesPresenter.kt | 2 +- .../util/episode/EpisodeRecognition.kt | 6 +- app/src/main/res/layout/anime_info_header.xml | 274 ------------------ 12 files changed, 64 insertions(+), 334 deletions(-) delete mode 100644 app/src/main/res/layout/anime_info_header.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/animesource/LocalAnimeSource.kt b/app/src/main/java/eu/kanade/tachiyomi/animesource/LocalAnimeSource.kt index 71d6515d07..a2704c8983 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/animesource/LocalAnimeSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/animesource/LocalAnimeSource.kt @@ -83,9 +83,9 @@ class LocalAnimeSource(private val context: Context) : AnimeCatalogueSource { when (state?.index) { 0 -> { animeDirs = if (state.ascending) { - animeDirs.sortedBy { it.name.toLowerCase(Locale.ENGLISH) } + animeDirs.sortedBy { it.name.lowercase(Locale.ENGLISH) } } else { - animeDirs.sortedByDescending { it.name.toLowerCase(Locale.ENGLISH) } + animeDirs.sortedByDescending { it.name.lowercase(Locale.ENGLISH) } } } 1 -> { @@ -239,7 +239,7 @@ class LocalAnimeSource(private val context: Context) : AnimeCatalogueSource { } private fun isSupportedFile(extension: String): Boolean { - return extension.toLowerCase(Locale.ROOT) in SUPPORTED_ARCHIVE_TYPES + return extension.lowercase(Locale.ROOT) in SUPPORTED_ARCHIVE_TYPES } fun getFormat(episode: SEpisode): Format { diff --git a/app/src/main/java/eu/kanade/tachiyomi/animesource/online/AnimeHttpSource.kt b/app/src/main/java/eu/kanade/tachiyomi/animesource/online/AnimeHttpSource.kt index 24f697be53..e345cd6605 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/animesource/online/AnimeHttpSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/animesource/online/AnimeHttpSource.kt @@ -53,7 +53,7 @@ abstract class AnimeHttpSource : AnimeCatalogueSource { * Note the generated id sets the sign bit to 0. */ override val id by lazy { - val key = "${name.toLowerCase()}/$lang/$versionId" + val key = "${name.lowercase()}/$lang/$versionId" val bytes = MessageDigest.getInstance("MD5").digest(key.toByteArray()) (0..7).map { bytes[it].toLong() and 0xff shl 8 * (7 - it) }.reduce(Long::or) and Long.MAX_VALUE } @@ -79,7 +79,7 @@ abstract class AnimeHttpSource : AnimeCatalogueSource { /** * Visible name of the source. */ - override fun toString() = "$name (${lang.toUpperCase()})" + override fun toString() = "$name (${lang.uppercase()})" /** * Returns an observable containing a page with a list of anime. Normally it's not needed to diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/info/AnimeInfoHeaderAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/info/AnimeInfoHeaderAdapter.kt index 476f607cd2..77eaf2853f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/info/AnimeInfoHeaderAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/info/AnimeInfoHeaderAdapter.kt @@ -13,7 +13,7 @@ import eu.kanade.tachiyomi.animesource.model.SAnime import eu.kanade.tachiyomi.animesource.online.AnimeHttpSource import eu.kanade.tachiyomi.data.database.models.Anime import eu.kanade.tachiyomi.data.track.TrackManager -import eu.kanade.tachiyomi.databinding.AnimeInfoHeaderBinding +import eu.kanade.tachiyomi.databinding.MangaInfoHeaderBinding import eu.kanade.tachiyomi.ui.anime.AnimeController import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.util.view.setChips @@ -39,12 +39,12 @@ class AnimeInfoHeaderAdapter( private var source: AnimeSource = controller.presenter.source private var trackCount: Int = 0 - private lateinit var binding: AnimeInfoHeaderBinding + private lateinit var binding: MangaInfoHeaderBinding private var initialLoad: Boolean = true override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HeaderViewHolder { - binding = AnimeInfoHeaderBinding.inflate(LayoutInflater.from(parent.context), parent, false) + binding = MangaInfoHeaderBinding.inflate(LayoutInflater.from(parent.context), parent, false) return HeaderViewHolder(binding.root) } @@ -76,7 +76,7 @@ class AnimeInfoHeaderAdapter( inner class HeaderViewHolder(private val view: View) : RecyclerView.ViewHolder(view) { fun bind() { // For rounded corners - binding.animeCover.clipToOutline = true + binding.mangaCover.clipToOutline = true binding.btnFavorite.clicks() .onEach { controller.onFavoriteClick() } @@ -121,61 +121,61 @@ class AnimeInfoHeaderAdapter( .launchIn(controller.viewScope) } - binding.animeFullTitle.longClicks() + binding.mangaFullTitle.longClicks() .onEach { controller.activity?.copyToClipboard( view.context.getString(R.string.title), - binding.animeFullTitle.text.toString() + binding.mangaFullTitle.text.toString() ) } .launchIn(controller.viewScope) - binding.animeFullTitle.clicks() + binding.mangaFullTitle.clicks() .onEach { - controller.performGlobalSearch(binding.animeFullTitle.text.toString()) + controller.performGlobalSearch(binding.mangaFullTitle.text.toString()) } .launchIn(controller.viewScope) - binding.animeAuthor.longClicks() + binding.mangaAuthor.longClicks() .onEach { controller.activity?.copyToClipboard( - binding.animeAuthor.text.toString(), - binding.animeAuthor.text.toString() + binding.mangaAuthor.text.toString(), + binding.mangaAuthor.text.toString() ) } .launchIn(controller.viewScope) - binding.animeAuthor.clicks() + binding.mangaAuthor.clicks() .onEach { - controller.performGlobalSearch(binding.animeAuthor.text.toString()) + controller.performGlobalSearch(binding.mangaAuthor.text.toString()) } .launchIn(controller.viewScope) - binding.animeArtist.longClicks() + binding.mangaArtist.longClicks() .onEach { controller.activity?.copyToClipboard( - binding.animeArtist.text.toString(), - binding.animeArtist.text.toString() + binding.mangaArtist.text.toString(), + binding.mangaArtist.text.toString() ) } .launchIn(controller.viewScope) - binding.animeArtist.clicks() + binding.mangaArtist.clicks() .onEach { - controller.performGlobalSearch(binding.animeArtist.text.toString()) + controller.performGlobalSearch(binding.mangaArtist.text.toString()) } .launchIn(controller.viewScope) - binding.animeSummaryText.longClicks() + binding.mangaSummaryText.longClicks() .onEach { controller.activity?.copyToClipboard( view.context.getString(R.string.description), - binding.animeSummaryText.text.toString() + binding.mangaSummaryText.text.toString() ) } .launchIn(controller.viewScope) - binding.animeCover.longClicks() + binding.mangaCover.longClicks() .onEach { controller.activity?.copyToClipboard( view.context.getString(R.string.title), @@ -195,14 +195,14 @@ class AnimeInfoHeaderAdapter( */ private fun setAnimeInfo(anime: Anime, source: AnimeSource?) { // Update full title TextView. - binding.animeFullTitle.text = if (anime.title.isBlank()) { + binding.mangaFullTitle.text = if (anime.title.isBlank()) { view.context.getString(R.string.unknown) } else { anime.title } // Update author TextView. - binding.animeAuthor.text = if (anime.author.isNullOrBlank()) { + binding.mangaAuthor.text = if (anime.author.isNullOrBlank()) { view.context.getString(R.string.unknown_author) } else { anime.author @@ -210,14 +210,14 @@ class AnimeInfoHeaderAdapter( // Update artist TextView. val hasArtist = !anime.artist.isNullOrBlank() && anime.artist != anime.author - binding.animeArtist.isVisible = hasArtist + binding.mangaArtist.isVisible = hasArtist if (hasArtist) { - binding.animeArtist.text = anime.artist + binding.mangaArtist.text = anime.artist } // If anime source is known update source TextView. val animeSource = source?.toString() - with(binding.animeSource) { + with(binding.mangaSource) { if (animeSource != null) { text = animeSource setOnClickListener { @@ -230,7 +230,7 @@ class AnimeInfoHeaderAdapter( } // Update status TextView. - binding.animeStatus.setText( + binding.mangaStatus.setText( when (anime.status) { SAnime.ONGOING -> R.string.ongoing SAnime.COMPLETED -> R.string.completed @@ -243,7 +243,7 @@ class AnimeInfoHeaderAdapter( setFavoriteButtonState(anime.favorite) // Set cover if changed. - listOf(binding.animeCover, binding.backdrop).forEach { + listOf(binding.mangaCover, binding.backdrop).forEach { it.loadAny(anime.thumbnail_url) } @@ -252,7 +252,7 @@ class AnimeInfoHeaderAdapter( showAnimeInfo(hasInfoContent) if (hasInfoContent) { // Update description TextView. - binding.animeSummaryText.text = if (anime.description.isNullOrBlank()) { + binding.mangaSummaryText.text = if (anime.description.isNullOrBlank()) { view.context.getString(R.string.unknown) } else { anime.description @@ -260,25 +260,24 @@ class AnimeInfoHeaderAdapter( // Update genres list if (!anime.genre.isNullOrBlank()) { - binding.animeGenresTagsCompactChips.setChips( + binding.mangaGenresTagsCompactChips.setChips( anime.getGenres(), controller::performSearch ) - binding.animeGenresTagsFullChips.setChips( + binding.mangaGenresTagsFullChips.setChips( anime.getGenres(), controller::performSearch ) } else { - binding.animeGenresTagsCompactChips.isVisible = false - binding.animeGenresTagsFullChips.isVisible = false + binding.mangaGenresTagsCompactChips.isVisible = false + binding.mangaGenresTagsFullChips.isVisible = false } // Handle showing more or less info merge( - binding.animeSummarySection.clicks(), - binding.animeSummaryText.clicks(), - binding.animeInfoToggleMore.clicks(), - binding.animeInfoToggleLess.clicks() + binding.mangaSummaryText.clicks(), + binding.mangaInfoToggleMore.clicks(), + binding.mangaInfoToggleLess.clicks() ) .onEach { toggleAnimeInfo() } .launchIn(controller.viewScope) @@ -293,24 +292,24 @@ class AnimeInfoHeaderAdapter( } private fun showAnimeInfo(visible: Boolean) { - binding.animeSummarySection.isVisible = visible + binding.mangaSummarySection.isVisible = visible } private fun toggleAnimeInfo() { - val isCurrentlyExpanded = binding.animeSummaryText.maxLines != 2 + val isCurrentlyExpanded = binding.mangaSummaryText.maxLines != 2 - binding.animeInfoToggleMoreScrim.isVisible = isCurrentlyExpanded - binding.animeInfoToggleMore.isVisible = isCurrentlyExpanded - binding.animeInfoToggleLess.isVisible = !isCurrentlyExpanded + binding.mangaInfoToggleMoreScrim.isVisible = isCurrentlyExpanded + binding.mangaInfoToggleMore.isVisible = isCurrentlyExpanded + binding.mangaInfoToggleLess.isVisible = !isCurrentlyExpanded - binding.animeSummaryText.maxLines = if (isCurrentlyExpanded) { + binding.mangaSummaryText.maxLines = if (isCurrentlyExpanded) { 2 } else { Int.MAX_VALUE } - binding.animeGenresTagsCompact.isVisible = isCurrentlyExpanded - binding.animeGenresTagsFullChips.isVisible = !isCurrentlyExpanded + binding.mangaGenresTagsCompact.isVisible = isCurrentlyExpanded + binding.mangaGenresTagsFullChips.isVisible = !isCurrentlyExpanded } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animeextension/AnimeExtensionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animeextension/AnimeExtensionHolder.kt index 46260cfead..cebbd52dcf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animeextension/AnimeExtensionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animeextension/AnimeExtensionHolder.kt @@ -40,7 +40,7 @@ class AnimeExtensionHolder(view: View, val adapter: AnimeExtensionAdapter) : extension is AnimeExtension.Installed && extension.isObsolete -> itemView.context.getString(R.string.ext_obsolete) extension.isNsfw && shouldLabelNsfw -> itemView.context.getString(R.string.ext_nsfw_short) else -> "" - }.toUpperCase() + }.uppercase() binding.image.clear() if (extension is AnimeExtension.Available) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animeextension/details/AnimeExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animeextension/details/AnimeExtensionDetailsController.kt index 50f7078015..b47c38369c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animeextension/details/AnimeExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animeextension/details/AnimeExtensionDetailsController.kt @@ -114,7 +114,7 @@ class AnimeExtensionDetailsController(bundle: Bundle? = null) : .forEach { val preferenceBlock = { it.value - .sortedWith(compareBy({ !it.isEnabled() }, { it.name.toLowerCase() })) + .sortedWith(compareBy({ !it.isEnabled() }, { it.name.lowercase() })) .forEach { source -> val sourcePrefs = mutableListOf() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/AnimeSourceFilterController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/AnimeSourceFilterController.kt index 8307eedc68..f956e965a8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/AnimeSourceFilterController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/AnimeSourceFilterController.kt @@ -42,7 +42,7 @@ class AnimeSourceFilterController : SettingsController() { ) orderedLangs.forEach { lang -> - val sources = sourcesByLang[lang].orEmpty().sortedBy { it.name.toLowerCase() } + val sources = sourcesByLang[lang].orEmpty().sortedBy { it.name.lowercase() } // Create a preference group and set initial state and change listener switchPreferenceCategory { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/AnimeSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/AnimeSourcePresenter.kt index 5ac40d84ef..12c6dd4127 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/AnimeSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/AnimeSourcePresenter.kt @@ -122,7 +122,7 @@ class AnimeSourcePresenter( return sourceManager.getCatalogueSources() .filter { it.lang in languages } .filterNot { it.id.toString() in disabledSourceIds } - .sortedBy { "(${it.lang}) ${it.name.toLowerCase()}" } + + .sortedBy { "(${it.lang}) ${it.name.lowercase()}" } + sourceManager.get(LocalAnimeSource.ID) as LocalAnimeSource } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/globalsearch/GlobalAnimeSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/globalsearch/GlobalAnimeSearchPresenter.kt index dc70dd2eb0..fb46b33b36 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/globalsearch/GlobalAnimeSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/animesource/globalsearch/GlobalAnimeSearchPresenter.kt @@ -105,7 +105,7 @@ open class GlobalAnimeSearchPresenter( return sourceManager.getCatalogueSources() .filter { it.lang in languages } .filterNot { it.id.toString() in disabledSourceIds } - .sortedWith(compareBy({ it.id.toString() !in pinnedSourceIds }, { "${it.name.toLowerCase()} (${it.lang})" })) + .sortedWith(compareBy({ it.id.toString() !in pinnedSourceIds }, { "${it.name.lowercase()} (${it.lang})" })) } private fun getSourcesToQuery(): List { @@ -185,7 +185,7 @@ open class GlobalAnimeSearchPresenter( { it.results.isNullOrEmpty() }, // Same as initial sort, i.e. pinned first then alphabetically { it.source.id.toString() !in pinnedSourceIds }, - { "${it.source.name.toLowerCase()} (${it.source.lang})" } + { "${it.source.name.lowercase()} (${it.source.lang})" } ) ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/AnimeSourceSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/AnimeSourceSearchController.kt index 6c63c74f13..e47bd067aa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/AnimeSourceSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/AnimeSourceSearchController.kt @@ -33,6 +33,11 @@ class AnimeSourceSearchController( dialog.showDialog(router) return true } + + override fun onItemLongClick(position: Int) { + view?.let { super.onItemClick(it, position) } + } + private companion object { const val ANIME_KEY = "oldAnime" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesPresenter.kt index 04fcf13527..b77f04bf7b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesPresenter.kt @@ -57,7 +57,7 @@ class MigrationSourcesPresenter( val source = animesourceManager.getOrStub(it.key) AnimeSourceItem(source, it.value.size) } - .sortedBy { it.source.name.toLowerCase() } + .sortedBy { it.source.name.lowercase() } .toList() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/episode/EpisodeRecognition.kt b/app/src/main/java/eu/kanade/tachiyomi/util/episode/EpisodeRecognition.kt index 1f677a9f17..f3e2e4a486 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/episode/EpisodeRecognition.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/episode/EpisodeRecognition.kt @@ -44,7 +44,7 @@ object EpisodeRecognition { } // Get episode title with lower case - var name = episode.name.toLowerCase() + var name = episode.name.lowercase() // Remove comma's from episode. name = name.replace(',', '.') @@ -77,7 +77,7 @@ object EpisodeRecognition { } // Remove anime title from episode title. - val nameWithoutAnime = name.replace(anime.title.toLowerCase(), "").trim() + val nameWithoutAnime = name.replace(anime.title.lowercase(), "").trim() // Check if first value is number after title remove. if (updateEpisode(withoutAnime.find(nameWithoutAnime), episode)) { @@ -147,6 +147,6 @@ object EpisodeRecognition { * x.a -> x.1, x.b -> x.2, etc */ private fun parseAlphaPostFix(alpha: Char): Float { - return ("0." + (alpha.toInt() - 96).toString()).toFloat() + return ("0." + (alpha.code - 96).toString()).toFloat() } } diff --git a/app/src/main/res/layout/anime_info_header.xml b/app/src/main/res/layout/anime_info_header.xml deleted file mode 100644 index 9cce110f7f..0000000000 --- a/app/src/main/res/layout/anime_info_header.xml +++ /dev/null @@ -1,274 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -