-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add seeking increment settings
- Loading branch information
Showing
6 changed files
with
305 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
app/tv/src/main/java/dev/jdtech/jellyfin/ui/components/SettingsDetailsLongCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package dev.jdtech.jellyfin.ui.components | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.text.KeyboardOptions | ||
import androidx.compose.material3.OutlinedTextField | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.input.KeyboardType | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.core.text.isDigitsOnly | ||
import androidx.media3.common.C.DEFAULT_SEEK_BACK_INCREMENT_MS | ||
import androidx.tv.material3.Button | ||
import androidx.tv.material3.ButtonScale | ||
import androidx.tv.material3.MaterialTheme | ||
import androidx.tv.material3.Surface | ||
import androidx.tv.material3.Text | ||
import dev.jdtech.jellyfin.Constants | ||
import dev.jdtech.jellyfin.models.PreferenceLong | ||
import dev.jdtech.jellyfin.ui.theme.FindroidTheme | ||
import dev.jdtech.jellyfin.ui.theme.spacings | ||
import dev.jdtech.jellyfin.core.R as CoreR | ||
|
||
@Composable | ||
fun SettingsDetailsLongCard( | ||
preference: PreferenceLong, | ||
modifier: Modifier = Modifier, | ||
onValueUpdate: (Long) -> Unit, | ||
) { | ||
Surface(modifier = modifier) { | ||
Column( | ||
modifier = Modifier.padding( | ||
horizontal = MaterialTheme.spacings.default, | ||
vertical = MaterialTheme.spacings.medium, | ||
), | ||
) { | ||
Text( | ||
text = stringResource(id = preference.nameStringResource), | ||
style = MaterialTheme.typography.headlineMedium | ||
) | ||
preference.descriptionStringRes?.let { | ||
Spacer(modifier = Modifier.height(MaterialTheme.spacings.small)) | ||
Text(text = stringResource(id = it), style = MaterialTheme.typography.bodyMedium) | ||
} | ||
Spacer(modifier = Modifier.height(MaterialTheme.spacings.default)) | ||
Column(modifier = Modifier.padding(vertical = MaterialTheme.spacings.medium)) { | ||
var text by remember(preference.value) { mutableStateOf(preference.value.toString()) } | ||
OutlinedTextField( | ||
value = text, | ||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), | ||
onValueChange = { | ||
if (it.isDigitsOnly()) { | ||
text = it | ||
} | ||
}, | ||
singleLine = true, | ||
modifier = Modifier.fillMaxWidth() | ||
) | ||
Spacer(modifier = Modifier.height(MaterialTheme.spacings.medium)) | ||
Box { | ||
Button( | ||
onClick = { | ||
onValueUpdate(text.toLongOrNull() ?: return@Button) | ||
}, | ||
enabled = text.isNotEmpty(), | ||
scale = ButtonScale.None, | ||
) { | ||
Box( | ||
modifier = Modifier.fillMaxWidth(), | ||
) { | ||
Text( | ||
text = stringResource(id = android.R.string.ok), | ||
modifier = Modifier.align(Alignment.Center), | ||
) | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun SettingsDetailLongCardPreview() { | ||
FindroidTheme { | ||
SettingsDetailsLongCard( | ||
preference = PreferenceLong( | ||
nameStringResource = CoreR.string.seek_back_increment, | ||
backendName = Constants.PREF_PLAYER_SEEK_BACK_INC, | ||
backendDefaultValue = DEFAULT_SEEK_BACK_INCREMENT_MS, | ||
value = DEFAULT_SEEK_BACK_INCREMENT_MS, | ||
), | ||
onValueUpdate = {}, | ||
) | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
app/tv/src/main/java/dev/jdtech/jellyfin/ui/components/SettingsLongCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package dev.jdtech.jellyfin.ui.components | ||
|
||
import androidx.compose.foundation.BorderStroke | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.media3.common.C.DEFAULT_SEEK_BACK_INCREMENT_MS | ||
import androidx.tv.material3.Border | ||
import androidx.tv.material3.ClickableSurfaceDefaults | ||
import androidx.tv.material3.ClickableSurfaceScale | ||
import androidx.tv.material3.Icon | ||
import androidx.tv.material3.MaterialTheme | ||
import androidx.tv.material3.Surface | ||
import androidx.tv.material3.Text | ||
import dev.jdtech.jellyfin.Constants | ||
import dev.jdtech.jellyfin.models.PreferenceLong | ||
import dev.jdtech.jellyfin.ui.theme.FindroidTheme | ||
import dev.jdtech.jellyfin.ui.theme.spacings | ||
import dev.jdtech.jellyfin.core.R as CoreR | ||
|
||
@Composable | ||
fun SettingsLongCard( | ||
preference: PreferenceLong, | ||
modifier: Modifier = Modifier, | ||
onClick: () -> Unit, | ||
) { | ||
Surface( | ||
onClick = onClick, | ||
enabled = preference.enabled, | ||
shape = ClickableSurfaceDefaults.shape(shape = RoundedCornerShape(10.dp)), | ||
colors = ClickableSurfaceDefaults.colors( | ||
containerColor = MaterialTheme.colorScheme.surface, | ||
focusedContainerColor = MaterialTheme.colorScheme.surface, | ||
), | ||
border = ClickableSurfaceDefaults.border( | ||
focusedBorder = Border( | ||
BorderStroke( | ||
4.dp, | ||
Color.White, | ||
), | ||
shape = RoundedCornerShape(10.dp), | ||
), | ||
), | ||
scale = ClickableSurfaceScale.None, | ||
modifier = modifier | ||
.fillMaxWidth(), | ||
) { | ||
Row( | ||
modifier = Modifier.padding(MaterialTheme.spacings.default), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
if (preference.iconDrawableId != null) { | ||
Icon( | ||
painter = painterResource(id = preference.iconDrawableId!!), | ||
contentDescription = null, | ||
) | ||
Spacer(modifier = Modifier.width(24.dp)) | ||
} | ||
|
||
Column( | ||
modifier = Modifier.weight(1f), | ||
) { | ||
Text( | ||
text = stringResource(id = preference.nameStringResource), | ||
style = MaterialTheme.typography.titleMedium, | ||
) | ||
|
||
Spacer(modifier = Modifier.height(MaterialTheme.spacings.extraSmall)) | ||
Text( | ||
text = preference.value.toString(), | ||
style = MaterialTheme.typography.labelMedium, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun SettingsLongCardPreview() { | ||
FindroidTheme { | ||
SettingsLongCard( | ||
preference = PreferenceLong( | ||
nameStringResource = CoreR.string.seek_back_increment, | ||
backendName = Constants.PREF_PLAYER_SEEK_BACK_INC, | ||
backendDefaultValue = DEFAULT_SEEK_BACK_INCREMENT_MS, | ||
value = DEFAULT_SEEK_BACK_INCREMENT_MS, | ||
), | ||
onClick = {}, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.