Skip to content

[WIP] Improve shared callbacks #544

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import net.primal.android.drawer.PrimalDrawerScaffold
import net.primal.android.drawer.multiaccount.events.AccountSwitcherCallbacks
import net.primal.android.feeds.list.FeedsBottomSheet
import net.primal.android.feeds.list.ui.model.FeedUi
import net.primal.android.navigation.navigator.PrimalNavigator
import net.primal.android.premium.legend.domain.LegendaryCustomization
import net.primal.domain.feeds.FeedSpecKind
import net.primal.domain.links.CdnImage
Expand All @@ -63,6 +64,7 @@ fun ReadsScreen(
onDrawerScreenClick: (DrawerScreenDestination) -> Unit,
accountSwitcherCallbacks: AccountSwitcherCallbacks,
callbacks: ReadsScreenContract.ScreenCallbacks,
navigator: PrimalNavigator,
) {
val uiState = viewModel.state.collectAsState()

Expand All @@ -73,6 +75,7 @@ fun ReadsScreen(
eventPublisher = viewModel::setEvent,
accountSwitcherCallbacks = accountSwitcherCallbacks,
callbacks = callbacks,
navigator = navigator,
)
}

Expand All @@ -85,6 +88,7 @@ private fun ReadsScreen(
eventPublisher: (ReadsScreenContract.UiEvent) -> Unit,
accountSwitcherCallbacks: AccountSwitcherCallbacks,
callbacks: ReadsScreenContract.ScreenCallbacks,
navigator: PrimalNavigator,
) {
val context = LocalContext.current
val uiScope = rememberCoroutineScope()
Expand Down Expand Up @@ -118,7 +122,7 @@ private fun ReadsScreen(
accountSwitcherCallbacks = accountSwitcherCallbacks,
onPrimaryDestinationChanged = onTopLevelDestinationChanged,
onDrawerDestinationClick = onDrawerScreenClick,
onDrawerQrCodeClick = callbacks.onDrawerQrCodeClick,
onDrawerQrCodeClick = { callbacks.onDrawerQrCodeClick() },
badges = state.badges,
focusModeEnabled = LocalContentDisplaySettings.current.focusModeEnabled,
topAppBar = { scrollBehavior ->
Expand All @@ -129,12 +133,13 @@ private fun ReadsScreen(
avatarLegendaryCustomization = state.activeAccountLegendaryCustomization,
avatarBlossoms = state.activeAccountBlossoms,
onAvatarClick = { uiScope.launch { drawerState.open() } },
onSearchClick = callbacks.onSearchClick,
onSearchClick = { callbacks.onSearchClick() },
onFeedChanged = { feed ->
val pageIndex = state.feeds.indexOf(feed)
uiScope.launch { pagerState.scrollToPage(page = pageIndex) }
},
scrollBehavior = scrollBehavior,
navigator = navigator,
)
},
content = { paddingValues ->
Expand All @@ -151,8 +156,8 @@ private fun ReadsScreen(
feedSpec = state.feeds[index].spec,
contentPadding = paddingValues,
shouldAnimateScrollToTop = shouldAnimateScrollToTop,
onArticleClick = callbacks.onArticleClick,
onGetPremiumClick = callbacks.onGetPremiumClick,
onArticleClick = { callbacks.onArticleClick(it) },
onGetPremiumClick = { callbacks.onGetPremiumClick() },
onUiError = { uiError: UiError ->
uiScope.launch {
snackbarHostState.showSnackbar(
Expand Down Expand Up @@ -196,6 +201,7 @@ private fun ArticleFeedTopAppBar(
avatarLegendaryCustomization: LegendaryCustomization? = null,
avatarBlossoms: List<String> = emptyList(),
scrollBehavior: TopAppBarScrollBehavior? = null,
navigator: PrimalNavigator,
) {
var feedPickerVisible by rememberSaveable { mutableStateOf(false) }

Expand All @@ -209,6 +215,7 @@ private fun ArticleFeedTopAppBar(
},
onDismissRequest = { feedPickerVisible = false },
sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true),
navigator = navigator,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ReadsScreenContract {
data class ScreenCallbacks(
val onDrawerQrCodeClick: () -> Unit,
val onSearchClick: () -> Unit,
val onArticleClick: (String) -> Unit,
val onArticleClick: (article: String) -> Unit,
val onGetPremiumClick: () -> Unit,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ import net.primal.android.core.compose.icons.PrimalIcons
import net.primal.android.core.compose.icons.primaliconpack.ArrowBack
import net.primal.android.core.errors.UiError
import net.primal.android.core.errors.resolveUiErrorMessage
import net.primal.android.navigation.navigator.PrimalNavigator
import net.primal.android.notes.feed.list.NoteFeedList
import net.primal.android.notes.feed.note.ui.events.NoteCallbacks
import net.primal.android.theme.AppTheme
import net.primal.domain.feeds.FeedSpecKind

@Composable
fun BookmarksScreen(
viewModel: BookmarksViewModel,
noteCallbacks: NoteCallbacks,
navigator: PrimalNavigator,
callbacks: BookmarksContract.ScreenCallbacks,
) {
val uiState = viewModel.state.collectAsState()

BookmarksScreen(
state = uiState.value,
eventPublisher = viewModel::setEvent,
noteCallbacks = noteCallbacks,
navigator = navigator,
callbacks = callbacks,
)
}
Expand All @@ -59,7 +59,7 @@ fun BookmarksScreen(
private fun BookmarksScreen(
state: BookmarksContract.UiState,
eventPublisher: (BookmarksContract.UiEvent) -> Unit,
noteCallbacks: NoteCallbacks,
navigator: PrimalNavigator,
callbacks: BookmarksContract.ScreenCallbacks,
) {
val uiScope = rememberCoroutineScope()
Expand Down Expand Up @@ -87,10 +87,10 @@ private fun BookmarksScreen(
ArticleFeedList(
contentPadding = paddingValues,
feedSpec = state.feedSpec,
onArticleClick = { naddr -> noteCallbacks.onArticleClick?.invoke(naddr) },
onArticleClick = { naddr -> navigator.onArticleClick(naddr) },
pullToRefreshEnabled = false,
noContentText = stringResource(R.string.bookmarks_no_content),
onGetPremiumClick = { noteCallbacks.onGetPrimalPremiumClick?.invoke() },
onGetPremiumClick = { navigator.onGetPrimalPremiumClick() },
onUiError = { uiError: UiError ->
uiScope.launch {
snackbarHostState.showSnackbar(
Expand All @@ -106,7 +106,7 @@ private fun BookmarksScreen(
NoteFeedList(
contentPadding = paddingValues,
feedSpec = state.feedSpec,
noteCallbacks = noteCallbacks,
navigator = navigator,
onGoToWallet = callbacks.onGoToWallet,
pollingEnabled = false,
pullToRefreshEnabled = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import net.primal.android.core.compose.UniversalAvatarThumbnail
import net.primal.android.core.compose.asBeforeNowFormat
import net.primal.android.core.compose.icons.PrimalIcons
import net.primal.android.core.compose.icons.primaliconpack.LightningBoltFilled
import net.primal.android.navigation.navigator.PrimalNavigator
import net.primal.android.notes.feed.model.NoteContentUi
import net.primal.android.notes.feed.note.ui.NoteContent
import net.primal.android.notes.feed.note.ui.events.NoteCallbacks
import net.primal.android.premium.legend.domain.LegendaryCustomization
import net.primal.android.theme.AppTheme
import net.primal.domain.links.CdnImage
Expand All @@ -41,7 +41,7 @@ fun ReferencedNoteZap(
noteContentUi: NoteContentUi,
amountInSats: ULong,
createdAt: Instant,
noteCallbacks: NoteCallbacks,
navigator: PrimalNavigator,
message: String?,
receiverDisplayName: String?,
modifier: Modifier = Modifier,
Expand All @@ -56,15 +56,15 @@ fun ReferencedNoteZap(
.clickable(
interactionSource = null,
indication = null,
onClick = { noteCallbacks.onNoteClick?.invoke(noteContentUi.noteId) },
onClick = { navigator.onNoteClick(noteContentUi.noteId) },
)
.background(AppTheme.extraColorScheme.surfaceVariantAlt3)
.padding(all = 8.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
ZapHeader(
onSenderAvatarClick = { senderId?.let { noteCallbacks.onProfileClick?.invoke(senderId) } },
onSenderAvatarClick = { senderId?.let { navigator.onProfileClick(senderId) } },
senderCdnImage = senderAvatarCdnImage,
amountSats = amountInSats,
message = message,
Expand All @@ -73,11 +73,11 @@ fun ReferencedNoteZap(
NoteSummary(
noteContent = noteContentUi,
noteTimestamp = createdAt,
noteCallbacks = noteCallbacks,
onNoteClick = { noteCallbacks.onNoteClick?.invoke(it) },
navigator = navigator,
onNoteClick = { navigator.onNoteClick(it) },
receiverCdnResource = receiverAvatarCdnImage,
receiverDisplayName = receiverDisplayName,
onReceiverAvatarClick = { receiverId?.let { noteCallbacks.onProfileClick?.invoke(receiverId) } },
onReceiverAvatarClick = { receiverId?.let { navigator.onProfileClick(receiverId) } },
receiverLegendaryCustomization = receiverLegendaryCustomization,
)
}
Expand All @@ -90,7 +90,7 @@ private fun NoteSummary(
receiverCdnResource: CdnImage?,
receiverLegendaryCustomization: LegendaryCustomization?,
noteTimestamp: Instant,
noteCallbacks: NoteCallbacks,
navigator: PrimalNavigator,
onReceiverAvatarClick: () -> Unit,
onNoteClick: (String) -> Unit,
) {
Expand Down Expand Up @@ -133,9 +133,7 @@ private fun NoteSummary(
}
NoteContent(
expanded = false,
noteCallbacks = noteCallbacks.copy(
onProfileClick = null,
),
navigator = navigator,
data = noteContent,
contentColor = AppTheme.extraColorScheme.onSurfaceVariantAlt3,
highlightColor = AppTheme.extraColorScheme.onSurfaceVariantAlt3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import net.primal.android.core.compose.UniversalAvatarThumbnail
import net.primal.android.core.compose.icons.PrimalIcons
import net.primal.android.core.compose.icons.primaliconpack.LightningBoltFilled
import net.primal.android.core.compose.preview.PrimalPreview
import net.primal.android.notes.feed.note.ui.events.NoteCallbacks
import net.primal.android.navigation.interactions.ContentInteractionCallbacks
import net.primal.android.premium.legend.domain.asLegendaryCustomization
import net.primal.android.theme.AppTheme
import net.primal.android.theme.domain.PrimalTheme
Expand All @@ -35,7 +35,6 @@ import net.primal.domain.premium.PrimalLegendProfile
@Composable
fun ReferencedZap(
modifier: Modifier = Modifier,
noteCallbacks: NoteCallbacks,
senderId: String,
receiverId: String,
amountInSats: Double,
Expand All @@ -45,6 +44,7 @@ fun ReferencedZap(
receiverDisplayName: String?,
receiverAvatarCdnImage: CdnImage? = null,
receiverPrimalLegendProfile: PrimalLegendProfile? = null,
contentInteractionCallbacks: ContentInteractionCallbacks,
) {
Row(
modifier = modifier
Expand All @@ -67,7 +67,7 @@ fun ReferencedZap(
avatarSize = 36.dp,
avatarCdnImage = senderAvatarCdnImage,
legendaryCustomization = senderPrimalLegendProfile?.asLegendaryCustomization(),
onClick = { noteCallbacks.onProfileClick?.invoke(senderId) },
onClick = { contentInteractionCallbacks.onProfileClick(senderId) },
)

ZapAmountAndMessageColumn(
Expand All @@ -79,7 +79,7 @@ fun ReferencedZap(
avatarSize = 36.dp,
avatarCdnImage = receiverAvatarCdnImage,
legendaryCustomization = receiverPrimalLegendProfile?.asLegendaryCustomization(),
onClick = { noteCallbacks.onProfileClick?.invoke(receiverId) },
onClick = { contentInteractionCallbacks.onProfileClick(receiverId) },
)
}

Expand Down Expand Up @@ -141,7 +141,10 @@ fun PreviewMessageAndDisplayName() {
PrimalPreview(primalTheme = PrimalTheme.Sunset) {
ReferencedZap(
modifier = Modifier.width(300.dp),
noteCallbacks = NoteCallbacks(),
contentInteractionCallbacks = object : ContentInteractionCallbacks {
override fun onProfileClick(profileId: String) = Unit
override fun onHashtagClick(hashtag: String) = Unit
},
senderId = "",
senderAvatarCdnImage = null,
senderPrimalLegendProfile = null,
Expand All @@ -161,7 +164,10 @@ fun PreviewNoMessageAndDisplayName() {
PrimalPreview(primalTheme = PrimalTheme.Sunset) {
ReferencedZap(
modifier = Modifier.width(300.dp),
noteCallbacks = NoteCallbacks(),
contentInteractionCallbacks = object : ContentInteractionCallbacks {
override fun onProfileClick(profileId: String) = Unit
override fun onHashtagClick(hashtag: String) = Unit
},
senderId = "",
senderAvatarCdnImage = null,
senderPrimalLegendProfile = null,
Expand All @@ -181,7 +187,10 @@ fun PreviewNoMessageAndNoDisplayName() {
PrimalPreview(primalTheme = PrimalTheme.Sunset) {
ReferencedZap(
modifier = Modifier.width(300.dp),
noteCallbacks = NoteCallbacks(),
contentInteractionCallbacks = object : ContentInteractionCallbacks {
override fun onProfileClick(profileId: String) = Unit
override fun onHashtagClick(hashtag: String) = Unit
},
senderId = "",
senderAvatarCdnImage = null,
senderPrimalLegendProfile = null,
Expand All @@ -201,7 +210,10 @@ fun PreviewMessageAndNoDisplayName() {
PrimalPreview(primalTheme = PrimalTheme.Sunset) {
ReferencedZap(
modifier = Modifier.width(300.dp),
noteCallbacks = NoteCallbacks(),
contentInteractionCallbacks = object : ContentInteractionCallbacks {
override fun onProfileClick(profileId: String) = Unit
override fun onHashtagClick(hashtag: String) = Unit
},
senderId = "",
senderAvatarCdnImage = null,
senderPrimalLegendProfile = null,
Expand Down
Loading
Loading