Skip to content

Commit

Permalink
Enforce resourcePrefix on Android library modules
Browse files Browse the repository at this point in the history
```
:ui-test-hilt-manifest -> ui_test_hilt_manifest_
:core:analytics -> core_analytics_
:core:common -> core_common_
:core:data -> core_data_
:core:data-test -> core_data_test_
:core:database -> core_database_
:core:datastore -> core_datastore_
:core:datastore-test -> core_datastore_test_
:core:designsystem -> core_designsystem_
:core:domain -> core_domain_
:core:network -> core_network_
:core:notifications -> core_notifications_
:core:testing -> core_testing_
:core:ui -> core_ui_
:feature:bookmarks -> feature_bookmarks_
:feature:foryou -> feature_foryou_
:feature:interests -> feature_interests_
:feature:search -> feature_search_
:feature:settings -> feature_settings_
:feature:topic -> feature_topic_
:sync:sync-test -> sync_test_
:sync:work -> sync_work_
```
  • Loading branch information
SimonMarquis committed Sep 16, 2023
1 parent 151f877 commit ebfe01a
Show file tree
Hide file tree
Showing 39 changed files with 193 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import javax.inject.Inject
import kotlin.properties.ReadOnlyProperty
import com.google.samples.apps.nowinandroid.feature.bookmarks.R as BookmarksR
import com.google.samples.apps.nowinandroid.feature.foryou.R as FeatureForyouR
import com.google.samples.apps.nowinandroid.feature.interests.R as FeatureInterestsR
import com.google.samples.apps.nowinandroid.feature.search.R as FeatureSearchR
import com.google.samples.apps.nowinandroid.feature.settings.R as SettingsR

