Show previews of most notes, including NIP94 - images, on new posts.

This commit is contained in:
Vitor Pamplona 2023-04-23 16:32:44 -04:00
parent c1d05f8b2f
commit cbc0f95498
7 changed files with 29 additions and 16 deletions

View File

@ -37,6 +37,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties import androidx.compose.ui.window.DialogProperties
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import coil.compose.AsyncImage import coil.compose.AsyncImage
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.Account
@ -44,13 +45,14 @@ import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.service.model.TextNoteEvent import com.vitorpamplona.amethyst.service.model.TextNoteEvent
import com.vitorpamplona.amethyst.ui.components.* import com.vitorpamplona.amethyst.ui.components.*
import com.vitorpamplona.amethyst.ui.note.ReplyInformation import com.vitorpamplona.amethyst.ui.note.ReplyInformation
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.UserLine import com.vitorpamplona.amethyst.ui.screen.loggedIn.UserLine
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@OptIn(ExperimentalComposeUiApi::class) @OptIn(ExperimentalComposeUiApi::class)
@Composable @Composable
fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = null, account: Account) { fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = null, account: Account, accountViewModel: AccountViewModel, navController: NavController) {
val postViewModel: NewPostViewModel = viewModel() val postViewModel: NewPostViewModel = viewModel()
val context = LocalContext.current val context = LocalContext.current
@ -234,6 +236,14 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n
} else { } else {
UrlPreview(myUrlPreview, myUrlPreview) UrlPreview(myUrlPreview, myUrlPreview)
} }
} else if (isBechLink(myUrlPreview)) {
BechLink(
myUrlPreview,
true,
MaterialTheme.colors.background,
accountViewModel,
navController
)
} else if (noProtocolUrlValidator.matcher(myUrlPreview).matches()) { } else if (noProtocolUrlValidator.matcher(myUrlPreview).matches()) {
UrlPreview("https://$myUrlPreview", myUrlPreview) UrlPreview("https://$myUrlPreview", myUrlPreview)
} }

View File

