Skip to content

Commit

Permalink
feat: setup ui WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jvsena42 committed Oct 24, 2024
1 parent 265417d commit 6ba6fe3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.core)
implementation(libs.koin.viewmodel)
implementation(libs.koin.compose)
implementation(libs.koin.android)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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.home.HomeViewModel
import org.koin.android.ext.koin.androidApplication
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
Expand All @@ -34,6 +35,11 @@ class FlorestaApplication : Application() {

private val presentationModule = module {
viewModel { MainViewmodel() }
viewModel { HomeViewModel(
walletRepository = get(),
walletManager = get(),
florestaDaemon = get()
) }
}

private val domainModule = module {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.github.jvsena42.floresta.presentation.ui.screens.home.ScreenHome
import com.github.jvsena42.floresta.presentation.ui.theme.FlorestaTheme

class MainActivity : ComponentActivity() {
Expand All @@ -20,28 +21,9 @@ class MainActivity : ComponentActivity() {
setContent {
FlorestaTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Greeting(
name = "Android",
modifier = Modifier.padding(innerPadding)
)
ScreenHome(innerPadding)
}
}
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
FlorestaTheme {
Greeting("Android")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.github.jvsena42.floresta.presentation.util.formatInBtc
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
Expand All @@ -19,10 +20,10 @@ class HomeViewModel(
private val walletRepository: WalletRepository,
private val walletManager: WalletManager,
private val florestaDaemon: FlorestaDaemon
) : ViewModel() {
) : ViewModel() {

private val _uiState = MutableStateFlow(HomeUIState())
val uiState = _uiState.asStateFlow()
val uiState: StateFlow<HomeUIState> = _uiState.asStateFlow()

init {
syncInLoop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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 All @@ -22,18 +23,30 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
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
import com.github.jvsena42.floresta.presentation.ui.theme.Primary

@Composable
fun ScreenHome(
innerPadding: PaddingValues,
viewmodel: HomeViewModel = viewModel()
) {
val uiState: HomeUIState by viewmodel.uiState.collectAsState()
ScreenHome(uiState)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun ScreenHome(
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ koin-bom = { module = "io.insert-koin:koin-bom", version.ref = "koin-bom" }
koin-core = { module = "io.insert-koin:koin-core" }
koin-android = { module = "io.insert-koin:koin-android" }
koin-viewmodel = { module = "io.insert-koin:koin-core-viewmodel" }
koin-compose = { module = "io.insert-koin:koin-androidx-compose" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down

0 comments on commit 6ba6fe3

Please sign in to comment.