mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
230 lines
No EOL
9.4 KiB
Kotlin
230 lines
No EOL
9.4 KiB
Kotlin
package com.lagradost.cloudstream3.ui.settings
|
|
|
|
import android.os.Bundle
|
|
import android.text.format.Formatter.formatShortFileSize
|
|
import android.view.View
|
|
import androidx.preference.PreferenceFragmentCompat
|
|
import androidx.preference.PreferenceManager
|
|
import com.lagradost.cloudstream3.R
|
|
import com.lagradost.cloudstream3.mvvm.logError
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getFolderSize
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
|
|
import com.lagradost.cloudstream3.ui.subtitles.ChromecastSubtitlesFragment
|
|
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment
|
|
import com.lagradost.cloudstream3.utils.Qualities
|
|
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
|
|
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog
|
|
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
|
|
|
class SettingsPlayer : PreferenceFragmentCompat() {
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
super.onViewCreated(view, savedInstanceState)
|
|
setUpToolbar(R.string.category_player)
|
|
setPaddingBottom()
|
|
}
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
|
hideKeyboard()
|
|
setPreferencesFromResource(R.xml.settings_player, rootKey)
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
|
|
|
getPref(R.string.video_buffer_length_key)?.setOnPreferenceClickListener {
|
|
val prefNames = resources.getStringArray(R.array.video_buffer_length_names)
|
|
val prefValues = resources.getIntArray(R.array.video_buffer_length_values)
|
|
|
|
val currentPrefSize =
|
|
settingsManager.getInt(getString(R.string.video_buffer_length_key), 0)
|
|
|
|
activity?.showDialog(
|
|
prefNames.toList(),
|
|
prefValues.indexOf(currentPrefSize),
|
|
getString(R.string.video_buffer_length_settings),
|
|
true,
|
|
{}) {
|
|
settingsManager.edit()
|
|
.putInt(getString(R.string.video_buffer_length_key), prefValues[it])
|
|
.apply()
|
|
}
|
|
return@setOnPreferenceClickListener true
|
|
}
|
|
|
|
getPref(R.string.prefer_limit_title_key)?.setOnPreferenceClickListener {
|
|
val prefNames = resources.getStringArray(R.array.limit_title_pref_names)
|
|
val prefValues = resources.getIntArray(R.array.limit_title_pref_values)
|
|
val current = settingsManager.getInt(getString(R.string.prefer_limit_title_key), 0)
|
|
|
|
activity?.showBottomDialog(
|
|
prefNames.toList(),
|
|
prefValues.indexOf(current),
|
|
getString(R.string.limit_title),
|
|
true,
|
|
{}) {
|
|
settingsManager.edit()
|
|
.putInt(getString(R.string.prefer_limit_title_key), prefValues[it])
|
|
.apply()
|
|
}
|
|
return@setOnPreferenceClickListener true
|
|
}
|
|
|
|
/*(getPref(R.string.double_tap_seek_time_key) as? SeekBarPreference?)?.let {
|
|
|
|
}*/
|
|
|
|
getPref(R.string.prefer_limit_title_rez_key)?.setOnPreferenceClickListener {
|
|
val prefNames = resources.getStringArray(R.array.limit_title_rez_pref_names)
|
|
val prefValues = resources.getIntArray(R.array.limit_title_rez_pref_values)
|
|
val current = settingsManager.getInt(getString(R.string.prefer_limit_title_rez_key), 3)
|
|
|
|
activity?.showBottomDialog(
|
|
prefNames.toList(),
|
|
prefValues.indexOf(current),
|
|
getString(R.string.limit_title_rez),
|
|
true,
|
|
{}) {
|
|
settingsManager.edit()
|
|
.putInt(getString(R.string.prefer_limit_title_rez_key), prefValues[it])
|
|
.apply()
|
|
}
|
|
return@setOnPreferenceClickListener true
|
|
}
|
|
|
|
getPref(R.string.quality_pref_key)?.setOnPreferenceClickListener {
|
|
val prefValues = Qualities.values().map { it.value }.reversed().toMutableList()
|
|
prefValues.remove(Qualities.Unknown.value)
|
|
|
|
val prefNames = prefValues.map { Qualities.getStringByInt(it) }
|
|
|
|
val currentQuality =
|
|
settingsManager.getInt(
|
|
getString(R.string.quality_pref_key),
|
|
Qualities.values().last().value
|
|
)
|
|
|
|
activity?.showBottomDialog(
|
|
prefNames.toList(),
|
|
prefValues.indexOf(currentQuality),
|
|
getString(R.string.watch_quality_pref),
|
|
true,
|
|
{}) {
|
|
settingsManager.edit().putInt(getString(R.string.quality_pref_key), prefValues[it])
|
|
.apply()
|
|
}
|
|
return@setOnPreferenceClickListener true
|
|
}
|
|
|
|
getPref(R.string.quality_pref_mobile_data_key)?.setOnPreferenceClickListener {
|
|
val prefValues = Qualities.values().map { it.value }.reversed().toMutableList()
|
|
prefValues.remove(Qualities.Unknown.value)
|
|
|
|
val prefNames = prefValues.map { Qualities.getStringByInt(it) }
|
|
|
|
val currentQuality =
|
|
settingsManager.getInt(
|
|
getString(R.string.quality_pref_mobile_data_key),
|
|
Qualities.values().last().value
|
|
)
|
|
|
|
activity?.showBottomDialog(
|
|
prefNames.toList(),
|
|
prefValues.indexOf(currentQuality),
|
|
getString(R.string.watch_quality_pref_data),
|
|
true,
|
|
{}) {
|
|
settingsManager.edit().putInt(getString(R.string.quality_pref_mobile_data_key), prefValues[it])
|
|
.apply()
|
|
}
|
|
return@setOnPreferenceClickListener true
|
|
}
|
|
|
|
getPref(R.string.player_pref_key)?.setOnPreferenceClickListener {
|
|
val prefNames = resources.getStringArray(R.array.player_pref_names)
|
|
val prefValues = resources.getIntArray(R.array.player_pref_values)
|
|
val current = settingsManager.getInt(getString(R.string.player_pref_key), 1)
|
|
|
|
activity?.showBottomDialog(
|
|
prefNames.toList(),
|
|
prefValues.indexOf(current),
|
|
getString(R.string.player_pref),
|
|
true,
|
|
{}) {
|
|
settingsManager.edit().putInt(getString(R.string.player_pref_key), prefValues[it]).apply()
|
|
}
|
|
return@setOnPreferenceClickListener true
|
|
}
|
|
|
|
getPref(R.string.subtitle_settings_key)?.setOnPreferenceClickListener {
|
|
SubtitlesFragment.push(activity, false)
|
|
return@setOnPreferenceClickListener true
|
|
}
|
|
|
|
getPref(R.string.subtitle_settings_chromecast_key)?.setOnPreferenceClickListener {
|
|
ChromecastSubtitlesFragment.push(activity, false)
|
|
return@setOnPreferenceClickListener true
|
|
}
|
|
|
|
getPref(R.string.video_buffer_disk_key)?.setOnPreferenceClickListener {
|
|
val prefNames = resources.getStringArray(R.array.video_buffer_size_names)
|
|
val prefValues = resources.getIntArray(R.array.video_buffer_size_values)
|
|
|
|
val currentPrefSize =
|
|
settingsManager.getInt(getString(R.string.video_buffer_disk_key), 0)
|
|
|
|
activity?.showDialog(
|
|
prefNames.toList(),
|
|
prefValues.indexOf(currentPrefSize),
|
|
getString(R.string.video_buffer_disk_settings),
|
|
true,
|
|
{}) {
|
|
settingsManager.edit()
|
|
.putInt(getString(R.string.video_buffer_disk_key), prefValues[it])
|
|
.apply()
|
|
}
|
|
return@setOnPreferenceClickListener true
|
|
}
|
|
getPref(R.string.video_buffer_size_key)?.setOnPreferenceClickListener {
|
|
val prefNames = resources.getStringArray(R.array.video_buffer_size_names)
|
|
val prefValues = resources.getIntArray(R.array.video_buffer_size_values)
|
|
|
|
val currentPrefSize =
|
|
settingsManager.getInt(getString(R.string.video_buffer_size_key), 0)
|
|
|
|
activity?.showDialog(
|
|
prefNames.toList(),
|
|
prefValues.indexOf(currentPrefSize),
|
|
getString(R.string.video_buffer_size_settings),
|
|
true,
|
|
{}) {
|
|
settingsManager.edit()
|
|
.putInt(getString(R.string.video_buffer_size_key), prefValues[it])
|
|
.apply()
|
|
}
|
|
return@setOnPreferenceClickListener true
|
|
}
|
|
|
|
getPref(R.string.video_buffer_clear_key)?.let { pref ->
|
|
val cacheDir = context?.cacheDir ?: return@let
|
|
|
|
fun updateSummery() {
|
|
try {
|
|
pref.summary = formatShortFileSize(view?.context, getFolderSize(cacheDir))
|
|
} catch (e: Exception) {
|
|
logError(e)
|
|
}
|
|
}
|
|
|
|
updateSummery()
|
|
|
|
pref.setOnPreferenceClickListener {
|
|
try {
|
|
cacheDir.deleteRecursively()
|
|
updateSummery()
|
|
} catch (e: Exception) {
|
|
logError(e)
|
|
}
|
|
return@setOnPreferenceClickListener true
|
|
}
|
|
}
|
|
|
|
}
|
|
} |