@ -88,7 +88,7 @@ fun FabColumn(account: Account) {
} }
if (wantsToPost) { if (wantsToPost) {
NewPostView({ wantsToPost = false }, account = NostrAccountDataSource.account) //NewPostView({ wantsToPost = false }, account = NostrAccountDataSource.account)
} }
if (wantsToPoll) { if (wantsToPoll) {

View File

@ -16,18 +16,20 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.ui.actions.NewPostView import com.vitorpamplona.amethyst.ui.actions.NewPostView
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
@Composable @Composable
fun NewNoteButton(account: Account) { fun NewNoteButton(account: Account, accountViewModel: AccountViewModel, navController: NavController) {
var wantsToPost by remember { var wantsToPost by remember {
mutableStateOf(false) mutableStateOf(false)
} }
if (wantsToPost) { if (wantsToPost) {
NewPostView({ wantsToPost = false }, account = account) NewPostView({ wantsToPost = false }, account = account, accountViewModel = accountViewModel, navController = navController)
} }
OutlinedButton( OutlinedButton(

View File

@ -450,7 +450,7 @@ fun NoteComposeInner(
} else if (noteEvent is LongTextNoteEvent) { } else if (noteEvent is LongTextNoteEvent) {
LongFormHeader(noteEvent, note, loggedIn) LongFormHeader(noteEvent, note, loggedIn)
ReactionsRow(note, accountViewModel) ReactionsRow(note, accountViewModel, navController)
Divider( Divider(
modifier = Modifier.padding(top = 10.dp), modifier = Modifier.padding(top = 10.dp),
@ -485,7 +485,7 @@ fun NoteComposeInner(
) )
} }
ReactionsRow(note, accountViewModel) ReactionsRow(note, accountViewModel, navController)
Divider( Divider(
modifier = Modifier.padding(top = 10.dp), modifier = Modifier.padding(top = 10.dp),
@ -512,7 +512,7 @@ fun NoteComposeInner(
) )
if (!makeItShort) { if (!makeItShort) {
ReactionsRow(note, accountViewModel) ReactionsRow(note, accountViewModel, navController)
} }
Divider( Divider(
@ -556,7 +556,7 @@ fun NoteComposeInner(
} }
if (!makeItShort) { if (!makeItShort) {
ReactionsRow(note, accountViewModel) ReactionsRow(note, accountViewModel, navController)
} }
Divider( Divider(

View File

@ -49,6 +49,7 @@ import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Popup import androidx.compose.ui.window.Popup
import androidx.navigation.NavController
import coil.compose.AsyncImage import coil.compose.AsyncImage
import coil.request.CachePolicy import coil.request.CachePolicy
import coil.request.ImageRequest import coil.request.ImageRequest
@ -66,7 +67,7 @@ import java.math.RoundingMode
import kotlin.math.roundToInt import kotlin.math.roundToInt
@Composable @Composable
fun ReactionsRow(baseNote: Note, accountViewModel: AccountViewModel) { fun ReactionsRow(baseNote: Note, accountViewModel: AccountViewModel, navController: NavController) {
val accountState by accountViewModel.accountLiveData.observeAsState() val accountState by accountViewModel.accountLiveData.observeAsState()
val account = accountState?.account ?: return val account = accountState?.account ?: return
@ -79,11 +80,11 @@ fun ReactionsRow(baseNote: Note, accountViewModel: AccountViewModel) {
} }
if (wantsToReplyTo != null) { if (wantsToReplyTo != null) {
NewPostView({ wantsToReplyTo = null }, wantsToReplyTo, null, account) NewPostView({ wantsToReplyTo = null }, wantsToReplyTo, null, account, accountViewModel, navController)
} }
if (wantsToQuote != null) { if (wantsToQuote != null) {
NewPostView({ wantsToQuote = null }, null, wantsToQuote, account) NewPostView({ wantsToQuote = null }, null, wantsToQuote, account, accountViewModel, navController)
} }
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))

View File

@ -378,7 +378,7 @@ fun NoteMaster(
} }
} }
ReactionsRow(note, accountViewModel) ReactionsRow(note, accountViewModel, navController)
Divider( Divider(
modifier = Modifier.padding(top = 10.dp), modifier = Modifier.padding(top = 10.dp),

View File

@ -73,7 +73,7 @@ fun MainScreen(accountViewModel: AccountViewModel, accountStateViewModel: Accoun
} }
}, },
floatingActionButton = { floatingActionButton = {
FloatingButtons(navController, accountStateViewModel) FloatingButtons(navController, accountViewModel, accountStateViewModel)
}, },
scaffoldState = scaffoldState scaffoldState = scaffoldState
) { ) {
@ -85,8 +85,8 @@ fun MainScreen(accountViewModel: AccountViewModel, accountStateViewModel: Accoun
} }
@Composable @Composable
fun FloatingButtons(navController: NavHostController, accountViewModel: AccountStateViewModel) { fun FloatingButtons(navController: NavHostController, accountViewModel: AccountViewModel, accountStateViewModel: AccountStateViewModel) {
val accountState by accountViewModel.accountContent.collectAsState() val accountState by accountStateViewModel.accountContent.collectAsState()
if (currentRoute(navController)?.substringBefore("?") == Route.Home.base) { if (currentRoute(navController)?.substringBefore("?") == Route.Home.base) {
Crossfade(targetState = accountState, animationSpec = tween(durationMillis = 100)) { state -> Crossfade(targetState = accountState, animationSpec = tween(durationMillis = 100)) { state ->
@ -98,7 +98,7 @@ fun FloatingButtons(navController: NavHostController, accountViewModel: AccountS
// Does nothing. // Does nothing.
} }
is AccountState.LoggedIn -> { is AccountState.LoggedIn -> {
NewNoteButton(state.account) NewNoteButton(state.account, accountViewModel, navController)
} }
} }
} }