[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
This commit is contained in:
Jace 2023-01-17 23:11:49 +08:00 committed by GitHub
parent cd8c5966e6
commit 42f90a79c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 2 deletions

View File

@ -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

View File

@ -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() {

View File

@ -99,6 +99,25 @@
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_margin="10dp">
<EditText
android:id="@+id/subtitles_search_year"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="18sp"
android:hint="@string/year"
android:gravity="start|center_vertical"
android:textAlignment="gravity"
android:maxLines="1"
android:inputType="numberSigned"
android:imeOptions="actionDone"/>
</LinearLayout>
<ListView
android:id="@+id/subtitle_adapter"
android:layout_width="match_parent"