Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
package com.example.jetnews.ui

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.add
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.systemBars
import androidx.compose.material3.DrawerState
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.ExperimentalMaterial3Api
Expand All @@ -33,8 +27,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.example.jetnews.data.AppContainer
Expand Down Expand Up @@ -98,7 +90,6 @@ fun JetnewsApp(
/**
* Determine the drawer state to pass to the modal drawer.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun rememberSizeAwareDrawerState(isExpandedScreen: Boolean): DrawerState {
val drawerState = rememberDrawerState(DrawerValue.Closed)
Expand All @@ -114,16 +105,3 @@ private fun rememberSizeAwareDrawerState(isExpandedScreen: Boolean): DrawerState
DrawerState(DrawerValue.Closed)
}
}

/**
* Determine the content padding to apply to the different screens of the app
*/
@Composable
fun rememberContentPaddingForScreen(
additionalTop: Dp = 0.dp,
excludeTop: Boolean = false
) =
WindowInsets.systemBars
.only(if (excludeTop) WindowInsetsSides.Bottom else WindowInsetsSides.Vertical)
.add(WindowInsets(top = additionalTop))
.asPaddingValues()
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ package com.example.jetnews.ui
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.core.view.WindowCompat
import com.example.jetnews.JetnewsApplication

class MainActivity : ComponentActivity() {

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)

val appContainer = (application as JetnewsApplication).container
setContent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ private fun ArticleScreenContent(
) { innerPadding ->
PostContent(
post = post,
contentPadding = innerPadding,
modifier = Modifier
.nestedScroll(scrollBehavior.nestedScrollConnection)
// innerPadding takes into account the top and bottom bar
.padding(innerPadding),
.nestedScroll(scrollBehavior.nestedScrollConnection),
state = lazyListState,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ private val defaultSpacerSize = 16.dp
fun PostContent(
post: Post,
modifier: Modifier = Modifier,
contentPadding: PaddingValues = PaddingValues(0.dp),
state: LazyListState = rememberLazyListState()
) {
LazyColumn(
contentPadding = PaddingValues(defaultSpacerSize),
modifier = modifier,
contentPadding = contentPadding,
modifier = modifier.padding(horizontal = defaultSpacerSize),
state = state,
) {
postContentItems(post)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ import com.example.jetnews.ui.article.postContentItems
import com.example.jetnews.ui.article.sharePost
import com.example.jetnews.ui.components.JetnewsSnackbarHost
import com.example.jetnews.ui.modifiers.interceptKey
import com.example.jetnews.ui.rememberContentPaddingForScreen
import com.example.jetnews.ui.theme.JetnewsTheme
import com.example.jetnews.ui.utils.BookmarkButton
import com.example.jetnews.ui.utils.FavoriteButton
Expand Down Expand Up @@ -144,11 +143,7 @@ fun HomeFeedWithArticleDetailsScreen(
openDrawer = openDrawer,
snackbarHostState = snackbarHostState,
modifier = modifier,
) { hasPostsUiState, contentModifier ->
val contentPadding = rememberContentPaddingForScreen(
additionalTop = if (showTopAppBar) 0.dp else 8.dp,
excludeTop = showTopAppBar
)
) { hasPostsUiState, contentPadding, contentModifier ->
Row(contentModifier) {
PostList(
postsFeed = hasPostsUiState.postsFeed,
Expand Down Expand Up @@ -246,17 +241,14 @@ fun HomeFeedScreen(
openDrawer = openDrawer,
snackbarHostState = snackbarHostState,
modifier = modifier
) { hasPostsUiState, contentModifier ->
) { hasPostsUiState, contentPadding, contentModifier ->
PostList(
postsFeed = hasPostsUiState.postsFeed,
favorites = hasPostsUiState.favorites,
showExpandedSearch = !showTopAppBar,
onArticleTapped = onSelectPost,
onToggleFavorite = onToggleFavorite,
contentPadding = rememberContentPaddingForScreen(
additionalTop = if (showTopAppBar) 0.dp else 8.dp,
excludeTop = showTopAppBar
),
contentPadding = contentPadding,
modifier = contentModifier,
state = homeListLazyListState,
searchInput = searchInput,
Expand Down Expand Up @@ -286,6 +278,7 @@ private fun HomeScreenWithList(
modifier: Modifier = Modifier,
hasPostsContent: @Composable (
uiState: HomeUiState.HasPosts,
contentPadding: PaddingValues,
modifier: Modifier
) -> Unit
) {
Expand All @@ -303,9 +296,7 @@ private fun HomeScreenWithList(
},
modifier = modifier
) { innerPadding ->
val contentModifier = Modifier
.padding(innerPadding)
.nestedScroll(scrollBehavior.nestedScrollConnection)
val contentModifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection)

LoadingContent(
empty = when (uiState) {
Expand All @@ -317,13 +308,14 @@ private fun HomeScreenWithList(
onRefresh = onRefreshPosts,
content = {
when (uiState) {
is HomeUiState.HasPosts -> hasPostsContent(uiState, contentModifier)
is HomeUiState.HasPosts ->
hasPostsContent(uiState, innerPadding, contentModifier)
is HomeUiState.NoPosts -> {
if (uiState.errorMessages.isEmpty()) {
// if there are no posts, and no error, let the user refresh manually
TextButton(
onClick = onRefreshPosts,
modifier.fillMaxSize()
modifier.padding(innerPadding).fillMaxSize()
) {
Text(
stringResource(id = R.string.home_tap_to_load_content),
Expand All @@ -332,7 +324,11 @@ private fun HomeScreenWithList(
}
} else {
// there's currently an error showing, don't show any content
Box(contentModifier.fillMaxSize()) { /* empty screen */ }
Box(
contentModifier
.padding(innerPadding)
.fillMaxSize()
) { /* empty screen */ }
}
}
}
Expand Down
11 changes: 1 addition & 10 deletions JetNews/app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,5 @@
limitations under the License.
-->
<resources>

<!-- Allows us to override platform level specific attributes in their
respective values-vXX folder. -->
<style name="Platform.Theme.Jetnews" parent="Theme.Material3.DayNight">
<item name="android:statusBarColor">@color/black30</item>
</style>

<!-- The actual theme we use. This varies for light theme (here),
and values-night for dark theme. -->
<style name="Theme.Jetnews" parent="Platform.Theme.Jetnews" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing needed for difference in dark vs light mode?

<style name="Theme.Jetnews" parent="android:Theme.Material.Light.NoActionBar"/>
</resources>