Prettified the subtitle year dialog

This commit is contained in:
Blatzar 2023-01-17 16:57:46 +01:00
parent 42f90a79c4
commit a8352d3f64
5 changed files with 166 additions and 133 deletions

View File

@ -49,10 +49,14 @@ inline fun debugWarning(assert: () -> Boolean, message: () -> String) {
} }
} }
fun <T> LifecycleOwner.observe(liveData: LiveData<T>, action: (t: T) -> Unit) { 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

View File

@ -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) dialog.year_btt.text = it?.toString() ?: txt(R.string.none).asString(context)
return@OnEditorActionListener true }
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()
} }
false
}) 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))
}
)
}
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>()

View File

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

View File

@ -1,159 +1,158 @@
<?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"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginBottom="60dp" android:layout_marginBottom="60dp"
android:baselineAligned="false" android:baselineAligned="false"
android:orientation="horizontal"> android:orientation="horizontal">
<LinearLayout <LinearLayout
android:id="@+id/sort_subtitles_holder" android:id="@+id/sort_subtitles_holder"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="50" android:layout_weight="50"
android:orientation="vertical"> android:orientation="vertical">
<!-- android:id="@+id/subs_settings" android:foreground="?android:attr/selectableItemBackgroundBorderless" <!-- android:id="@+id/subs_settings" android:foreground="?android:attr/selectableItemBackgroundBorderless"
--> -->
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
tools:ignore="UseCompoundDrawables"> tools:ignore="UseCompoundDrawables">
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_margin="10dp" android:layout_margin="10dp"
android:background="@drawable/search_background" android:background="@drawable/search_background"
android:visibility="visible"> android:visibility="visible">
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="30dp" android:layout_height="30dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginEnd="30dp"> android:layout_marginEnd="30dp">
<androidx.appcompat.widget.SearchView <androidx.appcompat.widget.SearchView
android:id="@+id/subtitles_search" android:id="@+id/subtitles_search"
app:iconifiedByDefault="false" android:layout_width="match_parent"
app:queryBackground="@color/transparent" android:layout_height="match_parent"
app:queryHint="@string/search_hint" android:layout_gravity="center_vertical"
app:searchIcon="@drawable/search_icon" android:imeOptions="actionSearch"
android:layout_width="match_parent" android:inputType="text"
android:layout_height="match_parent" android:paddingStart="-10dp"
android:layout_gravity="center_vertical" app:iconifiedByDefault="false"
android:imeOptions="actionSearch" app:queryBackground="@color/transparent"
android:inputType="text" app:queryHint="@string/search_hint"
android:paddingStart="-10dp" app:searchIcon="@drawable/search_icon"
tools:ignore="RtlSymmetry"> tools:ignore="RtlSymmetry">
<androidx.core.widget.ContentLoadingProgressBar
android:id="@+id/search_loading_bar"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:layout_marginStart="-70dp"
android:foregroundTint="@color/white"
android:visibility="visible"
tools:visibility="visible"
android:progressTint="@color/white">
</androidx.core.widget.ContentLoadingProgressBar>
<!--app:queryHint="@string/search_hint" <!--app:queryHint="@string/search_hint"
android:background="@color/grayBackground" @color/itemBackground android:background="@color/grayBackground" @color/itemBackground
app:searchHintIcon="@drawable/search_white" app:searchHintIcon="@drawable/search_white"
--> -->
</androidx.appcompat.widget.SearchView> </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
android:id="@+id/search_loading_bar"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:layout_marginEnd="10dp"
android:foregroundTint="@color/white"
android:progressTint="@color/white"
android:visibility="visible"
tools:visibility="visible">
</androidx.core.widget.ContentLoadingProgressBar>
<com.google.android.material.button.MaterialButton
android:id="@+id/year_btt"
style="@style/WhiteButton"
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" android:nextFocusLeft="@id/main_search"
android:nextFocusLeft="@id/main_search" 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"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_rowWeight="1" android:layout_rowWeight="1"
android:background="?attr/primaryBlackBackground" android:background="?attr/primaryBlackBackground"
android:nextFocusLeft="@id/sort_providers" android:nextFocusLeft="@id/sort_providers"
android:nextFocusRight="@id/cancel_btt" android:nextFocusRight="@id/cancel_btt"
android:requiresFadingEdge="vertical" android:requiresFadingEdge="vertical"
tools:listfooter="@layout/sort_bottom_footer_add_choice" tools:listfooter="@layout/sort_bottom_footer_add_choice"
tools:listitem="@layout/sort_bottom_single_choice" /> tools:listitem="@layout/sort_bottom_single_choice" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/apply_btt_holder" android:id="@+id/apply_btt_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="60dp" android:layout_height="60dp"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_marginTop="-60dp" android:layout_marginTop="-60dp"
android:gravity="bottom|end" android:gravity="bottom|end"
android:orientation="horizontal"> android:orientation="horizontal">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/apply_btt" android:id="@+id/apply_btt"
style="@style/WhiteButton" style="@style/WhiteButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_gravity="center_vertical|end" android:layout_gravity="center_vertical|end"
android:text="@string/sort_apply" /> android:text="@string/sort_apply" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/cancel_btt" android:id="@+id/cancel_btt"
style="@style/BlackButton" style="@style/BlackButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_gravity="center_vertical|end" android:layout_gravity="center_vertical|end"
android:text="@string/sort_cancel" /> android:text="@string/sort_cancel" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

0
gradlew vendored Normal file → Executable file
View File