forked from recloudstream/cloudstream
Prettified the subtitle year dialog
This commit is contained in:
parent
42f90a79c4
commit
a8352d3f64
5 changed files with 166 additions and 133 deletions
|
@ -53,6 +53,10 @@ fun <T> LifecycleOwner.observe(liveData: LiveData<T>, action: (t: T) -> Unit) {
|
||||||
liveData.observe(this) { it?.let { t -> action(t) } }
|
liveData.observe(this) { it?.let { t -> action(t) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> LifecycleOwner.observeNullable(liveData: LiveData<T>, action: (t: T) -> Unit) {
|
||||||
|
liveData.observe(this) { action(it) }
|
||||||
|
}
|
||||||
|
|
||||||
inline fun <reified T : Any> some(value: T?): Some<T> {
|
inline fun <reified T : Any> some(value: T?): Some<T> {
|
||||||
return if (value == null) {
|
return if (value == null) {
|
||||||
Some.None
|
Some.None
|
||||||
|
|
|
@ -28,19 +28,13 @@ import com.hippo.unifile.UniFile
|
||||||
import com.lagradost.cloudstream3.*
|
import com.lagradost.cloudstream3.*
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
|
import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
|
||||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||||
import com.lagradost.cloudstream3.mvvm.Resource
|
import com.lagradost.cloudstream3.mvvm.*
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
|
||||||
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
|
||||||
import com.lagradost.cloudstream3.mvvm.observe
|
|
||||||
import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities
|
import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.subtitleProviders
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.subtitleProviders
|
||||||
import com.lagradost.cloudstream3.ui.player.CS3IPlayer.Companion.preferredAudioTrackLanguage
|
import com.lagradost.cloudstream3.ui.player.CS3IPlayer.Companion.preferredAudioTrackLanguage
|
||||||
import com.lagradost.cloudstream3.ui.player.CustomDecoder.Companion.updateForcedEncoding
|
import com.lagradost.cloudstream3.ui.player.CustomDecoder.Companion.updateForcedEncoding
|
||||||
import com.lagradost.cloudstream3.ui.player.PlayerSubtitleHelper.Companion.toSubtitleMimeType
|
import com.lagradost.cloudstream3.ui.player.PlayerSubtitleHelper.Companion.toSubtitleMimeType
|
||||||
import com.lagradost.cloudstream3.ui.result.ResultEpisode
|
import com.lagradost.cloudstream3.ui.result.*
|
||||||
import com.lagradost.cloudstream3.ui.result.ResultFragment
|
|
||||||
import com.lagradost.cloudstream3.ui.result.SyncViewModel
|
|
||||||
import com.lagradost.cloudstream3.ui.result.setText
|
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
||||||
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.getAutoSelectLanguageISO639_1
|
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.getAutoSelectLanguageISO639_1
|
||||||
import com.lagradost.cloudstream3.utils.*
|
import com.lagradost.cloudstream3.utils.*
|
||||||
|
@ -63,6 +57,9 @@ import kotlinx.android.synthetic.main.player_select_source_and_subs.*
|
||||||
import kotlinx.android.synthetic.main.player_select_source_and_subs.subtitles_click_settings
|
import kotlinx.android.synthetic.main.player_select_source_and_subs.subtitles_click_settings
|
||||||
import kotlinx.android.synthetic.main.player_select_tracks.*
|
import kotlinx.android.synthetic.main.player_select_tracks.*
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
import kotlin.collections.HashMap
|
||||||
|
|
||||||
class GeneratorPlayer : FullScreenPlayer() {
|
class GeneratorPlayer : FullScreenPlayer() {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -332,28 +329,54 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
dialog.search_loading_bar.progressTintList = color
|
dialog.search_loading_bar.progressTintList = color
|
||||||
dialog.search_loading_bar.indeterminateTintList = color
|
dialog.search_loading_bar.indeterminateTintList = color
|
||||||
|
|
||||||
//Automatically search after entering Year
|
observeNullable(viewModel.currentSubtitleYear) {
|
||||||
dialog.subtitles_search_year.setOnEditorActionListener(OnEditorActionListener { v, actionId, event ->
|
// When year is changed search again
|
||||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
|
||||||
dialog.subtitles_search.setQuery(dialog.subtitles_search.query, true)
|
dialog.subtitles_search.setQuery(dialog.subtitles_search.query, true)
|
||||||
return@OnEditorActionListener true
|
dialog.year_btt.text = it?.toString() ?: txt(R.string.none).asString(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.year_btt?.setOnClickListener {
|
||||||
|
val none = txt(R.string.none).asString(context)
|
||||||
|
val currentYear = Calendar.getInstance().get(Calendar.YEAR)
|
||||||
|
val earliestYear = 1900
|
||||||
|
|
||||||
|
val years = (currentYear downTo earliestYear).toList()
|
||||||
|
val options = listOf(none) + years.map {
|
||||||
|
it.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
val selectedIndex = viewModel.currentSubtitleYear.value
|
||||||
|
?.let {
|
||||||
|
// + 1 since none also takes a space
|
||||||
|
years.indexOf(it) + 1
|
||||||
|
}
|
||||||
|
?.takeIf { it >= 0 } ?: 0
|
||||||
|
|
||||||
|
activity?.showDialog(
|
||||||
|
options,
|
||||||
|
selectedIndex,
|
||||||
|
txt(R.string.year).asString(context),
|
||||||
|
true, {
|
||||||
|
}, { index ->
|
||||||
|
viewModel.setSubtitleYear(years.getOrNull(index - 1))
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
false
|
|
||||||
})
|
|
||||||
|
|
||||||
dialog.subtitles_search.setOnQueryTextListener(object :
|
dialog.subtitles_search.setOnQueryTextListener(object :
|
||||||
androidx.appcompat.widget.SearchView.OnQueryTextListener {
|
androidx.appcompat.widget.SearchView.OnQueryTextListener {
|
||||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||||
dialog.search_loading_bar?.show()
|
dialog.search_loading_bar?.show()
|
||||||
ioSafe {
|
ioSafe {
|
||||||
val year = dialog.subtitles_search_year?.text?.toString()?.toIntOrNull()
|
|
||||||
val search =
|
val search =
|
||||||
AbstractSubtitleEntities.SubtitleSearch(query = query ?: return@ioSafe,
|
AbstractSubtitleEntities.SubtitleSearch(
|
||||||
|
query = query ?: return@ioSafe,
|
||||||
imdb = imdbId,
|
imdb = imdbId,
|
||||||
epNumber = currentTempMeta.episode,
|
epNumber = currentTempMeta.episode,
|
||||||
seasonNumber = currentTempMeta.season,
|
seasonNumber = currentTempMeta.season,
|
||||||
lang = currentLanguageTwoLetters.ifBlank { null },
|
lang = currentLanguageTwoLetters.ifBlank { null },
|
||||||
year = year)
|
year = viewModel.currentSubtitleYear.value
|
||||||
|
)
|
||||||
val results = providers.amap {
|
val results = providers.amap {
|
||||||
try {
|
try {
|
||||||
it.search(search)
|
it.search(search)
|
||||||
|
@ -361,7 +384,7 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}.filterNotNull()
|
}.filterNotNull()
|
||||||
val max = results.map { it.size }.maxOrNull() ?: return@ioSafe
|
val max = results.maxOfOrNull { it.size } ?: return@ioSafe
|
||||||
|
|
||||||
// very ugly
|
// very ugly
|
||||||
val items = ArrayList<AbstractSubtitleEntities.SubtitleEntity>()
|
val items = ArrayList<AbstractSubtitleEntities.SubtitleEntity>()
|
||||||
|
|
|
@ -35,6 +35,13 @@ class PlayerGeneratorViewModel : ViewModel() {
|
||||||
private val _currentStamps = MutableLiveData<List<EpisodeSkip.SkipStamp>>(emptyList())
|
private val _currentStamps = MutableLiveData<List<EpisodeSkip.SkipStamp>>(emptyList())
|
||||||
val currentStamps: LiveData<List<EpisodeSkip.SkipStamp>> = _currentStamps
|
val currentStamps: LiveData<List<EpisodeSkip.SkipStamp>> = _currentStamps
|
||||||
|
|
||||||
|
private val _currentSubtitleYear = MutableLiveData<Int?>(null)
|
||||||
|
val currentSubtitleYear: LiveData<Int?> = _currentSubtitleYear
|
||||||
|
|
||||||
|
fun setSubtitleYear(year: Int?) {
|
||||||
|
_currentSubtitleYear.postValue(year)
|
||||||
|
}
|
||||||
|
|
||||||
fun getId(): Int? {
|
fun getId(): Int? {
|
||||||
return generator?.getCurrentId()
|
return generator?.getCurrentId()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@null"
|
android:background="@null"
|
||||||
|
@ -44,48 +44,65 @@
|
||||||
|
|
||||||
<androidx.appcompat.widget.SearchView
|
<androidx.appcompat.widget.SearchView
|
||||||
android:id="@+id/subtitles_search"
|
android:id="@+id/subtitles_search"
|
||||||
app:iconifiedByDefault="false"
|
|
||||||
app:queryBackground="@color/transparent"
|
|
||||||
app:queryHint="@string/search_hint"
|
|
||||||
|
|
||||||
app:searchIcon="@drawable/search_icon"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
|
|
||||||
android:imeOptions="actionSearch"
|
android:imeOptions="actionSearch"
|
||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
|
|
||||||
android:paddingStart="-10dp"
|
android:paddingStart="-10dp"
|
||||||
|
app:iconifiedByDefault="false"
|
||||||
|
|
||||||
|
app:queryBackground="@color/transparent"
|
||||||
|
app:queryHint="@string/search_hint"
|
||||||
|
app:searchIcon="@drawable/search_icon"
|
||||||
tools:ignore="RtlSymmetry">
|
tools:ignore="RtlSymmetry">
|
||||||
|
|
||||||
|
<!--app:queryHint="@string/search_hint"
|
||||||
|
android:background="@color/grayBackground" @color/itemBackground
|
||||||
|
app:searchHintIcon="@drawable/search_white"
|
||||||
|
-->
|
||||||
|
</androidx.appcompat.widget.SearchView>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
android:gravity="end">
|
||||||
|
|
||||||
<androidx.core.widget.ContentLoadingProgressBar
|
<androidx.core.widget.ContentLoadingProgressBar
|
||||||
android:id="@+id/search_loading_bar"
|
android:id="@+id/search_loading_bar"
|
||||||
style="@style/Widget.AppCompat.ProgressBar"
|
style="@style/Widget.AppCompat.ProgressBar"
|
||||||
android:layout_width="20dp"
|
android:layout_width="20dp"
|
||||||
android:layout_height="20dp"
|
android:layout_height="20dp"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_marginStart="-70dp"
|
android:layout_marginEnd="10dp"
|
||||||
android:foregroundTint="@color/white"
|
android:foregroundTint="@color/white"
|
||||||
|
android:progressTint="@color/white"
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
tools:visibility="visible"
|
tools:visibility="visible">
|
||||||
android:progressTint="@color/white">
|
|
||||||
|
|
||||||
</androidx.core.widget.ContentLoadingProgressBar>
|
</androidx.core.widget.ContentLoadingProgressBar>
|
||||||
<!--app:queryHint="@string/search_hint"
|
|
||||||
android:background="@color/grayBackground" @color/itemBackground
|
<com.google.android.material.button.MaterialButton
|
||||||
app:searchHintIcon="@drawable/search_white"
|
android:id="@+id/year_btt"
|
||||||
-->
|
style="@style/WhiteButton"
|
||||||
</androidx.appcompat.widget.SearchView>
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center_vertical|end"
|
||||||
|
android:layout_marginEnd="20dp"
|
||||||
|
android:text="@string/none"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/search_filter"
|
android:id="@+id/search_filter"
|
||||||
app:tint="?attr/textColor"
|
|
||||||
android:layout_width="25dp"
|
android:layout_width="25dp"
|
||||||
android:layout_height="25dp"
|
android:layout_height="25dp"
|
||||||
|
|
||||||
android:layout_gravity="end|center_vertical"
|
android:layout_gravity="end|center_vertical"
|
||||||
|
|
||||||
android:layout_margin="10dp"
|
android:layout_margin="10dp"
|
||||||
android:background="?selectableItemBackgroundBorderless"
|
android:background="?selectableItemBackgroundBorderless"
|
||||||
android:contentDescription="@string/change_providers_img_des"
|
android:contentDescription="@string/change_providers_img_des"
|
||||||
|
@ -93,31 +110,13 @@
|
||||||
android:nextFocusRight="@id/main_search"
|
android:nextFocusRight="@id/main_search"
|
||||||
android:nextFocusUp="@id/nav_rail_view"
|
android:nextFocusUp="@id/nav_rail_view"
|
||||||
android:nextFocusDown="@id/search_autofit_results"
|
android:nextFocusDown="@id/search_autofit_results"
|
||||||
android:src="@drawable/ic_baseline_tune_24" />
|
android:src="@drawable/ic_baseline_tune_24"
|
||||||
|
app:tint="?attr/textColor" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</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
|
<ListView
|
||||||
android:id="@+id/subtitle_adapter"
|
android:id="@+id/subtitle_adapter"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
0
gradlew
vendored
Normal file → Executable file
0
gradlew
vendored
Normal file → Executable file
Loading…
Reference in a new issue