diff --git a/app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt b/app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt index 140ba56793..e349cf28ef 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt @@ -5,8 +5,10 @@ import java.util.regex.Pattern class AnimeNameAdapter { companion object { + val episodeRegex = "(episode|ep|e)[\\s:.\\-]*([\\d]+\\.?[\\d]*)[\\s:.\\-]*" + val seasonRegex = "(season|s)[\\s:.\\-]*(\\d+)[\\s:.\\-]*" + fun findSeasonNumber(text: String): Int? { - val seasonRegex = "(season|s)[\\s:.\\-]*(\\d+)" val seasonPattern: Pattern = Pattern.compile(seasonRegex, Pattern.CASE_INSENSITIVE) val seasonMatcher: Matcher = seasonPattern.matcher(text) @@ -18,7 +20,6 @@ class AnimeNameAdapter { } fun findEpisodeNumber(text: String): Float? { - val episodeRegex = "(episode|ep|e)[\\s:.\\-]*([\\d]+\\.?[\\d]*)" val episodePattern: Pattern = Pattern.compile(episodeRegex, Pattern.CASE_INSENSITIVE) val episodeMatcher: Matcher = episodePattern.matcher(text) @@ -29,4 +30,4 @@ class AnimeNameAdapter { } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt b/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt index ee69dc90c0..5653d6f3cc 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt @@ -17,6 +17,7 @@ import ani.dantotsu.* import ani.dantotsu.databinding.ItemAnimeWatchBinding import ani.dantotsu.databinding.ItemChipBinding import ani.dantotsu.databinding.DialogLayoutBinding +import ani.dantotsu.media.anime.AnimeNameAdapter import ani.dantotsu.media.Media import ani.dantotsu.media.MediaDetailsActivity import ani.dantotsu.media.SourceSearchDialogFragment @@ -310,70 +311,74 @@ class AnimeWatchAdapter( } @SuppressLint("SetTextI18n") - fun handleEpisodes() { - val binding = _binding - if (binding != null) { - if (media.anime?.episodes != null) { - val episodes = media.anime.episodes!!.keys.toTypedArray() - - val anilistEp = (media.userProgress ?: 0).plus(1) - val appEp = loadData("${media.id}_current_ep")?.toIntOrNull() ?: 1 - - var continueEp = (if (anilistEp > appEp) anilistEp else appEp).toString() - if (episodes.contains(continueEp)) { - binding.animeSourceContinue.visibility = View.VISIBLE - handleProgress( - binding.itemEpisodeProgressCont, - binding.itemEpisodeProgress, - binding.itemEpisodeProgressEmpty, - media.id, - continueEp - ) - if ((binding.itemEpisodeProgress.layoutParams as LinearLayout.LayoutParams).weight > fragment.playerSettings.watchPercentage) { - val e = episodes.indexOf(continueEp) - if (e != -1 && e + 1 < episodes.size) { - continueEp = episodes[e + 1] - handleProgress( - binding.itemEpisodeProgressCont, - binding.itemEpisodeProgress, - binding.itemEpisodeProgressEmpty, - media.id, - continueEp - ) - } - } - val ep = media.anime.episodes!![continueEp]!! - binding.itemEpisodeImage.loadImage( - ep.thumb ?: FileUrl[media.banner ?: media.cover], 0 - ) - if (ep.filler) binding.itemEpisodeFillerView.visibility = View.VISIBLE - binding.animeSourceContinueText.text = - currActivity()!!.getString(R.string.continue_episode) + "${ep.number}${if (ep.filler) " - Filler" else ""}${if (ep.title != null) "\n${ep.title}" else ""}" - binding.animeSourceContinue.setOnClickListener { - fragment.onEpisodeClick(continueEp) +fun handleEpisodes() { + val binding = _binding + if (binding != null) { + if (media.anime?.episodes != null) { + val episodes = media.anime.episodes!!.keys.toTypedArray() + + val anilistEp = (media.userProgress ?: 0).plus(1) + val appEp = loadData("${media.id}_current_ep")?.toIntOrNull() ?: 1 + + var continueEp = (if (anilistEp > appEp) anilistEp else appEp).toString() + if (episodes.contains(continueEp)) { + binding.animeSourceContinue.visibility = View.VISIBLE + handleProgress( + binding.itemEpisodeProgressCont, + binding.itemEpisodeProgress, + binding.itemEpisodeProgressEmpty, + media.id, + continueEp + ) + if ((binding.itemEpisodeProgress.layoutParams as LinearLayout.LayoutParams).weight > fragment.playerSettings.watchPercentage) { + val e = episodes.indexOf(continueEp) + if (e != -1 && e + 1 < episodes.size) { + continueEp = episodes[e + 1] + handleProgress( + binding.itemEpisodeProgressCont, + binding.itemEpisodeProgress, + binding.itemEpisodeProgressEmpty, + media.id, + continueEp + ) } - if (fragment.continueEp) { - if ((binding.itemEpisodeProgress.layoutParams as LinearLayout.LayoutParams).weight < fragment.playerSettings.watchPercentage) { - binding.animeSourceContinue.performClick() - fragment.continueEp = false - } + } + val ep = media.anime.episodes!![continueEp]!! + + val cleanedTitle = ep.title?.replace(Regex(AnimeNameAdapter.episodeRegex, RegexOption.IGNORE_CASE), "") + + binding.itemEpisodeImage.loadImage( + ep.thumb ?: FileUrl[media.banner ?: media.cover], 0 + ) + if (ep.filler) binding.itemEpisodeFillerView.visibility = View.VISIBLE + binding.animeSourceContinueText.text = + currActivity()!!.getString(R.string.continue_episode) + "${ep.number}${if (ep.filler) " - Filler" else ""}${if (cleanedTitle != null) "\n$cleanedTitle" else ""}" + binding.animeSourceContinue.setOnClickListener { + fragment.onEpisodeClick(continueEp) + } + if (fragment.continueEp) { + if ((binding.itemEpisodeProgress.layoutParams as LinearLayout.LayoutParams).weight < fragment.playerSettings.watchPercentage) { + binding.animeSourceContinue.performClick() + fragment.continueEp = false } - } else { - binding.animeSourceContinue.visibility = View.GONE } - binding.animeSourceProgressBar.visibility = View.GONE - if (media.anime.episodes!!.isNotEmpty()) - binding.animeSourceNotFound.visibility = View.GONE - else - binding.animeSourceNotFound.visibility = View.VISIBLE } else { binding.animeSourceContinue.visibility = View.GONE - binding.animeSourceNotFound.visibility = View.GONE - clearChips() - binding.animeSourceProgressBar.visibility = View.VISIBLE } + + binding.animeSourceProgressBar.visibility = View.GONE + if (media.anime.episodes!!.isNotEmpty()) + binding.animeSourceNotFound.visibility = View.GONE + else + binding.animeSourceNotFound.visibility = View.VISIBLE + } else { + binding.animeSourceContinue.visibility = View.GONE + binding.animeSourceNotFound.visibility = View.GONE + clearChips() + binding.animeSourceProgressBar.visibility = View.VISIBLE } } +} private fun setLanguageList(lang: Int, source: Int) { val binding = _binding @@ -413,4 +418,4 @@ class AnimeWatchAdapter( countDown(media, binding.animeSourceContainer) } } -} \ No newline at end of file +} diff --git a/app/src/main/java/ani/dantotsu/media/anime/EpisodeAdapters.kt b/app/src/main/java/ani/dantotsu/media/anime/EpisodeAdapters.kt index 1a85b9bf19..8e5afb516c 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/EpisodeAdapters.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/EpisodeAdapters.kt @@ -11,6 +11,7 @@ import ani.dantotsu.connections.updateProgress import ani.dantotsu.databinding.ItemEpisodeCompactBinding import ani.dantotsu.databinding.ItemEpisodeGridBinding import ani.dantotsu.databinding.ItemEpisodeListBinding +import ani.dantotsu.media.anime.AnimeNameAdapter import ani.dantotsu.media.Media import com.bumptech.glide.Glide import com.bumptech.glide.load.model.GlideUrl @@ -76,12 +77,11 @@ class EpisodeAdapter( @SuppressLint("SetTextI18n") override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { val ep = arr[position] - val title = - "${ - if (!ep.title.isNullOrEmpty() && ep.title != "null") "" else currContext()!!.getString( - R.string.episode_singular - ) - } ${if (!ep.title.isNullOrEmpty() && ep.title != "null") ep.title else ep.number}" +val title = if (!ep.title.isNullOrEmpty() && ep.title != "null") { + (ep.title as? String)?.replaceFirst(Regex(AnimeNameAdapter.episodeRegex, RegexOption.IGNORE_CASE), "") +} else { + ep.number +} ?: "" when (holder) { is EpisodeListViewHolder -> { @@ -246,4 +246,3 @@ class EpisodeAdapter( } } - diff --git a/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt b/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt index f96408676d..52b3e9a27b 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt @@ -69,6 +69,7 @@ import ani.dantotsu.connections.discord.DiscordServiceRunningSingleton import ani.dantotsu.connections.discord.RPC import ani.dantotsu.connections.updateProgress import ani.dantotsu.databinding.ActivityExoplayerBinding +import ani.dantotsu.media.anime.AnimeNameAdapter import ani.dantotsu.media.Media import ani.dantotsu.media.MediaDetailsViewModel import ani.dantotsu.media.SubtitleDownloader @@ -946,14 +947,17 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL //Anime Title animeTitle.text = media.userPreferredName - episodeArr = episodes.keys.toList() - currentEpisodeIndex = episodeArr.indexOf(media.anime!!.selectedEpisode!!) +episodeArr = episodes.keys.toList() +currentEpisodeIndex = episodeArr.indexOf(media.anime!!.selectedEpisode!!) - episodeTitleArr = arrayListOf() - episodes.forEach { - val episode = it.value - episodeTitleArr.add("${if (!episode.title.isNullOrEmpty() && episode.title != "null") "" else "Episode "}${episode.number}${if (episode.filler) " [Filler]" else ""}${if (!episode.title.isNullOrEmpty() && episode.title != "null") " : " + episode.title else ""}") - } +val episodeTitleArr = arrayListOf() +episodes.forEach { + val episode = it.value + episodeTitleArr.add("${if (!episode.title.isNullOrEmpty() && episode.title != "null") "" else "numeric :"}${episode.number}${if (episode.filler) " [Filler]" else ""}${if (!episode.title.isNullOrEmpty() && episode.title != "null") " : " + episode.title else ""}") +} + +val regexPattern = Regex(AnimeNameAdapter.episodeRegex, RegexOption.IGNORE_CASE) +episodeTitleArr.replaceAll { it.replace(regexPattern, "") } //Episode Change fun change(index: Int) { diff --git a/app/src/main/java/ani/dantotsu/media/manga/MangaNameAdapter.kt b/app/src/main/java/ani/dantotsu/media/manga/MangaNameAdapter.kt index 05e9b360da..af608a9edc 100644 --- a/app/src/main/java/ani/dantotsu/media/manga/MangaNameAdapter.kt +++ b/app/src/main/java/ani/dantotsu/media/manga/MangaNameAdapter.kt @@ -5,8 +5,8 @@ import java.util.regex.Pattern class MangaNameAdapter { companion object { + val chapterRegex = "(chapter|chap|ch|c)[\\s:.\\-]*([\\d]+\\.?[\\d]*)[\\s:.\\-]*" fun findChapterNumber(text: String): Float? { - val regex = "(chapter|chap|ch|c)[\\s:.\\-]*([\\d]+\\.?[\\d]*)" val pattern: Pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE) val matcher: Matcher = pattern.matcher(text) @@ -17,4 +17,4 @@ class MangaNameAdapter { } } } -} \ No newline at end of file +}