From 42f90a79c4bb5c7d8b2d22a5c111476d333a061f Mon Sep 17 00:00:00 2001 From: Jace <54625750+Jacekun@users.noreply.github.com> Date: Tue, 17 Jan 2023 23:11:49 +0800 Subject: [PATCH] [Feature] Allow input of Year on Subtitle search (#232) * Use query text as default filename of subtitle instead of empty string. * [Feature] Allow input of Year on Subtitle search --- .../providers/OpenSubtitlesApi.kt | 2 +- .../cloudstream3/ui/player/GeneratorPlayer.kt | 17 ++++++++++++++++- .../res/layout/dialog_online_subtitles.xml | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt index d5d6400c..8f06c98e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt @@ -206,7 +206,7 @@ class OpenSubtitlesApi(index: Int) : InAppAuthAPIManager(index), AbstractSubApi } //Use any valid name/title in hierarchy val name = filename ?: featureDetails?.movieName ?: featureDetails?.title - ?: featureDetails?.parentTitle ?: attr.release ?: "" + ?: featureDetails?.parentTitle ?: attr.release ?: query.query val lang = fixLanguageReverse(attr.language)?: "" val resEpNum = featureDetails?.episodeNumber ?: query.epNumber val resSeasonNum = featureDetails?.seasonNumber ?: query.seasonNumber diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index fa0a2a7f..37f13c6c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -11,7 +11,9 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.inputmethod.EditorInfo import android.widget.* +import android.widget.TextView.OnEditorActionListener import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AlertDialog import androidx.core.animation.addListener @@ -330,17 +332,28 @@ class GeneratorPlayer : FullScreenPlayer() { dialog.search_loading_bar.progressTintList = color dialog.search_loading_bar.indeterminateTintList = color + //Automatically search after entering Year + dialog.subtitles_search_year.setOnEditorActionListener(OnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_DONE) { + dialog.subtitles_search.setQuery(dialog.subtitles_search.query, true) + return@OnEditorActionListener true + } + false + }) + dialog.subtitles_search.setOnQueryTextListener(object : androidx.appcompat.widget.SearchView.OnQueryTextListener { override fun onQueryTextSubmit(query: String?): Boolean { dialog.search_loading_bar?.show() ioSafe { + val year = dialog.subtitles_search_year?.text?.toString()?.toIntOrNull() val search = AbstractSubtitleEntities.SubtitleSearch(query = query ?: return@ioSafe, imdb = imdbId, epNumber = currentTempMeta.episode, seasonNumber = currentTempMeta.season, - lang = currentLanguageTwoLetters.ifBlank { null }) + lang = currentLanguageTwoLetters.ifBlank { null }, + year = year) val results = providers.amap { try { it.search(search) @@ -414,6 +427,8 @@ class GeneratorPlayer : FullScreenPlayer() { dialog.show() dialog.subtitles_search.setQuery(currentTempMeta.name, true) + //TODO: Set year text from currently loaded movie on Player + //dialog.subtitles_search_year?.setText(currentTempMeta.year) } private fun openSubPicker() { diff --git a/app/src/main/res/layout/dialog_online_subtitles.xml b/app/src/main/res/layout/dialog_online_subtitles.xml index 824d8089..4acd27be 100644 --- a/app/src/main/res/layout/dialog_online_subtitles.xml +++ b/app/src/main/res/layout/dialog_online_subtitles.xml @@ -99,6 +99,25 @@ + + + +