-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Reader] Implement announcement card #20846
Merged
RenanLukas
merged 18 commits into
feature/tags-ia
from
issue/20621-tags-feed-onboarding
May 21, 2024
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c2fa592
Add reader announcement card feature config
RenanLukas 42fa1c8
Add show Reader card announcement methods to AppPrefs
RenanLukas 9643e59
WIP reader announcement card UI
RenanLukas 1c3dddc
Fix reader announcement card text style
RenanLukas 2b7e362
WIP Reader announcement card UI integration
RenanLukas 5c9f9bc
Fix scrolling of reader announcement card
RenanLukas b45ef93
Add real data to reader announcement card
RenanLukas e37d1db
Implement reader announcement card done button
RenanLukas 2c7c46b
Implement done button analytics event
RenanLukas b8b3dac
Implement unit tests for reader announcement card
RenanLukas c80c983
Fix dark theme colors
RenanLukas 5efab23
Merge branch 'feature/tags-ia' into issue/20621-tags-feed-onboarding
RenanLukas 06f28a7
Fix detekt
RenanLukas e0ebd70
Remove unused resource
d9b2bb1
Fix BuildConfig constant being true
8c20b4b
Replace LazyColumn with Column for announcement items
9d1a4b9
Add the Tags feed announcement item if it's enabled only
681ab48
Apply PR suggestion: rename loadAnnouncementCard to updateAnnouncemen…
RenanLukas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 183 additions & 0 deletions
183
...ess/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderAnnouncementCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
package org.wordpress.android.ui.reader.views.compose | ||
|
||
import android.content.res.Configuration | ||
import androidx.annotation.DrawableRes | ||
import androidx.annotation.StringRes | ||
import androidx.compose.animation.AnimatedVisibility | ||
import androidx.compose.animation.expandIn | ||
import androidx.compose.animation.shrinkOut | ||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.defaultMinSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.ButtonDefaults | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.drawBehind | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import org.wordpress.android.R | ||
import org.wordpress.android.designsystem.footnote | ||
import org.wordpress.android.ui.compose.theme.AppColor | ||
import org.wordpress.android.ui.compose.theme.AppTheme | ||
import org.wordpress.android.ui.compose.unit.Margin | ||
|
||
@Composable | ||
fun ReaderAnnouncementCard( | ||
shouldShow: Boolean, | ||
items: List<ReaderAnnouncementCardItemData>, | ||
onAnnouncementCardDoneClick: () -> Unit, | ||
) { | ||
val primaryColor = if (isSystemInDarkTheme()) AppColor.White else AppColor.Black | ||
val secondaryColor = if (isSystemInDarkTheme()) AppColor.Black else AppColor.White | ||
AnimatedVisibility( | ||
visible = shouldShow, | ||
enter = expandIn(), | ||
exit = shrinkOut( | ||
shrinkTowards = Alignment.TopCenter, | ||
), | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(Margin.ExtraLarge.value), | ||
verticalArrangement = Arrangement.spacedBy(Margin.ExtraLarge.value), | ||
) { | ||
// Title | ||
Text( | ||
text = stringResource(R.string.reader_announcement_card_title), | ||
style = MaterialTheme.typography.labelLarge, | ||
color = primaryColor, | ||
) | ||
// Items | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth(), | ||
verticalArrangement = Arrangement.spacedBy(Margin.ExtraLarge.value) | ||
) { | ||
items.forEach { | ||
ReaderAnnouncementCardItem(it) | ||
} | ||
} | ||
// Done button | ||
Button( | ||
modifier = Modifier | ||
.fillMaxWidth(), | ||
onClick = { onAnnouncementCardDoneClick() }, | ||
elevation = ButtonDefaults.elevation(0.dp), | ||
colors = ButtonDefaults.buttonColors( | ||
backgroundColor = primaryColor, | ||
), | ||
) { | ||
Text( | ||
text = stringResource(id = R.string.reader_btn_done), | ||
color = secondaryColor, | ||
style = MaterialTheme.typography.labelLarge, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ReaderAnnouncementCardItem(data: ReaderAnnouncementCardItemData) { | ||
val primaryColor = if (isSystemInDarkTheme()) AppColor.White else AppColor.Black | ||
val secondaryColor = if (isSystemInDarkTheme()) AppColor.Black else AppColor.White | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.defaultMinSize(minWidth = 54.dp, minHeight = 54.dp), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
val iconBackgroundColor = primaryColor | ||
Icon( | ||
modifier = Modifier | ||
.padding( | ||
start = Margin.Large.value, | ||
end = Margin.Large.value | ||
) | ||
.drawBehind { | ||
drawCircle( | ||
color = iconBackgroundColor, | ||
radius = this.size.maxDimension, | ||
) | ||
}, | ||
painter = painterResource(data.iconRes), | ||
tint = secondaryColor, | ||
contentDescription = null | ||
) | ||
Column(verticalArrangement = Arrangement.Center) { | ||
Text( | ||
modifier = Modifier.padding( | ||
start = Margin.Large.value, | ||
), | ||
text = stringResource(data.titleRes), | ||
style = MaterialTheme.typography.labelLarge, | ||
color = primaryColor, | ||
) | ||
val secondaryElementColor = primaryColor.copy( | ||
alpha = 0.6F | ||
) | ||
Text( | ||
modifier = Modifier.padding( | ||
start = Margin.Large.value, | ||
), | ||
text = stringResource(data.descriptionRes), | ||
style = MaterialTheme.typography.footnote, | ||
color = secondaryElementColor, | ||
) | ||
} | ||
} | ||
} | ||
|
||
data class ReaderAnnouncementCardItemData( | ||
@DrawableRes val iconRes: Int, | ||
@StringRes val titleRes: Int, | ||
@StringRes val descriptionRes: Int, | ||
) | ||
|
||
|
||
@Preview | ||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) | ||
@Composable | ||
fun ReaderTagsFeedPostListItemPreview() { | ||
AppTheme { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
) { | ||
ReaderAnnouncementCard( | ||
shouldShow = false, | ||
items = listOf( | ||
ReaderAnnouncementCardItemData( | ||
iconRes = R.drawable.ic_wifi_off_24px, | ||
titleRes = R.string.reader_tags_display_name, | ||
descriptionRes = R.string.reader_tags_feed_loading_error_description, | ||
), | ||
ReaderAnnouncementCardItemData( | ||
iconRes = R.drawable.ic_wifi_off_24px, | ||
titleRes = R.string.reader_tags_display_name, | ||
descriptionRes = R.string.reader_tags_feed_loading_error_description, | ||
), | ||
ReaderAnnouncementCardItemData( | ||
iconRes = R.drawable.ic_wifi_off_24px, | ||
titleRes = R.string.reader_tags_display_name, | ||
descriptionRes = R.string.reader_tags_feed_loading_error_description, | ||
), | ||
), | ||
onAnnouncementCardDoneClick = {}, | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...ss/src/main/java/org/wordpress/android/util/config/ReaderAnnouncementCardFeatureConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.wordpress.android.util.config | ||
|
||
import org.wordpress.android.BuildConfig | ||
import org.wordpress.android.annotation.Feature | ||
import javax.inject.Inject | ||
|
||
private const val READER_ANNOUNCEMENT_CARD_REMOTE_FIELD = "reader_announcement_card" | ||
@Feature(remoteField = READER_ANNOUNCEMENT_CARD_REMOTE_FIELD, defaultValue = false) | ||
class ReaderAnnouncementCardFeatureConfig @Inject constructor( | ||
appConfig: AppConfig | ||
) : FeatureConfig( | ||
appConfig, | ||
BuildConfig.READER_ANNOUNCEMENT_CARD, | ||
READER_ANNOUNCEMENT_CARD_REMOTE_FIELD, | ||
) |
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np: maybe I'd rename this something like setAnnouncementCardState, since in the end we use it for that and in this scope here for example we are not actually loading the cards but setting the "hide" state. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, that threw me off as well when I worked on the code yesterday. Maybe
updateAnnouncementCard
would be better.