Commit d0567165 authored by Habib Kazemi's avatar Habib Kazemi Committed by Geoffrey Métais

Send request instead of 65 when all languages are selected

Signed-off-by: default avatarGeoffrey Métais <geoffrey.metais@gmail.com>
parent 29d7906f
......@@ -83,10 +83,9 @@ class MultiSelectionSpinner : AppCompatSpinner, OnMultiChoiceClickListener, Dial
if (it >= 0 && it < selection.size) selection[it] = true
else throw IllegalArgumentException("Index $it is out of bounds.")
}
adapter.clear()
adapter.add(buildSelectedItemString())
listener?.onItemSelect(this.selectedIndices)
listener?.onItemSelect(selectedIndices)
}
private fun buildSelectedItemString(): String {
......@@ -94,7 +93,7 @@ class MultiSelectionSpinner : AppCompatSpinner, OnMultiChoiceClickListener, Dial
val selectedItems = items.filterIndexed { index, _ -> selection[index] }
if (selectedItems.isEmpty()) sb.append("All")
if (selectedItems.isEmpty() || selectedItems.size == items.size) sb.append("All")
else selectedItems.forEachIndexed { index, s ->
if (index > 0) sb.append(',')
sb.append(s)
......
......@@ -52,10 +52,12 @@ class SubtitleDownloadFragment : androidx.fragment.app.Fragment() {
val allEntriesOfLanguages = resources.getStringArray(R.array.language_entries)
binding.languageListSpinner.setOnItemsSelectListener(object: OnItemSelectListener {
override fun onItemSelect(selectedItems: List<Int>) {
val selectedLanguages = selectedItems.map { allValuesOfLanguages[it] }
val selectedLanguages = if (selectedItems.size == allValuesOfLanguages.size) listOf<String>()
else selectedItems.map { allValuesOfLanguages[it] }
viewModel.observableSearchLanguage.set(selectedLanguages)
}
})
binding.languageListSpinner.setItems(allEntriesOfLanguages.toList())
binding.languageListSpinner.setSelection(viewModel.getLastUsedLanguage().map { allValuesOfLanguages.indexOf(it) })
......
......@@ -18,7 +18,7 @@ import org.videolan.vlc.util.Settings
import java.io.File
import java.util.*
private const val LAST_USED_LANGUAGE = "last_used_subtitle"
private const val LAST_USED_LANGUAGES = "last_used_subtitles"
class SubtitlesModel(private val context: Context, private val mediaPath: String): ScopedModel() {
val observableSearchName = ObservableField<String>()
......@@ -156,9 +156,9 @@ class SubtitlesModel(private val context: Context, private val mediaPath: String
ExternalSubRepository.getInstance(context).deleteSubtitle(mediaPath, idSubtitle)
}
fun getLastUsedLanguage() = Settings.getInstance(context).getStringSet(LAST_USED_LANGUAGE, setOf(Locale.getDefault().isO3Language)).map { it.getCompliantLanguageID() }
fun getLastUsedLanguage() = Settings.getInstance(context).getStringSet(LAST_USED_LANGUAGES, setOf(Locale.getDefault().isO3Language)).map { it.getCompliantLanguageID() }
fun saveLastUsedLanguage(lastUsedLanguages: List<String>) = Settings.getInstance(context).edit().putStringSet(LAST_USED_LANGUAGE, lastUsedLanguages.toSet()).apply()
fun saveLastUsedLanguage(lastUsedLanguages: List<String>) = Settings.getInstance(context).edit().putStringSet(LAST_USED_LANGUAGES, lastUsedLanguages.toSet()).apply()
class Factory(private val context: Context, private val mediaPath: String): ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment