Skip to content

Commit

Permalink
fix #85
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Jul 26, 2024
1 parent 4fbd291 commit 6fe2624
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import androidx.compose.material.icons.rounded.Devices
import androidx.compose.material.icons.rounded.Speaker
import androidx.compose.material.icons.rounded.Tv
import androidx.compose.material.icons.rounded.Warning
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.graphics.vector.ImageVector
import com.arkivanov.decompose.router.slot.ChildSlot
import com.arkivanov.decompose.value.Value
Expand Down Expand Up @@ -50,6 +52,8 @@ interface MediumComponent : Component {

val isFavorite: StateFlow<Boolean>

val focus: Focus

fun back()
fun season(value: Series.Season)
fun language(value: Series.Language)
Expand All @@ -69,6 +73,25 @@ interface MediumComponent : Component {
streams: ImmutableCollection<DirectLink>
)

data class Focus(
val seasonAndLanguageButtons: FocusRequester,
val floatingActionButton: FocusRequester,
val descriptionExtender: FocusRequester
) {
companion object {
@OptIn(ExperimentalComposeUiApi::class)
fun create(): Focus {
val (sl, fab, desc) = FocusRequester.createRefs()

return Focus(
seasonAndLanguageButtons = sl,
floatingActionButton = fab,
descriptionExtender = desc
)
}
}
}

sealed interface Device {
val icon: ImageVector
val name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -122,22 +123,23 @@ fun MediumScreen(component: MediumComponent, updater: SchemeTheme.Updater?) {

dialogState.child?.instance?.render()

val (seasonFocus, fabFocus) = FocusRequester.createRefs()
Scaffold(
topBar = {
Toolbar(
component = component,
series = (seriesState as? SeriesState.Success)?.series,
seasonFocus = seasonFocus,
fabFocus = fabFocus
series = (seriesState as? SeriesState.Success)?.series
)
},
floatingActionButton = {
val nextEpisode by component.nextCombinedEpisode.collectAsStateWithLifecycle(null)

nextEpisode?.ifHasHoster()?.let { episode ->
ExtendedFloatingActionButton(
modifier = Modifier.focusRequester(fabFocus),
modifier = Modifier
.focusRequester(component.focus.floatingActionButton)
.focusProperties {
start = component.focus.seasonAndLanguageButtons
},
onClick = {
component.episode(episode)
},
Expand Down Expand Up @@ -192,7 +194,11 @@ fun MediumScreen(component: MediumComponent, updater: SchemeTheme.Updater?) {
.fillParentMaxWidth()
.padding(horizontal = 16.dp)
.padding(top = 8.dp)
.focusRequester(seasonFocus)
.focusRequester(component.focus.seasonAndLanguageButtons)
.focusProperties {
down = component.focus.descriptionExtender
next = component.focus.descriptionExtender
}
)
}
if (isAndroidPhone && isAnime && !isAniFlowInstalled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ class MediumScreenComponent(

private val userHelper by instance<UserHelper>()

override val focus: MediumComponent.Focus = MediumComponent.Focus.create()

init {
val hrefWithLanguage = if (initialLanguage != null) {
seriesData.toHref(newLanguage = initialLanguage.code)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package dev.datlag.burningseries.ui.navigation.screen.medium.component

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.animateIntAsState
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -23,6 +26,8 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import dev.datlag.burningseries.composeapp.generated.resources.Res
Expand Down Expand Up @@ -88,9 +93,19 @@ internal fun DescriptionSection(
}
)
}
if (descriptionExpandable) {
AnimatedVisibility(
visible = descriptionExpandable,
enter = fadeIn(),
exit = fadeOut()
) {
PlatformIconButton(
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
.focusRequester(component.focus.descriptionExtender)
.focusProperties {
previous = component.focus.seasonAndLanguageButtons
},
onClick = {
descriptionExpanded = !descriptionExpanded
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ import org.jetbrains.compose.resources.stringResource
@Composable
internal fun Toolbar(
component: MediumComponent,
series: Series?,
seasonFocus: FocusRequester,
fabFocus: FocusRequester
series: Series?
) {
TopAppBar(
navigationIcon = {
ProvideNonTvContentColor {
PlatformIconButton(
modifier = Modifier.focusProperties {
down = component.focus.seasonAndLanguageButtons
},
onClick = component::back
) {
PlatformIcon(
Expand Down Expand Up @@ -272,8 +273,8 @@ internal fun Toolbar(
if (isFavorite) {
PlatformIconButton(
modifier = Modifier.focusProperties {
end = fabFocus
down = seasonFocus
end = component.focus.floatingActionButton
down = component.focus.seasonAndLanguageButtons
},
onClick = {
if (series != null) {
Expand All @@ -290,8 +291,8 @@ internal fun Toolbar(
} else {
PlatformIconButton(
modifier = Modifier.focusProperties {
end = fabFocus
down = seasonFocus
end = component.focus.floatingActionButton
down = component.focus.seasonAndLanguageButtons
},
onClick = {
if (series != null) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ksoup = "0.1.2"
ksp = "2.0.0-1.0.23"
ktor = "2.3.12"
ktorfit = "2.0.0"
media3 = "1.4.0-rc01"
media3 = "1.4.0"
moko-resources = "0.24.1"
multidex = "2.0.1"
nanoid = "1.0.1"
Expand Down

0 comments on commit 6fe2624

Please sign in to comment.