Made Language into provider (#68)

* made the language category to Provider category

* Remove the translations for the language category since it's now changed
This commit is contained in:
KillerDogeEmpire 2022-08-29 15:20:03 -06:00 committed by GitHub
parent 9d1bc4800c
commit e503534ab1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 90 additions and 95 deletions

View file

@ -183,7 +183,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
R.id.navigation_settings_updates,
R.id.navigation_settings_ui,
R.id.navigation_settings_account,
R.id.navigation_settings_lang,
R.id.navigation_settings_providers,
R.id.navigation_settings_general,
R.id.navigation_settings_extensions,
R.id.navigation_settings_plugins,

View file

@ -173,7 +173,7 @@ class SettingsFragment : Fragment() {
Pair(settings_player, R.id.action_navigation_settings_to_navigation_settings_player),
Pair(settings_credits, R.id.action_navigation_settings_to_navigation_settings_account),
Pair(settings_ui, R.id.action_navigation_settings_to_navigation_settings_ui),
Pair(settings_lang, R.id.action_navigation_settings_to_navigation_settings_lang),
Pair(settings_providers, R.id.action_navigation_settings_to_navigation_settings_providers),
Pair(settings_updates, R.id.action_navigation_settings_to_navigation_settings_updates),
Pair(
settings_extensions,

View file

@ -1,5 +1,6 @@
package com.lagradost.cloudstream3.ui.settings
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
@ -17,6 +18,7 @@ import com.lagradost.cloudstream3.APIHolder.allProviders
import com.lagradost.cloudstream3.AcraApplication
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
import com.lagradost.cloudstream3.CommonActivity
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.app
@ -30,6 +32,7 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpTo
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog
import com.lagradost.cloudstream3.utils.SubtitleHelper
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import com.lagradost.cloudstream3.utils.USER_PROVIDER_API
@ -39,6 +42,44 @@ import kotlinx.android.synthetic.main.add_remove_sites.*
import kotlinx.android.synthetic.main.add_site_input.*
import java.io.File
fun getCurrentLocale(context: Context): String {
val res = context.resources
// Change locale settings in the app.
// val dm = res.displayMetrics
val conf = res.configuration
return conf?.locale?.language ?: "en"
}
// idk, if you find a way of automating this it would be great
// https://www.iemoji.com/view/emoji/1794/flags/antarctica
// Emoji Character Encoding Data --> C/C++/Java Src
// https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes leave blank for auto
val appLanguages = arrayListOf(
Triple("", "Spanish", "es"),
Triple("", "English", "en"),
Triple("", "Viet Nam", "vi"),
Triple("", "Dutch", "nl"),
Triple("", "French", "fr"),
Triple("", "Greek", "el"),
Triple("", "Swedish", "sv"),
Triple("", "Tagalog", "tl"),
Triple("", "Polish", "pl"),
Triple("", "Hindi", "hi"),
Triple("", "Malayalam", "ml"),
Triple("", "Norsk", "no"),
Triple("", "German", "de"),
Triple("", "Arabic", "ar"),
Triple("", "Turkish", "tr"),
Triple("", "Macedonian", "mk"),
Triple("\uD83C\uDDF5\uD83C\uDDF9", "Portuguese", "pt"),
Triple("\uD83C\uDDE7\uD83C\uDDF7", "Brazilian Portuguese", "bp"),
Triple("", "Romanian", "ro"),
Triple("", "Italian", "it"),
Triple("", "Chinese", "zh"),
Triple("\uD83C\uDDEE\uD83C\uDDE9", "Indonesian", "in"),
Triple("", "Czech", "cs"),
).sortedBy { it.second } //ye, we go alphabetical, so ppl don't put their lang on top
class SettingsGeneral : PreferenceFragmentCompat() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@ -95,6 +136,35 @@ class SettingsGeneral : PreferenceFragmentCompat() {
?: mutableListOf()
}
getPref(R.string.locale_key)?.setOnPreferenceClickListener { pref ->
val tempLangs = appLanguages.toMutableList()
//if (beneneCount > 100) {
// tempLangs.add(Triple("\uD83E\uDD8D", "mmmm... monke", "mo"))
//}
val current = getCurrentLocale(pref.context)
val languageCodes = tempLangs.map { (_, _, iso) -> iso }
val languageNames = tempLangs.map { (emoji, name, iso) ->
val flag = emoji.ifBlank { SubtitleHelper.getFlagFromIso(iso) ?: "ERROR" }
"$flag $name"
}
val index = languageCodes.indexOf(current)
activity?.showDialog(
languageNames, index, getString(R.string.app_language), true, { }
) { languageIndex ->
try {
val code = languageCodes[languageIndex]
CommonActivity.setLocale(activity, code)
settingsManager.edit().putString(getString(R.string.locale_key), code).apply()
activity?.recreate()
} catch (e: Exception) {
logError(e)
}
}
return@setOnPreferenceClickListener true
}
fun showAdd() {
val providers = allProviders.distinctBy { it.javaClass }.sortedBy { it.name }
activity?.showDialog(

View file

@ -20,54 +20,18 @@ import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog
import com.lagradost.cloudstream3.utils.SubtitleHelper
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
fun getCurrentLocale(context: Context): String {
val res = context.resources
// Change locale settings in the app.
// val dm = res.displayMetrics
val conf = res.configuration
return conf?.locale?.language ?: "en"
}
// idk, if you find a way of automating this it would be great
// https://www.iemoji.com/view/emoji/1794/flags/antarctica
// Emoji Character Encoding Data --> C/C++/Java Src
// https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes leave blank for auto
val appLanguages = arrayListOf(
Triple("", "Spanish", "es"),
Triple("", "English", "en"),
Triple("", "Viet Nam", "vi"),
Triple("", "Dutch", "nl"),
Triple("", "French", "fr"),
Triple("", "Greek", "el"),
Triple("", "Swedish", "sv"),
Triple("", "Tagalog", "tl"),
Triple("", "Polish", "pl"),
Triple("", "Hindi", "hi"),
Triple("", "Malayalam", "ml"),
Triple("", "Norsk", "no"),
Triple("", "German", "de"),
Triple("", "Arabic", "ar"),
Triple("", "Turkish", "tr"),
Triple("", "Macedonian", "mk"),
Triple("\uD83C\uDDF5\uD83C\uDDF9", "Portuguese", "pt"),
Triple("\uD83C\uDDE7\uD83C\uDDF7", "Brazilian Portuguese", "bp"),
Triple("", "Romanian", "ro"),
Triple("", "Italian", "it"),
Triple("", "Chinese", "zh"),
Triple("\uD83C\uDDEE\uD83C\uDDE9", "Indonesian", "in"),
Triple("", "Czech", "cs"),
).sortedBy { it.second } //ye, we go alphabetical, so ppl don't put their lang on top
class SettingsLang : PreferenceFragmentCompat() {
class SettingsProviders : PreferenceFragmentCompat() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setUpToolbar(R.string.category_preferred_media_and_lang)
setUpToolbar(R.string.category_providers)
setPaddingBottom()
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
hideKeyboard()
setPreferencesFromResource(R.xml.settings_media_lang, rootKey)
setPreferencesFromResource(R.xml.settings_providers, rootKey)
val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())
getPref(R.string.display_sub_key)?.setOnPreferenceClickListener {
@ -123,34 +87,6 @@ class SettingsLang : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true
}
getPref(R.string.locale_key)?.setOnPreferenceClickListener { pref ->
val tempLangs = appLanguages.toMutableList()
//if (beneneCount > 100) {
// tempLangs.add(Triple("\uD83E\uDD8D", "mmmm... monke", "mo"))
//}
val current = getCurrentLocale(pref.context)
val languageCodes = tempLangs.map { (_, _, iso) -> iso }
val languageNames = tempLangs.map { (emoji, name, iso) ->
val flag = emoji.ifBlank { SubtitleHelper.getFlagFromIso(iso) ?: "ERROR" }
"$flag $name"
}
val index = languageCodes.indexOf(current)
activity?.showDialog(
languageNames, index, getString(R.string.app_language), true, { }
) { languageIndex ->
try {
val code = languageCodes[languageIndex]
CommonActivity.setLocale(activity, code)
settingsManager.edit().putString(getString(R.string.locale_key), code).apply()
activity?.recreate()
} catch (e: Exception) {
logError(e)
}
}
return@setOnPreferenceClickListener true
}
getPref(R.string.provider_lang_key)?.setOnPreferenceClickListener {
activity?.getApiProviderLangSettings()?.let { current ->
val langs = APIHolder.apis.map { it.lang }.toSet()

View file

@ -65,22 +65,22 @@
style="@style/SettingsItem"
android:nextFocusUp="@id/settings_general"
android:nextFocusDown="@id/settings_lang"
android:nextFocusDown="@id/settings_providers"
android:text="@string/category_player" />
<TextView
android:id="@+id/settings_lang"
android:id="@+id/settings_providers"
style="@style/SettingsItem"
android:nextFocusUp="@id/settings_player"
android:nextFocusDown="@id/settings_ui"
android:text="@string/category_preferred_media_and_lang" />
android:text="@string/category_providers" />
<TextView
android:id="@+id/settings_ui"
style="@style/SettingsItem"
android:nextFocusUp="@id/settings_lang"
android:nextFocusUp="@id/settings_providers"
android:nextFocusDown="@id/settings_updates"
android:text="@string/category_ui" />

View file

@ -205,8 +205,8 @@
tools:layout="@layout/fragment_webview" />
<fragment
android:id="@+id/navigation_settings_lang"
android:name="com.lagradost.cloudstream3.ui.settings.SettingsLang"
android:id="@+id/navigation_settings_providers"
android:name="com.lagradost.cloudstream3.ui.settings.SettingsProviders"
android:label="@string/title_settings"
app:enterAnim="@anim/enter_anim"
app:exitAnim="@anim/exit_anim"
@ -326,8 +326,8 @@
app:popEnterAnim="@anim/enter_anim"
app:popExitAnim="@anim/exit_anim" />
<action
android:id="@+id/action_navigation_settings_to_navigation_settings_lang"
app:destination="@id/navigation_settings_lang"
android:id="@+id/action_navigation_settings_to_navigation_settings_providers"
app:destination="@id/navigation_settings_providers"
app:enterAnim="@anim/enter_anim"
app:exitAnim="@anim/exit_anim"
app:popEnterAnim="@anim/enter_anim"

View file

@ -357,7 +357,6 @@
<string name="app_layout">Layout do App</string>
<string name="preferred_media_settings">Mídia preferida</string>
<string name="subtitles_encoding">Codificação das legendas</string>
<string name="category_preferred_media_and_lang">Linguagem</string>
<string name="category_ui">Layout</string>
<string name="automatic">Auto</string>

View file

@ -342,7 +342,6 @@
<string name="app_layout">Rozložení aplikace</string>
<string name="preferred_media_settings">Preferovaná média</string>
<string name="subtitles_encoding">Kódování titulků</string>
<string name="category_preferred_media_and_lang">Jazyk</string>
<string name="category_ui">Rozložení</string>
<string name="automatic">Automaticky</string>

View file

@ -344,7 +344,6 @@
<string name="app_layout">App Layout</string>
<string name="preferred_media_settings">Bevorzugte Medien</string>
<string name="subtitles_encoding">Untertitel-Kodierung</string>
<string name="category_preferred_media_and_lang">Sprache</string>
<string name="category_ui">Layout</string>
<string name="automatic">Auto</string>

View file

@ -346,8 +346,7 @@
<string name="provider_lang_settings">Idiomas del proveedor</string>
<string name="app_layout">Diseño de la aplicación</string>
<string name="preferred_media_settings">Medios preferidos</string>
<string name="subtitles_encoding">Codificación de subtítulos</string>
<string name="category_preferred_media_and_lang">Idioma</string>
<string name="subtitles_encoding">Codificación de subtítulos</string>
<string name="category_ui">Diseño</string>
<string name="automatic">Automático</string>

View file

@ -337,7 +337,6 @@
<string name="provider_lang_settings">Bahasa provider</string>
<string name="app_layout">Tata Letak Aplikasi</string>
<string name="preferred_media_settings">Media yang lebih diinginkan</string>
<string name="category_preferred_media_and_lang">Media dan bahasa yang lebih diinginkan</string>
<string name="category_ui">Antarmuka pengguna</string>
<string name="automatic">Otomatis</string>

View file

@ -333,7 +333,6 @@
<string name="app_layout">Layout app</string>
<string name="preferred_media_settings">Media preferito</string>
<string name="subtitles_encoding">Encoding Sottotitoli</string>
<string name="category_preferred_media_and_lang">Media e lingua preferiti</string>
<string name="category_ui">Interfaccia utente</string>
<string name="automatic">Auto</string>

View file

@ -337,7 +337,6 @@
<string name="app_layout">App Layout</string>
<string name="preferred_media_settings">Preferred media</string>
<string name="subtitles_encoding">Subtitle encoding</string>
<string name="category_preferred_media_and_lang">Language</string>
<string name="category_ui">Layout</string>
<string name="automatic">Auto</string>

View file

@ -311,7 +311,6 @@
<string name="preferred_media_settings">Preferowane media</string>
<string name="subtitles_encoding">Kodowanie napisów</string>
<string name="category_preferred_media_and_lang">Język</string>
<string name="category_ui">Układ interfejsu</string>
<string name="automatic">Automatyczny</string>
<string name="tv_layout">Układ dla telewizorów</string>

View file

@ -342,7 +342,6 @@
<string name="app_layout">Layout da App</string>
<string name="preferred_media_settings">Mídia preferida</string>
<string name="subtitles_encoding">Codificação das legendas</string>
<string name="category_preferred_media_and_lang">Linguagem</string>
<string name="category_ui">Layout</string>
<string name="automatic">Auto</string>

View file

@ -347,7 +347,6 @@
<string name="app_layout">Aplicație de prezentare</string>
<string name="preferred_media_settings">Media preferată</string>
<string name="subtitles_encoding">Codificarea subtitrărilor</string>
<string name="category_preferred_media_and_lang">Media și limba preferată</string>
<string name="category_ui">Interfața utilizatorului</string>
<string name="automatic">Auto</string>

View file

@ -350,7 +350,6 @@
<string name="app_layout">Uygulama düzeni</string>
<string name="preferred_media_settings">Tercih edilen medya</string>
<string name="subtitles_encoding">Alt yazı kodlaması</string>
<string name="category_preferred_media_and_lang">Dil</string>
<string name="category_ui">Düzen</string>
<string name="automatic">Otomatik</string>

View file

@ -348,7 +348,6 @@
<string name="app_layout">Giao diện App</string>
<string name="preferred_media_settings">Thể loại ưu tiên</string>
<string name="subtitles_encoding">Mã hoá phụ đề</string>
<string name="category_preferred_media_and_lang">Ngôn ngữ</string>
<string name="category_ui">Giao diện</string>
<string name="automatic">Tự động</string>

View file

@ -447,7 +447,7 @@
<string name="preferred_media_settings">Preferred media</string>
<string name="enable_nsfw_on_providers">Enable NSFW on supported providers</string>
<string name="subtitles_encoding">Subtitle encoding</string>
<string name="category_preferred_media_and_lang">Language</string>
<string name="category_providers">Providers</string>
<string name="category_ui">Layout</string>
<string name="automatic">Auto</string>

View file

@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference
android:key="@string/locale_key"
android:title="@string/app_language"
android:icon="@drawable/ic_baseline_language_24" />
<Preference
android:icon="@drawable/ic_baseline_language_24"
android:key="@string/provider_lang_key"

View file

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference
android:key="@string/locale_key"
android:title="@string/app_language"
android:icon="@drawable/ic_baseline_language_24" />
<Preference
android:key="@string/override_site_key"
android:title="@string/add_site_pref"