Skip to content

Commit

Permalink
fix unnecessary duplicate layouts and deprecated..
Browse files Browse the repository at this point in the history
...functions
  • Loading branch information
jmir1 committed Jun 2, 2021
1 parent 4099433 commit f631428
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand Down Expand Up @@ -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() }
Expand Down Expand Up @@ -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),
Expand All @@ -195,29 +195,29 @@ 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
}

// 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 {
Expand All @@ -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
Expand All @@ -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)
}

Expand All @@ -252,33 +252,32 @@ 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
}

// 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)
Expand All @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Preference>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnimeCatalogueSource> {
Expand Down Expand Up @@ -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})" }
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(',', '.')
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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()
}
}
Loading

0 comments on commit f631428

Please sign in to comment.