[Android] SubtitlesModel: Set English for not supported lang

Geoffrey Métais git at videolan.org
Thu Feb 14 11:15:42 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 14 11:14:11 2019 +0100| [3ad6693661fc389aa6890032bd2c93ee2789a425] | committer: Geoffrey Métais

SubtitlesModel: Set English for not supported lang

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

 vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
index 7f205b62f..cb2323a71 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
@@ -1,10 +1,10 @@
 package org.videolan.vlc.viewmodels
 
-import androidx.lifecycle.*
 import android.content.Context
 import androidx.databinding.Observable
 import androidx.databinding.ObservableBoolean
 import androidx.databinding.ObservableField
+import androidx.lifecycle.*
 import kotlinx.coroutines.*
 import org.videolan.vlc.R
 import org.videolan.vlc.api.NoConnectivityException
@@ -166,7 +166,14 @@ class SubtitlesModel(private val context: Context, private val mediaPath: String
         ExternalSubRepository.getInstance(context).deleteSubtitle(mediaPath, idSubtitle)
     }
 
-    fun getLastUsedLanguage() = Settings.getInstance(context).getStringSet(LAST_USED_LANGUAGES, setOf(Locale.getDefault().isO3Language)).map { it.getCompliantLanguageID() }
+    fun getLastUsedLanguage() : List<String> {
+        val language = try {
+            Locale.getDefault().isO3Language
+        } catch (e: MissingResourceException) {
+            "eng"
+        }
+        return Settings.getInstance(context).getStringSet(LAST_USED_LANGUAGES, setOf(language))?.map { it.getCompliantLanguageID() } ?: emptyList()
+    }
 
     fun saveLastUsedLanguage(lastUsedLanguages: List<String>) = Settings.getInstance(context).edit().putStringSet(LAST_USED_LANGUAGES, lastUsedLanguages.toSet()).apply()
 



More information about the Android mailing list