data files setup

This commit is contained in:
Florian 2025-01-13 14:54:08 +01:00
parent 4057fc30f5
commit 5aae7b45dc
17 changed files with 171 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,4 @@
package at.xaxa.ledger.data
class Entry {
}

View File

@ -0,0 +1,4 @@
package at.xaxa.ledger.data
class EntryRepository {
}

View File

@ -0,0 +1,30 @@
package at.xaxa.ledger.data.db.Category
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.Entry.EntryEntity
import kotlinx.coroutines.flow.Flow
@Dao
interface CategoryDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun addCategory(entryEntity: CategoryEntity)
@Update
suspend fun updateCategory(category: CharCategory)
@Delete
suspend fun deleteCategory(category: CharCategory)
@Query("SELECT * FROM category WHERE _id = :id")
suspend fun findCategoryById(id: Int) : CategoryEntity
@Query("SELECT * FROM category")
fun getAllCategory(): Flow<List<CategoryEntity>>
}

View File

@ -0,0 +1,28 @@
package at.xaxa.ledger.data.db.Category
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import at.xaxa.ledger.data.db.Entry.EntryDao
@Database(entities = [CategoryEntity::class], version = 1)
abstract class CategoryDatabase : RoomDatabase() {
abstract fun CategoryDao(): EntryDao
companion object {
@Volatile
private var Instance: CategoryDatabase? = null
fun getDatabase(context: Context): CategoryDatabase {
return Instance ?: synchronized(this){
val instance =
Room.databaseBuilder(context, CategoryDatabase::class.java, "finance_database")
.fallbackToDestructiveMigration()
.build()
Instance = instance
return instance
}
}
}
}

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 name: String,
val icon: Int
)

View File

@ -0,0 +1,29 @@
package at.xaxa.ledger.data.db.Entry
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 kotlinx.coroutines.flow.Flow
@Dao
interface EntryDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun addEntry(entryEntity: EntryEntity)
@Update
suspend fun updateEntry(entryEntity: EntryEntity)
@Delete
suspend fun deleteEntry(entryEntity: EntryEntity)
@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,27 @@
package at.xaxa.ledger.data.db.Entry
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
@Database(entities = [EntryEntity::class], version = 1)
abstract class EntryDatabase : RoomDatabase() {
abstract fun EntryDao(): EntryDao
companion object {
@Volatile
private var Instance: EntryDatabase? = null
fun getDatabase(context: Context): EntryDatabase {
return Instance ?: synchronized(this){
val instance =
Room.databaseBuilder(context, EntryDatabase::class.java, "finance_database")
.fallbackToDestructiveMigration()
.build()
Instance = instance
return 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 category: Int
)

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" }