-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6df71d6
commit 2114bc5
Showing
29 changed files
with
1,406 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
.../java/io/github/reactivecircus/kstreamlined/android/common/ui/feed/DisplayableFeedItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.github.reactivecircus.kstreamlined.android.common.ui.feed | ||
|
||
import androidx.compose.runtime.Immutable | ||
import io.github.reactivecircus.kstreamlined.kmp.model.feed.FeedItem | ||
|
||
@Immutable | ||
public data class DisplayableFeedItem<T : FeedItem>( | ||
val value: T, | ||
val displayablePublishTime: String, | ||
) | ||
|
||
public fun <T : FeedItem> T.toDisplayable( | ||
displayablePublishTime: String, | ||
): DisplayableFeedItem<T> { | ||
return DisplayableFeedItem( | ||
value = this, | ||
displayablePublishTime = displayablePublishTime, | ||
) | ||
} |
135 changes: 135 additions & 0 deletions
135
.../main/java/io/github/reactivecircus/kstreamlined/android/common/ui/feed/KotlinBlogCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package io.github.reactivecircus.kstreamlined.android.common.ui.feed | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.unit.dp | ||
import coil.compose.AsyncImage | ||
import io.github.reactivecircus.kstreamlined.android.designsystem.ThemePreviews | ||
import io.github.reactivecircus.kstreamlined.android.designsystem.component.IconButton | ||
import io.github.reactivecircus.kstreamlined.android.designsystem.component.Surface | ||
import io.github.reactivecircus.kstreamlined.android.designsystem.component.Text | ||
import io.github.reactivecircus.kstreamlined.android.designsystem.foundation.KSTheme | ||
import io.github.reactivecircus.kstreamlined.android.designsystem.foundation.icon.BookmarkAdd | ||
import io.github.reactivecircus.kstreamlined.android.designsystem.foundation.icon.BookmarkFill | ||
import io.github.reactivecircus.kstreamlined.android.designsystem.foundation.icon.KSIcons | ||
import io.github.reactivecircus.kstreamlined.kmp.model.feed.FeedItem | ||
import kotlinx.datetime.toInstant | ||
|
||
@Composable | ||
public fun KotlinBlogCard( | ||
item: DisplayableFeedItem<FeedItem.KotlinBlog>, | ||
onItemClick: (FeedItem.KotlinBlog) -> Unit, | ||
onSaveButtonClick: (FeedItem.KotlinBlog) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Surface( | ||
onClick = { onItemClick(item.value) }, | ||
modifier = modifier.fillMaxWidth(), | ||
shape = RoundedCornerShape(16.dp), | ||
color = KSTheme.colorScheme.container, | ||
contentColor = KSTheme.colorScheme.onBackground, | ||
) { | ||
Column { | ||
AsyncImage( | ||
model = item.value.featuredImageUrl, | ||
contentDescription = item.value.title, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height(ImageHeight), | ||
contentScale = ContentScale.FillWidth, | ||
) | ||
|
||
Column( | ||
modifier = Modifier.padding( | ||
start = 16.dp, | ||
end = 8.dp, | ||
top = 24.dp, | ||
bottom = 8.dp, | ||
), | ||
verticalArrangement = Arrangement.spacedBy(4.dp), | ||
) { | ||
Text( | ||
text = item.value.title, | ||
style = KSTheme.typography.titleMedium, | ||
modifier = Modifier.padding(end = 8.dp), | ||
overflow = TextOverflow.Ellipsis, | ||
) | ||
Row(verticalAlignment = Alignment.CenterVertically) { | ||
Text( | ||
text = item.displayablePublishTime, | ||
style = KSTheme.typography.bodyMedium, | ||
color = KSTheme.colorScheme.onBackgroundVariant, | ||
) | ||
Spacer(modifier = Modifier.weight(1f)) | ||
IconButton( | ||
if (item.value.savedForLater) { | ||
KSIcons.BookmarkFill | ||
} else { | ||
KSIcons.BookmarkAdd | ||
}, | ||
contentDescription = null, | ||
onClick = { onSaveButtonClick(item.value) }, | ||
modifier = Modifier, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private val ImageHeight = 200.dp | ||
|
||
@Composable | ||
@ThemePreviews | ||
private fun PreviewKotlinBlogCard_unsaved() { | ||
KSTheme { | ||
Surface { | ||
KotlinBlogCard( | ||
item = FeedItem.KotlinBlog( | ||
id = "1", | ||
title = "Kotlin Multiplatform Development Roadmap for 2024", | ||
publishTime = "2023-11-16T11:59:46Z".toInstant(), | ||
contentUrl = "contentUrl", | ||
savedForLater = false, | ||
featuredImageUrl = "", | ||
).toDisplayable("Moments ago"), | ||
onItemClick = {}, | ||
onSaveButtonClick = {}, | ||
modifier = Modifier.padding(24.dp), | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@ThemePreviews | ||
private fun PreviewKotlinBlogCard_saved() { | ||
KSTheme { | ||
Surface { | ||
KotlinBlogCard( | ||
item = FeedItem.KotlinBlog( | ||
id = "1", | ||
title = "Kotlin Multiplatform Development Roadmap for 2024", | ||
publishTime = "2023-11-16T11:59:46Z".toInstant(), | ||
contentUrl = "contentUrl", | ||
savedForLater = true, | ||
featuredImageUrl = "", | ||
).toDisplayable("Moments ago"), | ||
onItemClick = {}, | ||
onSaveButtonClick = {}, | ||
modifier = Modifier.padding(24.dp), | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.