Skip to content

Commit

Permalink
Merge pull request #525 from DimensionDev/feature/cross_search_user
Browse files Browse the repository at this point in the history
add cross search for user
  • Loading branch information
Tlaster authored Oct 18, 2024
2 parents 72ed32f + f0fdf37 commit a2423c5
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,20 @@ internal class ComposeInAppNotification : InAppNotification {
}

override fun onSuccess(message: Message) {
val messageId =
when (message) {
Message.Compose -> R.string.compose_notification_success_title
}
_source.value = Event(Notification.StringNotification(messageId, success = true))
_source.value = Event(Notification.StringNotification(message.title, success = true))
}

override fun onError(
message: Message,
throwable: Throwable,
) {
val messageId =
when (message) {
Message.Compose -> R.string.compose_notification_error_title
}
_source.value = Event(Notification.StringNotification(messageId, success = false))
_source.value = Event(Notification.StringNotification(message.title, success = false))
}
}

private val Message.title
get() =
when (this) {
Message.Compose -> R.string.compose_notification_title
Message.LoginExpired -> R.string.notification_login_expired
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private fun UserListContent(
data: UiTimeline.ItemContent.UserList,
modifier: Modifier = Modifier,
) {
val uriHandler = LocalUriHandler.current
Column(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(8.dp),
Expand All @@ -112,7 +113,15 @@ private fun UserListContent(
) {
CommonStatusHeaderComponent(
data = user,
onUserClick = {},
onUserClick = {
user.onClicked.invoke(
ClickContext(
launcher = {
uriHandler.openUri(it)
},
),
)
},
modifier = Modifier.padding(8.dp),
)
}
Expand Down
163 changes: 153 additions & 10 deletions app/src/main/java/dev/dimension/flare/ui/screen/profile/ProfileScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import com.ramcosta.composedestinations.annotation.parameters.DeepLink
import com.ramcosta.composedestinations.annotation.parameters.FULL_ROUTE_PLACEHOLDER
import com.ramcosta.composedestinations.generated.destinations.EditAccountListRouteDestination
import com.ramcosta.composedestinations.generated.destinations.ProfileMediaRouteDestination
import com.ramcosta.composedestinations.generated.destinations.SearchRouteDestination
import com.ramcosta.composedestinations.generated.destinations.StatusMediaRouteDestination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import compose.icons.FontAwesomeIcons
Expand All @@ -97,6 +98,7 @@ import dev.dimension.flare.common.onSuccess
import dev.dimension.flare.data.datasource.microblog.ProfileAction
import dev.dimension.flare.model.AccountType
import dev.dimension.flare.model.MicroBlogKey
import dev.dimension.flare.model.PlatformType
import dev.dimension.flare.molecule.producePresenter
import dev.dimension.flare.ui.common.plus
import dev.dimension.flare.ui.component.AvatarComponent
Expand Down Expand Up @@ -126,6 +128,8 @@ import dev.dimension.flare.ui.presenter.profile.ProfileMedia
import dev.dimension.flare.ui.presenter.profile.ProfilePresenter
import dev.dimension.flare.ui.presenter.profile.ProfileState
import dev.dimension.flare.ui.presenter.profile.ProfileWithUserNameAndHostPresenter
import dev.dimension.flare.ui.presenter.settings.AccountsPresenter
import dev.dimension.flare.ui.presenter.settings.AccountsState
import dev.dimension.flare.ui.screen.home.RegisterTabCallback
import dev.dimension.flare.ui.theme.MediumAlpha
import dev.dimension.flare.ui.theme.screenHorizontalPadding
Expand Down Expand Up @@ -195,6 +199,14 @@ internal fun ProfileWithUserNameAndHostDeeplinkRoute(
),
)
},
toSearchUserUsingAccount = { handle, accountKey ->
navigator.navigate(
SearchRouteDestination(
handle,
AccountType.Specific(accountKey),
),
)
},
)
}.onLoading {
ProfileLoadingScreen(
Expand Down Expand Up @@ -262,6 +274,14 @@ internal fun ProfileWithUserNameAndHostRoute(
toEditAccountList = {
navigator.navigate(EditAccountListRouteDestination(accountType, it.key))
},
toSearchUserUsingAccount = { handle, accountKey ->
navigator.navigate(
SearchRouteDestination(
handle,
AccountType.Specific(accountKey),
),
)
},
)
}.onLoading {
ProfileLoadingScreen(
Expand Down Expand Up @@ -408,6 +428,14 @@ internal fun ProfileDeeplinkRoute(
),
)
},
toSearchUserUsingAccount = { handle, accountKey ->
navigator.navigate(
SearchRouteDestination(
handle,
AccountType.Specific(accountKey),
),
)
},
)
}

