From 505fe654c99aa3d31384fa2b80bea3045a864774 Mon Sep 17 00:00:00 2001 From: Noah Bond Date: Mon, 13 Jun 2022 11:18:37 -0700 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/25490 - Remove PrimaryText and SecondaryText --- .../mozilla/fenix/compose/ListItemTabLarge.kt | 10 ++- .../fenix/compose/TabSubtitleWithInterdot.kt | 10 ++- .../java/org/mozilla/fenix/compose/Text.kt | 81 ------------------- .../home/pocket/PocketStoriesComposables.kt | 20 +++-- .../recentsyncedtabs/view/RecentSyncedTab.kt | 9 ++- .../fenix/home/recenttabs/view/RecentTabs.kt | 14 ++-- .../tabstray/inactivetabs/InactiveTabs.kt | 9 ++- .../fenix/tabstray/syncedtabs/SyncedTabs.kt | 9 ++- 8 files changed, 49 insertions(+), 113 deletions(-) delete mode 100644 app/src/main/java/org/mozilla/fenix/compose/Text.kt diff --git a/app/src/main/java/org/mozilla/fenix/compose/ListItemTabLarge.kt b/app/src/main/java/org/mozilla/fenix/compose/ListItemTabLarge.kt index 00ccc3dce2..b26cd4b08a 100644 --- a/app/src/main/java/org/mozilla/fenix/compose/ListItemTabLarge.kt +++ b/app/src/main/java/org/mozilla/fenix/compose/ListItemTabLarge.kt @@ -15,6 +15,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Card +import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -51,16 +52,18 @@ fun ListItemTabLarge( onClick: (() -> Unit)? = null ) { ListItemTabSurface(imageUrl, onClick) { - PrimaryText( + Text( text = title, + color = FirefoxTheme.colors.textPrimary, fontSize = 14.sp, overflow = TextOverflow.Ellipsis, maxLines = 3, ) if (caption != null) { - SecondaryText( + Text( text = caption, + color = FirefoxTheme.colors.textSecondary, fontSize = 12.sp, overflow = TextOverflow.Ellipsis, maxLines = 1, @@ -167,8 +170,9 @@ private fun ListItemTabSurfacePreview() { ListItemTabSurface( imageUrl = "" ) { - PrimaryText( + Text( text = "This can be anything", + color = FirefoxTheme.colors.textPrimary, fontSize = 22.sp ) } diff --git a/app/src/main/java/org/mozilla/fenix/compose/TabSubtitleWithInterdot.kt b/app/src/main/java/org/mozilla/fenix/compose/TabSubtitleWithInterdot.kt index fd41a904de..208f6b31f8 100644 --- a/app/src/main/java/org/mozilla/fenix/compose/TabSubtitleWithInterdot.kt +++ b/app/src/main/java/org/mozilla/fenix/compose/TabSubtitleWithInterdot.kt @@ -7,6 +7,7 @@ package org.mozilla.fenix.compose import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box +import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.layout.Layout @@ -49,20 +50,23 @@ fun TabSubtitleWithInterdot( Layout( content = { - SecondaryText( + Text( text = firstText, + color = FirefoxTheme.colors.textSecondary, fontSize = 12.sp, overflow = TextOverflow.Ellipsis, maxLines = 1, ) - SecondaryText( + Text( text = " \u00b7 ", + color = FirefoxTheme.colors.textSecondary, fontSize = 12.sp, overflow = TextOverflow.Ellipsis, maxLines = 1, ) - SecondaryText( + Text( text = secondText, + color = FirefoxTheme.colors.textSecondary, fontSize = 12.sp, overflow = TextOverflow.Ellipsis, maxLines = 1, diff --git a/app/src/main/java/org/mozilla/fenix/compose/Text.kt b/app/src/main/java/org/mozilla/fenix/compose/Text.kt deleted file mode 100644 index 4c03b259f7..0000000000 --- a/app/src/main/java/org/mozilla/fenix/compose/Text.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package org.mozilla.fenix.compose - -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.text.font.FontFamily -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.TextUnit -import org.mozilla.fenix.theme.FirefoxTheme - -/** - * High level element for displaying Text based on the Primary text style. - * - * @param text The text to be displayed. - * @param modifier [Modifier] to apply to this layout node. - * @param fontSize The size of glyphs to use when painting the text. - * @param fontFamily The font family to be used when rendering the text. - * @param letterSpacing The amount of space to add between each letter. - * @param overflow How visual overflow should be handled. - * @param maxLines An optional maximum number of lines for the text to span. - */ -@Suppress("LongParameterList") -@Composable -fun PrimaryText( - text: String, - modifier: Modifier = Modifier, - fontSize: TextUnit, - fontFamily: FontFamily? = null, - letterSpacing: TextUnit = TextUnit.Unspecified, - overflow: TextOverflow = TextOverflow.Clip, - maxLines: Int = Int.MAX_VALUE -) { - Text( - text = text, - modifier = modifier, - color = FirefoxTheme.colors.textPrimary, - fontSize = fontSize, - fontFamily = fontFamily, - letterSpacing = letterSpacing, - overflow = overflow, - maxLines = maxLines, - ) -} - -/** - * High level element for displaying Text based on the Secondary text style. - * - * @param text The text to be displayed. - * @param modifier [Modifier] to apply to this layout node. - * @param fontSize The size of glyphs to use when painting the text. - * @param fontFamily The font family to be used when rendering the text. - * @param letterSpacing The amount of space to add between each letter. - * @param overflow How visual overflow should be handled. - * @param maxLines An optional maximum number of lines for the text to span. - */ -@Suppress("LongParameterList") -@Composable -fun SecondaryText( - text: String, - modifier: Modifier = Modifier, - fontSize: TextUnit, - fontFamily: FontFamily? = null, - letterSpacing: TextUnit = TextUnit.Unspecified, - overflow: TextOverflow = TextOverflow.Clip, - maxLines: Int = Int.MAX_VALUE, -) { - Text( - text = text, - modifier = modifier, - color = FirefoxTheme.colors.textSecondary, - fontSize = fontSize, - fontFamily = fontFamily, - letterSpacing = letterSpacing, - overflow = overflow, - maxLines = maxLines - ) -} diff --git a/app/src/main/java/org/mozilla/fenix/home/pocket/PocketStoriesComposables.kt b/app/src/main/java/org/mozilla/fenix/home/pocket/PocketStoriesComposables.kt index 03dc09c76a..3d8c0786b5 100644 --- a/app/src/main/java/org/mozilla/fenix/home/pocket/PocketStoriesComposables.kt +++ b/app/src/main/java/org/mozilla/fenix/home/pocket/PocketStoriesComposables.kt @@ -65,9 +65,7 @@ import org.mozilla.fenix.compose.ListItemTabLargePlaceholder import org.mozilla.fenix.compose.ListItemTabSurface import org.mozilla.fenix.compose.SelectableChip import org.mozilla.fenix.compose.StaggeredHorizontalGrid -import org.mozilla.fenix.compose.PrimaryText import org.mozilla.fenix.compose.TabSubtitleWithInterdot -import org.mozilla.fenix.compose.SecondaryText import org.mozilla.fenix.ext.settings import org.mozilla.fenix.theme.FirefoxTheme import org.mozilla.fenix.theme.Theme @@ -115,8 +113,9 @@ fun PocketStory( imageUrl = imageUrl, onClick = { onStoryClick(story) }, title = { - PrimaryText( + Text( text = story.title, + color = FirefoxTheme.colors.textPrimary, fontSize = 14.sp, overflow = TextOverflow.Ellipsis, maxLines = 2, @@ -126,15 +125,17 @@ fun PocketStory( if (isValidPublisher && isValidTimeToRead) { TabSubtitleWithInterdot(story.publisher, "${story.timeToRead} min") } else if (isValidPublisher) { - SecondaryText( + Text( text = story.publisher, + color = FirefoxTheme.colors.textSecondary, fontSize = 12.sp, overflow = TextOverflow.Ellipsis, maxLines = 1, ) } else if (isValidTimeToRead) { - SecondaryText( + Text( text = "${story.timeToRead} min", + color = FirefoxTheme.colors.textSecondary, fontSize = 12.sp, overflow = TextOverflow.Ellipsis, maxLines = 1, @@ -164,8 +165,9 @@ fun PocketSponsoredStory( ) ListItemTabSurface(imageUrl, { onStoryClick(story) }) { - PrimaryText( + Text( text = story.title, + color = FirefoxTheme.colors.textPrimary, fontSize = 14.sp, overflow = TextOverflow.Ellipsis, maxLines = 2, @@ -182,8 +184,9 @@ fun PocketSponsoredStory( Spacer(Modifier.width(8.dp)) - SecondaryText( + Text( text = stringResource(R.string.pocket_stories_sponsor_indication), + color = FirefoxTheme.colors.textSecondary, fontSize = 12.sp, overflow = TextOverflow.Ellipsis, maxLines = 1, @@ -192,8 +195,9 @@ fun PocketSponsoredStory( Spacer(Modifier.height(7.dp)) - SecondaryText( + Text( text = story.sponsor, + color = FirefoxTheme.colors.textSecondary, fontSize = 12.sp, overflow = TextOverflow.Ellipsis, maxLines = 1, diff --git a/app/src/main/java/org/mozilla/fenix/home/recentsyncedtabs/view/RecentSyncedTab.kt b/app/src/main/java/org/mozilla/fenix/home/recentsyncedtabs/view/RecentSyncedTab.kt index 89a149a95a..aa4db73427 100644 --- a/app/src/main/java/org/mozilla/fenix/home/recentsyncedtabs/view/RecentSyncedTab.kt +++ b/app/src/main/java/org/mozilla/fenix/home/recentsyncedtabs/view/RecentSyncedTab.kt @@ -21,6 +21,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Card +import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -33,8 +34,6 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import mozilla.components.concept.sync.DeviceType import org.mozilla.fenix.R -import org.mozilla.fenix.compose.PrimaryText -import org.mozilla.fenix.compose.SecondaryText import org.mozilla.fenix.compose.ThumbnailCard import org.mozilla.fenix.compose.button.Button import org.mozilla.fenix.home.recentsyncedtabs.RecentSyncedTab @@ -87,8 +86,9 @@ fun RecentSyncedTab( if (tab == null) { RecentTabTitlePlaceholder() } else { - PrimaryText( + Text( text = tab.title, + color = FirefoxTheme.colors.textPrimary, fontSize = 14.sp, overflow = TextOverflow.Ellipsis, maxLines = 2, @@ -117,8 +117,9 @@ fun RecentSyncedTab( if (tab == null) { TextLinePlaceHolder() } else { - SecondaryText( + Text( text = tab.deviceDisplayName, + color = FirefoxTheme.colors.textSecondary, fontSize = 12.sp, overflow = TextOverflow.Ellipsis, maxLines = 1, diff --git a/app/src/main/java/org/mozilla/fenix/home/recenttabs/view/RecentTabs.kt b/app/src/main/java/org/mozilla/fenix/home/recenttabs/view/RecentTabs.kt index c9b994704d..a9834a7697 100644 --- a/app/src/main/java/org/mozilla/fenix/home/recenttabs/view/RecentTabs.kt +++ b/app/src/main/java/org/mozilla/fenix/home/recenttabs/view/RecentTabs.kt @@ -56,8 +56,6 @@ import mozilla.components.ui.colors.PhotonColors import org.mozilla.fenix.R import org.mozilla.fenix.components.components import org.mozilla.fenix.compose.Image -import org.mozilla.fenix.compose.PrimaryText -import org.mozilla.fenix.compose.SecondaryText import org.mozilla.fenix.compose.ThumbnailCard import org.mozilla.fenix.home.recenttabs.RecentTab import org.mozilla.fenix.theme.FirefoxTheme @@ -149,8 +147,9 @@ private fun RecentTabItem( modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.SpaceBetween ) { - PrimaryText( + Text( text = tab.state.content.title.ifEmpty { tab.state.content.url }, + color = FirefoxTheme.colors.textPrimary, fontSize = 14.sp, maxLines = 2, overflow = TextOverflow.Ellipsis, @@ -165,8 +164,9 @@ private fun RecentTabItem( Spacer(modifier = Modifier.width(8.dp)) - SecondaryText( + Text( text = tab.state.content.url, + color = FirefoxTheme.colors.textSecondary, fontSize = 12.sp, overflow = TextOverflow.Ellipsis, maxLines = 1, @@ -225,8 +225,9 @@ private fun RecentSearchGroupItem( modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.SpaceBetween ) { - PrimaryText( + Text( text = stringResource(R.string.recent_tabs_search_term, searchTerm), + color = FirefoxTheme.colors.textPrimary, fontSize = 14.sp, overflow = TextOverflow.Ellipsis, maxLines = 2, @@ -245,8 +246,9 @@ private fun RecentSearchGroupItem( Spacer(modifier = Modifier.width(8.dp)) - SecondaryText( + Text( text = stringResource(R.string.recent_tabs_search_term_count_2, count), + color = FirefoxTheme.colors.textSecondary, fontSize = 12.sp, overflow = TextOverflow.Ellipsis, maxLines = 1, diff --git a/app/src/main/java/org/mozilla/fenix/tabstray/inactivetabs/InactiveTabs.kt b/app/src/main/java/org/mozilla/fenix/tabstray/inactivetabs/InactiveTabs.kt index b45365f67d..fe7370a48b 100644 --- a/app/src/main/java/org/mozilla/fenix/tabstray/inactivetabs/InactiveTabs.kt +++ b/app/src/main/java/org/mozilla/fenix/tabstray/inactivetabs/InactiveTabs.kt @@ -21,6 +21,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Card import androidx.compose.material.Icon import androidx.compose.material.IconButton +import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -38,8 +39,6 @@ import androidx.compose.ui.unit.sp import mozilla.components.browser.state.state.ContentState import mozilla.components.browser.state.state.TabSessionState import org.mozilla.fenix.R -import org.mozilla.fenix.compose.PrimaryText -import org.mozilla.fenix.compose.SecondaryText import org.mozilla.fenix.compose.button.TextButton import org.mozilla.fenix.compose.list.ExpandableListHeader import org.mozilla.fenix.compose.list.FaviconListItem @@ -186,8 +185,9 @@ private fun InactiveTabsAutoClosePrompt( Row( verticalAlignment = Alignment.CenterVertically, ) { - PrimaryText( + Text( text = stringResource(R.string.tab_tray_inactive_auto_close_title), + color = FirefoxTheme.colors.textPrimary, modifier = Modifier.weight(1f), fontSize = 14.sp, fontFamily = FontFamily(Font(R.font.metropolis_semibold)), @@ -206,11 +206,12 @@ private fun InactiveTabsAutoClosePrompt( } } - SecondaryText( + Text( text = stringResource( R.string.tab_tray_inactive_auto_close_body_2, stringResource(R.string.app_name) ), + color = FirefoxTheme.colors.textSecondary, modifier = Modifier.fillMaxWidth(), fontSize = 14.sp, ) diff --git a/app/src/main/java/org/mozilla/fenix/tabstray/syncedtabs/SyncedTabs.kt b/app/src/main/java/org/mozilla/fenix/tabstray/syncedtabs/SyncedTabs.kt index 4346d271b0..09c3a9ebff 100644 --- a/app/src/main/java/org/mozilla/fenix/tabstray/syncedtabs/SyncedTabs.kt +++ b/app/src/main/java/org/mozilla/fenix/tabstray/syncedtabs/SyncedTabs.kt @@ -22,6 +22,7 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.Divider +import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.runtime.toMutableStateList @@ -34,8 +35,6 @@ import androidx.compose.ui.unit.sp import mozilla.components.browser.storage.sync.TabEntry import mozilla.components.feature.syncedtabs.view.SyncedTabsView import org.mozilla.fenix.R -import org.mozilla.fenix.compose.PrimaryText -import org.mozilla.fenix.compose.SecondaryText import org.mozilla.fenix.compose.button.PrimaryButton import org.mozilla.fenix.compose.ext.dashedBorder import org.mozilla.fenix.compose.list.ExpandableListHeader @@ -202,8 +201,9 @@ fun SyncedTabsErrorItem( .padding(all = 16.dp) .fillMaxWidth() ) { - PrimaryText( + Text( text = errorText, + color = FirefoxTheme.colors.textPrimary, modifier = Modifier.fillMaxWidth(), fontSize = 14.sp ) @@ -226,8 +226,9 @@ fun SyncedTabsErrorItem( */ @Composable fun SyncedTabsNoTabsItem() { - SecondaryText( + Text( text = stringResource(R.string.synced_tabs_no_open_tabs), + color = FirefoxTheme.colors.textSecondary, modifier = Modifier .padding(horizontal = 16.dp, vertical = 8.dp) .fillMaxWidth(),