[Android] Send request instead of 65 when all languages are selected

Habib Kazemi git at videolan.org
Mon Oct 22 15:13:58 CEST 2018


vlc-android | branch: master | Habib Kazemi <kazemihabib1996 at gmail.com> | Sun Oct 21 10:49:56 2018 +0330| [d0567165b81e3e1536131315dfb84e20847697d9] | committer: Geoffrey Métais

Send request instead of 65 when all languages are selected

Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>

> https://code.videolan.org/videolan/vlc-android/commit/d0567165b81e3e1536131315dfb84e20847697d9
---

 vlc-android/src/org/videolan/vlc/gui/MultiSelectionSpinner.kt       | 5 ++---
 .../src/org/videolan/vlc/gui/dialogs/SubtitleDownloadFragment.kt    | 4 +++-
 vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt       | 6 +++---
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MultiSelectionSpinner.kt b/vlc-android/src/org/videolan/vlc/gui/MultiSelectionSpinner.kt
index 216d9dd3b..d319c4660 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MultiSelectionSpinner.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/MultiSelectionSpinner.kt
@@ -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)
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloadFragment.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloadFragment.kt
index ea4b266df..87436002f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloadFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloadFragment.kt
@@ -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) })
 
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
index 37fbd5f5c..e61918356 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
@@ -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 {



More information about the Android mailing list