Skip to content

Commit 20e488b

Browse files
nbradburyclaude
andcommitted
RS Posts: Deduplicate status-to-label mapping
Reuse the shared toLabel() extension in formatStatusLabel() instead of duplicating the PostStatus-to-string-resource mapping. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 03cd59d commit 20e488b

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

WordPress/src/main/java/org/wordpress/android/ui/postsrs/PostRsListUiState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private fun FullEntityAnyPostWithEditContext.toUiModel(
194194
}
195195

196196
@StringRes
197-
private fun PostStatus?.toLabel(): Int = when (this) {
197+
internal fun PostStatus?.toLabel(): Int = when (this) {
198198
is PostStatus.Publish ->
199199
R.string.post_status_post_published
200200
is PostStatus.Draft -> R.string.post_status_draft

WordPress/src/main/java/org/wordpress/android/ui/postsrs/PostRsSettingsViewModel.kt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -354,21 +354,12 @@ class PostRsSettingsViewModel @Inject constructor(
354354
}
355355

356356
private fun formatStatusLabel(status: PostStatus?): String {
357-
val resId = when (status) {
358-
is PostStatus.Publish ->
359-
R.string.post_status_post_published
360-
is PostStatus.Draft -> R.string.post_status_draft
361-
is PostStatus.Pending ->
362-
R.string.post_status_pending_review
363-
is PostStatus.Private ->
364-
R.string.post_status_post_private
365-
is PostStatus.Future ->
366-
R.string.post_status_post_scheduled
367-
is PostStatus.Trash ->
368-
R.string.post_status_post_trashed
369-
else -> return ""
357+
val resId = status.toLabel()
358+
return if (resId != 0) {
359+
resourceProvider.getString(resId)
360+
} else {
361+
""
370362
}
371-
return resourceProvider.getString(resId)
372363
}
373364

374365
private fun formatDate(dateGmt: Date): String {

0 commit comments

Comments
 (0)