Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.ui.subtitles.SUBTITLE_AUTO_SELECT_KEY
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.getAutoSelectLanguageTagIETF
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragmentDialog2
import com.lagradost.cloudstream3.utils.AppContextUtils.getShortSeasonText
import com.lagradost.cloudstream3.utils.AppContextUtils.html
import com.lagradost.cloudstream3.utils.AppContextUtils.sortSubs
Expand Down Expand Up @@ -1046,7 +1047,7 @@ class GeneratorPlayer : FullScreenPlayer() {

binding.subtitleSettingsBtt.setOnClickListener {
safe {
val subtitlesFragment = SubtitlesFragment()
val subtitlesFragment = SubtitlesFragmentDialog2()
subtitlesFragment.systemBarsAddPadding = true
subtitlesFragment.show(this.parentFragmentManager, "SubtitleSettings")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import com.lagradost.cloudstream3.utils.txt
import com.lagradost.cloudstream4.compose.Screen
import com.lagradost.cloudstream4.compose.TV
import com.lagradost.cloudstream4.compose.circle
import com.lagradost.cloudstream4.compose.circleBorder
import com.lagradost.cloudstream4.compose.focusOutline
import com.lagradost.cloudstream4.compose.isLayout
import com.lagradost.cloudstream4.theme.CloudStreamPreviewTheme
Expand Down Expand Up @@ -229,23 +230,12 @@ object SettingsFragmentScreen : Screen {
account.customImage ?: profileImages.getOrNull(account.defaultImageIndex)
?: profileImages.first()

Box(
modifier = Modifier
.size(50.dp)
.border(
2.dp,
MaterialTheme.colorScheme.onBackground.copy(alpha = 0.2f),
CircleShape
)
.circle(),
) {
AsyncImage(
contentScale = ContentScale.Crop,
model = image,
modifier = Modifier.fillMaxSize(),
contentDescription = null,
)
}
AsyncImage(
contentScale = ContentScale.Crop,
model = image,
modifier = Modifier.circleBorder(50.dp),
contentDescription = null,
)
Spacer(modifier = Modifier.width(MaterialTheme.padding.medium))
Column {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ object SettingsPlayerScreen : SearchableSettings {
title = stringResource(R.string.double_tap_to_seek_amount_settings),
icon = painterResource(R.drawable.go_forward_30),
valueRange = 5..60,
steps = 10,
//steps = 10,
onValueChanged = settings.player.doubleTapTime::set
),
)
Expand All @@ -242,7 +242,7 @@ object SettingsPlayerScreen : SearchableSettings {
subtitle = stringResource(R.string.android_tv_interface_on_seek_settings_summary),
icon = painterResource(R.drawable.go_forward_30),
valueRange = 5..60,
steps = 10,
//steps = 10,
onValueChanged = settings.player.tvSeekOnTime::set
),
Preference.PreferenceItem.SliderPreference(
Expand All @@ -251,7 +251,7 @@ object SettingsPlayerScreen : SearchableSettings {
subtitle = stringResource(R.string.android_tv_interface_off_seek_settings_summary),
icon = painterResource(R.drawable.go_forward_30),
valueRange = 5..60,
steps = 10,
//steps = 10,
onValueChanged = settings.player.tvSeekOffTime::set
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.OptIn
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.mutableStateOf
import androidx.media3.common.text.Cue
import androidx.media3.common.util.UnstableApi
import com.fasterxml.jackson.annotation.JsonProperty
Expand Down Expand Up @@ -44,15 +46,16 @@ import kotlinx.serialization.Serializable
const val CHROME_SUBTITLE_KEY = "chome_subtitle_settings"

@Serializable
@Immutable
data class SaveChromeCaptionStyle(
@JsonProperty("fontFamily") @SerialName("fontFamily") var fontFamily: String? = null,
@JsonProperty("fontGenericFamily") @SerialName("fontGenericFamily") var fontGenericFamily: Int? = null,
@JsonProperty("backgroundColor") @SerialName("backgroundColor") var backgroundColor: Int = 0x00FFFFFF, // transparent
@JsonProperty("edgeColor") @SerialName("edgeColor") var edgeColor: Int = Color.BLACK, // BLACK
@JsonProperty("edgeType") @SerialName("edgeType") var edgeType: Int = EDGE_TYPE_OUTLINE,
@JsonProperty("foregroundColor") @SerialName("foregroundColor") var foregroundColor: Int = Color.WHITE,
@JsonProperty("fontScale") @SerialName("fontScale") var fontScale: Float = 1.05f,
@JsonProperty("windowColor") @SerialName("windowColor") var windowColor: Int = Color.TRANSPARENT,
@JsonProperty("fontFamily") @SerialName("fontFamily") val fontFamily: String? = null,
@JsonProperty("fontGenericFamily") @SerialName("fontGenericFamily") val fontGenericFamily: Int? = null,
@JsonProperty("backgroundColor") @SerialName("backgroundColor") val backgroundColor: Int = 0x00FFFFFF, // transparent
@JsonProperty("edgeColor") @SerialName("edgeColor") val edgeColor: Int = Color.BLACK, // BLACK
@JsonProperty("edgeType") @SerialName("edgeType") val edgeType: Int = EDGE_TYPE_OUTLINE,
@JsonProperty("foregroundColor") @SerialName("foregroundColor") val foregroundColor: Int = Color.WHITE,
@JsonProperty("fontScale") @SerialName("fontScale") val fontScale: Float = 1.05f,
@JsonProperty("windowColor") @SerialName("windowColor") val windowColor: Int = Color.TRANSPARENT,
)

class ChromecastSubtitlesFragment : BaseFragment<ChromecastSubtitleSettingsBinding>(
Expand Down Expand Up @@ -92,6 +95,9 @@ class ChromecastSubtitlesFragment : BaseFragment<ChromecastSubtitleSettingsBindi
}

fun Context.saveStyle(style: SaveChromeCaptionStyle) {
if (chromeCastSubtitleState.value !== style) {
chromeCastSubtitleState.value = style
}
this.setKey(CHROME_SUBTITLE_KEY, style)
}

Expand All @@ -101,10 +107,13 @@ class ChromecastSubtitlesFragment : BaseFragment<ChromecastSubtitleSettingsBindi
}

fun getCurrentSavedStyle(): SaveChromeCaptionStyle {
return getKey<SaveChromeCaptionStyle>(CHROME_SUBTITLE_KEY) ?: defaultState
return chromeCastSubtitleState.value
}

private val defaultState = SaveChromeCaptionStyle()
val defaultChromeCastSubtitleState = SaveChromeCaptionStyle()
val chromeCastSubtitleState = mutableStateOf(
getKey<SaveChromeCaptionStyle>(CHROME_SUBTITLE_KEY) ?: defaultChromeCastSubtitleState
)
}

private fun onColorSelected(stuff: Pair<Int, Int>) {
Expand Down Expand Up @@ -134,10 +143,10 @@ class ChromecastSubtitlesFragment : BaseFragment<ChromecastSubtitleSettingsBindi
private fun setColor(id: Int, color: Int?) {
val realColor = color ?: getDefColor(id)
when (id) {
0 -> state.foregroundColor = realColor
1 -> state.edgeColor = realColor
2 -> state.backgroundColor = realColor
3 -> state.windowColor = realColor
0 -> state = state.copy(foregroundColor = realColor)
1 -> state = state.copy(edgeColor = realColor)
2 -> state = state.copy(backgroundColor = realColor)
3 -> state = state.copy(windowColor = realColor)

else -> Unit
}
Expand Down Expand Up @@ -240,13 +249,13 @@ class ChromecastSubtitlesFragment : BaseFragment<ChromecastSubtitleSettingsBindi
false,
dismissCallback
) { index ->
state.edgeType = edgeTypes.map { it.first }[index]
state = state.copy(edgeType = edgeTypes.map { it.first }[index])
updateState()
}
}

binding.subsEdgeType.setOnLongClickListener {
state.edgeType = defaultState.edgeType
state = state.copy(edgeType = defaultChromeCastSubtitleState.edgeType)
updateState()
showToast(R.string.subs_default_reset_toast, Toast.LENGTH_SHORT)
return@setOnLongClickListener true
Expand Down Expand Up @@ -281,13 +290,13 @@ class ChromecastSubtitlesFragment : BaseFragment<ChromecastSubtitleSettingsBindi
false,
dismissCallback
) { index ->
state.fontScale = fontSizes.map { it.first }[index]
state = state.copy(fontScale = fontSizes.map { it.first }[index])
//textView.context.updateState() // font size not changed
}
}

binding.subsFontSize.setOnLongClickListener { _ ->
state.fontScale = defaultState.fontScale
state = state.copy(fontScale = defaultChromeCastSubtitleState.fontScale)
//textView.context.updateState() // font size not changed
showToast(R.string.subs_default_reset_toast, Toast.LENGTH_SHORT)
return@setOnLongClickListener true
Expand All @@ -314,12 +323,12 @@ class ChromecastSubtitlesFragment : BaseFragment<ChromecastSubtitleSettingsBindi
false,
dismissCallback
) { index ->
state.fontFamily = fontTypes.map { it.first }[index]
state = state.copy(fontFamily = fontTypes.map { it.first }[index])
updateState()
}
}
binding.subsFont.setOnLongClickListener { _ ->
state.fontFamily = defaultState.fontFamily
state = state.copy(fontFamily = defaultChromeCastSubtitleState.fontFamily)
updateState()
showToast(activity, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT)
return@setOnLongClickListener true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.lagradost.cloudstream3.ui.subtitles

import com.lagradost.cloudstream3.utils.BaseComposeFragment
import com.lagradost.cloudstream4.compose.Screen

class ChromecastSubtitlesFragment2 : BaseComposeFragment(), Screen by ChromecastSubtitlesScreen
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package com.lagradost.cloudstream3.ui.subtitles

import androidx.compose.foundation.layout.RowScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import com.google.android.gms.cast.TextTrackStyle.EDGE_TYPE_DEPRESSED
import com.google.android.gms.cast.TextTrackStyle.EDGE_TYPE_DROP_SHADOW
import com.google.android.gms.cast.TextTrackStyle.EDGE_TYPE_NONE
import com.google.android.gms.cast.TextTrackStyle.EDGE_TYPE_OUTLINE
import com.google.android.gms.cast.TextTrackStyle.EDGE_TYPE_RAISED
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.ui.subtitles.ChromecastSubtitlesFragment.Companion.applyStyleEvent
import com.lagradost.cloudstream3.ui.subtitles.ChromecastSubtitlesFragment.Companion.chromeCastSubtitleState
import com.lagradost.cloudstream3.ui.subtitles.ChromecastSubtitlesFragment.Companion.defaultChromeCastSubtitleState
import com.lagradost.cloudstream3.ui.subtitles.ChromecastSubtitlesFragment.Companion.saveStyle
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesScreen.SetUpUndoBar
import com.mihon.presentation.settings.Preference
import com.mihon.presentation.settings.SearchableSettings
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.persistentMapOf
import kotlin.math.roundToInt

object ChromecastSubtitlesScreen : SearchableSettings {
@Composable
override fun getTitleRes(): String = stringResource(R.string.chromecast_subtitles_settings)

// For ux purposes we also want to show a diff of what will be reset
private val diff = arrayOf<Pair<Int, (SaveChromeCaptionStyle) -> Any?>>(
R.string.subs_font to { style -> style.fontFamily },
R.string.subs_text_color to { state -> state.foregroundColor },
R.string.subs_font_size to { state -> state.fontScale },
R.string.subs_edge_type to { state -> state.edgeType },
R.string.subs_outline_color to { state -> state.edgeColor },
R.string.subs_window_color to { state -> state.windowColor },
R.string.subs_background_color to { state -> state.backgroundColor },
)

@Composable
override fun RowScope.AppBarAction() {
val initialState = remember { chromeCastSubtitleState.value }
SetUpUndoBar(
diff = diff,
initialState = initialState,
currentState = chromeCastSubtitleState,
default = defaultChromeCastSubtitleState
)
}

@Composable
override fun getPreferences(): List<Preference> {
val initialState = remember { chromeCastSubtitleState.value }
var state by remember { chromeCastSubtitleState }

val context = LocalContext.current

SideEffect(state) {
// When we modify the state, we modify the stored data
context.saveStyle(state)
}

DisposableEffect(Unit) {
onDispose {
if (initialState != state) {
applyStyleEvent.invoke(state)
}
}
}
return getPreferences(state) { updater ->
state = updater(state)
}
}

/** Unfortunately this causes a lot of re-compositions, but what can you do? */
@Composable
fun getPreferences(
state : SaveChromeCaptionStyle,
update : (SaveChromeCaptionStyle.() -> SaveChromeCaptionStyle) -> Unit
): List<Preference> {
return persistentListOf(
Preference.PreferenceGroup(
title = stringResource(R.string.subs_font),
preferenceItems = persistentListOf(
Preference.PreferenceItem.BasicListPreference(
icon = painterResource(R.drawable.font_download_24px),
title = stringResource(R.string.subs_font),
value = state.fontFamily,
entries = persistentMapOf(
null to stringResource(R.string.normal),
"Droid Sans" to "Droid Sans",
"Droid Sans Mono" to "Droid Sans Mono",
"Droid Serif Regular" to "Droid Serif Regular",
"Cutive Mono" to "Cutive Mono",
"Short Stack" to "Short Stack",
"Quintessential" to "Quintessential",
"Alegreya Sans SC" to "Alegreya Sans SC",
),
onValueChanged = { newValue ->
update { copy(fontFamily = newValue) }
}),
Preference.PreferenceItem.BasicColorPreference(
title = stringResource(R.string.subs_text_color),
value = Color(state.foregroundColor),
icon = painterResource(R.drawable.format_color_text_24px),
onValueChanged = { newValue ->
update { copy(foregroundColor = newValue.toArgb()) }
}
),
Preference.PreferenceItem.SliderPreference(
value = state.fontScale.times(100.0f).roundToInt(),
icon = painterResource(R.drawable.text_fields_24px),
title = stringResource(R.string.subs_font_size),
valueRange = 75..150,
steps = 75/5 - 1,
onValueChanged = { newValue ->
update { copy(fontScale = newValue.toFloat() * 0.01f) }
})
)
),
Preference.PreferenceGroup(
title = stringResource(R.string.subs_edge),
preferenceItems = persistentListOf(
Preference.PreferenceItem.BasicListPreference(
icon = painterResource(R.drawable.shadow_24px),
title = stringResource(R.string.subs_edge_type),
value = state.edgeType,
entries = persistentMapOf(
EDGE_TYPE_NONE to stringResource(R.string.subtitles_none),
EDGE_TYPE_OUTLINE to stringResource(R.string.subtitles_outline),
EDGE_TYPE_DEPRESSED to stringResource(R.string.subtitles_depressed),
EDGE_TYPE_DROP_SHADOW to stringResource(R.string.subtitles_shadow),
EDGE_TYPE_RAISED to stringResource(R.string.subtitles_raised),
),
onValueChanged = { newValue ->
update { copy(edgeType = newValue) }
}),
Preference.PreferenceItem.BasicColorPreference(
enabled = state.edgeType != EDGE_TYPE_NONE,
title = stringResource(R.string.subs_outline_color),
value = Color(state.edgeColor),
icon = painterResource(R.drawable.border_color_24px),
onValueChanged = { newValue ->
update { copy(edgeColor = newValue.toArgb()) }
}
),
)),
Preference.PreferenceGroup(
title = stringResource(R.string.background),
preferenceItems = persistentListOf(
Preference.PreferenceItem.BasicColorPreference(
title = stringResource(R.string.subs_window_color),
value = Color(state.windowColor),
icon = painterResource(R.drawable.imagesearch_roller_24px),
onValueChanged = { newValue ->
update { copy(windowColor = newValue.toArgb()) }
}
),
Preference.PreferenceItem.BasicColorPreference(
title = stringResource(R.string.subs_background_color),
value = Color(state.backgroundColor),
icon = painterResource(R.drawable.format_color_fill_24px),
onValueChanged = { newValue ->
update { copy(backgroundColor = newValue.toArgb()) }
}
),
))
)
}
}
Loading