mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
commit
d44b288398
@ -17,8 +17,8 @@ import android.os.IBinder
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import com.arthenica.ffmpegkit.FFmpegKit
|
import com.arthenica.ffmpegkit.FFmpegKit
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
var IS_DOWNLOAD_RUNNING = false
|
var IS_DOWNLOAD_RUNNING = false
|
||||||
@ -48,8 +48,7 @@ class DownloadService : Service() {
|
|||||||
videoUrl = intent.getStringExtra("videoUrl")!!
|
videoUrl = intent.getStringExtra("videoUrl")!!
|
||||||
audioUrl = intent.getStringExtra("audioUrl")!!
|
audioUrl = intent.getStringExtra("audioUrl")!!
|
||||||
duration = intent.getIntExtra("duration", 1)
|
duration = intent.getIntExtra("duration", 1)
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
extension = PreferenceHelper.getString(this, "video_format", ".mp4")!!
|
||||||
extension = sharedPreferences.getString("video_format", ".mp4")!!
|
|
||||||
downloadType = if (audioUrl != "" && videoUrl != "") "mux"
|
downloadType = if (audioUrl != "" && videoUrl != "") "mux"
|
||||||
else if (audioUrl != "") "audio"
|
else if (audioUrl != "") "audio"
|
||||||
else if (videoUrl != "") "video"
|
else if (videoUrl != "") "video"
|
||||||
@ -83,9 +82,8 @@ class DownloadService : Service() {
|
|||||||
Log.e(TAG, "Directory already have")
|
Log.e(TAG, "Directory already have")
|
||||||
}
|
}
|
||||||
|
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
val downloadLocationPref = PreferenceHelper.getString(this, "download_location", "")
|
||||||
val downloadLocationPref = sharedPreferences.getString("download_location", "")
|
val folderName = PreferenceHelper.getString(this, "download_folder", "LibreTube")
|
||||||
val folderName = sharedPreferences.getString("download_folder", "")
|
|
||||||
|
|
||||||
val location = when (downloadLocationPref) {
|
val location = when (downloadLocationPref) {
|
||||||
"downloads" -> Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)
|
"downloads" -> Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)
|
||||||
|
@ -9,12 +9,12 @@ import android.widget.ProgressBar
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.adapters.TrendingAdapter
|
import com.github.libretube.adapters.TrendingAdapter
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -41,8 +41,8 @@ class Home : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
val recyclerView = view.findViewById<RecyclerView>(R.id.recview)
|
val recyclerView = view.findViewById<RecyclerView>(R.id.recview)
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
val grid = PreferenceHelper.getString(
|
||||||
val grid = sharedPreferences.getString(
|
requireContext(),
|
||||||
"grid",
|
"grid",
|
||||||
resources.getInteger(R.integer.grid_items).toString()
|
resources.getInteger(R.integer.grid_items).toString()
|
||||||
)!!
|
)!!
|
||||||
@ -61,9 +61,8 @@ class Home : Fragment() {
|
|||||||
fun run() {
|
fun run() {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val response = try {
|
val response = try {
|
||||||
val sharedPreferences =
|
val region = PreferenceHelper.getString(requireContext(), "region", "US")
|
||||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
RetrofitInstance.api.getTrending(region!!)
|
||||||
RetrofitInstance.api.getTrending(sharedPreferences.getString("region", "US")!!)
|
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
println(e)
|
println(e)
|
||||||
Log.e(TAG, "IOException, you might not have internet connection")
|
Log.e(TAG, "IOException, you might not have internet connection")
|
||||||
|
@ -58,6 +58,7 @@ import com.github.libretube.obj.Subscribe
|
|||||||
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.DescriptionAdapter
|
import com.github.libretube.util.DescriptionAdapter
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.github.libretube.util.formatShort
|
import com.github.libretube.util.formatShort
|
||||||
import com.google.android.exoplayer2.C
|
import com.google.android.exoplayer2.C
|
||||||
@ -347,9 +348,11 @@ class PlayerFragment : Fragment() {
|
|||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
// pause the player if the screen is turned off
|
// pause the player if the screen is turned off
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
val pausePlayerOnScreenOffEnabled = PreferenceHelper.getBoolean(
|
||||||
val pausePlayerOnScreenOffEnabled = sharedPreferences
|
requireContext(),
|
||||||
.getBoolean("pause_screen_off", false)
|
"pause_screen_off",
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
// check whether the screen is on
|
// check whether the screen is on
|
||||||
val pm = context?.getSystemService(Context.POWER_SERVICE) as PowerManager
|
val pm = context?.getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||||
@ -717,11 +720,8 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setResolutionAndSubtitles(view: View, response: Streams) {
|
private fun setResolutionAndSubtitles(view: View, response: Streams) {
|
||||||
val sharedPreferences =
|
val videoFormatPreference = PreferenceHelper.getString(requireContext(), "player_video_format", "WEBM")
|
||||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
val defres = PreferenceHelper.getString(requireContext(), "default_res", "")!!
|
||||||
|
|
||||||
val videoFormatPreference = sharedPreferences.getString("player_video_format", "WEBM")
|
|
||||||
val defres = sharedPreferences.getString("default_res", "")!!
|
|
||||||
|
|
||||||
val qualityText = view.findViewById<TextView>(R.id.quality_text)
|
val qualityText = view.findViewById<TextView>(R.id.quality_text)
|
||||||
val qualitySelect = view.findViewById<ImageButton>(R.id.quality_select)
|
val qualitySelect = view.findViewById<ImageButton>(R.id.quality_select)
|
||||||
|
@ -27,6 +27,7 @@ import com.github.libretube.adapters.SearchAdapter
|
|||||||
import com.github.libretube.adapters.SearchHistoryAdapter
|
import com.github.libretube.adapters.SearchHistoryAdapter
|
||||||
import com.github.libretube.adapters.SearchSuggestionsAdapter
|
import com.github.libretube.adapters.SearchSuggestionsAdapter
|
||||||
import com.github.libretube.hideKeyboard
|
import com.github.libretube.hideKeyboard
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
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 kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
@ -276,7 +277,7 @@ class SearchFragment : Fragment() {
|
|||||||
|
|
||||||
private fun addToHistory(query: String) {
|
private fun addToHistory(query: String) {
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
val searchHistoryEnabled = sharedPreferences.getBoolean("search_history_toggle", true)
|
val searchHistoryEnabled = PreferenceHelper.getBoolean(requireContext(), "search_history_toggle", true)
|
||||||
if (searchHistoryEnabled) {
|
if (searchHistoryEnabled) {
|
||||||
var historyList = getHistory()
|
var historyList = getHistory()
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@ import android.os.Bundle
|
|||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.requireMainActivityRestart
|
import com.github.libretube.requireMainActivityRestart
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
|
||||||
class AdvancedSettings : PreferenceFragmentCompat() {
|
class AdvancedSettings : PreferenceFragmentCompat() {
|
||||||
@ -21,9 +21,7 @@ class AdvancedSettings : PreferenceFragmentCompat() {
|
|||||||
|
|
||||||
val clearHistory = findPreference<Preference>("clear_history")
|
val clearHistory = findPreference<Preference>("clear_history")
|
||||||
clearHistory?.setOnPreferenceClickListener {
|
clearHistory?.setOnPreferenceClickListener {
|
||||||
val sharedPreferences =
|
PreferenceHelper.removePreference(requireContext(), "search_history")
|
||||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
|
||||||
sharedPreferences.edit().remove("search_history").commit()
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,9 +36,7 @@ class AdvancedSettings : PreferenceFragmentCompat() {
|
|||||||
MaterialAlertDialogBuilder(requireContext())
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
.setPositiveButton(R.string.reset) { _, _ ->
|
.setPositiveButton(R.string.reset) { _, _ ->
|
||||||
// clear default preferences
|
// clear default preferences
|
||||||
val sharedPreferences =
|
PreferenceHelper.clearPreferences(requireContext())
|
||||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
|
||||||
sharedPreferences.edit().clear().commit()
|
|
||||||
|
|
||||||
// clear login token
|
// clear login token
|
||||||
val sharedPrefToken =
|
val sharedPrefToken =
|
||||||
|
@ -25,6 +25,7 @@ import com.github.libretube.dialogs.CustomInstanceDialog
|
|||||||
import com.github.libretube.dialogs.DeleteAccountDialog
|
import com.github.libretube.dialogs.DeleteAccountDialog
|
||||||
import com.github.libretube.dialogs.LoginDialog
|
import com.github.libretube.dialogs.LoginDialog
|
||||||
import com.github.libretube.requireMainActivityRestart
|
import com.github.libretube.requireMainActivityRestart
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.json.JSONTokener
|
import org.json.JSONTokener
|
||||||
@ -134,11 +135,9 @@ class InstanceSettings : PreferenceFragmentCompat() {
|
|||||||
|
|
||||||
val clearCustomInstances = findPreference<Preference>("clearCustomInstances")
|
val clearCustomInstances = findPreference<Preference>("clearCustomInstances")
|
||||||
clearCustomInstances?.setOnPreferenceClickListener {
|
clearCustomInstances?.setOnPreferenceClickListener {
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
PreferenceHelper.removePreference(requireContext(), "custom_instances_name")
|
||||||
sharedPreferences.edit()
|
PreferenceHelper.removePreference(requireContext(), "custom_instances_url")
|
||||||
.remove("custom_instances_name")
|
PreferenceHelper.removePreference(requireContext(), "custom_instances_frontend_url")
|
||||||
.remove("custom_instances_url")
|
|
||||||
.commit()
|
|
||||||
activity?.recreate()
|
activity?.recreate()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,12 @@ package com.github.libretube.util
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class LocaleHelper {
|
class LocaleHelper {
|
||||||
|
|
||||||
fun updateLanguage(context: Context) {
|
fun updateLanguage(context: Context) {
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
val languageName = PreferenceHelper.getString(context, "language", "en")
|
||||||
val languageName = sharedPreferences.getString("language", "sys")
|
|
||||||
if (languageName != "") {
|
if (languageName != "") {
|
||||||
setLanguage(context, languageName!!)
|
setLanguage(context, languageName!!)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
package com.github.libretube.util
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
|
|
||||||
|
object PreferenceHelper {
|
||||||
|
fun setString(context: Context, key: String?, value: String?) {
|
||||||
|
val editor = getDefaultSharedPreferencesEditor(context)
|
||||||
|
editor.putString(key, value)
|
||||||
|
editor.apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setInt(context: Context, key: String?, value: Int) {
|
||||||
|
val editor = getDefaultSharedPreferencesEditor(context)
|
||||||
|
editor.putInt(key, value)
|
||||||
|
editor.apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setLong(context: Context, key: String?, value: Long) {
|
||||||
|
val editor = getDefaultSharedPreferencesEditor(context)
|
||||||
|
editor.putLong(key, value)
|
||||||
|
editor.apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setBoolean(context: Context, key: String?, value: Boolean) {
|
||||||
|
val editor = getDefaultSharedPreferencesEditor(context)
|
||||||
|
editor.putBoolean(key, value)
|
||||||
|
editor.apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getString(context: Context, key: String?, defValue: String?): String? {
|
||||||
|
val settings: SharedPreferences = getDefaultSharedPreferences(context)
|
||||||
|
return settings.getString(key, defValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getInt(context: Context, key: String?, defValue: Int): Int {
|
||||||
|
val settings: SharedPreferences = getDefaultSharedPreferences(context)
|
||||||
|
return settings.getInt(key, defValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getLong(context: Context, key: String?, defValue: Long): Long {
|
||||||
|
val settings: SharedPreferences = getDefaultSharedPreferences(context)
|
||||||
|
return settings.getLong(key, defValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getBoolean(context: Context, key: String?, defValue: Boolean): Boolean {
|
||||||
|
val settings: SharedPreferences = getDefaultSharedPreferences(context)
|
||||||
|
return settings.getBoolean(key, defValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clearPreferences(context: Context) {
|
||||||
|
val editor = getDefaultSharedPreferencesEditor(context)
|
||||||
|
editor.clear()
|
||||||
|
editor.commit()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removePreference(context: Context, value: String?) {
|
||||||
|
val editor = getDefaultSharedPreferencesEditor(context)
|
||||||
|
editor.remove(value)
|
||||||
|
editor.commit()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getDefaultSharedPreferences(context: Context): SharedPreferences {
|
||||||
|
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
}
|
||||||
|
private fun getDefaultSharedPreferencesEditor(context: Context): SharedPreferences.Editor {
|
||||||
|
return getDefaultSharedPreferences(context).edit()
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,6 @@ import android.content.Intent
|
|||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
|
|
||||||
class ThemeHelper {
|
class ThemeHelper {
|
||||||
@ -17,10 +16,8 @@ class ThemeHelper {
|
|||||||
updateThemeMode(context)
|
updateThemeMode(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateAccentColor(context: Context) {
|
private fun updateAccentColor(context: Context) {
|
||||||
val colorAccent =
|
when (PreferenceHelper.getString(context, "accent_color", "red")) {
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).getString("accent_color", "red")
|
|
||||||
when (colorAccent) {
|
|
||||||
"my" -> context.setTheme(R.style.Theme_MY)
|
"my" -> context.setTheme(R.style.Theme_MY)
|
||||||
"red" -> context.setTheme(R.style.Theme_Red)
|
"red" -> context.setTheme(R.style.Theme_Red)
|
||||||
"blue" -> context.setTheme(R.style.Theme_Blue)
|
"blue" -> context.setTheme(R.style.Theme_Blue)
|
||||||
@ -30,10 +27,8 @@ class ThemeHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateThemeMode(context: Context) {
|
private fun updateThemeMode(context: Context) {
|
||||||
val themeMode =
|
when (PreferenceHelper.getString(context, "theme_togglee", "A")) {
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).getString("theme_togglee", "A")
|
|
||||||
when (themeMode) {
|
|
||||||
"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)
|
||||||
"D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
"D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user