Skip to content

Commit

Permalink
UI and localisation improvements
Browse files Browse the repository at this point in the history
Complete SettingsItemLargeToggle and use for login buttons
Fix radio language
Localise LongPressMenu strings
Add Discord account preview
  • Loading branch information
toasterofbread committed May 7, 2023
1 parent 376086e commit 2c570ba
Show file tree
Hide file tree
Showing 28 changed files with 613 additions and 541 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ actual class PlatformContext(private val context: Context) {
clipboard.setText(AnnotatedString(getText()))

if (name != null) {
sendToast(getStringTODO("Copied {name} to clipboard").replace("{name}", name))
sendToast(getString("notif_copied_x_to_clipboard").replace("\$x", name))
}
else {
sendToast(getStringTODO("Copied to clipboard"))
sendToast(getString("notif_copied_to_clipboard"))
}
}) {
Icon(Icons.Filled.ContentCopy, null, Modifier.size(20.dp))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
@file:Suppress("MemberVisibilityCanBePrivate")

package com.spectre7.settings.model

import androidx.compose.animation.*
import com.spectre7.spmp.platform.PlatformContext
import com.spectre7.spmp.platform.ProjectPreferences
import androidx.compose.animation.Animatable
import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.TweenSpec
import androidx.compose.foundation.background
import androidx.compose.foundation.border
Expand Down Expand Up @@ -31,6 +32,7 @@ import com.github.krottv.compose.sliders.SliderValueHorizontal
import androidx.compose.animation.core.SpringSpec
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.filled.Info
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalDensity
import com.github.krottv.compose.sliders.DefaultThumb
Expand Down Expand Up @@ -776,13 +778,20 @@ class SettingsItemSubpage(

class SettingsItemLargeToggle(
val state: BasicSettingsValueState<Boolean>,
val enabled_text: String,
val disabled_text: String,
val enabled_text: String? = null,
val disabled_text: String? = null,
val enable_button: String,
val disable_button: String,
val checker: ((target: Boolean, openPage: (Int) -> Unit, onFinished: (allow_change: Boolean) -> Unit) -> Unit)? = null
val enabled_content: (@Composable (Modifier) -> Unit)? = null,
val disabled_content: (@Composable (Modifier) -> Unit)? = null,
val warning_text: String? = null,
val info_text: String? = null,
val onClicked: (target: Boolean, setEnabled: (Boolean) -> Unit, setLoading: (Boolean) -> Unit, openPage: (Int) -> Unit) -> Unit =
{ target, setEnabled, _, _ -> setEnabled(target) }
): SettingsItem() {
override fun initialiseValueStates(prefs: ProjectPreferences, default_provider: (String) -> Any) {}
override fun initialiseValueStates(prefs: ProjectPreferences, default_provider: (String) -> Any) {
state.init(prefs, default_provider)
}
override fun resetValues() {}

@Composable
Expand All @@ -792,6 +801,48 @@ class SettingsItemLargeToggle(
openCustomPage: (SettingsPage) -> Unit
) {
val shape = RoundedCornerShape(20.dp)
var loading: Boolean by remember { mutableStateOf(false) }

var showing_warning: Boolean by remember { mutableStateOf(false) }
var showing_info: Boolean by remember { mutableStateOf(false) }

if (showing_warning || showing_info) {
assert(!(showing_warning && showing_info))

PlatformAlertDialog(
{
showing_warning = false
showing_info = false
},
confirmButton = {
FilledTonalButton({
if (showing_warning) {
showing_warning = false
onClicked(
true,
{ state.value = it },
{ loading = it },
openPage
)
}
else {
showing_info = false
}
}) {
Text(getString("action_confirm_action"))
}
},
dismissButton =
if (showing_warning) ({
TextButton({ showing_warning = false }) { Text(getString("action_deny_action")) }
})
else null,
title = { Text(getString("prompt_confirm_action")) },
text = {
LinkifyText(if (showing_warning) warning_text!! else info_text!!)
}
)
}

Crossfade(state.value) { enabled ->
CompositionLocalProvider(LocalContentColor provides if (!enabled) theme.on_background else theme.on_accent) {
Expand All @@ -802,30 +853,57 @@ class SettingsItemLargeToggle(
shape
)
.border(Dp.Hairline, theme.vibrant_accent, shape)
.padding(start = 20.dp, end = 20.dp)
.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically
.padding(horizontal = 10.dp)
.fillMaxWidth()
.height(IntrinsicSize.Max),
horizontalArrangement = Arrangement.spacedBy(3.dp), verticalAlignment = Alignment.CenterVertically
) {
Text(if (enabled) enabled_text else disabled_text)
(if (enabled) enabled_content else disabled_content)?.invoke(Modifier.weight(1f).padding(vertical = 5.dp))
(if (enabled) enabled_text else disabled_text)?.also { Text(it, Modifier.fillMaxWidth().weight(1f)) }

Button(
{
if (checker == null) {
state.value = !enabled
{
if (!enabled && warning_text != null) {
showing_warning = true
}
else {
checker.invoke(!enabled, openPage) { allow_change ->
if (allow_change) {
state.value = !enabled
}
}
onClicked(
!enabled,
{ state.value = it },
{ loading = it },
openPage
)
}
},
colors = ButtonDefaults.buttonColors(
containerColor = if (enabled) theme.vibrant_accent else theme.background,
contentColor = if (enabled) theme.on_accent else theme.on_background
containerColor = if (enabled) theme.background else theme.vibrant_accent,
contentColor = if (enabled) theme.on_background else theme.on_accent
)
) {
Text(if (enabled) disable_button else enable_button)
Box(contentAlignment = Alignment.Center) {
this@Row.AnimatedVisibility(loading, enter = fadeIn(), exit = fadeOut()) {
SubtleLoadingIndicator()
}

val text_alpha = animateFloatAsState(if (loading) 0f else 1f)
Text(
if (enabled) disable_button else enable_button,
Modifier.graphicsLayer { alpha = text_alpha.value }
)
}
}

if (info_text != null) {
ShapedIconButton(
{ showing_info = !showing_info },
shape = CircleShape,
colors = IconButtonDefaults.iconButtonColors(
containerColor = if (enabled) theme.background else theme.vibrant_accent,
contentColor = if (enabled) theme.on_background else theme.on_accent
)
) {
Icon(Icons.Default.Info, null)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ class PlayerService : MediaPlayerService() {
return
}

check(song.artist?.title != null)

discord_status_update_thread = thread { runBlocking {

fun formatText(text: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.schabi.newpipe.extractor.downloader.Request as NewPipeRequest
import org.schabi.newpipe.extractor.downloader.Response as NewPipeResponse

fun <T> Result.Companion.failure(response: Response): Result<T> {
return failure(RuntimeException("${response.message}: ${response.body?.string()} (${response.code})"))
return failure<T>(RuntimeException("${response.message}: ${response.body?.string()} (${response.code})")).also { response.close() }
}
fun <I, O> Result<I>.cast(): Result<O> {
return fold(
Expand Down
Loading

0 comments on commit 2c570ba

Please sign in to comment.