Skip to content

Commit

Permalink
feat: local storage feed item icon.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Oct 11, 2023
1 parent 67e2340 commit 7c61aa8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fun M3UNavHost(
onCurrentPage = onCurrentPage,
navigateToFeed = { feed ->
helper.title = feed.title.ifEmpty {
if (feed.specially) context.getString(R.string.imported_feed_title)
if (feed.local) context.getString(R.string.imported_feed_title)
else ""
}
navigate(Destination.Feed(feed.url))
Expand Down
1 change: 0 additions & 1 deletion benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
alias(libs.plugins.com.android.test)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
2 changes: 1 addition & 1 deletion data/src/main/java/com/m3u/data/database/entity/Feed.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class Feed(
@ColumnInfo(name = "url")
val url: String
) {
val specially: Boolean
val local: Boolean
get() = url == URL_IMPORTED ||
url.startsWithAny("file://", "content://")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fun PortraitOrientationContent(
FeedItem(
label = detail.feed.calculateUiTitle(),
number = detail.count,
special = detail.feed.specially,
local = detail.feed.local,
modifier = Modifier.fillParentMaxWidth(),
onClick = {
navigateToFeed(detail.feed)
Expand Down Expand Up @@ -197,7 +197,7 @@ private fun LandscapeOrientationContent(
FeedItem(
label = detail.feed.calculateUiTitle(),
number = detail.count,
special = detail.feed.specially,
local = detail.feed.local,
modifier = Modifier.fillMaxWidth(),
onClick = {
navigateToFeed(detail.feed)
Expand All @@ -213,7 +213,7 @@ private fun LandscapeOrientationContent(
@Composable
private fun Feed.calculateUiTitle(): AnnotatedString {
val actual = title.ifEmpty {
if (specially) stringResource(R.string.imported_feed_title)
if (local) stringResource(R.string.imported_feed_title)
else ""
}
return AnnotatedString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ContentAlpha
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.DriveFileMove
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
Expand All @@ -34,7 +38,7 @@ import com.m3u.ui.model.LocalTheme
internal fun FeedItem(
label: AnnotatedString,
number: Int,
special: Boolean,
local: Boolean,
onClick: () -> Unit,
onLongClick: () -> Unit,
modifier: Modifier = Modifier
Expand All @@ -43,20 +47,20 @@ internal fun FeedItem(
val theme = LocalTheme.current
val actualBackgroundColor by theme.surface.animated("FeedItemBackground")
val actualContentColor by theme.onSurface.animated("FeedItemContent")
val actualBorder by animateDp("FeedItemBorder") {
if (special) spacing.extraSmall
val actualBorderDp by animateDp("FeedItemBorder") {
if (local) spacing.extraSmall
else spacing.none
}
val actualBorderColor by animateColor("FeedItemBorderColor") {
if (special) Color.Black.copy(alpha = 0.12f)
if (local) Color.Black.copy(alpha = 0.12f)
else Color.Transparent
}
Surface(
shape = RoundedCornerShape(spacing.medium),
color = actualBackgroundColor,
contentColor = actualContentColor,
elevation = spacing.none,
border = BorderStroke(actualBorder, actualBorderColor)
border = BorderStroke(actualBorderDp, actualBorderColor)
) {
OuterRow(
modifier = modifier
Expand All @@ -66,6 +70,13 @@ internal fun FeedItem(
),
verticalAlignment = Alignment.CenterVertically
) {
if (local) {
Icon(
imageVector = Icons.AutoMirrored.Rounded.DriveFileMove,
contentDescription = null,
tint = actualContentColor.copy(alpha = ContentAlpha.medium)
)
}
Text(
text = label,
style = MaterialTheme.typography.body1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,21 @@ internal fun MainDialog(
val context = LocalContext.current
val currentStatus = remember { status as MainDialog.Selections }
if (status is MainDialog.Selections) {
var renamedText by remember {
val editable = with(currentStatus.feed) {
!local || title.isNotEmpty()
}
var renamedText by remember(currentStatus) {
mutableStateOf(
if (!currentStatus.feed.specially) currentStatus.feed.title
else context.getString(R.string.imported_feed_title)
with(currentStatus.feed) {
if (editable) title else context.getString(R.string.imported_feed_title)
}
)
}
DialogTextField(
text = renamedText,
onTextChange = { renamedText = it },
readOnly = !editMode,
icon = Icons.Rounded.Edit.takeUnless { currentStatus.feed.specially },
icon = Icons.Rounded.Edit.takeIf { editable },
iconTint = if (editMode) theme.tint else theme.onBackground,
onIconClick = {
val target = !editMode
Expand All @@ -87,7 +91,7 @@ internal fun MainDialog(
unsubscribe(currentStatus.feed.url)
update(MainDialog.Idle)
}
if (!currentStatus.feed.specially) {
if (!currentStatus.feed.local) {
val clipboardManager = LocalClipboardManager.current
DialogItem(R.string.copy_feed_url) {
val annotatedString = AnnotatedString(currentStatus.feed.url)
Expand Down
1 change: 0 additions & 1 deletion ui/src/main/java/com/m3u/ui/components/Dialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ fun DialogTextField(
)
}
}

}

@Composable
Expand Down

0 comments on commit 7c61aa8

Please sign in to comment.