Skip to content

Commit

Permalink
chore: refactor aniskip & custom button (#1908)
Browse files Browse the repository at this point in the history
  • Loading branch information
Secozzi authored Jan 31, 2025
1 parent b24d31e commit ccbb44c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,17 @@

package eu.kanade.tachiyomi.ui.player.controls

import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AspectRatio
import androidx.compose.material.icons.filled.PictureInPictureAlt
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import eu.kanade.tachiyomi.ui.player.controls.components.ControlsButton
import eu.kanade.tachiyomi.ui.player.controls.components.FilledControlsButton
import eu.kanade.tachiyomi.ui.player.execute
import eu.kanade.tachiyomi.ui.player.executeLongPress
import tachiyomi.domain.custombuttons.model.CustomButton
import tachiyomi.presentation.core.components.material.Button
import tachiyomi.presentation.core.components.material.padding

@Composable
fun BottomRightPlayerControls(
Expand All @@ -48,50 +40,19 @@ fun BottomRightPlayerControls(
onPipClick: () -> Unit,
modifier: Modifier = Modifier,
) {
val clickEvent = LocalPlayerButtonsClickEvent.current

Row(modifier) {
if (aniskipButton != null) {
Box(
modifier = Modifier.padding(end = MaterialTheme.padding.small),
) {
Button(onClick = {}) {
Text(text = aniskipButton)
}
Box(
modifier = Modifier
.matchParentSize()
.combinedClickable(
onClick = {
clickEvent()
onPressAniSkipButton()
},
interactionSource = remember { MutableInteractionSource() },
indication = null,
),
)
}
FilledControlsButton(
text = aniskipButton,
onClick = onPressAniSkipButton,
onLongClick = {},
)
} else if (customButton != null) {
Box(
modifier = Modifier.padding(end = MaterialTheme.padding.small),
) {
Button(onClick = {}) {
Text(text = customButtonTitle)
}
Box(
modifier = Modifier
.matchParentSize()
.combinedClickable(
onClick = {
clickEvent()
customButton.execute()
},
onLongClick = { customButton.executeLongPress() },
interactionSource = remember { MutableInteractionSource() },
indication = null,
),
)
}
FilledControlsButton(
text = customButtonTitle,
onClick = customButton::execute,
onLongClick = customButton::executeLongPress,
)
}

if (isPipAvailable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import eu.kanade.tachiyomi.ui.player.controls.LocalPlayerButtonsClickEvent
import tachiyomi.presentation.core.components.material.Button
import tachiyomi.presentation.core.components.material.DISABLED_ALPHA
import tachiyomi.presentation.core.components.material.padding

Expand Down Expand Up @@ -128,6 +129,38 @@ fun ControlsButton(
}
}

@Composable
fun FilledControlsButton(
text: String,
onClick: () -> Unit,
onLongClick: () -> Unit,
modifier: Modifier = Modifier,
) {
val interactionSource = remember { MutableInteractionSource() }
val clickEvent = LocalPlayerButtonsClickEvent.current

Box(
modifier = modifier.padding(end = MaterialTheme.padding.small),
) {
Button(onClick = {}) {
Text(text = text)
}
Box(
modifier = Modifier
.matchParentSize()
.combinedClickable(
onClick = {
clickEvent()
onClick()
},
onLongClick = onLongClick,
interactionSource = interactionSource,
indication = null,
),
)
}
}

@Preview
@Composable
private fun PreviewControlsButton() {
Expand Down

0 comments on commit ccbb44c

Please sign in to comment.