@@ -12,6 +12,7 @@ import androidx.preference.Preference
12
12
import androidx.preference.PreferenceFragmentCompat
13
13
import androidx.preference.PreferenceManager
14
14
import com.lagradost.quicknovel.APIRepository.Companion.providersActive
15
+ import com.lagradost.quicknovel.CommonActivity
15
16
import com.lagradost.quicknovel.CommonActivity.showToast
16
17
import com.lagradost.quicknovel.R
17
18
import com.lagradost.quicknovel.mvvm.logError
@@ -43,7 +44,31 @@ class SettingsFragment : PreferenceFragmentCompat() {
43
44
}
44
45
}
45
46
47
+
46
48
companion object {
49
+ fun getCurrentLocale (context : Context ): String {
50
+ val res = context.resources
51
+ val conf = res.configuration
52
+
53
+ return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
54
+ conf?.locales?.get(0 )?.toString() ? : " en"
55
+ } else {
56
+ @Suppress(" DEPRECATION" )
57
+ conf?.locale?.toString() ? : " en"
58
+ }
59
+ }
60
+
61
+ // idk, if you find a way of automating this it would be great
62
+ // https://www.iemoji.com/view/emoji/1794/flags/antarctica
63
+ // Emoji Character Encoding Data --> C/C++/Java Src
64
+ // https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes leave blank for auto
65
+ val appLanguages = arrayListOf (
66
+ /* begin language list */
67
+ Triple (" " , " English" , " en" ),
68
+ Triple (" " , " Türkçe" , " tr" ),
69
+ /* end language list */
70
+ ).sortedBy { it.second.lowercase() } // ye, we go alphabetical, so ppl don't put their lang on top
71
+
47
72
fun showSearchProviders (context : Context ? ) {
48
73
if (context == null ) return
49
74
val apiNames = apis.map { it.name }
@@ -176,6 +201,31 @@ class SettingsFragment : PreferenceFragmentCompat() {
176
201
return@setOnPreferenceChangeListener true
177
202
}*/
178
203
204
+ getPref(R .string.locale_key)?.setOnPreferenceClickListener { pref ->
205
+ val tempLangs = appLanguages.toMutableList()
206
+ val current = getCurrentLocale(pref.context)
207
+ val languageCodes = tempLangs.map { (_, _, iso) -> iso }
208
+ val languageNames = tempLangs.map { (emoji, name, iso) ->
209
+ val flag = emoji.ifBlank { SubtitleHelper .getFlagFromIso(iso) ? : " ERROR" }
210
+ " $flag $name "
211
+ }
212
+ val index = languageCodes.indexOf(current)
213
+
214
+ activity?.showDialog(
215
+ languageNames, index, getString(R .string.provider_lang_settings), true , { }
216
+ ) { languageIndex ->
217
+ try {
218
+ val code = languageCodes[languageIndex]
219
+ CommonActivity .setLocale(activity, code)
220
+ settingsManager.edit().putString(getString(R .string.locale_key), code).apply ()
221
+ activity?.recreate()
222
+ } catch (e: Exception ) {
223
+ logError(e)
224
+ }
225
+ }
226
+ return @setOnPreferenceClickListener true
227
+ }
228
+
179
229
getPref(R .string.backup_key)?.setOnPreferenceClickListener {
180
230
activity?.backup()
181
231
return @setOnPreferenceClickListener true
0 commit comments