Merge remote-tracking branch 'origin/Florian'

This commit is contained in:
Xaver 2025-01-13 15:56:46 +01:00
commit bc9db1e5a9
17 changed files with 188 additions and 0 deletions

View File

@ -59,6 +59,8 @@ dependencies {
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.androidx.room.common)
implementation(libs.androidx.room.ktx)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

View File

@ -0,0 +1,13 @@
package at.xaxa.ledger
import android.app.Application
import at.xaxa.ledger.data.EntryRepository
import at.xaxa.ledger.data.db.LedgerDatabase
class LedgerApplication : Application(){
val entryRepository by lazy {
EntryRepository(
DatabaseInstance.getDatabase(this).LedgerDao()
)
}
}

View File

@ -0,0 +1,9 @@
package at.xaxa.ledger.data
class Entry (
val id: Int,
val name: String,
val amount: Float,
val date: Long,
val categoryName: Int
)

View File

@ -0,0 +1,35 @@
package at.xaxa.ledger.data
import at.xaxa.ledger.data.db.Entry.EntryEntity
import at.xaxa.ledger.data.db.LedgerDao
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
class EntryRepository(private val ledgerDao: LedgerDao){
fun getAllEntries(): Flow<List<Entry>> {
return ledgerDao.getAllEntries().map {
it.map {entry -> Entry(entry._id, entry.name, entry.amount, entry.date, entry.categoryName) }
}
}
suspend fun findEntryById(id: Int): Entry {
val entry = LedgerDao.findEntryById(id)
return Entry(
entry._id, entry.name, entry.amount, entry.date, entry.categoryName
)
}
suspend fun insertEntry(entry: Entry) {
LedgerDao.addEntry(EntryEntity(_id=0, entry.name, entry.amount, entry.date, entry.categoryName))
}
suspend fun updateEntry(entry: Entry) {
LedgerDao.updateEntry(EntryEntity(entry.id, entry.name, entry.amount, entry.date, entry.categoryName))
}
suspend fun deletePokemon(entry: Entry) {
LedgerDao.deleteEntry(EntryEntity(_id = entry.id, entry.name, entry.amount, entry.date, entry.categoryName))
}
}

View File

@ -0,0 +1,12 @@
package at.xaxa.ledger.data.db.Category
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "category")
data class CategoryEntity(
@PrimaryKey(autoGenerate = true)
val _id: Int = 0,
val categoryname: String,
val icon: Int
)

View File

@ -0,0 +1,20 @@
import android.content.Context
import androidx.room.Room
import at.xaxa.ledger.data.db.LedgerDatabase
object DatabaseInstance {
@Volatile
private var INSTANCE: LedgerDatabase? = null
fun getDatabase(context: Context): LedgerDatabase {
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
LedgerDatabase::class.java,
"ledger_database"
).build()
INSTANCE = instance
instance
}
}
}

View File

@ -0,0 +1,14 @@
package at.xaxa.ledger.data.db.Entry
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "transaction")
data class EntryEntity(
@PrimaryKey(autoGenerate = true)
val _id: Int = 0,
val name: String,
val amount: Float,
val date: Long,
val categoryName: Int
)

View File

@ -0,0 +1,50 @@
package at.xaxa.ledger.data.db
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import at.xaxa.ledger.data.db.Category.CategoryEntity
import at.xaxa.ledger.data.db.Entry.EntryEntity
import kotlinx.coroutines.flow.Flow
@Dao
interface LedgerDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun addCategory(entryEntity: CategoryEntity)
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun addEntry(entryEntity: EntryEntity)
@Update
suspend fun updateCategory(category: CharCategory)
@Update
suspend fun updateEntry(entryEntity: EntryEntity)
@Delete
suspend fun deleteCategory(category: CharCategory)
@Delete
suspend fun deleteEntry(entryEntity: EntryEntity)
@Query("SELECT * FROM category WHERE _id = :id")
suspend fun findCategoryById(id: Int) : CategoryEntity
@Query("SELECT * FROM category")
fun getAllCategory(): Flow<List<CategoryEntity>>
@Query("SELECT * FROM transaction WHERE _id = :id")
suspend fun findEntryById(id: Int) : EntryEntity
@Query("SELECT * FROM transaction")
fun getAllEntries(): Flow<List<EntryEntity>>
}

View File

@ -0,0 +1,12 @@
package at.xaxa.ledger.data.db
import androidx.room.Database
import androidx.room.RoomDatabase
import at.xaxa.ledger.data.db.Category.CategoryEntity
import at.xaxa.ledger.data.db.Entry.EntryEntity
@Database(entities = [EntryEntity::class, CategoryEntity::class], version = 1, exportSchema = false)
abstract class LedgerDatabase : RoomDatabase() {
abstract fun entryDao(): EntryDao
abstract fun categoryDao(): CategoryDao
}

View File

@ -0,0 +1,5 @@
package at.xaxa.ledger.ui
object AppViewModelProvider {
}

View File

@ -0,0 +1,2 @@
package at.xaxa.ledger.ui.add

View File

@ -0,0 +1,2 @@
package at.xaxa.ledger.ui.add

View File

@ -0,0 +1,2 @@
package at.xaxa.ledger.ui.edit

View File

@ -0,0 +1,2 @@
package at.xaxa.ledger.ui.edit

View File

@ -0,0 +1,2 @@
package at.xaxa.ledger.ui.home

View File

@ -0,0 +1,2 @@
package at.xaxa.ledger.ui.home

View File

@ -8,6 +8,8 @@ espressoCore = "3.6.1"
lifecycleRuntimeKtx = "2.8.7"
activityCompose = "1.9.3"
composeBom = "2024.04.01"
roomCommon = "2.6.1"
roomKtx = "2.6.1"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@ -24,6 +26,8 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-room-common = { group = "androidx.room", name = "room-common", version.ref = "roomCommon" }
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "roomKtx" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }