Skip to content

Commit

Permalink
reformat/optimize imports for all kotlin modules
Browse files Browse the repository at this point in the history
  • Loading branch information
luca992 committed Sep 14, 2023
1 parent b84b006 commit f6f2ec2
Show file tree
Hide file tree
Showing 52 changed files with 301 additions and 258 deletions.
18 changes: 9 additions & 9 deletions androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name=".android.DKMPApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NoActionBar">
android:name=".android.DKMPApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NoActionBar">
<activity
android:exported="true"
android:name=".android.MainActivity">
android:exported="true"
android:name=".android.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
2 changes: 1 addition & 1 deletion composables/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
<manifest/>
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package eu.baroncelli.dkmpsample.composables.navigation

import androidx.compose.runtime.Composable
import androidx.activity.compose.BackHandler
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.saveable.SaveableStateHolder
import eu.baroncelli.dkmpsample.shared.viewmodel.Navigation
import eu.baroncelli.dkmpsample.shared.viewmodel.NavigationState
import eu.baroncelli.dkmpsample.shared.viewmodel.debugLogger

@Composable
actual fun Navigation.HandleBackButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ import androidx.compose.runtime.saveable.rememberSaveableStateHolder
import androidx.compose.ui.unit.dp
import eu.baroncelli.dkmpsample.composables.navigation.templates.OnePane
import eu.baroncelli.dkmpsample.composables.navigation.templates.TwoPane
import eu.baroncelli.dkmpsample.shared.viewmodel.*
import eu.baroncelli.dkmpsample.shared.viewmodel.Navigation
import eu.baroncelli.dkmpsample.shared.viewmodel.NavigationState
import eu.baroncelli.dkmpsample.shared.viewmodel.ScreenIdentifier
import eu.baroncelli.dkmpsample.shared.viewmodel.ScreenParams
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.Level1Navigation
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.Screen



