Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fde/fix various a11y issues #257

Merged
merged 8 commits into from
Dec 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalMaterial3Api::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import org.scottishtecharmy.soundscape.screens.home.home.Home
import org.scottishtecharmy.soundscape.screens.home.locationDetails.LocationDescription
import org.scottishtecharmy.soundscape.screens.home.locationDetails.LocationDetailsScreen
import org.scottishtecharmy.soundscape.screens.home.settings.Settings
import org.scottishtecharmy.soundscape.screens.markers_routes.navigation.MarkersAndRoutesNavGraph
import org.scottishtecharmy.soundscape.screens.markers_routes.navigation.ScreensForMarkersAndRoutes
import org.scottishtecharmy.soundscape.screens.markers_routes.screens.MarkersAndRoutesScreen
import org.scottishtecharmy.soundscape.screens.markers_routes.screens.addroute.AddRouteScreen
import org.scottishtecharmy.soundscape.viewmodels.HomeViewModel
Expand Down Expand Up @@ -119,14 +117,6 @@ fun HomeScreen(
val selectedTab = backStackEntry.arguments?.getString("tab")
MarkersAndRoutesScreen(mainNavController = navController, selectedTab = selectedTab)
}

// Nested graph: Routes and Markers
composable(ScreensForMarkersAndRoutes.Markers.route) {
MarkersAndRoutesNavGraph(
navController = navController,
startDestination = "Markers",
)
}
}

