diff --git a/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NiaScreens.kt b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NiaScreens.kt index 1a80ed22f..5906ddede 100644 --- a/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NiaScreens.kt +++ b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NiaScreens.kt @@ -16,18 +16,63 @@ package com.google.samples.apps.nowinandroid.core.ui +import androidx.annotation.StringRes +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.wrapContentSize +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.MoreVert +import androidx.compose.material.icons.filled.Search import androidx.compose.material.ripple.RippleAlpha import androidx.compose.material.ripple.RippleTheme import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +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.graphics.Color +import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.text.font.FontWeight + +@Composable +fun NiaToolbar( + modifier: Modifier = Modifier, + @StringRes titleRes: Int, + onSearchClick: () -> Unit = {}, + onMenuClick: () -> Unit = {}, +) { + Row( + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, + modifier = modifier.fillMaxWidth() + ) { + IconButton(onClick = { onSearchClick() }) { + Icon( + imageVector = Icons.Filled.Search, + contentDescription = null + ) + } + Text( + text = stringResource(id = titleRes), + style = MaterialTheme.typography.titleLarge, + fontWeight = FontWeight.Bold + ) + IconButton(onClick = { onMenuClick() }) { + Icon( + imageVector = Icons.Filled.MoreVert, + contentDescription = null + ) + } + } +} @Composable fun NiaLoadingIndicator( diff --git a/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/component/TopAppBar.kt b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/component/TopAppBar.kt deleted file mode 100644 index 5a0caa2d2..000000000 --- a/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/component/TopAppBar.kt +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.samples.apps.nowinandroid.core.ui.component - -import androidx.annotation.StringRes -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.MoreVert -import androidx.compose.material.icons.filled.Search -import androidx.compose.material3.CenterAlignedTopAppBar -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.tooling.preview.Preview -import com.google.samples.apps.nowinandroid.core.ui.R - -@Composable -fun NiaTopAppBar( - @StringRes titleRes: Int, - navigationIcon: ImageVector, - navigationIconContentDescription: String?, - actionIcon: ImageVector, - actionIconContentDescription: String?, - modifier: Modifier = Modifier, - onNavigationClick: () -> Unit = {}, - onActionClick: () -> Unit = {} -) { - CenterAlignedTopAppBar( - title = { Text(text = stringResource(id = titleRes)) }, - navigationIcon = { - IconButton(onClick = onNavigationClick) { - Icon( - imageVector = navigationIcon, - contentDescription = navigationIconContentDescription, - tint = MaterialTheme.colorScheme.onSurface - ) - } - }, - actions = { - IconButton(onClick = onActionClick) { - Icon( - imageVector = actionIcon, - contentDescription = actionIconContentDescription, - tint = MaterialTheme.colorScheme.onSurface - ) - } - }, - modifier = modifier - ) -} - -@Preview("Top App Bar") -@Composable -fun NiaTopAppBarPreview() { - NiaTopAppBar( - titleRes = R.string.top_app_bar_preview_title, - navigationIcon = Icons.Default.Search, - navigationIconContentDescription = "Navigation icon", - actionIcon = Icons.Default.MoreVert, - actionIconContentDescription = "Action icon" - ) -} diff --git a/core-ui/src/main/res/values/strings.xml b/core-ui/src/main/res/values/strings.xml index 78412bb0a..46f144829 100644 --- a/core-ui/src/main/res/values/strings.xml +++ b/core-ui/src/main/res/values/strings.xml @@ -19,6 +19,4 @@ Back Open Resource Link - - Title diff --git a/feature-following/src/main/java/com/google/samples/apps/nowinandroid/feature/following/FollowingScreen.kt b/feature-following/src/main/java/com/google/samples/apps/nowinandroid/feature/following/FollowingScreen.kt index 349989dee..83ae7c4a1 100644 --- a/feature-following/src/main/java/com/google/samples/apps/nowinandroid/feature/following/FollowingScreen.kt +++ b/feature-following/src/main/java/com/google/samples/apps/nowinandroid/feature/following/FollowingScreen.kt @@ -18,9 +18,6 @@ package com.google.samples.apps.nowinandroid.feature.following import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.MoreVert -import androidx.compose.material.icons.filled.Search import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState @@ -31,9 +28,9 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import com.google.samples.apps.nowinandroid.core.ui.NiaLoadingIndicator +import com.google.samples.apps.nowinandroid.core.ui.NiaToolbar import com.google.samples.apps.nowinandroid.core.ui.component.NiaTab import com.google.samples.apps.nowinandroid.core.ui.component.NiaTabRow -import com.google.samples.apps.nowinandroid.core.ui.component.NiaTopAppBar @Composable fun InterestsRoute( @@ -72,17 +69,7 @@ fun FollowingScreen( modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally ) { - NiaTopAppBar( - titleRes = R.string.interests, - navigationIcon = Icons.Filled.Search, - navigationIconContentDescription = stringResource( - id = R.string.top_app_bar_navigation_button_content_desc - ), - actionIcon = Icons.Filled.MoreVert, - actionIconContentDescription = stringResource( - id = R.string.top_app_bar_navigation_button_content_desc - ) - ) + NiaToolbar(titleRes = R.string.interests) when (uiState) { FollowingUiState.Loading -> NiaLoadingIndicator( diff --git a/feature-following/src/main/res/values/strings.xml b/feature-following/src/main/res/values/strings.xml index 4ba1d1ecd..7b0d5ef1a 100644 --- a/feature-following/src/main/res/values/strings.xml +++ b/feature-following/src/main/res/values/strings.xml @@ -21,6 +21,4 @@ "No available data" Follow interest button Unfollow interest button - Menu - Search diff --git a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt index 398a628a6..71d713ed4 100644 --- a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt +++ b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt @@ -33,9 +33,6 @@ import androidx.compose.foundation.lazy.grid.items import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.CornerSize import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Search -import androidx.compose.material.icons.outlined.AccountCircle import androidx.compose.material3.Button import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon @@ -67,7 +64,6 @@ import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.ui.NewsResourceCardExpanded import com.google.samples.apps.nowinandroid.core.ui.NiaLoadingIndicator import com.google.samples.apps.nowinandroid.core.ui.component.NiaToggleButton -import com.google.samples.apps.nowinandroid.core.ui.component.NiaTopAppBar import com.google.samples.apps.nowinandroid.core.ui.icon.NiaIcons import com.google.samples.apps.nowinandroid.core.ui.theme.NiaTypography import com.google.samples.apps.nowinandroid.feature.foryou.ForYouFeedUiState.PopulatedFeed @@ -103,19 +99,6 @@ fun ForYouScreen( LazyColumn( modifier = modifier.fillMaxSize() ) { - item { - NiaTopAppBar( - titleRes = R.string.top_app_bar_title, - navigationIcon = Icons.Filled.Search, - navigationIconContentDescription = stringResource( - id = R.string.top_app_bar_navigation_button_content_desc - ), - actionIcon = Icons.Outlined.AccountCircle, - actionIconContentDescription = stringResource( - id = R.string.top_app_bar_navigation_button_content_desc - ) - ) - } when (uiState) { is ForYouFeedUiState.Loading -> { item { diff --git a/feature-foryou/src/main/res/values/strings.xml b/feature-foryou/src/main/res/values/strings.xml index 48c40620d..be136b32d 100644 --- a/feature-foryou/src/main/res/values/strings.xml +++ b/feature-foryou/src/main/res/values/strings.xml @@ -22,9 +22,6 @@ Navigate up What are you interested in? Updates from topics you follow will appear here. Follow some things to get started. - Now in Android - My account - Search You are following