Skip to content

Commit

Permalink
fix: "all Android release notes" item is not clickable [WPB-10125]
Browse files Browse the repository at this point in the history
  • Loading branch information
saleniuk committed Jul 19, 2024
1 parent e8fd207 commit 208e57b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.wire.android.ui.common.SurfaceBackgroundWrapper
import com.wire.android.ui.common.clickable
import com.wire.android.ui.theme.wireDimensions

// TODO: added onRowClick only for UI-Design purpose
@Composable
fun RowItem(
clickable: Clickable,
Expand All @@ -45,10 +44,13 @@ fun RowItem(
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.defaultMinSize(minHeight = MaterialTheme.wireDimensions.conversationItemRowHeight)
.fillMaxWidth()
modifier = Modifier
.clickable(clickable)
.then(
modifier
.defaultMinSize(minHeight = MaterialTheme.wireDimensions.conversationItemRowHeight)
.fillMaxWidth()
)
) {
content()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.wire.android.util.ui.UIText

@Composable
fun WhatsNewItem(
modifier: Modifier = Modifier,
title: String? = null,
boldTitle: Boolean = false,
text: String? = null,
Expand Down Expand Up @@ -93,7 +94,7 @@ fun WhatsNewItem(
} ?: Icons.Filled.ChevronRight
},
clickable = onRowPressed,
modifier = Modifier.padding(vertical = dimensions().spacing4x)
modifier = modifier.padding(vertical = dimensions().spacing4x)
)
}

Expand All @@ -110,17 +111,19 @@ sealed class WhatsNewItem(
direction = WelcomeToNewAndroidAppDestination
)

data object AllAndroidReleaseNotes : WhatsNewItem(
id = "android_release_notes",
data class AllAndroidReleaseNotes(
override val id: String = "android_release_notes"
) : WhatsNewItem(
id = id,
title = UIText.StringResource(R.string.whats_new_android_release_notes_label),
direction = AndroidReleaseNotesDestination
)

data class AndroidReleaseNotes(
override val id: String,
override val title: UIText,
override val boldTitle: Boolean,
override val text: UIText?,
override val boldTitle: Boolean = false,
override val text: UIText? = null,
val url: String
) : WhatsNewItem(
id = id,
Expand All @@ -141,7 +144,9 @@ fun PreviewFileRestrictionDialog() {
WhatsNewItem(
title = "What's new item",
text = "This is the text of the item",
trailingIcon = R.drawable.ic_arrow_right
trailingIcon = R.drawable.ic_arrow_right,
isLoading = false,
onRowPressed = Clickable(enabled = true) {}
)
}
}
Expand All @@ -155,6 +160,7 @@ fun PreviewFileRestrictionDialogLoading() {
text = "This is the text of the item",
trailingIcon = R.drawable.ic_arrow_right,
isLoading = true,
onRowPressed = Clickable(enabled = false) {}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ fun WhatsNewScreen(
@Composable
fun WhatsNewScreenContent(
state: WhatsNewState,
lazyListState: LazyListState = rememberLazyListState(),
onItemClicked: (WhatsNewItem) -> Unit
onItemClicked: (WhatsNewItem) -> Unit,
modifier: Modifier = Modifier,
lazyListState: LazyListState = rememberLazyListState()
) {
val context = LocalContext.current
LazyColumn(
state = lazyListState,
modifier = Modifier.fillMaxSize()
modifier = modifier.fillMaxSize()
) {
folderWithElements(
items = buildList {
Expand All @@ -85,6 +86,7 @@ fun WhatsNewScreenContent(
header = context.getString(R.string.whats_new_release_notes_group_title),
items = buildList {
if (state.isLoading) {
// placeholders with shimmer effect
for (i in 0..3) {
add(
WhatsNewItem.AndroidReleaseNotes(
Expand All @@ -96,6 +98,7 @@ fun WhatsNewScreenContent(
)
)
}
add(WhatsNewItem.AllAndroidReleaseNotes(id = "placeholder_all"))
} else {
state.releaseNotesItems.forEach {
add(
Expand All @@ -108,8 +111,8 @@ fun WhatsNewScreenContent(
)
)
}
add(WhatsNewItem.AllAndroidReleaseNotes())
}
add(WhatsNewItem.AllAndroidReleaseNotes)
},
onItemClicked = onItemClicked,
isLoading = state.isLoading,
Expand All @@ -131,7 +134,7 @@ private fun LazyListScope.folderWithElements(
title = item.title.asString(),
boldTitle = item.boldTitle,
text = item.text?.asString(),
onRowPressed = remember { Clickable(enabled = !isLoading) { onItemClicked(item) } },
onRowPressed = remember(isLoading) { Clickable(enabled = !isLoading) { onItemClicked(item) } },
trailingIcon = R.drawable.ic_arrow_right,
isLoading = isLoading,
)
Expand All @@ -141,11 +144,24 @@ private fun LazyListScope.folderWithElements(
@Preview(showBackground = false)
@Composable
fun PreviewWhatsNewScreen() {
WhatsNewScreenContent(WhatsNewState(isLoading = false)) {}
WhatsNewScreenContent(
state = WhatsNewState(
isLoading = false,
releaseNotesItems = buildList {
for (i in 0..3) {
add(ReleaseNotesItem(i.toString(), "Title $i", "https://www.example.com", "01 Jan 2024"))
}
}
),
onItemClicked = {}
)
}

@Preview(showBackground = false)
@Composable
fun PreviewWhatsNewScreenLoading() {
WhatsNewScreenContent(WhatsNewState(isLoading = true)) {}
WhatsNewScreenContent(
state = WhatsNewState(isLoading = true),
onItemClicked = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,34 @@ class WhatsNewViewModel @Inject constructor(context: Context) : ViewModel() {
private set

init {
@Suppress("TooGenericExceptionCaught")
viewModelScope.launch {
val feedUrl = context.resources.getString(R.string.url_android_release_notes_feed)
if (feedUrl.isNotBlank()) {
rssParser.getRssChannel(feedUrl).let {
state = state.copy(
isLoading = false,
releaseNotesItems = it.items
.map { item ->
ReleaseNotesItem(
id = item.guid.orEmpty(),
title = item.title.orEmpty(),
link = item.link.orEmpty(),
publishDate = item.pubDate?.let { publishDateFormat.parse(it)?.toMediumOnlyDateTime() }.orEmpty(),
)
}
.filter {
it.title.isNotBlank() && it.link.isNotBlank() && it.publishDate.isNotBlank()
}
)
val items = try {
if (feedUrl.isNotBlank()) {
rssParser.getRssChannel(feedUrl).items
} else {
emptyList()
}
} else {
state = state.copy(
isLoading = false,
releaseNotesItems = emptyList()
)
} catch (e: Exception) {
emptyList()
}

state = state.copy(
isLoading = false,
releaseNotesItems = items
.map { item ->
ReleaseNotesItem(
id = item.guid.orEmpty(),
title = item.title.orEmpty(),
link = item.link.orEmpty(),
publishDate = item.pubDate?.let { publishDateFormat.parse(it)?.toMediumOnlyDateTime() }.orEmpty(),
)
}
.filter {
it.title.isNotBlank() && it.link.isNotBlank() && it.publishDate.isNotBlank()
}
)
}
}
}

0 comments on commit 208e57b

Please sign in to comment.