@Composable
fun Navigation.Router() {

val screenUIsStateHolder = rememberSaveableStateHolder()
val localNavigationState = remember { mutableStateOf( navigationState ) }
val localNavigationState = remember { mutableStateOf(navigationState) }

val twopaneWidthThreshold = 1000.dp
BoxWithConstraints {
if (maxWidth < maxHeight || maxWidth<twopaneWidthThreshold) {
if (maxWidth < maxHeight || maxWidth < twopaneWidthThreshold) {
OnePane(screenUIsStateHolder, localNavigationState)
} else {
TwoPane(screenUIsStateHolder, localNavigationState)
Expand All @@ -34,15 +36,15 @@ fun Navigation.Router() {

}

fun Navigation.navigationProcessor(localNavigationState: MutableState<NavigationState>) : (Screen, ScreenParams?) -> Unit {
fun Navigation.navigationProcessor(localNavigationState: MutableState<NavigationState>): (Screen, ScreenParams?) -> Unit {
return { screen, screenParams ->
val screenIdentifier = ScreenIdentifier.get(screen, screenParams)
navigateToScreen(screenIdentifier) // shared navigationState is updated
localNavigationState.value = navigationState // update localNavigationState
}
}

fun Navigation.level1NavigationProcessor(localNavigationState: MutableState<NavigationState>) : (Level1Navigation) -> Unit {
fun Navigation.level1NavigationProcessor(localNavigationState: MutableState<NavigationState>): (Level1Navigation) -> Unit {
return {
selectLevel1Navigation(it.screenIdentifier) // shared navigationState is updated
localNavigationState.value = navigationState // update localNavigationState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import eu.baroncelli.dkmpsample.composables.screens.countrydetail.CountryDetailScreen
import eu.baroncelli.dkmpsample.composables.screens.countrieslist.CountriesListScreen
import eu.baroncelli.dkmpsample.composables.screens.countrieslist.CountriesListTwoPaneDefaultDetail
import eu.baroncelli.dkmpsample.composables.screens.countrydetail.CountryDetailScreen
import eu.baroncelli.dkmpsample.shared.viewmodel.Navigation
import eu.baroncelli.dkmpsample.shared.viewmodel.ScreenIdentifier
import eu.baroncelli.dkmpsample.shared.viewmodel.ScreenParams
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.Screen
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.Screen.*
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.Screen.CountriesList
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.Screen.CountryDetail
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.countrieslist.CountriesListState
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.countrieslist.selectFavorite
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.countrydetail.CountryDetailParams
Expand Down Expand Up @@ -50,7 +51,6 @@ fun Navigation.ScreenPicker(
}



@Composable
fun Navigation.TwoPaneDefaultDetail(
screenIdentifier: ScreenIdentifier
Expand All @@ -61,7 +61,7 @@ fun Navigation.TwoPaneDefaultDetail(
CountriesList ->
CountriesListTwoPaneDefaultDetail()

else -> Box{}
else -> Box {}
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package eu.baroncelli.dkmpsample.composables.navigation.bars

import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.BottomAppBar
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Star
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package eu.baroncelli.dkmpsample.composables.navigation.bars
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.Icon
import androidx.compose.material.LocalContentColor
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Star
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import eu.baroncelli.dkmpsample.shared.viewmodel.Navigation
Expand Down Expand Up @@ -50,11 +52,15 @@ fun Navigation.Level1NavigationRail(
}



@Composable
fun ColumnScope.NavigationRailItem(icon : @Composable () -> Unit , label : @Composable () -> Unit, selected : Boolean, onClick : () -> Unit) {
fun ColumnScope.NavigationRailItem(
icon: @Composable () -> Unit,
label: @Composable () -> Unit,
selected: Boolean,
onClick: () -> Unit
) {
CompositionLocalProvider(
LocalContentColor provides if (selected) MaterialTheme.colors.background else MaterialTheme.colors.primaryVariant
LocalContentColor provides if (selected) MaterialTheme.colors.background else MaterialTheme.colors.primaryVariant
) {
Row(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package eu.baroncelli.dkmpsample.composables.navigation.bars

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.*
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.sp

@Composable
fun TopBar(
title : String
){
title: String
) {
TopAppBar(title = {
Text(text = title, fontSize = 20.sp, textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth())
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.saveable.SaveableStateHolder
import eu.baroncelli.dkmpsample.composables.navigation.*
import eu.baroncelli.dkmpsample.composables.navigation.ScreenPicker
import eu.baroncelli.dkmpsample.composables.navigation.bars.Level1BottomBar
import eu.baroncelli.dkmpsample.composables.navigation.bars.TopBar
import eu.baroncelli.dkmpsample.composables.navigation.level1NavigationProcessor
import eu.baroncelli.dkmpsample.composables.navigation.navigationProcessor
import eu.baroncelli.dkmpsample.shared.viewmodel.Navigation
import eu.baroncelli.dkmpsample.shared.viewmodel.NavigationState
import eu.baroncelli.dkmpsample.shared.viewmodel.debugLogger

@Composable
fun Navigation.OnePane(
Expand All @@ -25,6 +26,11 @@ fun Navigation.OnePane(
ScreenPicker(screenIdentifier, navigationProcessor(localNavigationState))
}
},
bottomBar = { if (screenIdentifier.screen.navigationLevel == 1) Level1BottomBar(screenIdentifier, level1NavigationProcessor(localNavigationState)) }
bottomBar = {
if (screenIdentifier.screen.navigationLevel == 1) Level1BottomBar(
screenIdentifier,
level1NavigationProcessor(localNavigationState)
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.saveable.SaveableStateHolder
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import eu.baroncelli.dkmpsample.composables.navigation.*
import eu.baroncelli.dkmpsample.composables.navigation.ScreenPicker
import eu.baroncelli.dkmpsample.composables.navigation.TwoPaneDefaultDetail
import eu.baroncelli.dkmpsample.composables.navigation.bars.Level1NavigationRail
import eu.baroncelli.dkmpsample.composables.navigation.bars.TopBar
import eu.baroncelli.dkmpsample.composables.navigation.level1NavigationProcessor
import eu.baroncelli.dkmpsample.composables.navigation.navigationProcessor
import eu.baroncelli.dkmpsample.shared.viewmodel.Navigation
import eu.baroncelli.dkmpsample.shared.viewmodel.NavigationState
import eu.baroncelli.dkmpsample.shared.viewmodel.ScreenIdentifier
import eu.baroncelli.dkmpsample.shared.viewmodel.debugLogger

@Composable
fun Navigation.TwoPane(
Expand All @@ -27,40 +29,45 @@ fun Navigation.TwoPane(
topBar = { TopBar(title) },
content = {
Row {
Column(Modifier
.fillMaxHeight()
.width(80.dp)) {
Level1NavigationRail(masterScreenIdentifier, level1NavigationProcessor(localNavigationState))
Column(
Modifier
.fillMaxHeight()
.width(80.dp)
) {
Level1NavigationRail(masterScreenIdentifier, level1NavigationProcessor(localNavigationState))
}
Column(Modifier
.weight(0.4f)) {
saveableStateHolder.SaveableStateProvider(masterScreenIdentifier.URI) {
ScreenPicker(masterScreenIdentifier, navigationProcessor(localNavigationState))
}
Column(
Modifier
.weight(0.4f)
) {
saveableStateHolder.SaveableStateProvider(masterScreenIdentifier.URI) {
ScreenPicker(masterScreenIdentifier, navigationProcessor(localNavigationState))
}
}
Column(Modifier
.weight(0.6f)
.padding(20.dp)) {
if (detailScreenIdentifier == null) {
TwoPaneDefaultDetail(masterScreenIdentifier)
} else {
saveableStateHolder.SaveableStateProvider(detailScreenIdentifier.URI) {
ScreenPicker(detailScreenIdentifier, navigationProcessor(localNavigationState))
}
Column(
Modifier
.weight(0.6f)
.padding(20.dp)
) {
if (detailScreenIdentifier == null) {
TwoPaneDefaultDetail(masterScreenIdentifier)
} else {
saveableStateHolder.SaveableStateProvider(detailScreenIdentifier.URI) {
ScreenPicker(detailScreenIdentifier, navigationProcessor(localNavigationState))
}
}
}
}
}
)
}



fun Navigation.twoPaneMasterScreen(navState: MutableState<NavigationState>) : ScreenIdentifier {
fun Navigation.twoPaneMasterScreen(navState: MutableState<NavigationState>): ScreenIdentifier {
return navState.value.currentLevel1ScreenIdentifier
}

fun Navigation.twoPaneDetailScreen(navState: MutableState<NavigationState>) : ScreenIdentifier? {
fun Navigation.twoPaneDetailScreen(navState: MutableState<NavigationState>): ScreenIdentifier? {
if (navState.value.topScreenIdentifier.screen.navigationLevel > 1) {
return navState.value.topScreenIdentifier
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package eu.baroncelli.dkmpsample.composables.screens

import androidx.compose.material.Text
import androidx.compose.foundation.layout.*
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -12,7 +12,11 @@ import androidx.compose.ui.unit.sp

@Composable
fun LoadingScreen() {
Column(modifier = Modifier.fillMaxWidth() then Modifier.padding(top=120.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
Column(
modifier = Modifier.fillMaxWidth() then Modifier.padding(top = 120.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(text = "loading...", fontSize = 18.sp)
Spacer(modifier = Modifier.size(40.dp))
CircularProgressIndicator(color = Color.LightGray)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package eu.baroncelli.dkmpsample.composables.screens.countrieslist

import androidx.compose.foundation.background
import androidx.compose.material.Text
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -13,7 +13,10 @@ import androidx.compose.ui.unit.sp

@Composable
fun CountriesListHeader() {
Row(modifier = Modifier.fillMaxWidth().height(50.dp).background(Color.LightGray).padding(start=10.dp), verticalAlignment = Alignment.CenterVertically) {
Row(
modifier = Modifier.fillMaxWidth().height(50.dp).background(Color.LightGray).padding(start = 10.dp),
verticalAlignment = Alignment.CenterVertically
) {
Column(modifier = Modifier.weight(1f)) {
Text(text = "country", fontSize = 16.sp)
}
Expand Down
Loading

0 comments on commit f6f2ec2

Please sign in to comment.