home ui start
This commit is contained in:
parent
bc9db1e5a9
commit
4905433a3b
@ -61,6 +61,7 @@ dependencies {
|
|||||||
implementation(libs.androidx.material3)
|
implementation(libs.androidx.material3)
|
||||||
implementation(libs.androidx.room.common)
|
implementation(libs.androidx.room.common)
|
||||||
implementation(libs.androidx.room.ktx)
|
implementation(libs.androidx.room.ktx)
|
||||||
|
implementation(libs.androidx.navigation.compose)
|
||||||
testImplementation(libs.junit)
|
testImplementation(libs.junit)
|
||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
androidTestImplementation(libs.androidx.espresso.core)
|
androidTestImplementation(libs.androidx.espresso.core)
|
||||||
|
@ -6,8 +6,8 @@ import at.xaxa.ledger.data.db.LedgerDatabase
|
|||||||
|
|
||||||
class LedgerApplication : Application(){
|
class LedgerApplication : Application(){
|
||||||
val entryRepository by lazy {
|
val entryRepository by lazy {
|
||||||
EntryRepository(
|
/*EntryRepository(
|
||||||
DatabaseInstance.getDatabase(this).LedgerDao()
|
DatabaseInstance.getDatabase(this).LedgerDao()
|
||||||
)
|
)*/
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,6 +11,7 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import at.xaxa.ledger.ui.LedgerApp
|
||||||
import at.xaxa.ledger.ui.theme.LedgerTheme
|
import at.xaxa.ledger.ui.theme.LedgerTheme
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
@ -20,8 +21,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
setContent {
|
setContent {
|
||||||
LedgerTheme {
|
LedgerTheme {
|
||||||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
||||||
Greeting(
|
LedgerApp(
|
||||||
name = "Android",
|
|
||||||
modifier = Modifier.padding(innerPadding)
|
modifier = Modifier.padding(innerPadding)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import kotlinx.coroutines.flow.map
|
|||||||
|
|
||||||
class EntryRepository(private val ledgerDao: LedgerDao){
|
class EntryRepository(private val ledgerDao: LedgerDao){
|
||||||
|
|
||||||
|
/*
|
||||||
fun getAllEntries(): Flow<List<Entry>> {
|
fun getAllEntries(): Flow<List<Entry>> {
|
||||||
return ledgerDao.getAllEntries().map {
|
return ledgerDao.getAllEntries().map {
|
||||||
it.map {entry -> Entry(entry._id, entry.name, entry.amount, entry.date, entry.categoryName) }
|
it.map {entry -> Entry(entry._id, entry.name, entry.amount, entry.date, entry.categoryName) }
|
||||||
@ -30,6 +30,6 @@ class EntryRepository(private val ledgerDao: LedgerDao){
|
|||||||
}
|
}
|
||||||
suspend fun deletePokemon(entry: Entry) {
|
suspend fun deletePokemon(entry: Entry) {
|
||||||
LedgerDao.deleteEntry(EntryEntity(_id = entry.id, entry.name, entry.amount, entry.date, entry.categoryName))
|
LedgerDao.deleteEntry(EntryEntity(_id = entry.id, entry.name, entry.amount, entry.date, entry.categoryName))
|
||||||
}
|
}*/
|
||||||
|
|
||||||
}
|
}
|
@ -7,6 +7,6 @@ import at.xaxa.ledger.data.db.Entry.EntryEntity
|
|||||||
|
|
||||||
@Database(entities = [EntryEntity::class, CategoryEntity::class], version = 1, exportSchema = false)
|
@Database(entities = [EntryEntity::class, CategoryEntity::class], version = 1, exportSchema = false)
|
||||||
abstract class LedgerDatabase : RoomDatabase() {
|
abstract class LedgerDatabase : RoomDatabase() {
|
||||||
abstract fun entryDao(): EntryDao
|
/*abstract fun entryDao(): EntryDao
|
||||||
abstract fun categoryDao(): CategoryDao
|
abstract fun categoryDao(): CategoryDao*/
|
||||||
}
|
}
|
56
Ledger/app/src/main/java/at/xaxa/ledger/ui/LedgerApp.kt
Normal file
56
Ledger/app/src/main/java/at/xaxa/ledger/ui/LedgerApp.kt
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package at.xaxa.ledger.ui
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.navigation.compose.NavHost
|
||||||
|
import androidx.navigation.compose.composable
|
||||||
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
|
import androidx.navigation.compose.rememberNavController
|
||||||
|
import at.xaxa.ledger.ui.home.Home
|
||||||
|
|
||||||
|
enum class AppRoutes(val route: String) {
|
||||||
|
Home("home"),
|
||||||
|
Add("add"),
|
||||||
|
Edit("edit/{gameId}")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LedgerApp(modifier: Modifier = Modifier){
|
||||||
|
val navController = rememberNavController()
|
||||||
|
val currentRoute = navController.currentBackStackEntryAsState().value?.destination?.route
|
||||||
|
|
||||||
|
Scaffold() { innerPadding ->
|
||||||
|
NavHost(
|
||||||
|
navController = navController,
|
||||||
|
startDestination = AppRoutes.Home.route,
|
||||||
|
modifier = Modifier.padding(innerPadding),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
composable(AppRoutes.Home.route){
|
||||||
|
Home(onCardClick = {
|
||||||
|
navController.navigate("home")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
composable(AppRoutes.Add.route) {
|
||||||
|
SearchList(onCardClick = {
|
||||||
|
navController.navigate("add/$it")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
composable(
|
||||||
|
route = AppRoutes.Edit.route,
|
||||||
|
arguments = listOf(navArgument("gameId") {
|
||||||
|
type = NavType.IntType
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
backStackEntry ->
|
||||||
|
DetailView(
|
||||||
|
modifier = Modifier
|
||||||
|
)
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package at.xaxa.ledger.ui
|
package at.xaxa.ledger.ui
|
||||||
|
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@ -25,6 +27,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.draw.shadow
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
@ -37,6 +40,7 @@ import androidx.compose.ui.unit.sp
|
|||||||
// region Header Card
|
// region Header Card
|
||||||
@Composable
|
@Composable
|
||||||
fun HeaderCard(modifier: Modifier = Modifier, balance: String) {
|
fun HeaderCard(modifier: Modifier = Modifier, balance: String) {
|
||||||
|
|
||||||
Surface(
|
Surface(
|
||||||
shape = RoundedCornerShape(12.dp),
|
shape = RoundedCornerShape(12.dp),
|
||||||
color = Color(0xfff9f9f9),
|
color = Color(0xfff9f9f9),
|
||||||
@ -44,6 +48,12 @@ fun HeaderCard(modifier: Modifier = Modifier, balance: String) {
|
|||||||
modifier = modifier
|
modifier = modifier
|
||||||
.requiredWidth(width = 360.dp)
|
.requiredWidth(width = 360.dp)
|
||||||
.clip(shape = RoundedCornerShape(12.dp))
|
.clip(shape = RoundedCornerShape(12.dp))
|
||||||
|
.shadow(
|
||||||
|
elevation = 8.dp,
|
||||||
|
shape = RoundedCornerShape(16.dp),
|
||||||
|
clip = true
|
||||||
|
)
|
||||||
|
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -53,6 +63,7 @@ fun HeaderCard(modifier: Modifier = Modifier, balance: String) {
|
|||||||
LayoutMediaTextHeader(modifier, balance)
|
LayoutMediaTextHeader(modifier, balance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -100,8 +111,9 @@ private fun HeaderCardPreview() {
|
|||||||
|
|
||||||
// region Horizontal Card
|
// region Horizontal Card
|
||||||
@Composable
|
@Composable
|
||||||
fun HorizontalCard(modifier: Modifier = Modifier, name: String, date: String, amount:String) {
|
fun HorizontalCard(modifier: Modifier = Modifier, name: String, date: String, amount:String, onClick: () -> Unit ) {
|
||||||
Surface(
|
Surface(
|
||||||
|
onClick = onClick,
|
||||||
shape = RoundedCornerShape(12.dp),
|
shape = RoundedCornerShape(12.dp),
|
||||||
color = Color(0xfff9f9f9),
|
color = Color(0xfff9f9f9),
|
||||||
border = BorderStroke(1.dp, Color(0xffc6c6c6)),
|
border = BorderStroke(1.dp, Color(0xffc6c6c6)),
|
||||||
@ -171,7 +183,7 @@ fun LayoutMediaText(modifier: Modifier = Modifier, name: String, date: String, a
|
|||||||
@Preview(widthDp = 360, heightDp = 80)
|
@Preview(widthDp = 360, heightDp = 80)
|
||||||
@Composable
|
@Composable
|
||||||
private fun HorizontalCardPreview() {
|
private fun HorizontalCardPreview() {
|
||||||
HorizontalCard(Modifier, "McDonald's", "12th Feb, 23:32", "-124234.00€")
|
HorizontalCard(Modifier, "McDonald's", "12th Feb, 23:32", "-124234.00€", onClick = { println("success") })
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
@ -1,2 +1,47 @@
|
|||||||
package at.xaxa.ledger.ui.home
|
package at.xaxa.ledger.ui.home
|
||||||
|
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import at.xaxa.ledger.ui.HeaderCard
|
||||||
|
import at.xaxa.ledger.ui.HorizontalCard
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
@Composable
|
||||||
|
fun Home(modifier: Modifier = Modifier, onCardClick: (Int) -> Unit) {
|
||||||
|
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally) {
|
||||||
|
|
||||||
|
val items = (1..20).toList()
|
||||||
|
LazyColumn() {
|
||||||
|
stickyHeader {
|
||||||
|
HeaderCard(modifier = modifier, "-13563.00€")
|
||||||
|
}
|
||||||
|
items(items) { index ->
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(vertical = 4.dp) // Add vertical padding
|
||||||
|
) {
|
||||||
|
HorizontalCard(
|
||||||
|
modifier = modifier,
|
||||||
|
name = "McDonald's $index",
|
||||||
|
date = "12th Feb, 23:32",
|
||||||
|
amount = "-12.99",
|
||||||
|
onClick = { onCardClick(index) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ activityCompose = "1.9.3"
|
|||||||
composeBom = "2024.04.01"
|
composeBom = "2024.04.01"
|
||||||
roomCommon = "2.6.1"
|
roomCommon = "2.6.1"
|
||||||
roomKtx = "2.6.1"
|
roomKtx = "2.6.1"
|
||||||
|
navigationCompose = "2.8.5"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||||
@ -28,6 +29,7 @@ androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit
|
|||||||
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
|
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||||
androidx-room-common = { group = "androidx.room", name = "room-common", version.ref = "roomCommon" }
|
androidx-room-common = { group = "androidx.room", name = "room-common", version.ref = "roomCommon" }
|
||||||
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "roomKtx" }
|
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "roomKtx" }
|
||||||
|
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
|
Loading…
Reference in New Issue
Block a user