Skip to content

Commit

Permalink
feat: implement nav host WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jvsena42 committed Oct 25, 2024
1 parent 3efde88 commit a4a0f98
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:theme="@style/Theme.Floresta"
tools:targetApi="31">
<activity
android:name=".presentation.MainActivity"
android:name=".presentation.ui.screens.main.MainActivity"
android:exported="true"
android:theme="@style/Theme.Floresta">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.github.jvsena42.floresta.domain.bitcoin.WalletRepositoryImpl
import com.github.jvsena42.floresta.domain.floresta.FlorestaDaemon
import com.github.jvsena42.floresta.domain.floresta.FlorestaDaemonImpl
import com.github.jvsena42.floresta.domain.floresta.FlorestaService
import com.github.jvsena42.floresta.presentation.MainViewmodel
import com.github.jvsena42.floresta.presentation.ui.screens.main.MainViewmodel
import com.github.jvsena42.floresta.presentation.ui.screens.home.HomeViewModel
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.github.jvsena42.floresta.presentation.ui.screens.home
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
Expand Down Expand Up @@ -32,7 +31,6 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.github.jvsena42.floresta.R
import com.github.jvsena42.floresta.presentation.ui.screens.home.components.TransactionItem
import com.github.jvsena42.floresta.presentation.ui.theme.FlorestaTheme
Expand All @@ -41,7 +39,6 @@ import org.koin.androidx.compose.koinViewModel

@Composable
fun ScreenHome(
innerPadding: PaddingValues,
viewmodel: HomeViewModel = koinViewModel()
) {
val uiState: HomeUIState by viewmodel.uiState.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.jvsena42.floresta.presentation.ui.screens.main

import androidx.annotation.DrawableRes
import com.github.jvsena42.floresta.R



enum class Destinations(
val route: String,
val label: String,
@DrawableRes val icon: Int
) {
HOME(route = "Home", label = "Home", R.drawable.ic_add)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.github.jvsena42.floresta.presentation.ui.screens.main

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarDefaults
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.github.jvsena42.floresta.presentation.ui.screens.home.ScreenHome
import com.github.jvsena42.floresta.presentation.ui.theme.FlorestaTheme
import com.github.jvsena42.floresta.presentation.ui.theme.Primary
import org.koin.androidx.compose.KoinAndroidContext

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
var navigationSelectedItem by remember { mutableStateOf(Destinations.HOME) }
val navController = rememberNavController()

FlorestaTheme {
KoinAndroidContext {
Scaffold(modifier = Modifier.fillMaxSize(),
bottomBar = {
NavigationBar(
containerColor = Primary
) {
Destinations.entries.forEach { destination ->
NavigationBarItem(
selected = destination == navigationSelectedItem,
onClick = {
navigationSelectedItem = destination
navController.navigate(destination.route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
},
label = {
destination.label
},
icon = {
Icon(
painter = painterResource(destination.icon),
contentDescription = destination.label
)
}
)
}
}
}
) { innerPadding ->
NavHost(
navController = navController,
startDestination = Destinations.HOME.route,
modifier = Modifier.padding(paddingValues = innerPadding)
) {
composable(Destinations.HOME.route) {
ScreenHome()
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jvsena42.floresta.presentation
package com.github.jvsena42.floresta.presentation.ui.screens.main

import androidx.lifecycle.ViewModel

Expand Down

0 comments on commit a4a0f98

Please sign in to comment.