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

Update community block msg to display unblock if blocked already #1185

Merged
merged 5 commits into from
Aug 22, 2023
Merged
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
18 changes: 14 additions & 4 deletions app/src/main/java/com/jerboa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1200,13 +1200,23 @@ fun showBlockCommunityToast(blockCommunityRes: ApiState<BlockCommunityResponse>,
is ApiState.Success -> {
Toast.makeText(
ctx,
"${blockCommunityRes.data.community_view.community.name} Blocked",
ctx.getString(
if (blockCommunityRes.data.blocked) {
R.string.blocked_community_toast
} else R.string.unblocked_community_toast,
blockCommunityRes.data.community_view.community.name,
),
Toast.LENGTH_SHORT,
)
.show()
).show()
}

else -> {}
else -> {
Toast.makeText(
ctx,
ctx.getText(R.string.community_block_toast_failure),
Toast.LENGTH_SHORT,
).show()
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/com/jerboa/model/CommunityViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,12 @@ class CommunityViewModel : ViewModel(), Initializable {
fun blockCommunity(form: BlockCommunity, ctx: Context) {
viewModelScope.launch {
blockCommunityRes = ApiState.Loading
blockCommunityRes =
apiWrapper(API.getInstance().blockCommunity(form))
blockCommunityRes = apiWrapper(API.getInstance().blockCommunity(form))

showBlockCommunityToast(blockCommunityRes, ctx)

when (val blockCommunity = blockCommunityRes) {
is ApiState.Success -> {
showBlockCommunityToast(blockCommunity, ctx)

when (val existing = communityRes) {
is ApiState.Success -> {
val newRes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ fun CommunityHeader(
onClickCommunityInfo: () -> Unit,
onClickBack: () -> Unit,
scrollBehavior: TopAppBarScrollBehavior,
isBlocked: Boolean,
) {
var showSortOptions by remember { mutableStateOf(false) }
var showTopOptions by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -227,6 +228,7 @@ fun CommunityHeader(
onBlockCommunityClick()
},
onClickCommunityInfo = onClickCommunityInfo,
isBlocked = isBlocked,
)
}
},
Expand Down Expand Up @@ -262,6 +264,7 @@ fun CommunityMoreDropdown(
onClickRefresh: () -> Unit,
onClickCommunityInfo: () -> Unit,
onClickShowPostViewModeDialog: () -> Unit,
isBlocked: Boolean,
) {
DropdownMenu(
expanded = expanded,
Expand Down Expand Up @@ -292,7 +295,11 @@ fun CommunityMoreDropdown(
},
)
MenuItem(
text = stringResource(R.string.community_block_community),
text = stringResource(
if (isBlocked) {
R.string.community_unblock_community
} else R.string.community_block_community,
),
icon = Icons.Outlined.Block,
onClick = onBlockCommunityClick,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ fun CommunityActivity(
onClickCommunityInfo = appState::toCommunitySideBar,
onClickBack = appState::navigateUp,
selectedPostViewMode = getPostViewMode(appSettingsViewModel),
isBlocked = communityRes.data.community_view.blocked,
)
}
else -> {}
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 @@ -393,6 +393,10 @@
<string name="post_actionbar_mode_short_right">Short righthand post actionbar</string>
<string name="post_actionbar">Post actionbar mode</string>
<string name="settings_autoplaygifs">Auto play GIFs</string>
<string name="community_unblock_community">Unblock Community</string>
<string name="blocked_community_toast">%1$s is blocked</string>
<string name="unblocked_community_toast">%1$s is unblocked</string>
<string name="community_block_toast_failure">Failed to (un)block this community</string>
<string name="saving_media">Saving media...</string>
<string name="saved_media">Saved media</string>
<string name="share_image">Share image</string>
Expand Down