Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*.{kt,kts}]
ktlint_code_style = android_studio
ktlint_function_naming_ignore_when_annotated_with=Composable
ktlint_standard_filename = disabled
max_line_length = 1000
7 changes: 7 additions & 0 deletions AccessibilityCodelab/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*.{kt,kts}]
ktlint_code_style = android_studio
ktlint_function_naming_ignore_when_annotated_with=Composable
ktlint_standard_filename = disabled
max_line_length = 1000
4 changes: 2 additions & 2 deletions AccessibilityCodelab/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ android {
}

dependencies {
def composeBom = platform('androidx.compose:compose-bom:2026.06.01')
def composeBom = platform('androidx.compose:compose-bom:2026.08.00')
implementation(composeBom)
testImplementation(composeBom)
androidTestImplementation(composeBom)
Expand All @@ -112,7 +112,7 @@ dependencies {

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2"

implementation 'androidx.appcompat:appcompat:1.7.1'
implementation 'androidx.appcompat:appcompat:1.8.0'
implementation 'androidx.activity:activity-ktx:1.13.0'
implementation 'androidx.core:core-ktx:1.19.0'
implementation "androidx.activity:activity-compose:1.13.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ val paragraphsPost1 = listOf(

Paragraph(
ParagraphType.Text,
"At I/O I was lucky enough to attend the “Android Studio: Tips and Tricks” talk where Ivan Gravilovic, from Google, shared some amazing tips. One of these was a possible solution for my problem: setting a custom path for my modules.",
"At I/O I was lucky enough to attend the “Android Studio: Tips and Tricks” talk where Ivan " +
"Gravilovic, from Google, shared some amazing tips. One of these was a possible solution for " +
"my problem: setting a custom path for my modules.",
listOf(
Markup(
MarkupType.Italic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ enum class MarkupType {
Link,
Code,
Italic,
Bold,
Bold
}

enum class ParagraphType {
Expand All @@ -74,5 +74,5 @@ enum class ParagraphType {
Text,
CodeBlock,
Quote,
Bullet,
Bullet
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.example.jetnews.ui

import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -28,14 +27,14 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.ListAlt
import androidx.compose.material3.Divider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.ListAlt
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -49,12 +48,7 @@ import com.example.jetnews.R
import com.example.jetnews.ui.theme.JetnewsTheme

@Composable
fun AppDrawer(
currentRoute: String,
navigateToHome: () -> Unit,
navigateToInterests: () -> Unit,
closeDrawer: () -> Unit
) {
fun AppDrawer(currentRoute: String, navigateToHome: () -> Unit, navigateToInterests: () -> Unit, closeDrawer: () -> Unit) {
Column(modifier = Modifier.fillMaxSize()) {
Spacer(Modifier.height(24.dp))
JetNewsLogo(Modifier.padding(16.dp))
Expand Down Expand Up @@ -99,13 +93,7 @@ private fun JetNewsLogo(modifier: Modifier = Modifier) {
}

@Composable
private fun DrawerButton(
icon: ImageVector,
label: String,
isSelected: Boolean,
action: () -> Unit,
modifier: Modifier = Modifier
) {
private fun DrawerButton(icon: ImageVector, label: String, isSelected: Boolean, action: () -> Unit, modifier: Modifier = Modifier) {
val colors = MaterialTheme.colorScheme
val imageAlpha = if (isSelected) {
1f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ import kotlinx.coroutines.launch

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@Composable
fun JetnewsApp(
appContainer: AppContainer
) {
fun JetnewsApp(appContainer: AppContainer) {
JetnewsTheme {
val systemUiController = rememberSystemUiController()
SideEffect {
Expand All @@ -61,11 +59,18 @@ fun JetnewsApp(
ModalNavigationDrawer(
drawerState = drawerState,
drawerContent = {
ModalDrawerSheet(modifier = Modifier.width(300.dp), windowInsets = WindowInsets(0.dp, 0.dp, 0.dp, 0.dp)) {
ModalDrawerSheet(
modifier = Modifier.width(300.dp),
windowInsets = WindowInsets(0.dp, 0.dp, 0.dp, 0.dp)
) {
AppDrawer(
currentRoute = currentRoute,
navigateToHome = { navController.navigate(MainDestinations.HOME_ROUTE) },
navigateToInterests = { navController.navigate(MainDestinations.INTERESTS_ROUTE) },
navigateToInterests = {
navController.navigate(
MainDestinations.INTERESTS_ROUTE
)
},
closeDrawer = { coroutineScope.launch { drawerState.close() } }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand All @@ -45,12 +44,7 @@ object MainDestinations {
}

@Composable
fun JetnewsNavGraph(
appContainer: AppContainer,
navController: NavHostController = rememberNavController(),
drawerState: DrawerState = rememberDrawerState(DrawerValue.Closed),
startDestination: String = MainDestinations.HOME_ROUTE
) {
fun JetnewsNavGraph(appContainer: AppContainer, navController: NavHostController = rememberNavController(), drawerState: DrawerState = rememberDrawerState(DrawerValue.Closed), startDestination: String = MainDestinations.HOME_ROUTE) {
val actions = remember(navController) { MainActions(navController) }
val coroutineScope = rememberCoroutineScope()
val openDrawer: () -> Unit = { coroutineScope.launch { drawerState.open() } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package com.example.jetnews.ui.article

import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand All @@ -26,8 +28,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -72,11 +72,7 @@ fun ArticleScreen(
* @param onBack (event) request navigate back
*/
@Composable
fun ArticleScreen(
post: Post,
onBack: () -> Unit
) {

fun ArticleScreen(post: Post, onBack: () -> Unit) {
var showDialog by rememberSaveable { mutableStateOf(false) }
if (showDialog) {
FunctionalityNotAvailablePopup { showDialog = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.Typography
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -89,7 +89,9 @@ fun PostContent(post: Post, modifier: Modifier = Modifier) {
}
post.subtitle?.let { subtitle ->
item {
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant) {
CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant
) {
Text(
text = subtitle,
style = MaterialTheme.typography.bodyMedium,
Expand Down Expand Up @@ -146,7 +148,9 @@ private fun PostMetadata(metadata: Metadata) {
modifier = Modifier.padding(top = 4.dp)
)

CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant) {
CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant
) {
Text(
text = "${metadata.date} • ${metadata.readTimeMinutes} min read",
style = typography.bodySmall
Expand Down Expand Up @@ -194,11 +198,7 @@ private fun Paragraph(paragraph: Paragraph) {
}

@Composable
private fun CodeBlockParagraph(
text: AnnotatedString,
textStyle: TextStyle,
paragraphStyle: ParagraphStyle
) {
private fun CodeBlockParagraph(text: AnnotatedString, textStyle: TextStyle, paragraphStyle: ParagraphStyle) {
Surface(
color = MaterialTheme.colorScheme.codeBlockBackground,
shape = MaterialTheme.shapes.small,
Expand All @@ -213,11 +213,7 @@ private fun CodeBlockParagraph(
}

@Composable
private fun BulletParagraph(
text: AnnotatedString,
textStyle: TextStyle,
paragraphStyle: ParagraphStyle
) {
private fun BulletParagraph(text: AnnotatedString, textStyle: TextStyle, paragraphStyle: ParagraphStyle) {
Row {
with(LocalDensity.current) {
// this box is acting as a character, so it's sized with font scaling (sp)
Expand All @@ -228,7 +224,7 @@ private fun BulletParagraph(
// Add an alignment "baseline" 1sp below the bottom of the circle
9.sp.roundToPx()
}
.background(LocalContentColor.current, CircleShape),
.background(LocalContentColor.current, CircleShape)
) { /* no content */ }
}
Text(
Expand Down Expand Up @@ -284,20 +280,13 @@ private fun ParagraphType.getTextAndParagraphStyle(): ParagraphStyling {
)
}

private fun paragraphToAnnotatedString(
paragraph: Paragraph,
typography: Typography,
codeBlockBackground: Color
): AnnotatedString {
private fun paragraphToAnnotatedString(paragraph: Paragraph, typography: Typography, codeBlockBackground: Color): AnnotatedString {
val styles: List<AnnotatedString.Range<SpanStyle>> = paragraph.markups
.map { it.toAnnotatedStringItem(typography, codeBlockBackground) }
return AnnotatedString(text = paragraph.text, spanStyles = styles)
}

fun Markup.toAnnotatedStringItem(
typography: Typography,
codeBlockBackground: Color
): AnnotatedString.Range<SpanStyle> {
fun Markup.toAnnotatedStringItem(typography: Typography, codeBlockBackground: Color): AnnotatedString.Range<SpanStyle> {
return when (this.type) {
MarkupType.Italic -> {
AnnotatedString.Range(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@ import androidx.compose.ui.unit.dp
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun InsetAwareTopAppBar(
title: @Composable () -> Unit,
modifier: Modifier = Modifier,
navigationIcon: @Composable (() -> Unit),
actions: @Composable RowScope.() -> Unit = {},
backgroundColor: Color = MaterialTheme.colorScheme.surface,
elevation: Dp = 4.dp
) {
fun InsetAwareTopAppBar(title: @Composable () -> Unit, modifier: Modifier = Modifier, navigationIcon: @Composable (() -> Unit), actions: @Composable RowScope.() -> Unit = {}, backgroundColor: Color = MaterialTheme.colorScheme.surface, elevation: Dp = 4.dp) {
Surface(
color = backgroundColor,
shadowElevation = elevation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,11 @@ import kotlinx.coroutines.launch
* @param openDrawer (event) request opening the app drawer
*/
@Composable
fun HomeScreen(
postsRepository: PostsRepository,
navigateToArticle: (String) -> Unit,
openDrawer: () -> Unit,
) {
fun HomeScreen(postsRepository: PostsRepository, navigateToArticle: (String) -> Unit, openDrawer: () -> Unit) {
HomeScreen(
posts = postsRepository.getPosts(),
navigateToArticle = navigateToArticle,
openDrawer = openDrawer,
openDrawer = openDrawer
)
}

Expand All @@ -83,11 +79,7 @@ fun HomeScreen(
* @param openDrawer (event) request opening the app drawer
*/
@Composable
fun HomeScreen(
posts: List<Post>,
navigateToArticle: (String) -> Unit,
openDrawer: () -> Unit,
) {
fun HomeScreen(posts: List<Post>, navigateToArticle: (String) -> Unit, openDrawer: () -> Unit) {
val coroutineScope = rememberCoroutineScope()
Scaffold(
topBar = {
Expand Down Expand Up @@ -121,11 +113,7 @@ fun HomeScreen(
* @param modifier modifier for the root element
*/
@Composable
private fun PostList(
posts: List<Post>,
navigateToArticle: (postId: String) -> Unit,
modifier: Modifier = Modifier
) {
private fun PostList(posts: List<Post>, navigateToArticle: (postId: String) -> Unit, modifier: Modifier = Modifier) {
val postsHistory = posts.subList(0, 3)
val postsPopular = posts.subList(3, 5)
val contentPadding = rememberContentPaddingForScreen(additionalTop = 8.dp)
Expand All @@ -150,10 +138,7 @@ private fun PostList(
* @param navigateToArticle (event) request navigation to Article screen
*/
@Composable
private fun PostListPopularSection(
posts: List<Post>,
navigateToArticle: (String) -> Unit
) {
private fun PostListPopularSection(posts: List<Post>, navigateToArticle: (String) -> Unit) {
Column {
Text(
modifier = Modifier.padding(16.dp),
Expand Down Expand Up @@ -189,11 +174,10 @@ private fun PostListDivider() {
* Determine the content padding to apply to the different screens of the app
*/
@Composable
fun rememberContentPaddingForScreen(additionalTop: Dp = 0.dp) =
WindowInsets.systemBars
.only(WindowInsetsSides.Bottom)
.add(WindowInsets(top = additionalTop))
.asPaddingValues()
fun rememberContentPaddingForScreen(additionalTop: Dp = 0.dp) = WindowInsets.systemBars
.only(WindowInsetsSides.Bottom)
.add(WindowInsets(top = additionalTop))
.asPaddingValues()

@Preview("Home screen")
@Preview("Home screen (dark)", uiMode = UI_MODE_NIGHT_YES)
Expand All @@ -205,7 +189,7 @@ fun PreviewHomeScreen() {
HomeScreen(
posts = PostsRepository().getPosts(),
navigateToArticle = { /*TODO*/ },
openDrawer = { /*TODO*/ },
openDrawer = { /*TODO*/ }
)
}
}
Loading
Loading