/**
Expand Down Expand Up @@ -93,15 +93,15 @@ class NavigationTest {
ReadOnlyProperty<Any?, String> { _, _ -> activity.getString(resId) }

// The strings used for matching in these tests
private val navigateUp by composeTestRule.stringResource(FeatureForyouR.string.navigate_up)
private val forYou by composeTestRule.stringResource(FeatureForyouR.string.for_you)
private val interests by composeTestRule.stringResource(FeatureInterestsR.string.interests)
private val navigateUp by composeTestRule.stringResource(FeatureForyouR.string.feature_foryou_navigate_up)
private val forYou by composeTestRule.stringResource(FeatureForyouR.string.feature_foryou_title)
private val interests by composeTestRule.stringResource(FeatureSearchR.string.feature_search_interests)
private val sampleTopic = "Headlines"
private val appName by composeTestRule.stringResource(R.string.app_name)
private val saved by composeTestRule.stringResource(BookmarksR.string.saved)
private val settings by composeTestRule.stringResource(SettingsR.string.top_app_bar_action_icon_description)
private val brand by composeTestRule.stringResource(SettingsR.string.brand_android)
private val ok by composeTestRule.stringResource(SettingsR.string.dismiss_dialog_button_text)
private val saved by composeTestRule.stringResource(BookmarksR.string.feature_bookmarks_title)
private val settings by composeTestRule.stringResource(SettingsR.string.feature_settings_top_app_bar_action_icon_description)
private val brand by composeTestRule.stringResource(SettingsR.string.feature_settings_brand_android)
private val ok by composeTestRule.stringResource(SettingsR.string.feature_settings_dismiss_dialog_button_text)

@Before
fun setup() = hiltRule.inject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.google.samples.apps.nowinandroid.R
import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons
import com.google.samples.apps.nowinandroid.feature.bookmarks.R as bookmarksR
import com.google.samples.apps.nowinandroid.feature.foryou.R as forYouR
import com.google.samples.apps.nowinandroid.feature.interests.R as interestsR
import com.google.samples.apps.nowinandroid.feature.search.R as searchR

/**
* Type for the top level destinations in the application. Each of these destinations
Expand All @@ -37,19 +37,19 @@ enum class TopLevelDestination(
FOR_YOU(
selectedIcon = NiaIcons.Upcoming,
unselectedIcon = NiaIcons.UpcomingBorder,
iconTextId = forYouR.string.for_you,
iconTextId = forYouR.string.feature_foryou_title,
titleTextId = R.string.app_name,
),
BOOKMARKS(
selectedIcon = NiaIcons.Bookmarks,
unselectedIcon = NiaIcons.BookmarksBorder,
iconTextId = bookmarksR.string.saved,
titleTextId = bookmarksR.string.saved,
iconTextId = bookmarksR.string.feature_bookmarks_title,
titleTextId = bookmarksR.string.feature_bookmarks_title,
),
INTERESTS(
selectedIcon = NiaIcons.Grid3x3,
unselectedIcon = NiaIcons.Grid3x3,
iconTextId = interestsR.string.interests,
titleTextId = interestsR.string.interests,
iconTextId = searchR.string.feature_search_interests,
titleTextId = searchR.string.feature_search_interests,
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ fun NiaApp(
titleRes = destination.titleTextId,
navigationIcon = NiaIcons.Search,
navigationIconContentDescription = stringResource(
id = settingsR.string.top_app_bar_navigation_icon_description,
id = settingsR.string.feature_settings_top_app_bar_navigation_icon_description,
),
actionIcon = NiaIcons.Settings,
actionIconContentDescription = stringResource(
id = settingsR.string.top_app_bar_action_icon_description,
id = settingsR.string.feature_settings_top_app_bar_action_icon_description,
),
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
containerColor = Color.Transparent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
defaultConfig.targetSdk = 34
configureFlavors(this)
configureGradleManagedDevices(this)
// The resource prefix is derived from the module name,
// so resources inside ":core:module1" must be prefixed with "core_module1_"
resourcePrefix = path.split("""\W""".toRegex()).drop(1).distinct().joinToString(separator = "_").lowercase() + "_"
}
extensions.configure<LibraryAndroidComponentsExtension> {
configurePrintApksTask(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun DynamicAsyncImage(
imageUrl: String,
contentDescription: String?,
modifier: Modifier = Modifier,
placeholder: Painter = painterResource(R.drawable.ic_placeholder_default),
placeholder: Painter = painterResource(R.drawable.core_designsystem_ic_placeholder_default),
) {
val iconTint = LocalTintTheme.current.iconTint
var isLoading by remember { mutableStateOf(true) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SystemTrayNotifier @Inject constructor(
.map { newsResource ->
createNewsNotification {
setSmallIcon(
com.google.samples.apps.nowinandroid.core.common.R.drawable.ic_nia_notification,
com.google.samples.apps.nowinandroid.core.common.R.drawable.core_common_ic_nia_notification,
)
.setContentTitle(newsResource.title)
.setContentText(newsResource.content)
Expand All @@ -83,13 +83,13 @@ class SystemTrayNotifier @Inject constructor(
}
val summaryNotification = createNewsNotification {
val title = getString(
R.string.news_notification_group_summary,
R.string.core_notifications_news_notification_group_summary,
truncatedNewsResources.size,
)
setContentTitle(title)
.setContentText(title)
.setSmallIcon(
com.google.samples.apps.nowinandroid.core.common.R.drawable.ic_nia_notification,
com.google.samples.apps.nowinandroid.core.common.R.drawable.core_common_ic_nia_notification,
)
// Build summary info into InboxStyle template.
.setStyle(newsNotificationStyle(truncatedNewsResources, title))
Expand Down Expand Up @@ -148,10 +148,10 @@ private fun Context.ensureNotificationChannelExists() {

val channel = NotificationChannel(
NEWS_NOTIFICATION_CHANNEL_ID,
getString(R.string.news_notification_channel_name),
getString(R.string.core_notifications_news_notification_channel_name),
NotificationManager.IMPORTANCE_DEFAULT,
).apply {
description = getString(R.string.news_notification_channel_description)
description = getString(R.string.core_notifications_news_notification_channel_description)
}
// Register the channel with the system
NotificationManagerCompat.from(this).createNotificationChannel(channel)
Expand Down
6 changes: 3 additions & 3 deletions core/notifications/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
limitations under the License.
-->
<resources>
<string name="news_notification_channel_name">News updates</string>
<string name="news_notification_channel_description">The latest updates on what\'s new in Android</string>
<string name="news_notification_group_summary">%1$d news updates</string>
<string name="core_notifications_news_notification_channel_name">News updates</string>
<string name="core_notifications_news_notification_channel_description">The latest updates on what\'s new in Android</string>
<string name="core_notifications_news_notification_group_summary">%1$d news updates</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class NewsResourceCardTest {
composeTestRule
.onNodeWithText(
composeTestRule.activity.getString(
R.string.card_meta_data_text,
R.string.core_ui_card_meta_data_text,
dateFormatted,
newsWithKnownResourceType.type,
),
Expand Down Expand Up @@ -123,7 +123,7 @@ class NewsResourceCardTest {
composeTestRule
.onNodeWithContentDescription(
composeTestRule.activity.getString(
R.string.unread_resource_dot_content_description,
R.string.core_ui_unread_resource_dot_content_description,
),
)
.assertIsDisplayed()
Expand All @@ -147,7 +147,7 @@ class NewsResourceCardTest {
composeTestRule
.onNodeWithContentDescription(
composeTestRule.activity.getString(
R.string.unread_resource_dot_content_description,
R.string.core_ui_unread_resource_dot_content_description,
),
)
.assertDoesNotExist()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fun NewsResourceCardExpanded(
onTopicClick: (String) -> Unit,
modifier: Modifier = Modifier,
) {
val clickActionLabel = stringResource(R.string.card_tap_action)
val clickActionLabel = stringResource(R.string.core_ui_card_tap_action)
Card(
onClick = onClick,
shape = RoundedCornerShape(16.dp),
Expand Down Expand Up @@ -183,7 +183,7 @@ fun NewsResourceHeaderImage(
painter = if (isError.not() && !isLocalInspection) {
imageLoader
} else {
painterResource(drawable.ic_placeholder_default)
painterResource(drawable.core_designsystem_ic_placeholder_default)
},
// TODO b/226661685: Investigate using alt text of image to populate content description
contentDescription = null, // decorative image,
Expand Down Expand Up @@ -212,13 +212,13 @@ fun BookmarkButton(
icon = {
Icon(
imageVector = NiaIcons.BookmarkBorder,
contentDescription = stringResource(R.string.bookmark),
contentDescription = stringResource(R.string.core_ui_bookmark),
)
},
checkedIcon = {
Icon(
imageVector = NiaIcons.Bookmark,
contentDescription = stringResource(R.string.unbookmark),
contentDescription = stringResource(R.string.core_ui_unbookmark),
)
},
)
Expand All @@ -229,7 +229,7 @@ fun NotificationDot(
color: Color,
modifier: Modifier = Modifier,
) {
val description = stringResource(R.string.unread_resource_dot_content_description)
val description = stringResource(R.string.core_ui_unread_resource_dot_content_description)
Canvas(
modifier = modifier
.semantics { contentDescription = description },
Expand Down Expand Up @@ -273,7 +273,7 @@ fun NewsResourceMetaData(
val formattedDate = dateFormatted(publishDate)
Text(
if (resourceType.isNotBlank()) {
stringResource(R.string.card_meta_data_text, formattedDate, resourceType)
stringResource(R.string.core_ui_card_meta_data_text, formattedDate, resourceType)
} else {
formattedDate
},
Expand Down Expand Up @@ -305,12 +305,12 @@ fun NewsResourceTopics(
text = {
val contentDescription = if (followableTopic.isFollowed) {
stringResource(
R.string.topic_chip_content_description_when_followed,
R.string.core_ui_topic_chip_content_description_when_followed,
followableTopic.topic.name,
)
} else {
stringResource(
R.string.topic_chip_content_description_when_not_followed,
R.string.core_ui_topic_chip_content_description_when_not_followed,
followableTopic.topic.name,
)
}
Expand Down
16 changes: 8 additions & 8 deletions core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
limitations under the License.
-->
<resources>
<string name="bookmark">Bookmark</string>
<string name="unbookmark">Unbookmark</string>
<string name="back">Back</string>
<string name="core_ui_bookmark">Bookmark</string>
<string name="core_ui_unbookmark">Unbookmark</string>
<string name="core_ui_back">Back</string>

<string name="unread_resource_dot_content_description">Unread</string>
<string name="core_ui_unread_resource_dot_content_description">Unread</string>

<string name="card_tap_action">Open Resource Link</string>
<string name="card_meta_data_text">%1$s • %2$s</string>
<string name="core_ui_card_tap_action">Open Resource Link</string>
<string name="core_ui_card_meta_data_text">%1$s • %2$s</string>

<string name="topic_chip_content_description_when_followed">%1$s is followed</string>
<string name="topic_chip_content_description_when_not_followed">%1$s is not followed</string>
<string name="core_ui_topic_chip_content_description_when_followed">%1$s is followed</string>
<string name="core_ui_topic_chip_content_description_when_not_followed">%1$s is not followed</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class BookmarksScreenTest {

composeTestRule
.onNodeWithContentDescription(
composeTestRule.activity.resources.getString(R.string.saved_loading),
composeTestRule.activity.resources.getString(R.string.feature_bookmarks_loading),
)
.assertExists()
}
Expand Down Expand Up @@ -125,7 +125,7 @@ class BookmarksScreenTest {
composeTestRule
.onAllNodesWithContentDescription(
composeTestRule.activity.getString(
com.google.samples.apps.nowinandroid.core.ui.R.string.unbookmark,
com.google.samples.apps.nowinandroid.core.ui.R.string.core_ui_unbookmark,
),
).filter(
hasAnyAncestor(
Expand Down Expand Up @@ -156,13 +156,13 @@ class BookmarksScreenTest {

composeTestRule
.onNodeWithText(
composeTestRule.activity.getString(R.string.bookmarks_empty_error),
composeTestRule.activity.getString(R.string.feature_bookmarks_empty_error),
)
.assertExists()

composeTestRule
.onNodeWithText(
composeTestRule.activity.getString(R.string.bookmarks_empty_description),
composeTestRule.activity.getString(R.string.feature_bookmarks_empty_description),
)
.assertExists()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ internal fun BookmarksScreen(
undoBookmarkRemoval: () -> Unit = {},
clearUndoState: () -> Unit = {},
) {
val bookmarkRemovedMessage = stringResource(id = R.string.bookmark_removed)
val undoText = stringResource(id = R.string.undo)
val bookmarkRemovedMessage = stringResource(id = R.string.feature_bookmarks_removed)
val undoText = stringResource(id = R.string.feature_bookmarks_undo)

LaunchedEffect(shouldDisplayUndoBookmark) {
if (shouldDisplayUndoBookmark) {
Expand Down Expand Up @@ -163,7 +163,7 @@ private fun LoadingState(modifier: Modifier = Modifier) {
.fillMaxWidth()
.wrapContentSize()
.testTag("forYou:loading"),
contentDesc = stringResource(id = R.string.saved_loading),
contentDesc = stringResource(id = R.string.feature_bookmarks_loading),
)
}

Expand Down Expand Up @@ -236,15 +236,15 @@ private fun EmptyState(modifier: Modifier = Modifier) {
val iconTint = LocalTintTheme.current.iconTint
Image(
modifier = Modifier.fillMaxWidth(),
painter = painterResource(id = R.drawable.img_empty_bookmarks),
painter = painterResource(id = R.drawable.feature_bookmarks_img_empty_bookmarks),
colorFilter = if (iconTint != null) ColorFilter.tint(iconTint) else null,
contentDescription = null,
)

Spacer(modifier = Modifier.height(48.dp))

Text(
text = stringResource(id = R.string.bookmarks_empty_error),
text = stringResource(id = R.string.feature_bookmarks_empty_error),
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.titleMedium,
Expand All @@ -254,7 +254,7 @@ private fun EmptyState(modifier: Modifier = Modifier) {
Spacer(modifier = Modifier.height(8.dp))

Text(
text = stringResource(id = R.string.bookmarks_empty_description),
text = stringResource(id = R.string.feature_bookmarks_empty_description),
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodyMedium,
Expand Down
12 changes: 6 additions & 6 deletions feature/bookmarks/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
limitations under the License.
-->
<resources>
<string name="saved">Saved</string>
<string name="saved_loading">Loading saved…</string>
<string name="bookmarks_empty_error">No saved updates</string>
<string name="bookmarks_empty_description">Updates you save will be stored here\nto read later</string>
<string name="bookmark_removed">Bookmark removed</string>
<string name="undo">UNDO</string>
<string name="feature_bookmarks_title">Saved</string>
<string name="feature_bookmarks_loading">Loading saved…</string>
<string name="feature_bookmarks_empty_error">No saved updates</string>
<string name="feature_bookmarks_empty_description">Updates you save will be stored here\nto read later</string>
<string name="feature_bookmarks_removed">Bookmark removed</string>
<string name="feature_bookmarks_undo">UNDO</string>
</resources>
Loading

0 comments on commit ebfe01a

Please sign in to comment.