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
@ -38,6 +38,7 @@ class MainActivity : AppCompatActivity() {
|
||||
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,25 +51,7 @@ 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
|
||||
@ -142,7 +125,6 @@ class MainActivity : AppCompatActivity() {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
@ -164,8 +146,7 @@ class MainActivity : AppCompatActivity() {
|
||||
navController.navigate(R.id.channel, bundle)
|
||||
} else if (data.path!!.contains("/playlist")) {
|
||||
var playlist = data.query!!
|
||||
if (playlist.contains("&"))
|
||||
{
|
||||
if (playlist.contains("&")) {
|
||||
var playlists = playlist.split("&")
|
||||
for (v in playlists) {
|
||||
if (v.contains("list=")) {
|
||||
@ -197,8 +178,7 @@ class MainActivity : AppCompatActivity() {
|
||||
} else if (data.path!!.contains("/watch") && data.query != null) {
|
||||
Log.d("dafaq", data.query!!)
|
||||
var watch = data.query!!
|
||||
if (watch.contains("&"))
|
||||
{
|
||||
if (watch.contains("&")) {
|
||||
var watches = watch.split("&")
|
||||
for (v in watches) {
|
||||
if (v.contains("v=")) {
|
||||
@ -222,7 +202,6 @@ class MainActivity : AppCompatActivity() {
|
||||
motionLayout.transitionToEnd()
|
||||
motionLayout.transitionToStart()
|
||||
}, 100)
|
||||
|
||||
} else {
|
||||
var watch = data.path!!.replace("/", "")
|
||||
var bundle = Bundle()
|
||||
@ -242,9 +221,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}, 100)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -299,12 +276,14 @@ 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() {
|
||||
@ -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,7 +31,8 @@ import java.io.InputStream
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
class SettingsActivity : AppCompatActivity(),
|
||||
class SettingsActivity :
|
||||
AppCompatActivity(),
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -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"
|
||||
|
||||
@ -132,8 +128,6 @@ class SettingsActivity : AppCompatActivity(),
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
@ -186,10 +180,12 @@ 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
|
||||
),
|
||||
1
|
||||
) // permission request code is just an int
|
||||
} else if (token != "") {
|
||||
getContent.launch("*/*")
|
||||
@ -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
|
||||
}
|
||||
@ -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