Skip to content

Commit 014582c

Browse files
MV-GHtwizmwazin
andauthored
Update community block msg to display unblock if blocked already (#1185)
* Update community block msg to display unblock if blocked already * Trigger woodpecker * Trigger woodpecker --------- Co-authored-by: Kevin Phoenix <[email protected]>
1 parent 6abe938 commit 014582c

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

app/src/main/java/com/jerboa/Utils.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,13 +1200,23 @@ fun showBlockCommunityToast(blockCommunityRes: ApiState<BlockCommunityResponse>,
12001200
is ApiState.Success -> {
12011201
Toast.makeText(
12021202
ctx,
1203-
"${blockCommunityRes.data.community_view.community.name} Blocked",
1203+
ctx.getString(
1204+
if (blockCommunityRes.data.blocked) {
1205+
R.string.blocked_community_toast
1206+
} else R.string.unblocked_community_toast,
1207+
blockCommunityRes.data.community_view.community.name,
1208+
),
12041209
Toast.LENGTH_SHORT,
1205-
)
1206-
.show()
1210+
).show()
12071211
}
12081212

1209-
else -> {}
1213+
else -> {
1214+
Toast.makeText(
1215+
ctx,
1216+
ctx.getText(R.string.community_block_toast_failure),
1217+
Toast.LENGTH_SHORT,
1218+
).show()
1219+
}
12101220
}
12111221
}
12121222

app/src/main/java/com/jerboa/model/CommunityViewModel.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,12 @@ class CommunityViewModel : ViewModel(), Initializable {
211211
fun blockCommunity(form: BlockCommunity, ctx: Context) {
212212
viewModelScope.launch {
213213
blockCommunityRes = ApiState.Loading
214-
blockCommunityRes =
215-
apiWrapper(API.getInstance().blockCommunity(form))
214+
blockCommunityRes = apiWrapper(API.getInstance().blockCommunity(form))
215+
216+
showBlockCommunityToast(blockCommunityRes, ctx)
216217

217218
when (val blockCommunity = blockCommunityRes) {
218219
is ApiState.Success -> {
219-
showBlockCommunityToast(blockCommunity, ctx)
220-
221220
when (val existing = communityRes) {
222221
is ApiState.Success -> {
223222
val newRes =

app/src/main/java/com/jerboa/ui/components/community/Community.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ fun CommunityHeader(
137137
onClickCommunityInfo: () -> Unit,
138138
onClickBack: () -> Unit,
139139
scrollBehavior: TopAppBarScrollBehavior,
140+
isBlocked: Boolean,
140141
) {
141142
var showSortOptions by remember { mutableStateOf(false) }
142143
var showTopOptions by remember { mutableStateOf(false) }
@@ -227,6 +228,7 @@ fun CommunityHeader(
227228
onBlockCommunityClick()
228229
},
229230
onClickCommunityInfo = onClickCommunityInfo,
231+
isBlocked = isBlocked,
230232
)
231233
}
232234
},
@@ -262,6 +264,7 @@ fun CommunityMoreDropdown(
262264
onClickRefresh: () -> Unit,
263265
onClickCommunityInfo: () -> Unit,
264266
onClickShowPostViewModeDialog: () -> Unit,
267+
isBlocked: Boolean,
265268
) {
266269
DropdownMenu(
267270
expanded = expanded,
@@ -292,7 +295,11 @@ fun CommunityMoreDropdown(
292295
},
293296
)
294297
MenuItem(
295-
text = stringResource(R.string.community_block_community),
298+
text = stringResource(
299+
if (isBlocked) {
300+
R.string.community_unblock_community
301+
} else R.string.community_block_community,
302+
),
296303
icon = Icons.Outlined.Block,
297304
onClick = onBlockCommunityClick,
298305
)

app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ fun CommunityActivity(
240240
onClickCommunityInfo = appState::toCommunitySideBar,
241241
onClickBack = appState::navigateUp,
242242
selectedPostViewMode = getPostViewMode(appSettingsViewModel),
243+
isBlocked = communityRes.data.community_view.blocked,
243244
)
244245
}
245246
else -> {}

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@
396396
<string name="post_actionbar_mode_short_right">Short righthand post actionbar</string>
397397
<string name="post_actionbar">Post actionbar mode</string>
398398
<string name="settings_autoplaygifs">Auto play GIFs</string>
399+
<string name="community_unblock_community">Unblock Community</string>
400+
<string name="blocked_community_toast">%1$s is blocked</string>
401+
<string name="unblocked_community_toast">%1$s is unblocked</string>
402+
<string name="community_block_toast_failure">Failed to (un)block this community</string>
399403
<string name="saving_media">Saving media...</string>
400404
<string name="saved_media">Saved media</string>
401405
<string name="share_image">Share image</string>

0 commit comments

Comments
 (0)