mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
refactor: general and ui settings and added explicit unstable api opt ins (#787)
This commit is contained in:
parent
6e5a52e440
commit
fe30a85a1c
9 changed files with 24 additions and 7 deletions
|
@ -5,6 +5,7 @@ import android.util.Log
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.media3.common.Format
|
import androidx.media3.common.Format
|
||||||
import androidx.media3.common.MimeTypes
|
import androidx.media3.common.MimeTypes
|
||||||
|
import androidx.media3.common.util.UnstableApi
|
||||||
import androidx.media3.exoplayer.text.ExoplayerCuesDecoder
|
import androidx.media3.exoplayer.text.ExoplayerCuesDecoder
|
||||||
import androidx.media3.exoplayer.text.SubtitleDecoderFactory
|
import androidx.media3.exoplayer.text.SubtitleDecoderFactory
|
||||||
import androidx.media3.extractor.text.SubtitleDecoder
|
import androidx.media3.extractor.text.SubtitleDecoder
|
||||||
|
@ -30,6 +31,7 @@ import java.nio.charset.Charset
|
||||||
* @param fallbackFormat used to create a decoder based on mimetype if the subtitle string is not
|
* @param fallbackFormat used to create a decoder based on mimetype if the subtitle string is not
|
||||||
* enough to identify the subtitle format.
|
* enough to identify the subtitle format.
|
||||||
**/
|
**/
|
||||||
|
@UnstableApi
|
||||||
class CustomDecoder(private val fallbackFormat: Format?) : SubtitleDecoder {
|
class CustomDecoder(private val fallbackFormat: Format?) : SubtitleDecoder {
|
||||||
companion object {
|
companion object {
|
||||||
fun updateForcedEncoding(context: Context) {
|
fun updateForcedEncoding(context: Context) {
|
||||||
|
@ -260,6 +262,7 @@ class CustomDecoder(private val fallbackFormat: Format?) : SubtitleDecoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** See https://github.com/google/ExoPlayer/blob/release-v2/library/core/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java */
|
/** See https://github.com/google/ExoPlayer/blob/release-v2/library/core/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java */
|
||||||
|
@UnstableApi
|
||||||
class CustomSubtitleDecoderFactory : SubtitleDecoderFactory {
|
class CustomSubtitleDecoderFactory : SubtitleDecoderFactory {
|
||||||
override fun supportsFormat(format: Format): Boolean {
|
override fun supportsFormat(format: Format): Boolean {
|
||||||
// return SubtitleDecoderFactory.DEFAULT.supportsFormat(format)
|
// return SubtitleDecoderFactory.DEFAULT.supportsFormat(format)
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package com.lagradost.cloudstream3.ui.player
|
package com.lagradost.cloudstream3.ui.player
|
||||||
|
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import androidx.media3.common.util.UnstableApi
|
||||||
import androidx.media3.exoplayer.text.SubtitleDecoderFactory
|
import androidx.media3.exoplayer.text.SubtitleDecoderFactory
|
||||||
import androidx.media3.exoplayer.text.TextOutput
|
import androidx.media3.exoplayer.text.TextOutput
|
||||||
|
|
||||||
|
@UnstableApi
|
||||||
class CustomTextRenderer(
|
class CustomTextRenderer(
|
||||||
offset: Long,
|
offset: Long,
|
||||||
output: TextOutput?,
|
output: TextOutput?,
|
||||||
|
|
|
@ -27,6 +27,7 @@ import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.Format;
|
import androidx.media3.common.Format;
|
||||||
|
@ -34,6 +35,7 @@ import androidx.media3.common.text.Cue;
|
||||||
import androidx.media3.common.text.CueGroup;
|
import androidx.media3.common.text.CueGroup;
|
||||||
import androidx.media3.common.MimeTypes;
|
import androidx.media3.common.MimeTypes;
|
||||||
import androidx.media3.common.util.Log;
|
import androidx.media3.common.util.Log;
|
||||||
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import androidx.media3.common.util.Util;
|
import androidx.media3.common.util.Util;
|
||||||
import androidx.media3.exoplayer.BaseRenderer;
|
import androidx.media3.exoplayer.BaseRenderer;
|
||||||
import androidx.media3.exoplayer.FormatHolder;
|
import androidx.media3.exoplayer.FormatHolder;
|
||||||
|
@ -64,6 +66,7 @@ import java.util.stream.Collectors;
|
||||||
* obtained from a {@link SubtitleDecoderFactory}. The actual rendering of the subtitle {@link Cue}s
|
* obtained from a {@link SubtitleDecoderFactory}. The actual rendering of the subtitle {@link Cue}s
|
||||||
* is delegated to a {@link TextOutput}.
|
* is delegated to a {@link TextOutput}.
|
||||||
*/
|
*/
|
||||||
|
@UnstableApi
|
||||||
public class NonFinalTextRenderer extends BaseRenderer implements Callback {
|
public class NonFinalTextRenderer extends BaseRenderer implements Callback {
|
||||||
|
|
||||||
private static final String TAG = "TextRenderer";
|
private static final String TAG = "TextRenderer";
|
||||||
|
@ -163,13 +166,14 @@ public class NonFinalTextRenderer extends BaseRenderer implements Callback {
|
||||||
finalStreamEndPositionUs = C.TIME_UNSET;
|
finalStreamEndPositionUs = C.TIME_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Capabilities int supportsFormat(Format format) {
|
public @Capabilities int supportsFormat(@NonNull Format format) {
|
||||||
if (decoderFactory.supportsFormat(format)) {
|
if (decoderFactory.supportsFormat(format)) {
|
||||||
return RendererCapabilities.create(
|
return RendererCapabilities.create(
|
||||||
format.cryptoType == C.CRYPTO_TYPE_NONE ? C.FORMAT_HANDLED : C.FORMAT_UNSUPPORTED_DRM);
|
format.cryptoType == C.CRYPTO_TYPE_NONE ? C.FORMAT_HANDLED : C.FORMAT_UNSUPPORTED_DRM);
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.ui.settings
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
@ -41,12 +42,18 @@ import com.lagradost.cloudstream3.utils.VideoDownloadManager
|
||||||
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getBasePath
|
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getBasePath
|
||||||
import com.lagradost.safefile.SafeFile
|
import com.lagradost.safefile.SafeFile
|
||||||
|
|
||||||
|
// Change local language settings in the app.
|
||||||
fun getCurrentLocale(context: Context): String {
|
fun getCurrentLocale(context: Context): String {
|
||||||
val res = context.resources
|
|
||||||
// Change locale settings in the app.
|
|
||||||
// val dm = res.displayMetrics
|
// val dm = res.displayMetrics
|
||||||
|
val res = context.resources
|
||||||
val conf = res.configuration
|
val conf = res.configuration
|
||||||
return conf?.locale?.toString() ?: "en"
|
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
conf?.locales?.get(0)?.toString() ?: "en"
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
conf?.locale?.toString() ?: "en"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// idk, if you find a way of automating this it would be great
|
// idk, if you find a way of automating this it would be great
|
||||||
|
@ -162,7 +169,7 @@ class SettingsGeneral : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
setPreferencesFromResource(R.xml.settins_general, rootKey)
|
setPreferencesFromResource(R.xml.settings_general, rootKey)
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
|
|
||||||
fun getCurrent(): MutableList<CustomSite> {
|
fun getCurrent(): MutableList<CustomSite> {
|
||||||
|
|
|
@ -29,7 +29,7 @@ class SettingsUI : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
setPreferencesFromResource(R.xml.settins_ui, rootKey)
|
setPreferencesFromResource(R.xml.settings_ui, rootKey)
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
|
|
||||||
getPref(R.string.poster_ui_key)?.setOnPreferenceClickListener {
|
getPref(R.string.poster_ui_key)?.setOnPreferenceClickListener {
|
||||||
|
|
|
@ -45,7 +45,7 @@ data class SaveChromeCaptionStyle(
|
||||||
@JsonProperty("fontScale") var fontScale: Float = 1.05f,
|
@JsonProperty("fontScale") var fontScale: Float = 1.05f,
|
||||||
@JsonProperty("windowColor") var windowColor: Int = Color.TRANSPARENT,
|
@JsonProperty("windowColor") var windowColor: Int = Color.TRANSPARENT,
|
||||||
)
|
)
|
||||||
|
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
|
||||||
class ChromecastSubtitlesFragment : Fragment() {
|
class ChromecastSubtitlesFragment : Fragment() {
|
||||||
companion object {
|
companion object {
|
||||||
val applyStyleEvent = Event<SaveChromeCaptionStyle>()
|
val applyStyleEvent = Event<SaveChromeCaptionStyle>()
|
||||||
|
|
|
@ -65,6 +65,7 @@ data class SaveCaptionStyle(
|
||||||
|
|
||||||
const val DEF_SUBS_ELEVATION = 20
|
const val DEF_SUBS_ELEVATION = 20
|
||||||
|
|
||||||
|
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
|
||||||
class SubtitlesFragment : Fragment() {
|
class SubtitlesFragment : Fragment() {
|
||||||
companion object {
|
companion object {
|
||||||
val applyStyleEvent = Event<SaveCaptionStyle>()
|
val applyStyleEvent = Event<SaveCaptionStyle>()
|
||||||
|
|
Loading…
Reference in a new issue