Skip to content

Commit

Permalink
WIP: Clean up the nav drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrowlands committed Oct 29, 2024
1 parent 06b6d19 commit 93fca3c
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.craxiom.networksurvey.ui.UNKNOWN_RSSI
import com.craxiom.networksurvey.ui.bluetooth.BluetoothDetailsScreen
import com.craxiom.networksurvey.ui.bluetooth.BluetoothDetailsViewModel
import com.craxiom.networksurvey.ui.main.SharedViewModel
import com.craxiom.networksurvey.util.NsTheme
import com.craxiom.networksurvey.ui.theme.NsTheme
import com.craxiom.networksurvey.util.PreferenceUtils
import timber.log.Timber

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.viewmodel.compose.viewModel
import com.craxiom.networksurvey.ui.cellular.CalculatorScreen
import com.craxiom.networksurvey.ui.cellular.model.CalculatorViewModel
import com.craxiom.networksurvey.util.NsTheme
import com.craxiom.networksurvey.ui.theme.NsTheme

/**
* The fragment that is responsible for displaying the cellular calculators screen.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import com.craxiom.networksurvey.ui.gnss.GnssStatusScreen
import com.craxiom.networksurvey.ui.gnss.model.SignalInfoViewModel
import com.craxiom.networksurvey.util.NsTheme
import com.craxiom.networksurvey.ui.theme.NsTheme
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.ExperimentalCoroutinesApi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ import com.craxiom.networksurvey.ui.gnss.data.FixState
import com.craxiom.networksurvey.ui.gnss.data.LocationRepository
import com.craxiom.networksurvey.ui.gnss.model.SatelliteMetadata
import com.craxiom.networksurvey.ui.gnss.model.SignalInfoViewModel
import com.craxiom.networksurvey.ui.theme.NsTheme
import com.craxiom.networksurvey.util.LibUIUtils
import com.craxiom.networksurvey.util.MathUtils
import com.craxiom.networksurvey.util.NsTheme
import com.craxiom.networksurvey.util.PreferenceUtils.clearGnssFilter
import com.craxiom.networksurvey.util.PreferenceUtils.gnssFilter
import dagger.hilt.android.AndroidEntryPoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.craxiom.networksurvey.services.NetworkSurveyService
import com.craxiom.networksurvey.ui.cellular.TowerMapScreen
import com.craxiom.networksurvey.ui.cellular.model.ServingCellInfo
import com.craxiom.networksurvey.ui.cellular.model.TowerMapViewModel
import com.craxiom.networksurvey.util.NsTheme
import com.craxiom.networksurvey.ui.theme.NsTheme
import com.craxiom.networksurvey.util.PreferenceUtils
import timber.log.Timber
import java.util.Collections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import com.craxiom.networksurvey.model.WifiRecordWrapper
import com.craxiom.networksurvey.services.NetworkSurveyService
import com.craxiom.networksurvey.ui.UNKNOWN_RSSI
import com.craxiom.networksurvey.ui.main.SharedViewModel
import com.craxiom.networksurvey.ui.theme.NsTheme
import com.craxiom.networksurvey.ui.wifi.WifiDetailsScreen
import com.craxiom.networksurvey.ui.wifi.model.WifiDetailsViewModel
import com.craxiom.networksurvey.util.NsTheme
import com.craxiom.networksurvey.util.PreferenceUtils
import timber.log.Timber

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.craxiom.networksurvey.listeners.IWifiSurveyRecordListener
import com.craxiom.networksurvey.model.WifiRecordWrapper
import com.craxiom.networksurvey.services.NetworkSurveyService
import com.craxiom.networksurvey.ui.main.SharedViewModel
import com.craxiom.networksurvey.ui.theme.NsTheme
import com.craxiom.networksurvey.ui.wifi.WifiSpectrumScreen
import com.craxiom.networksurvey.ui.wifi.model.WifiNetworkInfoList
import com.craxiom.networksurvey.ui.wifi.model.WifiSpectrum24ViewModel
Expand All @@ -24,7 +25,6 @@ import com.craxiom.networksurvey.ui.wifi.model.WifiSpectrum5Group2ViewModel
import com.craxiom.networksurvey.ui.wifi.model.WifiSpectrum5Group3ViewModel
import com.craxiom.networksurvey.ui.wifi.model.WifiSpectrum6ViewModel
import com.craxiom.networksurvey.ui.wifi.model.WifiSpectrumScreenViewModel
import com.craxiom.networksurvey.util.NsTheme
import com.craxiom.networksurvey.util.PreferenceUtils
import com.craxiom.networksurvey.util.WifiUtils

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ package com.craxiom.networksurvey.ui.cellular

import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import com.craxiom.networksurvey.util.CellularTheme
import com.craxiom.networksurvey.ui.theme.NsTheme

fun setContent(composeView: ComposeView, viewModel: CellularChartViewModel) {
composeView.apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
CellularTheme {
NsTheme {
CellularChartComponent(viewModel = viewModel)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.craxiom.networksurvey.fragments.model.MqttConnectionSettings
import com.craxiom.networksurvey.model.WifiNetwork
import com.craxiom.networksurvey.ui.main.appdrawer.AppDrawerContent
import com.craxiom.networksurvey.ui.main.appdrawer.AppDrawerItemInfo
import com.craxiom.networksurvey.util.NsTheme
import com.craxiom.networksurvey.ui.theme.NsTheme


@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.craxiom.networksurvey.ui.main.appdrawer

import android.graphics.Bitmap
import android.graphics.Canvas
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.DrawerState
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalDrawerSheet
Expand All @@ -19,7 +25,16 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.content.res.ResourcesCompat
import com.craxiom.networksurvey.R
import com.craxiom.networksurvey.ui.main.DrawerParams
import com.craxiom.networksurvey.ui.main.NavDrawerOption
import com.craxiom.networksurvey.ui.theme.NsTheme
import kotlinx.coroutines.launch

@Composable
Expand All @@ -34,18 +49,28 @@ fun <T : Enum<T>> AppDrawerContent(
var currentPick by remember { mutableStateOf(defaultPick) }
val coroutineScope = rememberCoroutineScope()

ModalDrawerSheet {
ModalDrawerSheet(drawerContainerColor = MaterialTheme.colorScheme.background) {
Surface(color = MaterialTheme.colorScheme.background) {
Column(
horizontalAlignment = Alignment.CenterHorizontally
horizontalAlignment = Alignment.Start,
modifier = Modifier.padding(8.dp)
) {
AppIcon()

// App Title
Text(
text = stringResource(id = R.string.app_name),
style = MaterialTheme.typography.headlineSmall,
modifier = Modifier.padding(top = 8.dp, bottom = 16.dp)
)

// Menu Items
LazyColumn(
modifier = Modifier.padding(horizontal = 8.dp),
horizontalAlignment = Alignment.CenterHorizontally
modifier = Modifier.padding(horizontal = 0.dp),
horizontalAlignment = Alignment.Start
) {
items(menuItems) { item ->
AppDrawerItem(item = item) { navOption ->

if (currentPick == navOption) {
coroutineScope.launch {
drawerState.close()
Expand All @@ -62,8 +87,8 @@ fun <T : Enum<T>> AppDrawerContent(
}

item {
// TODO Figure out a way to prevent this from making the drawer wider
HorizontalDivider(thickness = 1.dp)
// Divider between menu and external links
HorizontalDivider(thickness = 1.dp, modifier = Modifier.width(220.dp))
}

items(externalLinks) { item ->
Expand All @@ -86,11 +111,55 @@ fun <T : Enum<T>> AppDrawerContent(

Spacer(modifier = Modifier.weight(1f))

// App Version at Bottom
Text(
text = "App Version: $appVersion",
modifier = Modifier.align(Alignment.CenterHorizontally)
text = appVersion,
modifier = Modifier.align(Alignment.CenterHorizontally),
style = MaterialTheme.typography.bodySmall
)
}
}
}
}

@Composable
fun AppIcon() {
ResourcesCompat.getDrawable(
LocalContext.current.resources,
R.mipmap.ic_launcher, LocalContext.current.theme
)?.let { drawable ->
val bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth, drawable.intrinsicHeight,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
Column(
modifier = Modifier
.padding(8.dp),
horizontalAlignment = Alignment.Start
) {
Image(
bitmap = bitmap.asImageBitmap(),
"Network Survey App Icon",
modifier = Modifier.requiredSize(54.dp)
)
}
}
}

@Preview
@Composable
fun AppDrawerContentPreview() {
NsTheme {
AppDrawerContent(
appVersion = "1.0",
drawerState = DrawerState(DrawerValue.Closed),
menuItems = DrawerParams.drawerButtons,
externalLinks = DrawerParams.externalDrawerLinks,
defaultPick = NavDrawerOption.CellularCalculators,
onClick = {}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,22 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import com.craxiom.networksurvey.ui.main.DrawerParams
import com.craxiom.networksurvey.ui.main.NavDrawerOption
import com.craxiom.networksurvey.util.NsTheme
import com.craxiom.networksurvey.ui.theme.NsTheme

@Composable
fun <T> AppDrawerItem(item: AppDrawerItemInfo<T>, onClick: (options: T) -> Unit) =
Surface(
color = MaterialTheme.colorScheme.onPrimary,
modifier = Modifier
.width(200.dp)
.padding(16.dp),
.padding(vertical = 4.dp),
onClick = { onClick(item.drawerOption) },
shape = RoundedCornerShape(50),
) {
Row(
horizontalArrangement = Arrangement.Start,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.padding(8.dp)
.padding(vertical = 8.dp, horizontal = 6.dp)
) {
Icon(
painter = painterResource(id = item.drawableId),
Expand All @@ -51,7 +50,8 @@ fun <T> AppDrawerItem(item: AppDrawerItemInfo<T>, onClick: (options: T) -> Unit)
Text(
text = stringResource(id = item.title),
style = MaterialTheme.typography.bodyMedium,
textAlign = TextAlign.Center,
textAlign = TextAlign.Start,
maxLines = 1
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.craxiom.networksurvey.ui.theme

import androidx.compose.ui.graphics.Color

val ColorBlack = Color(0xFF000000)
val ColorOffBlack = Color(0xFF161616)
val ColorWhiteCultured = Color(0xFFF4F4F4)
val ColorRedFieryRose = Color(0xFFF45B69)
val ColorBlueIceberg = Color(0xFF8BAED0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.craxiom.networksurvey.ui.theme

import android.app.Activity
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Typography
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.colorResource
import androidx.core.view.WindowCompat
import com.craxiom.networksurvey.R

@Composable
fun OldNsTheme(content: @Composable () -> Unit) {
val darkColorScheme =
darkColorScheme(
surface = colorResource(id = R.color.colorCardDark),
background = Color.Black,
primary = colorResource(id = R.color.colorAccent),
tertiary = colorResource(id = R.color.colorAccent),
)
MaterialTheme(
colorScheme = darkColorScheme,
typography = Typography(),
content = content,
)
}

private val DarkColorScheme: ColorScheme
@Composable
get() = darkColorScheme(
primary = colorResource(id = R.color.colorAccent),
secondary = ColorBlueIceberg,
tertiary = colorResource(id = R.color.colorAccent),
background = ColorBlack,
surface = ColorBlack,
onPrimary = ColorOffBlack,
onSecondary = ColorWhiteCultured,
onTertiary = ColorWhiteCultured,
onBackground = ColorWhiteCultured,
onSurface = colorResource(id = R.color.normalText),
surfaceTint = ColorWhiteCultured
)

private val LightColorScheme = lightColorScheme(
primary = ColorWhiteCultured,
secondary = ColorBlueIceberg,
tertiary = ColorRedFieryRose,
background = ColorBlueIceberg,
surface = ColorBlueIceberg,
onPrimary = ColorOffBlack,
onSecondary = ColorWhiteCultured,
onTertiary = ColorWhiteCultured,
onBackground = ColorWhiteCultured,
onSurface = ColorWhiteCultured,
surfaceTint = ColorBlack
)

@Composable
fun NsTheme(
darkTheme: Boolean = true,
content: @Composable () -> Unit
) {
val colorScheme = DarkColorScheme
val view = LocalView.current
val currentWindow = (view.context as? Activity)?.window
if (!view.isInEditMode && currentWindow != null) {
/*val currentWindow = (view.context as? Activity)?.window
?: throw Exception("Not in an activity - unable to get Window reference")*/

SideEffect {
(view.context as Activity).window.statusBarColor = colorScheme.background.toArgb()
(view.context as Activity).window.navigationBarColor = colorScheme.background.toArgb()
WindowCompat.getInsetsController(currentWindow, view).isAppearanceLightStatusBars =
false
/*WindowCompat.setDecorFitsSystemWindows(currentWindow, false)
val insetsController = WindowCompat.getInsetsController(currentWindow, view)
insetsController.isAppearanceLightStatusBars = false
insetsController.hide(WindowInsetsCompat.Type.statusBars())*/
}
}

MaterialTheme(
colorScheme = colorScheme, typography = Typography(), content = content
)
}
Loading

0 comments on commit 93fca3c

Please sign in to comment.