Skip to content

Commit

Permalink
Merge pull request #52 from egorikftp/feature/cameras_2.0
Browse files Browse the repository at this point in the history
Voice Alerts
  • Loading branch information
egorikftp committed Jul 27, 2023
2 parents a6944bf + e42c42a commit 05568cc
Show file tree
Hide file tree
Showing 135 changed files with 1,968 additions and 342 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ android {
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}

packaging {
Expand Down Expand Up @@ -103,6 +103,7 @@ dependencies {
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.material3.window)
implementation(libs.androidx.compose.material.icons)
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.compose.ui)
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/com/egoriku/grodnoroads/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand All @@ -17,10 +20,12 @@ import com.egoriku.grodnoroads.screen.root.RoadsRootComponent
import com.egoriku.grodnoroads.screen.root.RoadsRootComponentImpl
import com.egoriku.grodnoroads.screen.root.RootContent
import com.egoriku.grodnoroads.shared.appsettings.types.appearance.Theme
import com.egoriku.grodnoroads.util.LocalWindowSizeClass
import com.google.accompanist.systemuicontroller.rememberSystemUiController

class MainActivity : AppCompatActivity() {

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
val splash = installSplashScreen()

Expand Down Expand Up @@ -56,7 +61,11 @@ class MainActivity : AppCompatActivity() {
}
onDispose {}
}
RootContent(roadsRootComponent = root)
CompositionLocalProvider(
LocalWindowSizeClass provides calculateWindowSizeClass(this),
) {
RootContent(roadsRootComponent = root)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ internal class MainComponentImpl(

private sealed class Config : Parcelable {
@Parcelize
object Map : Config()
data object Map : Config()

@Parcelize
object Settings : Config()
data object Settings : Config()
}
}
73 changes: 68 additions & 5 deletions app/src/main/java/com/egoriku/grodnoroads/screen/main/MainUi.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,55 @@
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.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Text
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.Modifier
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.stringResource
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.map.MapScreen
import com.egoriku.grodnoroads.screen.main.MainComponent.Child
import com.egoriku.grodnoroads.setting.screen.SettingsScreen
import com.egoriku.grodnoroads.util.LocalWindowSizeClass

@Composable
fun MainUi(component: MainComponent) {
val bottomNavItems = listOf(Screen.Map, Screen.Settings)
val windowSizeClass = LocalWindowSizeClass.current

val childStack by component.childStack.subscribeAsState()

when (windowSizeClass.widthSizeClass) {
Expanded -> {
HorizontalOrientationLayout(
childStack = childStack,
component = component
)
}

else -> {
VerticalOrientationLayout(
childStack = childStack,
component = component
)
}
}
}

@Composable
private fun VerticalOrientationLayout(
childStack: ChildStack<*, Child>,
component: MainComponent
) {
val bottomNavItems = remember { listOf(Screen.Map, Screen.Settings) }

Column(modifier = Modifier.fillMaxSize()) {
Children(
modifier = Modifier.weight(1f),
Expand Down Expand Up @@ -53,4 +79,41 @@ fun MainUi(component: MainComponent) {
}
}
}
}

@Composable
private fun HorizontalOrientationLayout(
childStack: ChildStack<*, Child>,
component: MainComponent
) {
val bottomNavItems = remember { listOf(Screen.Map, Screen.Settings) }

Row(modifier = Modifier.fillMaxSize()) {
NavigationRail {
bottomNavItems.forEach { screen ->
NavigationRailItem(
selected = screen.index == childStack.active.instance.index,
onClick = { component.onSelectTab(index = screen.index) },
icon = {
Icon(
painter = rememberVectorPainter(image = screen.icon),
contentDescription = null
)
},
label = {
Text(text = stringResource(id = screen.labelId))
}
)
}
}
Children(
modifier = Modifier.weight(1f),
stack = childStack,
) { created ->
when (val child = created.instance) {
is Child.Map -> MapScreen(component = child.component)
is Child.Settings -> SettingsScreen(settingsComponent = child.component)
}
}
}
}
12 changes: 10 additions & 2 deletions app/src/main/java/com/egoriku/grodnoroads/screen/main/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import com.egoriku.grodnoroads.resources.R

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

object Map : Screen(index = 0, icon = Icons.Default.Explore, labelId = R.string.tab_map)
object Settings : Screen(index = 1, icon = Icons.Default.Settings, labelId = R.string.tab_settings)
data object Map : Screen(
index = 0,
icon = Icons.Default.Explore,
labelId = R.string.tab_map
)
data object Settings : Screen(
index = 1,
icon = Icons.Default.Settings,
labelId = R.string.tab_settings
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,24 @@ class RoadsRootComponentImpl(

private sealed class Config : Parcelable {
@Parcelize
object Main : Config()
data object Main : Config()

@Parcelize
object Appearance : Config()
data object Appearance : Config()

@Parcelize
object MapSettings : Config()
data object MapSettings : Config()

@Parcelize
object Alerts : Config()
data object Alerts : Config()

@Parcelize
object WhatsNew : Config()
data object WhatsNew : Config()

@Parcelize
object NextFeatures : Config()
data object NextFeatures : Config()

@Parcelize
object FAQ : Config()
data object FAQ : Config()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RootStoreFactory(
) {

sealed interface Intent {
object CloseDialog : Intent
data object CloseDialog : Intent
}

sealed interface Message {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -41,7 +38,7 @@ fun HeadLampDialog(headlampType: HeadLampType, onClose: () -> Unit) {
DialogContent {
Column(verticalArrangement = Arrangement.Center) {
Text(modifier = Modifier.padding(16.dp), text = dialogContent)
Divider()
HorizontalDivider()
DialogButton(
modifier = Modifier.fillMaxWidth(),
textResId = R.string.ok,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.egoriku.grodnoroads.util

import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.runtime.compositionLocalOf

val LocalWindowSizeClass = compositionLocalOf<WindowSizeClass> { error("SizeClass not present") }
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AndroidLibraryComposePlugin : Plugin<Project> {
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.Locale

plugins {
Expand Down Expand Up @@ -39,7 +40,7 @@ fun isNonStable(version: String): Boolean {

//assembleRelease -Pgrodnoroads.enableComposeCompilerReports=true
subprojects {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
if (project.findProperty("grodnoroads.enableComposeCompilerReports") == "true") {
freeCompilerArgs = freeCompilerArgs +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.google.android.gms.maps.model.LatLng
import kotlinx.collections.immutable.mutate
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList
import java.util.UUID

private const val MERGE_ALERT_DISTANCE = 200

Expand Down Expand Up @@ -51,6 +52,7 @@ internal object ReportsMapper : (List<ReportsDTO>) -> List<Reports> {
)
} else {
val action = Reports(
id = UUID.randomUUID().toString(),
messages = persistentListOf(
MessageItem(
message = "(${DateUtil.formatToTime(data.timestamp)}) ${data.message.emojiFix()}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.google.firebase.database.DatabaseReference
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import java.util.UUID

internal class MobileCameraRepositoryImpl(
private val databaseReference: DatabaseReference
Expand All @@ -24,6 +25,8 @@ internal class MobileCameraRepositoryImpl(
is Failure -> Failure(resultOf.exception)
is Success -> Success(resultOf.value.map { data ->
MobileCamera(
// TODO: use from backend
id = UUID.randomUUID().toString(),
name = data.name,
position = LatLng(data.latitude, data.longitude),
speedCar = data.speed,
Expand Down
Loading

0 comments on commit 05568cc

Please sign in to comment.