mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
move locale settings
This commit is contained in:
parent
7ba9ecf7bd
commit
4382942085
@ -16,8 +16,8 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
import com.github.libretube.adapters.TrendingAdapter
|
import com.github.libretube.adapters.TrendingAdapter
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import retrofit2.HttpException
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import retrofit2.HttpException
|
||||||
|
|
||||||
class Home : Fragment() {
|
class Home : Fragment() {
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|||||||
import com.github.libretube.adapters.PlaylistsAdapter
|
import com.github.libretube.adapters.PlaylistsAdapter
|
||||||
import com.github.libretube.dialogs.CreatePlaylistDialog
|
import com.github.libretube.dialogs.CreatePlaylistDialog
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import retrofit2.HttpException
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import retrofit2.HttpException
|
||||||
|
|
||||||
class Library : Fragment() {
|
class Library : Fragment() {
|
||||||
|
|
||||||
|
@ -35,9 +35,9 @@ import com.github.libretube.fragments.PlayerFragment
|
|||||||
import com.github.libretube.fragments.isFullScreen
|
import com.github.libretube.fragments.isFullScreen
|
||||||
import com.github.libretube.preferences.SponsorBlockSettings
|
import com.github.libretube.preferences.SponsorBlockSettings
|
||||||
import com.github.libretube.util.CronetHelper
|
import com.github.libretube.util.CronetHelper
|
||||||
|
import com.github.libretube.util.LocaleHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.github.libretube.util.updateLanguage
|
import com.github.libretube.util.ThemeHelper
|
||||||
import com.github.libretube.util.updateTheme
|
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
import com.google.android.material.color.DynamicColors
|
import com.google.android.material.color.DynamicColors
|
||||||
|
|
||||||
@ -69,8 +69,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
SponsorBlockSettings.outroEnabled =
|
SponsorBlockSettings.outroEnabled =
|
||||||
sharedPreferences.getBoolean("outro_category_key", false)
|
sharedPreferences.getBoolean("outro_category_key", false)
|
||||||
|
|
||||||
updateTheme(this)
|
ThemeHelper().updateTheme(this)
|
||||||
updateLanguage(this)
|
LocaleHelper().updateLanguage(this)
|
||||||
|
|
||||||
val connectivityManager =
|
val connectivityManager =
|
||||||
this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
@ -6,7 +6,7 @@ import android.net.Uri
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.github.libretube.util.restartMainActivity
|
import com.github.libretube.util.ThemeHelper
|
||||||
|
|
||||||
class RouterActivity : AppCompatActivity() {
|
class RouterActivity : AppCompatActivity() {
|
||||||
val TAG = "RouterActivity"
|
val TAG = "RouterActivity"
|
||||||
@ -17,7 +17,7 @@ class RouterActivity : AppCompatActivity() {
|
|||||||
handleSendText(intent)
|
handleSendText(intent)
|
||||||
} else {
|
} else {
|
||||||
// start app as normal if URI not in host list
|
// start app as normal if URI not in host list
|
||||||
restartMainActivity(this)
|
ThemeHelper().restartMainActivity(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,8 +7,7 @@ import android.view.View
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import com.github.libretube.preferences.SettingsFragment
|
import com.github.libretube.preferences.SettingsFragment
|
||||||
import com.github.libretube.util.restartMainActivity
|
import com.github.libretube.util.ThemeHelper
|
||||||
import com.github.libretube.util.updateTheme
|
|
||||||
import com.google.android.material.color.DynamicColors
|
import com.google.android.material.color.DynamicColors
|
||||||
|
|
||||||
var isCurrentViewMainSettings = true
|
var isCurrentViewMainSettings = true
|
||||||
@ -18,7 +17,7 @@ class SettingsActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
DynamicColors.applyToActivityIfAvailable(this)
|
DynamicColors.applyToActivityIfAvailable(this)
|
||||||
updateTheme(this)
|
ThemeHelper().updateTheme(this)
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
@ -43,9 +42,9 @@ class SettingsActivity : AppCompatActivity() {
|
|||||||
requireMainActivityRestart = false
|
requireMainActivityRestart = false
|
||||||
// kill player notification
|
// kill player notification
|
||||||
val nManager =
|
val nManager =
|
||||||
this.getSystemService(AppCompatActivity.NOTIFICATION_SERVICE) as NotificationManager
|
this.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||||
nManager.cancelAll()
|
nManager.cancelAll()
|
||||||
restartMainActivity(this)
|
ThemeHelper().restartMainActivity(this)
|
||||||
ActivityCompat.finishAffinity(this)
|
ActivityCompat.finishAffinity(this)
|
||||||
} else {
|
} else {
|
||||||
super.onBackPressed()
|
super.onBackPressed()
|
||||||
|
@ -26,8 +26,8 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|||||||
import com.github.libretube.adapters.SubscriptionAdapter
|
import com.github.libretube.adapters.SubscriptionAdapter
|
||||||
import com.github.libretube.adapters.SubscriptionChannelAdapter
|
import com.github.libretube.adapters.SubscriptionChannelAdapter
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import retrofit2.HttpException
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import retrofit2.HttpException
|
||||||
|
|
||||||
class Subscriptions : Fragment() {
|
class Subscriptions : Fragment() {
|
||||||
val TAG = "SubFragment"
|
val TAG = "SubFragment"
|
||||||
|
@ -20,10 +20,10 @@ import com.github.libretube.obj.PlaylistId
|
|||||||
import com.github.libretube.obj.StreamItem
|
import com.github.libretube.obj.StreamItem
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
|
import java.io.IOException
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
|
||||||
|
|
||||||
class PlaylistAdapter(
|
class PlaylistAdapter(
|
||||||
private val videoFeed: MutableList<StreamItem>,
|
private val videoFeed: MutableList<StreamItem>,
|
||||||
|
@ -17,10 +17,10 @@ import com.github.libretube.obj.Playlists
|
|||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
|
import java.io.IOException
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
|
||||||
|
|
||||||
class PlaylistsAdapter(
|
class PlaylistsAdapter(
|
||||||
private val playlists: MutableList<Playlists>,
|
private val playlists: MutableList<Playlists>,
|
||||||
|
@ -15,11 +15,11 @@ import com.github.libretube.obj.Subscribe
|
|||||||
import com.github.libretube.obj.Subscription
|
import com.github.libretube.obj.Subscription
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
|
import java.io.IOException
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
|
||||||
|
|
||||||
class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscription>) :
|
class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscription>) :
|
||||||
RecyclerView.Adapter<SubscriptionChannelViewHolder>() {
|
RecyclerView.Adapter<SubscriptionChannelViewHolder>() {
|
||||||
|
@ -19,8 +19,8 @@ import com.github.libretube.R
|
|||||||
import com.github.libretube.obj.PlaylistId
|
import com.github.libretube.obj.PlaylistId
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import retrofit2.HttpException
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import retrofit2.HttpException
|
||||||
|
|
||||||
class AddtoPlaylistDialog : DialogFragment() {
|
class AddtoPlaylistDialog : DialogFragment() {
|
||||||
private val TAG = "AddToPlaylistDialog"
|
private val TAG = "AddToPlaylistDialog"
|
||||||
|
@ -19,8 +19,8 @@ import com.github.libretube.obj.Playlists
|
|||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
import retrofit2.HttpException
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import retrofit2.HttpException
|
||||||
|
|
||||||
class CreatePlaylistDialog : DialogFragment() {
|
class CreatePlaylistDialog : DialogFragment() {
|
||||||
val TAG = "CreatePlaylistDialog"
|
val TAG = "CreatePlaylistDialog"
|
||||||
|
@ -17,8 +17,8 @@ import com.github.libretube.R
|
|||||||
import com.github.libretube.obj.Login
|
import com.github.libretube.obj.Login
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import retrofit2.HttpException
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import retrofit2.HttpException
|
||||||
|
|
||||||
class LoginDialog : DialogFragment() {
|
class LoginDialog : DialogFragment() {
|
||||||
private val TAG = "LoginDialog"
|
private val TAG = "LoginDialog"
|
||||||
|
@ -22,8 +22,8 @@ import com.github.libretube.obj.Subscribe
|
|||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import retrofit2.HttpException
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import retrofit2.HttpException
|
||||||
|
|
||||||
class ChannelFragment : Fragment() {
|
class ChannelFragment : Fragment() {
|
||||||
|
|
||||||
|
@ -82,11 +82,11 @@ import com.google.android.exoplayer2.util.RepeatModeUtil
|
|||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import org.chromium.net.CronetEngine
|
|
||||||
import retrofit2.HttpException
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
import org.chromium.net.CronetEngine
|
||||||
|
import retrofit2.HttpException
|
||||||
|
|
||||||
var isFullScreen = false
|
var isFullScreen = false
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.adapters.PlaylistAdapter
|
import com.github.libretube.adapters.PlaylistAdapter
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import retrofit2.HttpException
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import retrofit2.HttpException
|
||||||
|
|
||||||
class PlaylistFragment : Fragment() {
|
class PlaylistFragment : Fragment() {
|
||||||
private var playlist_id: String? = null
|
private var playlist_id: String? = null
|
||||||
|
@ -30,11 +30,11 @@ import com.github.libretube.adapters.SearchHistoryAdapter
|
|||||||
import com.github.libretube.hideKeyboard
|
import com.github.libretube.hideKeyboard
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import java.io.IOException
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
|
||||||
|
|
||||||
class SearchFragment : Fragment() {
|
class SearchFragment : Fragment() {
|
||||||
private val TAG = "SearchFragment"
|
private val TAG = "SearchFragment"
|
||||||
|
@ -8,7 +8,7 @@ import androidx.preference.PreferenceFragmentCompat
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.SettingsActivity
|
import com.github.libretube.SettingsActivity
|
||||||
import com.github.libretube.requireMainActivityRestart
|
import com.github.libretube.requireMainActivityRestart
|
||||||
import com.github.libretube.util.changeIcon
|
import com.github.libretube.util.ThemeHelper
|
||||||
|
|
||||||
class AppearanceSettings : PreferenceFragmentCompat() {
|
class AppearanceSettings : PreferenceFragmentCompat() {
|
||||||
private val TAG = "CustomizationSettings"
|
private val TAG = "CustomizationSettings"
|
||||||
@ -33,7 +33,7 @@ class AppearanceSettings : PreferenceFragmentCompat() {
|
|||||||
|
|
||||||
val iconChange = findPreference<ListPreference>("icon_change")
|
val iconChange = findPreference<ListPreference>("icon_change")
|
||||||
iconChange?.setOnPreferenceChangeListener { _, newValue ->
|
iconChange?.setOnPreferenceChangeListener { _, newValue ->
|
||||||
changeIcon(requireContext(), newValue.toString())
|
ThemeHelper().changeIcon(requireContext(), newValue.toString())
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,16 +26,16 @@ import com.github.libretube.dialogs.LoginDialog
|
|||||||
import com.github.libretube.isCurrentViewMainSettings
|
import com.github.libretube.isCurrentViewMainSettings
|
||||||
import com.github.libretube.requireMainActivityRestart
|
import com.github.libretube.requireMainActivityRestart
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
|
import com.github.libretube.util.ThemeHelper
|
||||||
import com.github.libretube.util.checkUpdate
|
import com.github.libretube.util.checkUpdate
|
||||||
import com.github.libretube.util.restartMainActivity
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import org.json.JSONObject
|
|
||||||
import org.json.JSONTokener
|
|
||||||
import retrofit2.HttpException
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipInputStream
|
import java.util.zip.ZipInputStream
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.json.JSONTokener
|
||||||
|
import retrofit2.HttpException
|
||||||
|
|
||||||
class SettingsFragment : PreferenceFragmentCompat() {
|
class SettingsFragment : PreferenceFragmentCompat() {
|
||||||
val TAG = "Settings"
|
val TAG = "Settings"
|
||||||
@ -130,7 +130,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||||||
|
|
||||||
val language = findPreference<ListPreference>("language")
|
val language = findPreference<ListPreference>("language")
|
||||||
language?.setOnPreferenceChangeListener { _, _ ->
|
language?.setOnPreferenceChangeListener { _, _ ->
|
||||||
restartMainActivity(requireContext())
|
ThemeHelper().restartMainActivity(requireContext())
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
40
app/src/main/java/com/github/libretube/util/LocaleHelper.kt
Normal file
40
app/src/main/java/com/github/libretube/util/LocaleHelper.kt
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package com.github.libretube.util
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class LocaleHelper {
|
||||||
|
|
||||||
|
fun updateLanguage(context: Context) {
|
||||||
|
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
val languageName = sharedPreferences.getString("language", "sys")
|
||||||
|
if (languageName != "") {
|
||||||
|
setLanguage(context, languageName!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setLanguage(context: Context, languageName: String) {
|
||||||
|
val 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()
|
||||||
|
}
|
||||||
|
// Change API Language
|
||||||
|
Locale.setDefault(locale)
|
||||||
|
|
||||||
|
// Change App Language
|
||||||
|
val res = context.resources
|
||||||
|
val dm = res.displayMetrics
|
||||||
|
val conf = res.configuration
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||||
|
conf.setLocale(locale)
|
||||||
|
} else {
|
||||||
|
conf.locale = locale
|
||||||
|
}
|
||||||
|
res.updateConfiguration(conf, dm)
|
||||||
|
}
|
||||||
|
}
|
@ -1,97 +0,0 @@
|
|||||||
package com.github.libretube.util
|
|
||||||
|
|
||||||
import android.app.NotificationManager
|
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import com.github.libretube.R
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
fun updateTheme(context: Context) {
|
|
||||||
updateAccentColor(context)
|
|
||||||
updateThemeMode(context)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateAccentColor(context: Context) {
|
|
||||||
val colorAccent =
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).getString("accent_color", "red")
|
|
||||||
when (colorAccent) {
|
|
||||||
"my" -> context.setTheme(R.style.Theme_MY)
|
|
||||||
"red" -> context.setTheme(R.style.Theme_Red)
|
|
||||||
"blue" -> context.setTheme(R.style.Theme_Blue)
|
|
||||||
"yellow" -> context.setTheme(R.style.Theme_Yellow)
|
|
||||||
"green" -> context.setTheme(R.style.Theme_Green)
|
|
||||||
"purple" -> context.setTheme(R.style.Theme_Purple)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateThemeMode(context: Context) {
|
|
||||||
val themeMode =
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).getString("theme_togglee", "A")
|
|
||||||
when (themeMode) {
|
|
||||||
"A" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
|
||||||
"L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
|
||||||
"D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
|
||||||
"O" -> {
|
|
||||||
context.setTheme(R.style.OLED)
|
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateLanguage(context: Context) {
|
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
val languageName = sharedPreferences.getString("language", "sys")
|
|
||||||
if (languageName != "") {
|
|
||||||
val 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
|
|
||||||
// Change App Language
|
|
||||||
conf.setLocale(locale)
|
|
||||||
// Change API Language
|
|
||||||
Locale.setDefault(locale)
|
|
||||||
res.updateConfiguration(conf, dm)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun changeIcon(context: Context, newLogoActivityAlias: String) {
|
|
||||||
val activityAliases = context.resources.getStringArray(R.array.iconsValue)
|
|
||||||
// Disable Old Icon(s)
|
|
||||||
for (activityAlias in activityAliases) {
|
|
||||||
context.packageManager.setComponentEnabledSetting(
|
|
||||||
ComponentName(context.packageName, "com.github.libretube.$activityAlias"),
|
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
||||||
PackageManager.DONT_KILL_APP
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// Enable New Icon
|
|
||||||
context.packageManager.setComponentEnabledSetting(
|
|
||||||
ComponentName(context.packageName, "com.github.libretube.$newLogoActivityAlias"),
|
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
|
||||||
PackageManager.DONT_KILL_APP
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Needed due to different MainActivity Aliases because of the app icons
|
|
||||||
fun restartMainActivity(context: Context) {
|
|
||||||
// kill player notification
|
|
||||||
val nManager = context
|
|
||||||
.getSystemService(AppCompatActivity.NOTIFICATION_SERVICE) as NotificationManager
|
|
||||||
nManager.cancelAll()
|
|
||||||
// restart to MainActivity
|
|
||||||
val pm: PackageManager = context.packageManager
|
|
||||||
val intent = pm.getLaunchIntentForPackage(context.packageName)
|
|
||||||
intent?.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
||||||
context.startActivity(intent)
|
|
||||||
}
|
|
77
app/src/main/java/com/github/libretube/util/ThemeHelper.kt
Normal file
77
app/src/main/java/com/github/libretube/util/ThemeHelper.kt
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package com.github.libretube.util
|
||||||
|
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
|
import com.github.libretube.R
|
||||||
|
|
||||||
|
class ThemeHelper {
|
||||||
|
|
||||||
|
fun updateTheme(context: Context) {
|
||||||
|
updateAccentColor(context)
|
||||||
|
updateThemeMode(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateAccentColor(context: Context) {
|
||||||
|
val colorAccent =
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(context).getString("accent_color", "red")
|
||||||
|
when (colorAccent) {
|
||||||
|
"my" -> context.setTheme(R.style.Theme_MY)
|
||||||
|
"red" -> context.setTheme(R.style.Theme_Red)
|
||||||
|
"blue" -> context.setTheme(R.style.Theme_Blue)
|
||||||
|
"yellow" -> context.setTheme(R.style.Theme_Yellow)
|
||||||
|
"green" -> context.setTheme(R.style.Theme_Green)
|
||||||
|
"purple" -> context.setTheme(R.style.Theme_Purple)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateThemeMode(context: Context) {
|
||||||
|
val themeMode =
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(context).getString("theme_togglee", "A")
|
||||||
|
when (themeMode) {
|
||||||
|
"A" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||||
|
"L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||||
|
"D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||||
|
"O" -> {
|
||||||
|
context.setTheme(R.style.OLED)
|
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun changeIcon(context: Context, newLogoActivityAlias: String) {
|
||||||
|
val activityAliases = context.resources.getStringArray(R.array.iconsValue)
|
||||||
|
// Disable Old Icon(s)
|
||||||
|
for (activityAlias in activityAliases) {
|
||||||
|
context.packageManager.setComponentEnabledSetting(
|
||||||
|
ComponentName(context.packageName, "com.github.libretube.$activityAlias"),
|
||||||
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||||
|
PackageManager.DONT_KILL_APP
|
||||||
|
)
|
||||||
|
}
|
||||||
|
// Enable New Icon
|
||||||
|
context.packageManager.setComponentEnabledSetting(
|
||||||
|
ComponentName(context.packageName, "com.github.libretube.$newLogoActivityAlias"),
|
||||||
|
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
||||||
|
PackageManager.DONT_KILL_APP
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Needed due to different MainActivity Aliases because of the app icons
|
||||||
|
fun restartMainActivity(context: Context) {
|
||||||
|
// kill player notification
|
||||||
|
val nManager = context
|
||||||
|
.getSystemService(AppCompatActivity.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
nManager.cancelAll()
|
||||||
|
// restart to MainActivity
|
||||||
|
val pm: PackageManager = context.packageManager
|
||||||
|
val intent = pm.getLaunchIntentForPackage(context.packageName)
|
||||||
|
intent?.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
|
context.startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
@ -4,12 +4,12 @@ import android.util.Log
|
|||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import com.github.libretube.BuildConfig
|
import com.github.libretube.BuildConfig
|
||||||
import com.github.libretube.dialogs.UpdateAvailableDialog
|
import com.github.libretube.dialogs.UpdateAvailableDialog
|
||||||
import org.json.JSONArray
|
|
||||||
import org.json.JSONObject
|
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import javax.net.ssl.HttpsURLConnection
|
import javax.net.ssl.HttpsURLConnection
|
||||||
|
import org.json.JSONArray
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
fun checkUpdate(childFragmentManager: FragmentManager) {
|
fun checkUpdate(childFragmentManager: FragmentManager) {
|
||||||
var updateInfo: UpdateInfo? = UpdateInfo("", "")
|
var updateInfo: UpdateInfo? = UpdateInfo("", "")
|
||||||
|
Loading…
Reference in New Issue
Block a user