mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 13:50:30 +05:30
Fixes and Linted
This commit is contained in:
parent
4f59a85ad9
commit
b5f1c49e5a
@ -35,9 +35,10 @@ class MainActivity : AppCompatActivity() {
|
||||
val TAG = "MainActivity"
|
||||
lateinit var bottomNavigationView: BottomNavigationView
|
||||
lateinit var toolbar: Toolbar
|
||||
lateinit var navController : NavController
|
||||
lateinit var navController: NavController
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
DynamicColors.applyToActivitiesIfAvailable(application)
|
||||
super.onCreate(savedInstanceState)
|
||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
RetrofitInstance.url = sharedPreferences.getString("instance", "https://pipedapi.kavin.rocks/")!!
|
||||
@ -50,28 +51,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
updateAccentColor(this)
|
||||
updateThemeMode(this)
|
||||
|
||||
DynamicColors.applyToActivitiesIfAvailable(application)
|
||||
|
||||
val languageName = sharedPreferences.getString("language", "sys")
|
||||
if (languageName != "") {
|
||||
var locale = if (languageName != "sys" && "$languageName".length < 3 ){
|
||||
Locale(languageName)
|
||||
} else if ("$languageName".length > 3) {
|
||||
Locale(languageName?.substring(0,2), languageName?.substring(4,6))
|
||||
} else {
|
||||
Locale.getDefault()
|
||||
}
|
||||
val res = resources
|
||||
val dm = res.displayMetrics
|
||||
val conf = res.configuration
|
||||
conf.setLocale(locale)
|
||||
Locale.setDefault(locale)
|
||||
res.updateConfiguration(conf, dm)
|
||||
}
|
||||
updateLanguage(this)
|
||||
|
||||
val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
val networkInfo=connectivityManager.activeNetworkInfo
|
||||
val networkInfo = connectivityManager.activeNetworkInfo
|
||||
val isConnected = networkInfo != null && networkInfo.isConnected
|
||||
|
||||
if (!isConnected) {
|
||||
@ -102,12 +85,12 @@ class MainActivity : AppCompatActivity() {
|
||||
true
|
||||
}
|
||||
R.id.subscriptions -> {
|
||||
//navController.backQueue.clear()
|
||||
// navController.backQueue.clear()
|
||||
navController.navigate(R.id.subscriptions)
|
||||
true
|
||||
}
|
||||
R.id.library -> {
|
||||
//navController.backQueue.clear()
|
||||
// navController.backQueue.clear()
|
||||
navController.navigate(R.id.library)
|
||||
true
|
||||
}
|
||||
@ -125,12 +108,12 @@ class MainActivity : AppCompatActivity() {
|
||||
)
|
||||
toolbar.title = appName
|
||||
|
||||
toolbar.setNavigationOnClickListener{
|
||||
//settings activity stuff
|
||||
val intent = Intent(this, SettingsActivity::class.java)
|
||||
startActivity(intent)
|
||||
true
|
||||
}
|
||||
toolbar.setNavigationOnClickListener {
|
||||
// settings activity stuff
|
||||
val intent = Intent(this, SettingsActivity::class.java)
|
||||
startActivity(intent)
|
||||
true
|
||||
}
|
||||
|
||||
toolbar.setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
@ -142,134 +125,128 @@ class MainActivity : AppCompatActivity() {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
val action: String? = intent?.action
|
||||
val data: Uri? = intent?.data
|
||||
Log.d(TAG, "dafaq"+data.toString())
|
||||
Log.d(TAG, "dafaq" + data.toString())
|
||||
|
||||
if (data != null) {
|
||||
Log.d("dafaq",data.host+" ${data.path} ")
|
||||
if(data.host != null){
|
||||
if(data.path != null){
|
||||
//channel
|
||||
if(data.path!!.contains("/channel/") || data.path!!.contains("/c/") || data.path!!.contains("/user/")){
|
||||
var channel = data.path
|
||||
channel = channel!!.replace("/c/","")
|
||||
channel = channel!!.replace("/user/","")
|
||||
val bundle = bundleOf("channel_id" to channel)
|
||||
navController.navigate(R.id.channel,bundle)
|
||||
}else if(data.path!!.contains("/playlist")){
|
||||
var playlist = data.query!!
|
||||
if (playlist.contains("&"))
|
||||
{
|
||||
var playlists = playlist.split("&")
|
||||
for (v in playlists){
|
||||
if (v.contains("list=")){
|
||||
playlist = v
|
||||
break
|
||||
}
|
||||
Log.d("dafaq", data.host + " ${data.path} ")
|
||||
if (data.host != null) {
|
||||
if (data.path != null) {
|
||||
// channel
|
||||
if (data.path!!.contains("/channel/") || data.path!!.contains("/c/") || data.path!!.contains("/user/")) {
|
||||
var channel = data.path
|
||||
channel = channel!!.replace("/c/", "")
|
||||
channel = channel!!.replace("/user/", "")
|
||||
val bundle = bundleOf("channel_id" to channel)
|
||||
navController.navigate(R.id.channel, bundle)
|
||||
} else if (data.path!!.contains("/playlist")) {
|
||||
var playlist = data.query!!
|
||||
if (playlist.contains("&")) {
|
||||
var playlists = playlist.split("&")
|
||||
for (v in playlists) {
|
||||
if (v.contains("list=")) {
|
||||
playlist = v
|
||||
break
|
||||
}
|
||||
}
|
||||
playlist = playlist.replace("list=","")
|
||||
val bundle = bundleOf("playlist_id" to playlist)
|
||||
navController.navigate(R.id.playlistFragment,bundle)
|
||||
}else if(data.path!!.contains("/shorts/") || data.path!!.contains("/embed/") || data.path!!.contains("/v/")){
|
||||
var watch = data.path!!.replace("/shorts/","").replace("/v/","").replace("/embed/","")
|
||||
var bundle = Bundle()
|
||||
bundle.putString("videoId",watch)
|
||||
var frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, frag)
|
||||
.commitNow()
|
||||
Handler().postDelayed({
|
||||
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout)
|
||||
motionLayout.transitionToEnd()
|
||||
motionLayout.transitionToStart()
|
||||
}, 100)
|
||||
}else if(data.path!!.contains("/watch") && data.query != null){
|
||||
Log.d("dafaq",data.query!!)
|
||||
var watch = data.query!!
|
||||
if (watch.contains("&"))
|
||||
{
|
||||
var watches = watch.split("&")
|
||||
for (v in watches){
|
||||
if (v.contains("v=")){
|
||||
watch = v
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
var bundle = Bundle()
|
||||
bundle.putString("videoId",watch.replace("v=",""))
|
||||
var frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, frag)
|
||||
.commitNow()
|
||||
Handler().postDelayed({
|
||||
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout)
|
||||
motionLayout.transitionToEnd()
|
||||
motionLayout.transitionToStart()
|
||||
}, 100)
|
||||
|
||||
}else{
|
||||
var watch = data.path!!.replace("/","")
|
||||
var bundle = Bundle()
|
||||
bundle.putString("videoId",watch)
|
||||
var frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, frag)
|
||||
.commitNow()
|
||||
Handler().postDelayed({
|
||||
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout)
|
||||
motionLayout.transitionToEnd()
|
||||
motionLayout.transitionToStart()
|
||||
}, 100)
|
||||
}
|
||||
playlist = playlist.replace("list=", "")
|
||||
val bundle = bundleOf("playlist_id" to playlist)
|
||||
navController.navigate(R.id.playlistFragment, bundle)
|
||||
} else if (data.path!!.contains("/shorts/") || data.path!!.contains("/embed/") || data.path!!.contains("/v/")) {
|
||||
var watch = data.path!!.replace("/shorts/", "").replace("/v/", "").replace("/embed/", "")
|
||||
var bundle = Bundle()
|
||||
bundle.putString("videoId", watch)
|
||||
var frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, frag)
|
||||
.commitNow()
|
||||
Handler().postDelayed({
|
||||
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout)
|
||||
motionLayout.transitionToEnd()
|
||||
motionLayout.transitionToStart()
|
||||
}, 100)
|
||||
} else if (data.path!!.contains("/watch") && data.query != null) {
|
||||
Log.d("dafaq", data.query!!)
|
||||
var watch = data.query!!
|
||||
if (watch.contains("&")) {
|
||||
var watches = watch.split("&")
|
||||
for (v in watches) {
|
||||
if (v.contains("v=")) {
|
||||
watch = v
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
var bundle = Bundle()
|
||||
bundle.putString("videoId", watch.replace("v=", ""))
|
||||
var frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, frag)
|
||||
.commitNow()
|
||||
Handler().postDelayed({
|
||||
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout)
|
||||
motionLayout.transitionToEnd()
|
||||
motionLayout.transitionToStart()
|
||||
}, 100)
|
||||
} else {
|
||||
var watch = data.path!!.replace("/", "")
|
||||
var bundle = Bundle()
|
||||
bundle.putString("videoId", watch)
|
||||
var frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, frag)
|
||||
.commitNow()
|
||||
Handler().postDelayed({
|
||||
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout)
|
||||
motionLayout.transitionToEnd()
|
||||
motionLayout.transitionToStart()
|
||||
}, 100)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
try{
|
||||
try {
|
||||
val mainMotionLayout = findViewById<MotionLayout>(R.id.mainMotionLayout)
|
||||
if (mainMotionLayout.progress == 0.toFloat()){
|
||||
if (mainMotionLayout.progress == 0.toFloat()) {
|
||||
mainMotionLayout.transitionToEnd()
|
||||
findViewById<ConstraintLayout>(R.id.main_container).isClickable=false
|
||||
findViewById<ConstraintLayout>(R.id.main_container).isClickable = false
|
||||
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout)
|
||||
motionLayout.transitionToEnd()
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
with(motionLayout) {
|
||||
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
|
||||
enableTransition(R.id.yt_transition,true)
|
||||
enableTransition(R.id.yt_transition, true)
|
||||
}
|
||||
findViewById<LinearLayout>(R.id.linLayout).visibility=View.VISIBLE
|
||||
isFullScreen=false
|
||||
}else{
|
||||
findViewById<LinearLayout>(R.id.linLayout).visibility = View.VISIBLE
|
||||
isFullScreen = false
|
||||
} else {
|
||||
navController.popBackStack()
|
||||
if (navController.currentBackStackEntry == null && (parent as View).id != R.id.settings){
|
||||
if (navController.currentBackStackEntry == null && (parent as View).id != R.id.settings) {
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
}catch (e: Exception){
|
||||
} catch (e: Exception) {
|
||||
navController.popBackStack()
|
||||
moveTaskToBack(true)
|
||||
}
|
||||
@ -299,15 +276,17 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
@Suppress("DEPRECATION")
|
||||
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
window.decorView.systemUiVisibility = (
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_IMMERSIVE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
)
|
||||
}
|
||||
}
|
||||
private fun unsetFullscreen(){
|
||||
private fun unsetFullscreen() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
window.attributes.layoutInDisplayCutoutMode =
|
||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
|
||||
@ -331,7 +310,6 @@ class MainActivity : AppCompatActivity() {
|
||||
(fragment as? PlayerFragment)?.onUserLeaveHint()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
fun Fragment.hideKeyboard() {
|
||||
view?.let { activity?.hideKeyboard(it) }
|
||||
|
@ -15,7 +15,6 @@ import android.widget.Toast
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
@ -32,8 +31,9 @@ import java.io.InputStream
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
class SettingsActivity : AppCompatActivity(),
|
||||
SharedPreferences.OnSharedPreferenceChangeListener{
|
||||
class SettingsActivity :
|
||||
AppCompatActivity(),
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
updateAccentColor(this)
|
||||
@ -47,8 +47,6 @@ class SettingsActivity : AppCompatActivity(),
|
||||
view.setAlpha(0F)
|
||||
view.animate().alpha(1F).setDuration(300)
|
||||
|
||||
|
||||
|
||||
setContentView(R.layout.activity_settings)
|
||||
if (savedInstanceState == null) {
|
||||
supportFragmentManager
|
||||
@ -59,12 +57,10 @@ class SettingsActivity : AppCompatActivity(),
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.registerOnSharedPreferenceChangeListener(this)
|
||||
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, rootKey: String?) {}
|
||||
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
val TAG = "Settings"
|
||||
|
||||
@ -83,23 +79,23 @@ class SettingsActivity : AppCompatActivity(),
|
||||
|
||||
// "rw" for read-and-write;
|
||||
// "rwt" for truncating or overwriting existing file contents.
|
||||
//val readOnlyMode = "r"
|
||||
// val readOnlyMode = "r"
|
||||
// uri - I have got from onActivityResult
|
||||
val type = resolver.getType(uri)
|
||||
|
||||
var inputStream: InputStream? = resolver.openInputStream(uri)
|
||||
val channels = ArrayList<String>()
|
||||
if(type == "application/json"){
|
||||
if (type == "application/json") {
|
||||
val json = inputStream?.bufferedReader()?.readLines()?.get(0)
|
||||
val jsonObject = JSONTokener(json).nextValue() as JSONObject
|
||||
Log.e(TAG,jsonObject.getJSONArray("subscriptions").toString())
|
||||
Log.e(TAG, jsonObject.getJSONArray("subscriptions").toString())
|
||||
for (i in 0 until jsonObject.getJSONArray("subscriptions").length()) {
|
||||
var url = jsonObject.getJSONArray("subscriptions").getJSONObject(i).getString("url")
|
||||
url = url.replace("https://www.youtube.com/channel/","")
|
||||
Log.e(TAG,url)
|
||||
url = url.replace("https://www.youtube.com/channel/", "")
|
||||
Log.e(TAG, url)
|
||||
channels.add(url)
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
if (type == "application/zip") {
|
||||
val zis = ZipInputStream(inputStream)
|
||||
var entry: ZipEntry? = zis.nextEntry
|
||||
@ -132,8 +128,6 @@ class SettingsActivity : AppCompatActivity(),
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
@ -166,7 +160,7 @@ class SettingsActivity : AppCompatActivity(),
|
||||
val sponsorblock = findPreference<Preference>("sponsorblock")
|
||||
sponsorblock?.setOnPreferenceClickListener {
|
||||
val newFragment = SponsorBlockSettings()
|
||||
parentFragmentManager.beginTransaction()
|
||||
parentFragmentManager.beginTransaction()
|
||||
.replace(R.id.settings, newFragment)
|
||||
.commitNow()
|
||||
true
|
||||
@ -176,7 +170,7 @@ class SettingsActivity : AppCompatActivity(),
|
||||
importFromYt?.setOnPreferenceClickListener {
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
val token = sharedPref?.getString("token", "")!!
|
||||
//check StorageAccess
|
||||
// check StorageAccess
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
Log.d("myz", "" + Build.VERSION.SDK_INT)
|
||||
if (ContextCompat.checkSelfPermission(
|
||||
@ -186,11 +180,13 @@ class SettingsActivity : AppCompatActivity(),
|
||||
!= PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
ActivityCompat.requestPermissions(
|
||||
this.requireActivity(), arrayOf(
|
||||
this.requireActivity(),
|
||||
arrayOf(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.MANAGE_EXTERNAL_STORAGE
|
||||
), 1
|
||||
) //permission request code is just an int
|
||||
),
|
||||
1
|
||||
) // permission request code is just an int
|
||||
} else if (token != "") {
|
||||
getContent.launch("*/*")
|
||||
} else {
|
||||
@ -201,9 +197,9 @@ class SettingsActivity : AppCompatActivity(),
|
||||
requireContext(),
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(
|
||||
requireContext(),
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
requireContext(),
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
ActivityCompat.requestPermissions(
|
||||
this.requireActivity(),
|
||||
@ -230,7 +226,7 @@ class SettingsActivity : AppCompatActivity(),
|
||||
}
|
||||
|
||||
val accentColor = findPreference<Preference>("accent_color")
|
||||
accentColor?.setOnPreferenceChangeListener {_, _ ->
|
||||
accentColor?.setOnPreferenceChangeListener { _, _ ->
|
||||
val refresh = Intent(context, SettingsActivity::class.java)
|
||||
startActivity(refresh)
|
||||
true
|
||||
@ -238,7 +234,7 @@ class SettingsActivity : AppCompatActivity(),
|
||||
|
||||
val changeLanguage = findPreference<ListPreference>("language")
|
||||
changeLanguage?.setOnPreferenceChangeListener { _, _ ->
|
||||
val refresh = Intent(context, SettingsActivity::class.java)
|
||||
val refresh = Intent(context, MainActivity::class.java)
|
||||
startActivity(refresh)
|
||||
true
|
||||
}
|
||||
@ -260,16 +256,16 @@ class SettingsActivity : AppCompatActivity(),
|
||||
|
||||
val license = findPreference<Preference>("license")
|
||||
license?.setOnPreferenceClickListener {
|
||||
val licenseString = view?.context?.assets!!.open("gpl3.html").bufferedReader().use{
|
||||
val licenseString = view?.context?.assets!!.open("gpl3.html").bufferedReader().use {
|
||||
it.readText()
|
||||
}
|
||||
val licenseHtml = if (Build.VERSION.SDK_INT >= 24) {
|
||||
Html.fromHtml(licenseString,1)
|
||||
Html.fromHtml(licenseString, 1)
|
||||
} else {
|
||||
Html.fromHtml(licenseString)
|
||||
}
|
||||
AlertDialog.Builder(view?.context!!)
|
||||
.setPositiveButton(getString(R.string.okay), DialogInterface.OnClickListener{ _,_ -> })
|
||||
.setPositiveButton(getString(R.string.okay), DialogInterface.OnClickListener { _, _ -> })
|
||||
.setMessage(licenseHtml)
|
||||
.create()
|
||||
.show()
|
||||
@ -323,7 +319,6 @@ class SettingsActivity : AppCompatActivity(),
|
||||
activity?.runOnUiThread(action)
|
||||
}
|
||||
|
||||
|
||||
private fun subscribe(channels: List<String>) {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
@ -360,5 +355,4 @@ class SettingsActivity : AppCompatActivity(),
|
||||
intent = Intent(this, MainActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.github.libretube
|
||||
import android.content.Context
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.preference.PreferenceManager
|
||||
import java.util.*
|
||||
|
||||
fun updateAccentColor(context: Context) {
|
||||
val colorAccent = PreferenceManager.getDefaultSharedPreferences(context).getString("accent_color", "red")
|
||||
@ -29,3 +30,23 @@ fun oledMode(context: Context) {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
context.setTheme(R.style.Theme_OLED)
|
||||
}
|
||||
|
||||
fun updateLanguage(context: Context) {
|
||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val languageName = sharedPreferences.getString("language", "sys")
|
||||
if (languageName != "") {
|
||||
var locale = if (languageName != "sys" && "$languageName".length < 3 ) {
|
||||
Locale(languageName)
|
||||
} else if ("$languageName".length > 3) {
|
||||
Locale(languageName?.substring(0,2), languageName?.substring(4,6))
|
||||
} else {
|
||||
Locale.getDefault()
|
||||
}
|
||||
val res = context.resources
|
||||
val dm = res.displayMetrics
|
||||
val conf = res.configuration
|
||||
conf.setLocale(locale)
|
||||
Locale.setDefault(locale)
|
||||
res.updateConfiguration(conf, dm)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user