Skip to content

Commit

Permalink
fix(ui): collapse/expand all groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashinch committed Jun 28, 2024
1 parent b03f381 commit ce348cf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 41 deletions.
64 changes: 24 additions & 40 deletions app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
Expand All @@ -17,19 +16,15 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.KeyboardArrowRight
import androidx.compose.material.icons.outlined.KeyboardArrowRight
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.rounded.Add
import androidx.compose.material.icons.rounded.ExpandLess
import androidx.compose.material.icons.rounded.ExpandMore
import androidx.compose.material.icons.rounded.Refresh
import androidx.compose.material.icons.rounded.UnfoldLess
import androidx.compose.material.icons.rounded.UnfoldMore
Expand Down Expand Up @@ -73,7 +68,6 @@ import me.ash.reader.ui.component.base.Banner
import me.ash.reader.ui.component.base.DisplayText
import me.ash.reader.ui.component.base.FeedbackIconButton
import me.ash.reader.ui.component.base.RYScaffold
import me.ash.reader.ui.component.base.Subtitle
import me.ash.reader.ui.ext.alphaLN
import me.ash.reader.ui.ext.collectAsStateValue
import me.ash.reader.ui.ext.currentAccountId
Expand Down Expand Up @@ -124,6 +118,7 @@ fun FeedsPage(
val groupWithFeedList =
feedsUiState.groupWithFeedList.collectAsStateValue(initial = emptyList())
val groupsVisible: SnapshotStateMap<String, Boolean> = feedsUiState.groupsVisible
var hasGroupVisible by remember { mutableStateOf(groupListExpand.value) }

val newVersion = LocalNewVersionNumber.current
val skipVersion = LocalSkipVersionNumber.current
Expand Down Expand Up @@ -161,7 +156,7 @@ fun FeedsPage(
}
}

fun expandAll() {
fun expandAllGroups() {
groupWithFeedList.forEach { groupWithFeed ->
when (groupWithFeed) {
is GroupFeedsView.Group -> {
Expand All @@ -170,9 +165,10 @@ fun FeedsPage(
else -> {}
}
}
hasGroupVisible = true
}

fun collapseAll() {
fun collapseAllGroups() {
groupWithFeedList.forEach { groupWithFeed ->
when (groupWithFeed) {
is GroupFeedsView.Group -> {
Expand All @@ -181,6 +177,7 @@ fun FeedsPage(
else -> {}
}
}
hasGroupVisible = false
}

LaunchedEffect(Unit) {
Expand Down Expand Up @@ -280,38 +277,20 @@ fun FeedsPage(
color = MaterialTheme.colorScheme.primary,
style = MaterialTheme.typography.labelLarge,
)
Row() {
Row(
modifier = Modifier
.padding(end = 16.dp) // Space between icons
.size(24.dp)
.clip(CircleShape)
.background(MaterialTheme.colorScheme.surfaceTint.copy(alpha = groupIndicatorAlpha))
.clickable { collapseAll() },
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
imageVector = Icons.Rounded.UnfoldLess,
contentDescription = stringResource(R.string.unfold_less),
tint = MaterialTheme.colorScheme.onSecondaryContainer,
)
}
Row(
modifier = Modifier
.size(24.dp)
.clip(CircleShape)
.background(MaterialTheme.colorScheme.surfaceTint.copy(alpha = groupIndicatorAlpha))
.clickable { expandAll() },
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
imageVector = Icons.Rounded.UnfoldMore,
contentDescription = stringResource(R.string.unfold_more),
tint = MaterialTheme.colorScheme.onSecondaryContainer,
)
}
Row(
modifier = Modifier
.padding(end = 12.dp)
.size(20.dp)
.clip(CircleShape)
.clickable { if (hasGroupVisible) collapseAllGroups() else expandAllGroups() },
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
imageVector = if (hasGroupVisible) Icons.Rounded.UnfoldLess else Icons.Rounded.UnfoldMore,
contentDescription = stringResource(R.string.unfold_less),
tint = MaterialTheme.colorScheme.primary,
)
}
}
Spacer(modifier = Modifier.height(8.dp))
Expand Down Expand Up @@ -342,6 +321,11 @@ fun FeedsPage(
groupWithFeed.group.id,
groupListExpand::value
).not()
hasGroupVisible = if (groupsVisible[groupWithFeed.group.id] == true) {
true
} else {
groupsVisible.any { it.value }
}
}
) {
filterChange(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import me.ash.reader.R
import me.ash.reader.domain.model.account.Account
Expand Down

0 comments on commit ce348cf

Please sign in to comment.