mirror of https://github.com/Ashinch/ReadYou.git
feat(ui): article item line number adaptive
This commit is contained in:
parent
80f335ab71
commit
a9cb9a33f2
|
@ -2,20 +2,40 @@ package me.ash.reader.ui.page.home.flow
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.material.*
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.material.DismissDirection
|
||||||
|
import androidx.compose.material.DismissValue
|
||||||
|
import androidx.compose.material.ExperimentalMaterialApi
|
||||||
|
import androidx.compose.material.SwipeToDismiss
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.CheckCircleOutline
|
import androidx.compose.material.icons.rounded.CheckCircleOutline
|
||||||
import androidx.compose.material.icons.rounded.Star
|
import androidx.compose.material.icons.rounded.Star
|
||||||
|
import androidx.compose.material.rememberDismissState
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
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.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.alpha
|
import androidx.compose.ui.draw.alpha
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
|
import androidx.compose.ui.layout.onGloballyPositioned
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
@ -24,7 +44,13 @@ import coil.size.Precision
|
||||||
import coil.size.Scale
|
import coil.size.Scale
|
||||||
import me.ash.reader.R
|
import me.ash.reader.R
|
||||||
import me.ash.reader.domain.model.article.ArticleWithFeed
|
import me.ash.reader.domain.model.article.ArticleWithFeed
|
||||||
import me.ash.reader.infrastructure.preference.*
|
import me.ash.reader.infrastructure.preference.FlowArticleReadIndicatorPreference
|
||||||
|
import me.ash.reader.infrastructure.preference.LocalFlowArticleListDesc
|
||||||
|
import me.ash.reader.infrastructure.preference.LocalFlowArticleListFeedIcon
|
||||||
|
import me.ash.reader.infrastructure.preference.LocalFlowArticleListFeedName
|
||||||
|
import me.ash.reader.infrastructure.preference.LocalFlowArticleListImage
|
||||||
|
import me.ash.reader.infrastructure.preference.LocalFlowArticleListReadIndicator
|
||||||
|
import me.ash.reader.infrastructure.preference.LocalFlowArticleListTime
|
||||||
import me.ash.reader.ui.component.FeedIcon
|
import me.ash.reader.ui.component.FeedIcon
|
||||||
import me.ash.reader.ui.component.base.RYAsyncImage
|
import me.ash.reader.ui.component.base.RYAsyncImage
|
||||||
import me.ash.reader.ui.component.base.SIZE_1000
|
import me.ash.reader.ui.component.base.SIZE_1000
|
||||||
|
@ -43,6 +69,18 @@ fun ArticleItem(
|
||||||
val articleListDesc = LocalFlowArticleListDesc.current
|
val articleListDesc = LocalFlowArticleListDesc.current
|
||||||
val articleListDate = LocalFlowArticleListTime.current
|
val articleListDate = LocalFlowArticleListTime.current
|
||||||
val articleListReadIndicator = LocalFlowArticleListReadIndicator.current
|
val articleListReadIndicator = LocalFlowArticleListReadIndicator.current
|
||||||
|
var titleHeight by remember { mutableStateOf(0) }
|
||||||
|
val density = LocalDensity.current
|
||||||
|
var descriptionLines by remember { mutableStateOf(1) }
|
||||||
|
LaunchedEffect(titleHeight) {
|
||||||
|
with(density) {
|
||||||
|
descriptionLines = if (titleHeight > 0 && titleHeight + 16.dp.roundToPx() / 16 > 32) {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
@ -136,8 +174,15 @@ fun ArticleItem(
|
||||||
text = articleWithFeed.article.title,
|
text = articleWithFeed.article.title,
|
||||||
color = MaterialTheme.colorScheme.onSurface,
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
maxLines = if (articleListDesc.value) 2 else 4,
|
// maxLines = if (articleListDesc.value) 2 else 4,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
modifier = Modifier.onGloballyPositioned {coordinates ->
|
||||||
|
if (titleHeight == 0) {
|
||||||
|
titleHeight = with(density) {
|
||||||
|
coordinates.size.height.toDp().value.toInt()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Description
|
// Description
|
||||||
|
@ -147,7 +192,7 @@ fun ArticleItem(
|
||||||
text = articleWithFeed.article.shortDescription,
|
text = articleWithFeed.article.shortDescription,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
maxLines = 2,
|
maxLines = descriptionLines,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue