Skip to content

Commit

Permalink
πŸ‘” Little UI adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzovngl committed Dec 9, 2023
1 parent 1406a18 commit b4a32dd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.lorenzovainigli.foodexpirationdates.view.composable
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarDuration
Expand Down Expand Up @@ -97,23 +97,33 @@ fun MyScaffold(
activity = activity,
title = when (destination) {
Screen.AboutScreen.route -> stringResource(id = R.string.about_this_app)
Screen.InsertScreen.route -> stringResource(id = R.string.insert)
Screen.SettingsScreen.route -> stringResource(id = R.string.settings)
else -> stringResource(id = R.string.app_name)
else -> {
if (destination?.contains(Screen.InsertScreen.route) == true) {
if (currentBackStackEntry?.arguments?.getString("itemId") != null){
stringResource(id = R.string.edit_item)
} else {
stringResource(id = R.string.add_item)
}
} else {
stringResource(id = R.string.app_name)
}
}
},
actions = {
AppIcon(size = 48.dp)
},
navigationIcon = {
if (currentBackStackEntry?.destination?.route == Screen.InsertScreen.route) {
Icon(
modifier = Modifier.clickable {
navController.popBackStack()
},
imageVector = Icons.Filled.ArrowBack,
contentDescription = stringResource(id = R.string.back),
tint = MaterialTheme.colorScheme.primary
)
if (destination?.contains(Screen.InsertScreen.route) == true) {
IconButton(
onClick = { navController.popBackStack() }
) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = stringResource(id = R.string.back),
tint = MaterialTheme.colorScheme.primary
)
}
}
},
scrollBehavior = scrollBehavior
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
package com.lorenzovainigli.foodexpirationdates.view.composable

import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LargeTopAppBar
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import com.lorenzovainigli.foodexpirationdates.R
import com.lorenzovainigli.foodexpirationdates.model.repository.PreferencesRepository
import com.lorenzovainigli.foodexpirationdates.ui.theme.FoodExpirationDatesTheme
import com.lorenzovainigli.foodexpirationdates.view.MainActivity
import com.lorenzovainigli.foodexpirationdates.viewmodel.PreferencesViewModel

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand All @@ -32,15 +29,12 @@ fun MyTopAppBar(
actions: @Composable RowScope.() -> Unit = {},
navigationIcon: @Composable () -> Unit = {},
scrollBehavior: TopAppBarScrollBehavior? = null,
prefsViewModel: PreferencesViewModel? = null
) {
val context = LocalContext.current
val topBarFontState = activity?.preferencesViewModel?.getTopBarFont(context)?.collectAsState()?.value
?: PreferencesRepository.Companion.TopBarFont.NORMAL.ordinal

LargeTopAppBar(
modifier = Modifier
.padding(bottom = 4.dp),
title = {
Text(
text = title,
Expand Down Expand Up @@ -70,11 +64,13 @@ fun MyTopAppBarPreview(){
activity = null,
title = "Lorem Ipsum",
navigationIcon = {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = stringResource(id = R.string.back),
tint = MaterialTheme.colorScheme.primary
)
IconButton(onClick = {}) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = stringResource(id = R.string.back),
tint = MaterialTheme.colorScheme.primary
)
}
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ fun InsertScreen(
Button(
modifier = Modifier.testTag("Insert date"),
onClick = { isDialogOpen = false },
// colors = ButtonDefaults.buttonColors(
// containerColor = MaterialTheme.colorScheme.tertiary,
// contentColor = MaterialTheme.colorScheme.onTertiary
// )
colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.tertiary,
contentColor = MaterialTheme.colorScheme.onTertiary
)
) {
Text(text = stringResource(id = R.string.insert))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun MainScreen(
) {
Box(
modifier = Modifier
.padding(4.dp)
.padding(start = 4.dp, end = 4.dp)
.fillMaxSize()
) {
val itemsState = activity?.viewModel?.getDates()?.collectAsState(emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun SettingsScreen(
val context = LocalContext.current
val prefsViewModel = activity?.preferencesViewModel
val darkThemeState = prefsViewModel?.getThemeMode(context)?.collectAsState()?.value
?: PreferencesRepository.Companion.ThemeMode.SYSTEM
?: PreferencesRepository.Companion.ThemeMode.SYSTEM.ordinal
val dynamicColorsState = prefsViewModel?.getDynamicColors(context)?.collectAsState()?.value
?: false
val topBarFontState = prefsViewModel?.getTopBarFont(context)?.collectAsState()?.value
Expand Down

0 comments on commit b4a32dd

Please sign in to comment.