refactor: general and ui settings and added explicit unstable api opt ins (#787)

This commit is contained in:
IndusAryan 2023-12-14 02:48:12 +05:30 committed by GitHub
parent 6e5a52e440
commit fe30a85a1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 24 additions and 7 deletions

View file

@ -5,6 +5,7 @@ import android.util.Log
import androidx.preference.PreferenceManager
import androidx.media3.common.Format
import androidx.media3.common.MimeTypes
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.text.ExoplayerCuesDecoder
import androidx.media3.exoplayer.text.SubtitleDecoderFactory
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
* enough to identify the subtitle format.
**/
@UnstableApi
class CustomDecoder(private val fallbackFormat: Format?) : SubtitleDecoder {
companion object {
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 */
@UnstableApi
class CustomSubtitleDecoderFactory : SubtitleDecoderFactory {
override fun supportsFormat(format: Format): Boolean {
// return SubtitleDecoderFactory.DEFAULT.supportsFormat(format)

View file

@ -1,9 +1,11 @@
package com.lagradost.cloudstream3.ui.player
import android.os.Looper
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.text.SubtitleDecoderFactory
import androidx.media3.exoplayer.text.TextOutput
@UnstableApi
class CustomTextRenderer(
offset: Long,
output: TextOutput?,

View file

@ -27,6 +27,7 @@ import android.os.Looper;
import android.os.Message;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
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.MimeTypes;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.BaseRenderer;
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
* is delegated to a {@link TextOutput}.
*/
@UnstableApi
public class NonFinalTextRenderer extends BaseRenderer implements Callback {
private static final String TAG = "TextRenderer";
@ -163,13 +166,14 @@ public class NonFinalTextRenderer extends BaseRenderer implements Callback {
finalStreamEndPositionUs = C.TIME_UNSET;
}
@NonNull
@Override
public String getName() {
return TAG;
}
@Override
public @Capabilities int supportsFormat(Format format) {
public @Capabilities int supportsFormat(@NonNull Format format) {
if (decoderFactory.supportsFormat(format)) {
return RendererCapabilities.create(
format.cryptoType == C.CRYPTO_TYPE_NONE ? C.FORMAT_HANDLED : C.FORMAT_UNSUPPORTED_DRM);

View file

@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.ui.settings
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.Toast
@ -41,12 +42,18 @@ import com.lagradost.cloudstream3.utils.VideoDownloadManager
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getBasePath
import com.lagradost.safefile.SafeFile
// Change local language settings in the app.
fun getCurrentLocale(context: Context): String {
val res = context.resources
// Change locale settings in the app.
// val dm = res.displayMetrics
val res = context.resources
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
@ -162,7 +169,7 @@ class SettingsGeneral : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
hideKeyboard()
setPreferencesFromResource(R.xml.settins_general, rootKey)
setPreferencesFromResource(R.xml.settings_general, rootKey)
val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())
fun getCurrent(): MutableList<CustomSite> {

View file

@ -29,7 +29,7 @@ class SettingsUI : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
hideKeyboard()
setPreferencesFromResource(R.xml.settins_ui, rootKey)
setPreferencesFromResource(R.xml.settings_ui, rootKey)
val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())
getPref(R.string.poster_ui_key)?.setOnPreferenceClickListener {

View file

@ -45,7 +45,7 @@ data class SaveChromeCaptionStyle(
@JsonProperty("fontScale") var fontScale: Float = 1.05f,
@JsonProperty("windowColor") var windowColor: Int = Color.TRANSPARENT,
)
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
class ChromecastSubtitlesFragment : Fragment() {
companion object {
val applyStyleEvent = Event<SaveChromeCaptionStyle>()

View file

@ -65,6 +65,7 @@ data class SaveCaptionStyle(
const val DEF_SUBS_ELEVATION = 20
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
class SubtitlesFragment : Fragment() {
companion object {
val applyStyleEvent = Event<SaveCaptionStyle>()