Skip to content

Commit

Permalink
Merge pull request #53 from egorikftp/version/1.2.3
Browse files Browse the repository at this point in the history
Version/1.2.3
  • Loading branch information
egorikftp authored Sep 12, 2023
2 parents 43fcdea + e104b53 commit bf676c4
Show file tree
Hide file tree
Showing 70 changed files with 559 additions and 430 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins {
alias(libs.plugins.firebase.crashlytics)
alias(libs.plugins.google.services)
alias(libs.plugins.kotlin.parcelize)
alias(libs.plugins.ksp)
alias(libs.plugins.secrets)
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
android:localeConfig="@xml/locales_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:enableOnBackInvokedCallback="true"
android:theme="@style/SplashTheme">

<activity
Expand Down
78 changes: 61 additions & 17 deletions app/src/main/java/com/egoriku/grodnoroads/screen/main/MainUi.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
package com.egoriku.grodnoroads.screen.main

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.*
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass.Companion.Expanded
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.extensions.compose.jetpack.stack.Children
import com.arkivanov.decompose.extensions.compose.jetpack.subscribeAsState
import com.arkivanov.decompose.router.stack.ChildStack
import com.egoriku.grodnoroads.foundation.theme.tonalElevation
import com.egoriku.grodnoroads.map.MapScreen
import com.egoriku.grodnoroads.screen.main.MainComponent.Child
import com.egoriku.grodnoroads.setting.screen.SettingsScreen
import com.egoriku.grodnoroads.util.LocalWindowSizeClass

private val NavigationBarHeight: Dp = 80.dp

@Composable
fun MainUi(component: MainComponent) {
val windowSizeClass = LocalWindowSizeClass.current
Expand Down Expand Up @@ -50,25 +55,52 @@ private fun VerticalOrientationLayout(
) {
val bottomNavItems = remember { listOf(Screen.Map, Screen.Settings) }

Column(modifier = Modifier.fillMaxSize()) {
val contentPaddingValues = WindowInsets
.navigationBars
.add(WindowInsets(bottom = NavigationBarHeight))
.asPaddingValues()

Box(modifier = Modifier.fillMaxSize()) {
Children(
modifier = Modifier.weight(1f),
modifier = Modifier.fillMaxSize(1f),
stack = childStack,
) { created ->
when (val child = created.instance) {
is Child.Map -> MapScreen(component = child.component)
is Child.Settings -> SettingsScreen(settingsComponent = child.component)
is Child.Map -> {
MapScreen(
contentPadding = contentPaddingValues,
component = child.component
)
}

is Child.Settings -> SettingsScreen(
contentPadding = contentPaddingValues,
settingsComponent = child.component
)
}
}

NavigationBar(tonalElevation = 1.dp) {
val tonalElevation = MaterialTheme.tonalElevation
NavigationBar(
modifier = Modifier
.align(Alignment.BottomStart)
.clip(RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp)),
tonalElevation = tonalElevation
) {
bottomNavItems.forEach { screen ->
NavigationBarItem(
selected = screen.index == childStack.active.instance.index,
onClick = { component.onSelectTab(index = screen.index) },
colors = NavigationBarItemDefaults.colors(
unselectedIconColor = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.45f),
unselectedTextColor = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.45f),
indicatorColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
tonalElevation
)
),
icon = {
Icon(
painter = rememberVectorPainter(image = screen.icon),
painter = painterResource(id = screen.iconRes),
contentDescription = null
)
},
Expand All @@ -89,19 +121,24 @@ private fun HorizontalOrientationLayout(
val bottomNavItems = remember { listOf(Screen.Map, Screen.Settings) }

Row(modifier = Modifier.fillMaxSize()) {
NavigationRail {
val tonalElevation = MaterialTheme.tonalElevation
val containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(tonalElevation)

NavigationRail(containerColor = containerColor) {
bottomNavItems.forEach { screen ->
NavigationRailItem(
colors = NavigationRailItemDefaults.colors(
unselectedIconColor = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.45f),
unselectedTextColor = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.45f),
indicatorColor = containerColor
),
selected = screen.index == childStack.active.instance.index,
onClick = { component.onSelectTab(index = screen.index) },
icon = {
Icon(
painter = rememberVectorPainter(image = screen.icon),
painter = painterResource(id = screen.iconRes),
contentDescription = null
)
},
label = {
Text(text = stringResource(id = screen.labelId))
}
)
}
Expand All @@ -111,8 +148,15 @@ private fun HorizontalOrientationLayout(
stack = childStack,
) { created ->
when (val child = created.instance) {
is Child.Map -> MapScreen(component = child.component)
is Child.Settings -> SettingsScreen(settingsComponent = child.component)
is Child.Map -> MapScreen(
contentPadding = PaddingValues(),
component = child.component
)

is Child.Settings -> SettingsScreen(
contentPadding = PaddingValues(),
settingsComponent = child.component
)
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions app/src/main/java/com/egoriku/grodnoroads/screen/main/Screen.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.egoriku.grodnoroads.screen.main

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Explore
import androidx.compose.material.icons.filled.Settings
import androidx.compose.ui.graphics.vector.ImageVector
import com.egoriku.grodnoroads.resources.R

sealed class Screen(val index: Int, val icon: ImageVector, val labelId: Int) {
sealed class Screen(
val index: Int,
val labelId: Int,
val iconRes: Int
) {

data object Map : Screen(
index = 0,
icon = Icons.Default.Explore,
labelId = R.string.tab_map
labelId = R.string.tab_map,
iconRes = R.drawable.ic_map
)

data object Settings : Screen(
index = 1,
icon = Icons.Default.Settings,
labelId = R.string.tab_settings
labelId = R.string.tab_settings,
iconRes = R.drawable.ic_settings
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.FaultyDecomposeApi
import com.arkivanov.decompose.extensions.compose.jetpack.stack.Children
import com.arkivanov.decompose.extensions.compose.jetpack.stack.animation.*
import com.egoriku.grodnoroads.screen.main.MainUi
Expand All @@ -18,6 +19,7 @@ import com.egoriku.grodnoroads.setting.faq.screen.FaqScreen
import com.egoriku.grodnoroads.setting.map.MapSettingsScreen
import com.egoriku.grodnoroads.setting.whatsnew.screen.WhatsNewScreen

@OptIn(FaultyDecomposeApi::class)
@Composable
fun RootContent(roadsRootComponent: RoadsRootComponent) {
Surface(modifier = Modifier.fillMaxSize()) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<resources>

<style name="SplashTheme" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#FF242f3e</item>
<item name="windowSplashScreenBackground">#FF1A1F26</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash</item>
<item name="windowSplashScreenAnimationDuration">800</item>
<item name="postSplashScreenTheme">@style/GrodnoRoadsTheme</item>
Expand Down
14 changes: 6 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,18 @@ plugins {
alias(libs.plugins.gradle.dependency.check)
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.parcelize) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.secrets) apply false
}

tasks {
registering(Delete::class) {
delete(buildDir)
delete(layout.buildDirectory)
}
withType<DependencyUpdatesTask> {
rejectVersionIf {
isNonStable(candidate.version)
}
}

registering(Delete::class) {
delete(buildDir)
}
}

fun isNonStable(version: String): Boolean {
Expand All @@ -43,9 +38,12 @@ subprojects {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
if (project.findProperty("grodnoroads.enableComposeCompilerReports") == "true") {
val reportsPath =
project.layout.buildDirectory.dir("compose_metrics").get().asFile.absolutePath

freeCompilerArgs = freeCompilerArgs +
"-P=plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=${project.buildDir.absolutePath}/compose_metrics" +
"-P=plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=${project.buildDir.absolutePath}/compose_metrics"
"-P=plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=$reportsPath" +
"-P=plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=$reportsPath"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ internal class MapComponentImpl(
combine(
flow = alerts,
flow2 = alertInfo,
flow3 = appMode,
transform = alertSoundTransformation()
).distinctUntilChanged()
.debounce(500)
Expand Down Expand Up @@ -104,6 +105,13 @@ internal class MapComponentImpl(
}
}
.launchIn(coroutineScope)

alertInfo
.distinctUntilChanged()
.onEach {
soundUtil.setVolume(level = it.alertsVolumeLevel.level)
}
.launchIn(coroutineScope)
}

override val appMode: Flow<AppMode>
Expand Down Expand Up @@ -148,6 +156,7 @@ internal class MapComponentImpl(
flow = mapEvents,
flow2 = lastLocation,
flow3 = mapConfig,
flow4 = appMode,
transform = alertMessagesTransformation()
).flowOn(Dispatchers.Default)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.egoriku.grodnoroads.map.domain.model

import com.egoriku.grodnoroads.shared.appsettings.types.alert.VolumeLevel
import com.egoriku.grodnoroads.shared.appsettings.types.map.mapstyle.Style

internal data class MapInternalConfig(
Expand All @@ -26,6 +27,7 @@ internal data class MapInternalConfig(

internal data class AlertsInfo(
val alertsEnabled: Boolean,
val alertsVolumeLevel: VolumeLevel,
val voiceAlertsEnabled: Boolean,
val notifyStationaryCameras: Boolean,
val notifyMediumSpeedCameras: Boolean,
Expand Down Expand Up @@ -55,6 +57,7 @@ internal data class MapInternalConfig(
),
alertsInfo = AlertsInfo(
alertsEnabled = false,
alertsVolumeLevel = VolumeLevel.High,
voiceAlertsEnabled = false,
notifyStationaryCameras = false,
notifyMediumSpeedCameras = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ internal class MapConfigStoreFactory(
),
alertsInfo = AlertsInfo(
alertsEnabled = pref.alertsEnabled,
alertsVolumeLevel = pref.alertsVolumeLevel,
voiceAlertsEnabled = pref.alertsVoiceAlertEnabled,
notifyStationaryCameras = pref.isNotifyStationaryCameras,
notifyMediumSpeedCameras = pref.isNotifyMediumSpeedCameras,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package com.egoriku.grodnoroads.map.domain.util

import com.egoriku.grodnoroads.extensions.util.computeOffset
import com.egoriku.grodnoroads.extensions.util.distanceTo
import com.egoriku.grodnoroads.map.domain.model.Alert
import com.egoriku.grodnoroads.map.domain.model.*
import com.egoriku.grodnoroads.map.domain.model.Alert.CameraAlert
import com.egoriku.grodnoroads.map.domain.model.Alert.IncidentAlert
import com.egoriku.grodnoroads.map.domain.model.LastLocation
import com.egoriku.grodnoroads.map.domain.model.MapConfig
import com.egoriku.grodnoroads.map.domain.model.MapEvent
import com.egoriku.grodnoroads.map.domain.model.MapEvent.Camera
import com.egoriku.grodnoroads.map.domain.model.MapEvent.Reports
import com.google.android.gms.maps.model.LatLng
Expand All @@ -20,12 +17,12 @@ private const val MIN_SPEED = 10

private val emptyList = persistentListOf<Alert>()

fun alertMessagesTransformation(): suspend (List<MapEvent>, LastLocation, MapConfig) -> ImmutableList<Alert> =
{ mapEvents, lastLocation, config ->
fun alertMessagesTransformation(): suspend (List<MapEvent>, LastLocation, MapConfig, AppMode) -> ImmutableList<Alert> =
{ mapEvents, lastLocation, config, appMode ->
when (lastLocation) {
LastLocation.None -> emptyList
else -> when {
!config.alertsEnabled -> emptyList
!config.alertsEnabled && appMode != AppMode.Drive -> emptyList
lastLocation.speed > MIN_SPEED -> makeAlertMessage(
mapEvents = mapEvents,
lastLocation = lastLocation,
Expand Down Expand Up @@ -79,7 +76,8 @@ private fun makeAlertMessage(

is Reports -> {
IncidentAlert(
id = event.id,
// TODO: in future use id from Group
id = event.markerMessage,
distance = distance,
messages = event.messages,
mapEventType = event.mapEventType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.egoriku.grodnoroads.map.domain.util

import com.egoriku.grodnoroads.map.domain.model.Alert
import com.egoriku.grodnoroads.map.domain.model.Alert.CameraAlert
import com.egoriku.grodnoroads.map.domain.model.AppMode
import com.egoriku.grodnoroads.map.domain.model.CameraType.*
import com.egoriku.grodnoroads.map.domain.model.MapEventType.*
import com.egoriku.grodnoroads.map.domain.model.MapInternalConfig.AlertsInfo
Expand All @@ -11,9 +12,9 @@ import kotlinx.collections.immutable.toImmutableList

val alertPersistentList = persistentListOf<Alert>()

internal fun alertSoundTransformation(): suspend (ImmutableList<Alert>, AlertsInfo) -> ImmutableList<Alert> =
{ alerts, alertInfo ->
if (alertInfo.voiceAlertsEnabled) {
internal fun alertSoundTransformation(): suspend (ImmutableList<Alert>, AlertsInfo, AppMode) -> ImmutableList<Alert> =
{ alerts, alertInfo, appMode ->
if (alertInfo.voiceAlertsEnabled && appMode == AppMode.Drive) {
alerts.mapNotNull { alert ->
when (alert) {
is CameraAlert -> {
Expand Down
Loading

0 comments on commit bf676c4

Please sign in to comment.