Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add embed external support #87

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion app/src/main/java/io/github/akiomik/seiun/ui/feed/FeedPost.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.akiomik.seiun.ui.feed

import android.content.Intent
import android.net.Uri
import android.text.format.DateFormat
import android.widget.Toast
import androidx.compose.foundation.ExperimentalFoundationApi
Expand Down Expand Up @@ -33,8 +35,10 @@ import androidx.compose.material.icons.sharp.VolumeMute
import androidx.compose.material.icons.sharp.Warning
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
Expand All @@ -53,8 +57,10 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.core.content.ContextCompat.startActivity
import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage
import io.github.akiomik.seiun.R
Expand Down Expand Up @@ -366,6 +372,7 @@ private fun FeedPostContent(viewPost: FeedViewPost) {
}

ImageTile(viewPost)
ExternalCard(viewPost)

Row(
modifier = Modifier
Expand All @@ -388,6 +395,58 @@ private fun FeedPostContent(viewPost: FeedViewPost) {
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ExternalCard(viewPost: FeedViewPost) {
if (viewPost.post.embed is Union4.Element2) {
val external = viewPost.post.embed.value.external
val context = LocalContext.current

OutlinedCard(
modifier = Modifier.padding(top = 16.dp),
onClick = {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(external.uri))
context.startActivity(intent)
}
) {
external.thumb?.let { uri ->
AsyncImage(
model = uri,
contentDescription = external.title,
modifier = Modifier.fillMaxWidth().height(160.dp),
contentScale = ContentScale.Crop
)
}
Column(
modifier = Modifier.padding(12.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(
text = external.title,
style = MaterialTheme.typography.titleMedium,
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
Text(
text = external.uri,
style = MaterialTheme.typography.labelMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
color = Color.Gray
)
if (external.description.isNotEmpty()) {
Text(
text = external.description,
style = MaterialTheme.typography.bodySmall,
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
}
}
}
}
}

@Composable
fun ImageTile(viewPost: FeedViewPost) {
var showImagePager by remember { mutableStateOf(false) }
Expand All @@ -399,7 +458,11 @@ fun ImageTile(viewPost: FeedViewPost) {
if (viewPost.post.embed is Union4.Element1) {
val images = viewPost.post.embed.value.images
if (images.size == 1) {
Box(modifier = Modifier.fillMaxWidth().padding(top = paddingTop)) {
Box(
modifier = Modifier
.fillMaxWidth()
.padding(top = paddingTop)
) {
AsyncImage(
model = images[0].thumb,
contentDescription = images[0].alt,
Expand Down