Skip to content

Commit

Permalink
Detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
louis993546 committed Jul 5, 2024
1 parent d0cfe63 commit 7144bff
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,54 @@ import de.berlindroid.zeapp.R
import de.berlindroid.zeapp.zeui.zetheme.ZeBlack
import de.berlindroid.zeapp.zeui.zetheme.ZeWhite

@Composable
fun NavDrawerItem(
text: String,
vector: ImageVector? = null,
painter: Painter? = null,
onClick: () -> Unit,
onCloseDrawer: () -> Unit,
) {
val shape = RoundedCornerShape(
topStart = 0.dp,
bottomStart = 0.dp,
topEnd = 30.dp,
bottomEnd = 30.dp,
)
NavigationDrawerItem(
modifier = Modifier
.padding(
start = 0.dp,
end = 32.dp,
top = 4.dp,
bottom = 4.dp,
)
.border(
width = 1.dp,
color = ZeWhite,
shape = shape,
),
colors = NavigationDrawerItemDefaults.colors(
unselectedTextColor = ZeWhite,
unselectedContainerColor = ZeBlack,
),
shape = shape,
icon = {
if (vector != null) {
Icon(imageVector = vector, contentDescription = text, tint = ZeWhite)
} else if (painter != null) {
Icon(painter = painter, contentDescription = text, tint = ZeWhite)
}
},
label = { Text(text = text) },
selected = false,
onClick = {
onClick()
onCloseDrawer()
},
)
}

@Composable
@Preview
internal fun ZeDrawerContent(
Expand All @@ -48,53 +96,6 @@ internal fun ZeDrawerContent(
val viewModel: ZeDrawerViewModel = hiltViewModel()
val uiState by viewModel.uiState.collectAsState()

@Composable
fun NavDrawerItem(
text: String,
vector: ImageVector? = null,
painter: Painter? = null,
onClick: () -> Unit,
) {
val shape = RoundedCornerShape(
topStart = 0.dp,
bottomStart = 0.dp,
topEnd = 30.dp,
bottomEnd = 30.dp,
)
NavigationDrawerItem(
modifier = Modifier
.padding(
start = 0.dp,
end = 32.dp,
top = 4.dp,
bottom = 4.dp,
)
.border(
width = 1.dp,
color = ZeWhite,
shape = shape,
),
colors = NavigationDrawerItemDefaults.colors(
unselectedTextColor = ZeWhite,
unselectedContainerColor = ZeBlack,
),
shape = shape,
icon = {
if (vector != null) {
Icon(imageVector = vector, contentDescription = text, tint = ZeWhite)
} else if (painter != null) {
Icon(painter = painter, contentDescription = text, tint = ZeWhite)
}
},
label = { Text(text = text) },
selected = false,
onClick = {
onClick()
onCloseDrawer()
},
)
}

ModalDrawerSheet(
drawerContainerColor = MaterialTheme.colorScheme.secondary,
drawerShape = DrawerDefaults.shape,
Expand All @@ -117,13 +118,15 @@ internal fun ZeDrawerContent(
text = "{YOUR NAME HERE, ADD BADGE OR SOMETHING}",
vector = Icons.Default.AccountBox,
onClick = onGotoZePass,
onCloseDrawer = onCloseDrawer,
)
}
item {
NavDrawerItem(
onClick = onSaveAllClick,
painter = painterResource(id = R.drawable.save_all),
text = stringResource(id = R.string.ze_navdrawer_save_all_pages),
onCloseDrawer = onCloseDrawer,
)
}

Expand All @@ -132,6 +135,7 @@ internal fun ZeDrawerContent(
text = stringResource(id = R.string.ze_navdrawer_update_config),
vector = Icons.Default.ThumbUp,
onClick = onUpdateConfig,
onCloseDrawer = onCloseDrawer,
)
}

Expand All @@ -140,27 +144,18 @@ internal fun ZeDrawerContent(
painter = painterResource(id = R.drawable.ic_random),
text = stringResource(id = R.string.ze_navdrawer_send_random_page),
onClick = onGetStoredPages,
onCloseDrawer = onCloseDrawer,
)
}

item {
HorizontalDivider(
thickness = 0.dp,
color = MaterialTheme.colorScheme.background,
modifier = Modifier.padding(
start = 0.dp,
end = 0.dp,
top = 16.dp,
bottom = 16.dp,
),
)
}
item { Divider() }

item {
NavDrawerItem(
text = stringResource(id = R.string.ze_navdrawer_contributors),
painter = rememberVectorPainter(Icons.Default.Info),
onClick = onGotoContributors,
onCloseDrawer = onCloseDrawer,
)
}

Expand All @@ -169,21 +164,11 @@ internal fun ZeDrawerContent(
text = stringResource(id = R.string.ze_navdrawer_open_source),
painter = painterResource(id = R.drawable.ic_open_source_initiative),
onClick = onGotoOpenSourceClick,
onCloseDrawer = onCloseDrawer,
)
}

item {
HorizontalDivider(
thickness = 0.dp,
color = MaterialTheme.colorScheme.background,
modifier = Modifier.padding(
start = 0.dp,
end = 0.dp,
top = 16.dp,
bottom = 16.dp,
),
)
}
item { Divider() }

uiState.newReleaseVersion?.let { version ->
item {
Expand All @@ -198,8 +183,23 @@ internal fun ZeDrawerContent(
text = stringResource(id = R.string.ze_navdrawer_open_release_page),
painter = painterResource(id = R.drawable.ic_update),
onClick = onGotoReleaseClick,
onCloseDrawer = onCloseDrawer,
)
}
}
}
}

@Composable
private fun Divider() {
HorizontalDivider(
thickness = 0.dp,
color = MaterialTheme.colorScheme.background,
modifier = Modifier.padding(
start = 0.dp,
end = 0.dp,
top = 16.dp,
bottom = 16.dp,
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ fun ZeUserProfile(
val viewModel: ZePassVm = hiltViewModel()

val state by viewModel.uiState.collectAsState()
val context = LocalContext.current

Surface(
modifier = Modifier.fillMaxSize(),
Expand Down

0 comments on commit 7144bff

Please sign in to comment.