mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Added an option to change the language
This commit is contained in:
parent
8c5a34861c
commit
9088236620
@ -2,6 +2,7 @@ package com.github.libretube
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@ -27,6 +28,7 @@ import androidx.navigation.ui.setupWithNavController
|
|||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.google.android.material.color.DynamicColors
|
import com.google.android.material.color.DynamicColors
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
val TAG = "MainActivity"
|
val TAG = "MainActivity"
|
||||||
@ -40,6 +42,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
RetrofitInstance.url = sharedPreferences.getString("instance", "https://pipedapi.kavin.rocks/")!!
|
RetrofitInstance.url = sharedPreferences.getString("instance", "https://pipedapi.kavin.rocks/")!!
|
||||||
DynamicColors.applyToActivitiesIfAvailable(application)
|
DynamicColors.applyToActivitiesIfAvailable(application)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
var languageName = sharedPreferences.getString("language", "en")!!
|
||||||
|
if (languageName != "") {
|
||||||
|
val locale = Locale("$languageName")
|
||||||
|
val res = resources
|
||||||
|
val dm = res.displayMetrics
|
||||||
|
val conf = res.configuration
|
||||||
|
conf.locale = locale
|
||||||
|
res.updateConfiguration(conf, dm)
|
||||||
|
}
|
||||||
when (sharedPreferences.getString("theme_togglee", "A")!!) {
|
when (sharedPreferences.getString("theme_togglee", "A")!!) {
|
||||||
"A" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
"A" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||||
"L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
"L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||||
|
@ -8,6 +8,7 @@ import android.content.pm.PackageManager
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.LocaleList
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
@ -16,6 +17,7 @@ import androidx.activity.result.contract.ActivityResultContracts
|
|||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.os.LocaleListCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
@ -27,8 +29,10 @@ import org.json.JSONTokener
|
|||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
import java.util.*
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipInputStream
|
import java.util.zip.ZipInputStream
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
|
|
||||||
class Settings : PreferenceFragmentCompat() {
|
class Settings : PreferenceFragmentCompat() {
|
||||||
@ -189,6 +193,24 @@ class Settings : PreferenceFragmentCompat() {
|
|||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val changeLanguage = findPreference<ListPreference>("language")
|
||||||
|
changeLanguage?.setOnPreferenceChangeListener { _, languageName ->
|
||||||
|
val locale = Locale("$languageName")
|
||||||
|
val res = resources
|
||||||
|
val dm = res.displayMetrics
|
||||||
|
val conf = res.configuration
|
||||||
|
conf.locale = locale
|
||||||
|
res.updateConfiguration(conf, dm)
|
||||||
|
val refresh = Intent(
|
||||||
|
context,
|
||||||
|
MainActivity::class.java
|
||||||
|
)
|
||||||
|
refresh.putExtra("$languageName", "$languageName")
|
||||||
|
startActivity(refresh)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
val about = findPreference<Preference>("about")
|
val about = findPreference<Preference>("about")
|
||||||
about?.setOnPreferenceClickListener {
|
about?.setOnPreferenceClickListener {
|
||||||
val uri = Uri.parse("https://libre-tube.github.io/")
|
val uri = Uri.parse("https://libre-tube.github.io/")
|
||||||
|
@ -405,6 +405,50 @@
|
|||||||
<item>ZW</item>
|
<item>ZW</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="languages">
|
||||||
|
<item>Arabic</item>
|
||||||
|
<item>Czech</item>
|
||||||
|
<item>English</item>
|
||||||
|
<item>French</item>
|
||||||
|
<item>German</item>
|
||||||
|
<item>Hindi</item>
|
||||||
|
<item>Hungarian</item>
|
||||||
|
<item>Italian</item>
|
||||||
|
<item>Korean</item>
|
||||||
|
<item>Marathi</item>
|
||||||
|
<item>Norwegian</item>
|
||||||
|
<item>Persian</item>
|
||||||
|
<item>Polish</item>
|
||||||
|
<item>Portuguese</item>
|
||||||
|
<item>Portuguese (Brazil)</item>
|
||||||
|
<item>Russian</item>
|
||||||
|
<item>Sorani</item>
|
||||||
|
<item>Spanish</item>
|
||||||
|
<item>Turkish</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="languagesValue">
|
||||||
|
<item>ar</item>
|
||||||
|
<item>cs</item>
|
||||||
|
<item>en</item>
|
||||||
|
<item>fr</item>
|
||||||
|
<item>de</item>
|
||||||
|
<item>hi</item>
|
||||||
|
<item>hu</item>
|
||||||
|
<item>it</item>
|
||||||
|
<item>ko</item>
|
||||||
|
<item>mr</item>
|
||||||
|
<item>nb-rNO</item>
|
||||||
|
<item>ckb</item>
|
||||||
|
<item>pl</item>
|
||||||
|
<item>pt</item>
|
||||||
|
<item>pr-rBR</item>
|
||||||
|
<item>ru</item>
|
||||||
|
<item>fa</item>
|
||||||
|
<item>es</item>
|
||||||
|
<item>tr</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="themes">
|
<string-array name="themes">
|
||||||
<item>System Default</item>
|
<item>System Default</item>
|
||||||
<item>Light Theme</item>
|
<item>Light Theme</item>
|
||||||
|
@ -53,4 +53,5 @@
|
|||||||
<string name="success">Success!</string>
|
<string name="success">Success!</string>
|
||||||
<string name="fail">Failed :(</string>
|
<string name="fail">Failed :(</string>
|
||||||
<string name="about">About</string>
|
<string name="about">About</string>
|
||||||
|
<string name="changeLanguage">Change Language</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -11,6 +11,16 @@
|
|||||||
android:icon="@drawable/ic_language"
|
android:icon="@drawable/ic_language"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
app:key="language"
|
||||||
|
app:title="@string/changeLanguage"
|
||||||
|
app:entries="@array/languages"
|
||||||
|
app:entryValues="@array/languagesValue"
|
||||||
|
app:defaultValue="en"
|
||||||
|
app:useSimpleSummaryProvider="true"
|
||||||
|
android:icon="@drawable/ic_language"
|
||||||
|
/>
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
app:key="instance"
|
app:key="instance"
|
||||||
app:title="@string/instances"
|
app:title="@string/instances"
|
||||||
|
Loading…
Reference in New Issue
Block a user