// AddRouteScreen, accessible within the MarkersAndRoutesScreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -123,7 +126,7 @@ fun Home(
onNavigate = onNavigate,
searchBar = {
MainSearchBar(
searchText = "Hello Dave",
searchText = "",
isSearching = false,
itemList = emptyList(),
onSearchTextChange = { },
Expand Down Expand Up @@ -153,7 +156,10 @@ fun HomeTopAppBar(
containerColor = MaterialTheme.colorScheme.background,
titleContentColor = Color.White,
),
title = { Text(stringResource(R.string.app_name)) },
title = { Text(
text = stringResource(R.string.app_name),
modifier = Modifier.semantics { heading() }
) },
navigationIcon = {
IconButton(
onClick = {
Expand Down Expand Up @@ -181,7 +187,17 @@ fun HomeTopAppBar(
},
) {
if (streetPreviewEnabled) {
Icon(Icons.Rounded.Preview, contentDescription = "Street Preview enabled")
Icon(
Icons.Rounded.Preview,
tint = MaterialTheme.colorScheme.primary,
contentDescription = stringResource(R.string.street_preview_enabled)
)
} else {
Icon(
painterResource(R.drawable.preview_off),
tint = MaterialTheme.colorScheme.secondary,
contentDescription = stringResource(R.string.street_preview_disabled)
)
}
}
IconToggleButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private fun HomeBottomAppBarButton(
},
shape = RectangleShape,
modifier = modifier,
contentPadding = PaddingValues(0.dp)
contentPadding = PaddingValues(4.dp)
) {
Column(
verticalArrangement = Arrangement.Top,
Expand All @@ -143,8 +143,9 @@ private fun HomeBottomAppBarButton(
Text(
text = text,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.labelMedium
style = MaterialTheme.typography.labelMedium,
)

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import me.zhanghai.compose.preference.ProvidePreferenceLocals
import me.zhanghai.compose.preference.listPreference
Expand Down Expand Up @@ -53,20 +56,13 @@ fun Settings(
Text(
text = stringResource(R.string.menu_manage_callouts),
color = MaterialTheme.colorScheme.onPrimary,
modifier = Modifier.semantics { heading() },
)
}
switchPreference(
key = MainActivity.ALLOW_CALLOUTS_KEY,
defaultValue = MainActivity.ALLOW_CALLOUTS_DEFAULT,
title = { Text(text = stringResource(R.string.callouts_allow_callouts)) },
summary = {
Text(
text = if (it) stringResource(R.string.callouts_callouts_on) else stringResource(
R.string.callouts_callouts_off
),
color = MaterialTheme.colorScheme.onPrimary
)
}
)
switchPreference(
key = MainActivity.PLACES_AND_LANDMARKS_KEY,
Expand All @@ -93,7 +89,8 @@ fun Settings(
Text(
text = "Manage Audio Engine",
color = MaterialTheme.colorScheme.onPrimary,
)
modifier = Modifier.semantics { heading() },
)
}
listPreference(
key = MainActivity.BEACON_TYPE_KEY,
Expand Down Expand Up @@ -124,7 +121,8 @@ fun Settings(
Text(
text = "Debug settings",
color = MaterialTheme.colorScheme.onPrimary,
)
modifier = Modifier.semantics { heading() },
)
}
switchPreference(
key = MainActivity.MAP_DEBUG_KEY,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.scottishtecharmy.soundscape.screens.markers_routes.components

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.expandHorizontally
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkHorizontally
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.IntrinsicSize
Expand All @@ -13,17 +8,15 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -34,8 +27,6 @@ import org.scottishtecharmy.soundscape.ui.theme.SoundscapeTheme
@Composable
fun CustomAppBar(title : String,
onNavigateUp: () -> Unit,
onAddClicked: (() -> Unit)? = null,
showAddIcon: Boolean = false,
navigationButtonTitle: String = stringResource(R.string.ui_back_button_title),
) {
Surface(
Expand All @@ -62,27 +53,9 @@ fun CustomAppBar(title : String,
) {
Text(
text = title,
modifier = Modifier.semantics { heading() }
)
}


AnimatedVisibility(
visible = showAddIcon,
enter = fadeIn() + expandHorizontally(),
exit = fadeOut() + shrinkHorizontally(),
modifier = Modifier.fillMaxHeight()
) {
IconButton(
onClick = {
onAddClicked?.invoke()
}
){
Icon(
Icons.Default.Add,
contentDescription = stringResource(R.string.general_alert_add),
)
}
}
}
}
}
Expand All @@ -95,9 +68,7 @@ fun CustomAppBarPreview() {
CustomAppBar(
"Test app bar with long title",
navigationButtonTitle = "Back",
showAddIcon = false,
onNavigateUp = {},
onAddClicked = {}
)
}
}
Expand All @@ -110,9 +81,7 @@ fun CustomAppBarWithActionButtonPreview() {
CustomAppBar(
"Test app bar",
navigationButtonTitle = "Back",
showAddIcon = true,
onNavigateUp = {},
onAddClicked = {}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ import androidx.compose.ui.tooling.preview.Preview
import org.scottishtecharmy.soundscape.R
import org.scottishtecharmy.soundscape.ui.theme.SoundscapeTheme

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MarkersAndRoutesAppBar(showAddIcon: Boolean,
onNavigateUp: () -> Unit,
onNavigateToDestination: () -> Unit
fun MarkersAndRoutesAppBar(
onNavigateUp: () -> Unit,
) {

CustomAppBar(
title = stringResource(R.string.search_view_markers),
navigationButtonTitle = stringResource(R.string.ui_back_button_title),
onNavigateUp = onNavigateUp,
showAddIcon = showAddIcon,
onAddClicked = onNavigateToDestination,
)
}

Expand All @@ -28,10 +24,7 @@ fun MarkersAndRoutesAppBar(showAddIcon: Boolean,
fun MarkersAndRoutesAppBarPreview() {
SoundscapeTheme {
MarkersAndRoutesAppBar(
showAddIcon = true,
onNavigateUp = {},
onNavigateToDestination = {}

)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.scottishtecharmy.soundscape.screens.markers_routes.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
Expand All @@ -23,7 +24,7 @@ val items = listOf(
)

@Composable
fun BottomNavigationBar(navController: NavController,
fun MarkersAndRoutesTabs(navController: NavController,
) {
val currentRoute = navController.currentBackStackEntryAsState().value?.destination?.route

Expand All @@ -47,23 +48,19 @@ fun BottomNavigationBar(navController: NavController,
Text(item.title, style = MaterialTheme.typography.bodyLarge)
},
icon = {
Image(
painter = painterResource(
id = if (isSelected) {
item.selectedIconResId!!
} else {
item.unselectedIconResId!!
}
),
contentDescription = null, // No need of contentDescription as text is below
)
item.iconResId?.let {
Icon(painter = painterResource(it),
contentDescription = null, // No need of contentDescription as text is below,
modifier = Modifier.size(64.dp)
)
}

},
colors = NavigationBarItemDefaults.colors(
selectedIconColor = MaterialTheme.colorScheme.onPrimary,
unselectedIconColor = MaterialTheme.colorScheme.onSurfaceVariant,
unselectedIconColor = MaterialTheme.colorScheme.onPrimary.copy(alpha = 0.7f),
selectedTextColor = MaterialTheme.colorScheme.onPrimary,
unselectedTextColor = MaterialTheme.colorScheme.onSurfaceVariant,
indicatorColor = MaterialTheme.colorScheme.surfaceDim
unselectedTextColor = MaterialTheme.colorScheme.onPrimary.copy(alpha = 0.7f),
)
)
}
Expand All @@ -75,7 +72,7 @@ fun BottomNavigationBar(navController: NavController,
fun BottomNavigationBarPreview() {
val navController = rememberNavController()
MaterialTheme {
BottomNavigationBar(navController = navController,
MarkersAndRoutesTabs(navController = navController,
)
}
}
Loading
Loading