Skip to content

Commit

Permalink
Merge pull request #104 from DimensionDev/feature/user_actions
Browse files Browse the repository at this point in the history
[WIP][Android]add follow and unfollow for bluesky misskey and mastodon
  • Loading branch information
Tlaster authored Nov 17, 2023
2 parents f2fa875 + 51e6dd9 commit 5db9713
Show file tree
Hide file tree
Showing 28 changed files with 1,035 additions and 92 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ dependencies {
ksp(libs.ktorfit.ksp)
implementation(libs.bundles.coil)
implementation(libs.bundles.ktor)
implementation(libs.twitter.parser)
implementation(libs.material.icons.extended)
implementation(libs.molecule.runtime)
implementation(libs.ktml)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fun HtmlText2(
) {
with(element) {
RenderElement(context)
context.RenderTextAndReset()
}
}
}
Expand Down
43 changes: 40 additions & 3 deletions app/src/main/java/dev/dimension/flare/ui/screen/profile/Bluesky.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package dev.dimension.flare.ui.screen.profile

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -28,6 +30,7 @@ import dev.dimension.flare.ui.theme.screenHorizontalPadding
internal fun BlueskyProfileHeader(
user: UiUser.Bluesky,
relationState: UiState<UiRelation>,
onFollowClick: (UiRelation.Bluesky) -> Unit,
modifier: Modifier = Modifier,
) {
CommonProfileHeader(
Expand All @@ -40,7 +43,9 @@ internal fun BlueskyProfileHeader(
is UiState.Error -> Unit
is UiState.Loading -> {
FilledTonalButton(
onClick = { /*TODO*/ },
onClick = {
// No-op
},
modifier =
Modifier.placeholder(
true,
Expand All @@ -55,13 +60,16 @@ internal fun BlueskyProfileHeader(
when (val data = relationState.data) {
is UiRelation.Bluesky -> {
FilledTonalButton(
onClick = { /*TODO*/ },
onClick = {
onFollowClick.invoke(data)
},
) {
Text(
text =
stringResource(
when {
data.isFollowing -> R.string.profile_header_button_following
data.blocking -> R.string.profile_header_button_blocked
data.following -> R.string.profile_header_button_following
else -> R.string.profile_header_button_follow
},
),
Expand Down Expand Up @@ -123,3 +131,32 @@ internal fun BlueskyProfileHeader(
modifier = modifier,
)
}

@Composable
internal fun ColumnScope.BlueskyUserMenu(
user: UiUser,
relation: UiRelation.Bluesky,
onBlockClick: () -> Unit,
onMuteClick: () -> Unit,
) {
DropdownMenuItem(
text = {
if (relation.muting) {
Text(text = stringResource(R.string.user_unmute, user.handle))
} else {
Text(text = stringResource(R.string.user_mute, user.handle))
}
},
onClick = onMuteClick,
)
DropdownMenuItem(
text = {
if (relation.blocking) {
Text(text = stringResource(R.string.user_unblock, user.handle))
} else {
Text(text = stringResource(R.string.user_block, user.handle))
}
},
onClick = onBlockClick,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.dimension.flare.ui.screen.profile

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -10,6 +11,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Lock
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
Expand All @@ -34,6 +36,7 @@ import dev.dimension.flare.ui.theme.screenHorizontalPadding
internal fun MastodonProfileHeader(
user: UiUser.Mastodon,
relationState: UiState<UiRelation>,
onFollowClick: (UiRelation.Mastodon) -> Unit,
modifier: Modifier = Modifier,
) {
CommonProfileHeader(
Expand All @@ -58,7 +61,9 @@ internal fun MastodonProfileHeader(
is UiState.Error -> Unit
is UiState.Loading -> {
FilledTonalButton(
onClick = { /*TODO*/ },
onClick = {
// No-op
},
modifier =
Modifier.placeholder(
true,
Expand All @@ -73,12 +78,15 @@ internal fun MastodonProfileHeader(
when (val data = relationState.data) {
is UiRelation.Mastodon -> {
FilledTonalButton(
onClick = { /*TODO*/ },
onClick = {
onFollowClick.invoke(data)
},
) {
Text(
text =
stringResource(
when {
data.blocking -> R.string.profile_header_button_blocked
data.following -> R.string.profile_header_button_following
data.requested -> R.string.profile_header_button_requested
else -> R.string.profile_header_button_follow
Expand All @@ -87,6 +95,7 @@ internal fun MastodonProfileHeader(
)
}
}

else -> Unit
}
}
Expand Down Expand Up @@ -139,3 +148,32 @@ internal fun MastodonProfileHeader(
modifier = modifier,
)
}

@Composable
internal fun ColumnScope.MastodonUserMenu(
user: UiUser,
relation: UiRelation.Mastodon,
onBlockClick: () -> Unit,
onMuteClick: () -> Unit,
) {
DropdownMenuItem(
text = {
if (relation.muting) {
Text(text = stringResource(R.string.user_unmute, user.handle))
} else {
Text(text = stringResource(R.string.user_mute, user.handle))
}
},
onClick = onMuteClick,
)
DropdownMenuItem(
text = {
if (relation.blocking) {
Text(text = stringResource(R.string.user_unblock, user.handle))
} else {
Text(text = stringResource(R.string.user_block, user.handle))
}
},
onClick = onBlockClick,
)
}
46 changes: 42 additions & 4 deletions app/src/main/java/dev/dimension/flare/ui/screen/profile/Misskey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package dev.dimension.flare.ui.screen.profile

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -28,6 +30,7 @@ import dev.dimension.flare.ui.theme.screenHorizontalPadding
internal fun MisskeyProfileHeader(
user: UiUser.Misskey,
relationState: UiState<UiRelation>,
onFollowClick: (UiRelation.Misskey) -> Unit,
modifier: Modifier = Modifier,
) {
CommonProfileHeader(
Expand All @@ -51,7 +54,9 @@ internal fun MisskeyProfileHeader(
is UiState.Error -> Unit
is UiState.Loading -> {
FilledTonalButton(
onClick = { /*TODO*/ },
onClick = {
// No-op
},
modifier =
Modifier.placeholder(
true,
Expand All @@ -64,22 +69,26 @@ internal fun MisskeyProfileHeader(

is UiState.Success -> {
when (val data = relationState.data) {
is UiRelation.Mastodon -> {
is UiRelation.Misskey -> {
FilledTonalButton(
onClick = { /*TODO*/ },
onClick = {
onFollowClick.invoke(data)
},
) {
Text(
text =
stringResource(
when {
data.blocking -> R.string.profile_header_button_blocked
data.following -> R.string.profile_header_button_following
data.requested -> R.string.profile_header_button_requested
data.hasPendingFollowRequestFromYou -> R.string.profile_header_button_requested
else -> R.string.profile_header_button_follow
},
),
)
}
}

else -> Unit
}
}
Expand Down Expand Up @@ -134,3 +143,32 @@ internal fun MisskeyProfileHeader(
modifier = modifier,
)
}

@Composable
internal fun ColumnScope.MisskeyUserMenu(
user: UiUser,
relation: UiRelation.Misskey,
onBlockClick: () -> Unit,
onMuteClick: () -> Unit,
) {
DropdownMenuItem(
text = {
if (relation.muted) {
Text(text = stringResource(R.string.user_unmute, user.handle))
} else {
Text(text = stringResource(R.string.user_mute, user.handle))
}
},
onClick = onMuteClick,
)
DropdownMenuItem(
text = {
if (relation.blocking) {
Text(text = stringResource(R.string.user_unblock, user.handle))
} else {
Text(text = stringResource(R.string.user_block, user.handle))
}
},
onClick = onBlockClick,
)
}
Loading

0 comments on commit 5db9713

Please sign in to comment.