Expand Down Expand Up @@ -456,6 +484,14 @@ internal fun ProfileRoute(
navigator.navigate(EditAccountListRouteDestination(accountType, userKey))
}
},
toSearchUserUsingAccount = { handle, accountKey ->
navigator.navigate(
SearchRouteDestination(
handle,
AccountType.Specific(accountKey),
),
)
},
)
}

Expand All @@ -466,6 +502,7 @@ internal fun ProfileRoute(
private fun ProfileScreen(
accountType: AccountType,
toEditAccountList: () -> Unit,
toSearchUserUsingAccount: (String, MicroBlogKey) -> Unit,
userKey: MicroBlogKey? = null,
onBack: () -> Unit = {},
showBackButton: Boolean = true,
Expand Down Expand Up @@ -574,6 +611,8 @@ private fun ProfileScreen(
setShowMoreMenus = state::setShowMoreMenus,
showMoreMenus = state.showMoreMenus,
toEditAccountList = toEditAccountList,
accountsState = state.allAccountsState,
toSearchUserUsingAccount = toSearchUserUsingAccount,
)
}
},
Expand Down Expand Up @@ -608,6 +647,8 @@ private fun ProfileScreen(
setShowMoreMenus = state::setShowMoreMenus,
showMoreMenus = state.showMoreMenus,
toEditAccountList = toEditAccountList,
accountsState = state.allAccountsState,
toSearchUserUsingAccount = toSearchUserUsingAccount,
)
},
expandMatrices = true,
Expand All @@ -621,6 +662,7 @@ private fun ProfileScreen(
// it.banner?.let { it1 -> onMediaClick(it1) }
}
},
isBigScreen = bigScreen,
)
}
}
Expand Down Expand Up @@ -735,6 +777,7 @@ private fun ProfileScreen(
// it.banner?.let { it1 -> onMediaClick(it1) }
}
},
isBigScreen = bigScreen,
)
}
},
Expand Down Expand Up @@ -806,9 +849,11 @@ private fun ProfileMediaTab(
@Composable
private fun ProfileMenu(
profileState: ProfileState,
accountsState: AccountsState,
setShowMoreMenus: (Boolean) -> Unit,
showMoreMenus: Boolean,
toEditAccountList: () -> Unit,
toSearchUserUsingAccount: (String, MicroBlogKey) -> Unit,
) {
profileState.isMe.onSuccess { isMe ->
if (!isMe) {
Expand Down Expand Up @@ -848,6 +893,49 @@ private fun ProfileMenu(
}
}
}
accountsState.accounts.onSuccess { accounts ->
profileState.myAccountKey.onSuccess { myKey ->
if (accounts.size > 1) {
for (i in 0 until accounts.size) {
val account = accounts[i]
account.second.onSuccess { accountData ->
if (accountData.key != user.key &&
accountData.key != myKey &&
accountData.platformType != user.platformType
) {
DropdownMenuItem(
text = {
Text(
text =
stringResource(
id = R.string.profile_search_user_using_account,
user.handleWithoutAtAndHost,
accountData.platformType.name,
accountData.handleWithoutAt,
),
)
},
onClick = {
setShowMoreMenus(false)
val actualHandle =
if (accountData.platformType == PlatformType.Bluesky) {
user.handleWithoutAtAndHost
.replace("_", "")
} else {
user.handleWithoutAtAndHost
}
toSearchUserUsingAccount(
actualHandle,
accountData.key,
)
},
)
}
}
}
}
}
}
profileState.actions.onSuccess { actions ->
for (i in 0..<actions.size) {
val action = actions[i]
Expand Down Expand Up @@ -926,6 +1014,7 @@ private fun ProfileHeader(
isMe: UiState<Boolean>,
menu: @Composable RowScope.() -> Unit,
expandMatrices: Boolean,
isBigScreen: Boolean,
modifier: Modifier = Modifier,
) {
when (userState) {
Expand All @@ -948,6 +1037,7 @@ private fun ProfileHeader(
expandMatrices = expandMatrices,
onAvatarClick = onAvatarClick,
onBannerClick = onBannerClick,
isBigScreen = isBigScreen,
)
}
}
Expand All @@ -962,6 +1052,7 @@ private fun ProfileHeaderSuccess(
onBannerClick: () -> Unit,
isMe: UiState<Boolean>,
menu: @Composable RowScope.() -> Unit,
isBigScreen: Boolean,
modifier: Modifier = Modifier,
expandMatrices: Boolean = false,
) {
Expand All @@ -972,6 +1063,7 @@ private fun ProfileHeaderSuccess(
displayName = user.name.data,
userKey = user.key,
handle = user.handle,
isBigScreen = isBigScreen,
headerTrailing = {
isMe.onSuccess {
if (!it) {
Expand Down Expand Up @@ -1144,6 +1236,7 @@ internal fun CommonProfileHeader(
displayName: Element,
userKey: MicroBlogKey,
handle: String,
isBigScreen: Boolean,
modifier: Modifier = Modifier,
onAvatarClick: (() -> Unit)? = null,
onBannerClick: (() -> Unit)? = null,
Expand Down Expand Up @@ -1251,11 +1344,60 @@ internal fun CommonProfileHeader(
},
)
}
Column(
if (!isBigScreen) {
Column(
modifier =
Modifier
.weight(1f)
.padding(top = actualBannerHeight),
) {
HtmlText(
element = displayName,
textStyle = MaterialTheme.typography.titleMedium,
// modifier =
// Modifier
// .sharedElement(
// rememberSharedContentState(key = "profile-display-name-$userKey"),
// animatedVisibilityScope = this@AnimatedVisibilityScope,
// ),
)
Row(
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = handle,
style = MaterialTheme.typography.bodySmall,
// modifier =
// Modifier
// .sharedElement(
// rememberSharedContentState(key = "profile-handle-$userKey"),
// animatedVisibilityScope = this@AnimatedVisibilityScope,
// ),
)
handleTrailing.invoke(this)
}
}
} else {
Spacer(
modifier =
Modifier
.weight(1f),
)
}
Row(
modifier =
Modifier
.weight(1f)
.padding(top = actualBannerHeight),
) {
headerTrailing()
}
}
if (isBigScreen) {
Column(
modifier =
Modifier
.padding(horizontal = screenHorizontalPadding),
) {
HtmlText(
element = displayName,
Expand Down Expand Up @@ -1284,13 +1426,6 @@ internal fun CommonProfileHeader(
handleTrailing.invoke(this)
}
}
Row(
modifier =
Modifier
.padding(top = actualBannerHeight),
) {
headerTrailing()
}
}
// content
Box {
Expand Down Expand Up @@ -1387,7 +1522,10 @@ internal fun ProfileHeaderLoading(
}
Text(
text = "Lorem Ipsum is simply dummy text",
modifier = Modifier.placeholder(true),
modifier =
Modifier
.placeholder(true)
.padding(horizontal = screenHorizontalPadding),
)
}
}
Expand Down Expand Up @@ -1421,8 +1559,13 @@ private fun profilePresenter(
null
},
)
val allAccounts =
remember {
AccountsPresenter()
}.invoke()
object {
val state = state
val allAccountsState = allAccounts
val showMoreMenus = showMoreMenus
val isRefreshing = isRefreshing
val profileTabs = profileTabs
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,8 @@
<string name="poll_voted">Voted</string>
<string name="poll_expired_at">Expired at %1$s</string>

<string name="profile_search_user_using_account">Find %1$s in %2$s using %3$s</string>

<string name="notification_login_expired">Login expired, please login again</string>

</resources>
Loading

0 comments on commit a2423c5

Please sign in to comment.