data files setup
This commit is contained in:
parent
4057fc30f5
commit
5aae7b45dc
@ -59,6 +59,8 @@ dependencies {
|
|||||||
implementation(libs.androidx.ui.graphics)
|
implementation(libs.androidx.ui.graphics)
|
||||||
implementation(libs.androidx.ui.tooling.preview)
|
implementation(libs.androidx.ui.tooling.preview)
|
||||||
implementation(libs.androidx.material3)
|
implementation(libs.androidx.material3)
|
||||||
|
implementation(libs.androidx.room.common)
|
||||||
|
implementation(libs.androidx.room.ktx)
|
||||||
testImplementation(libs.junit)
|
testImplementation(libs.junit)
|
||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
androidTestImplementation(libs.androidx.espresso.core)
|
androidTestImplementation(libs.androidx.espresso.core)
|
||||||
|
4
Ledger/app/src/main/java/at/xaxa/ledger/data/Entry.kt
Normal file
4
Ledger/app/src/main/java/at/xaxa/ledger/data/Entry.kt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package at.xaxa.ledger.data
|
||||||
|
|
||||||
|
class Entry {
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package at.xaxa.ledger.data
|
||||||
|
|
||||||
|
class EntryRepository {
|
||||||
|
}
|
@ -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>>
|
||||||
|
}
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
||||||
|
)
|
@ -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>>
|
||||||
|
}
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
||||||
|
)
|
@ -0,0 +1,5 @@
|
|||||||
|
package at.xaxa.ledger.ui
|
||||||
|
|
||||||
|
object AppViewModelProvider {
|
||||||
|
|
||||||
|
}
|
2
Ledger/app/src/main/java/at/xaxa/ledger/ui/add/AddUI.kt
Normal file
2
Ledger/app/src/main/java/at/xaxa/ledger/ui/add/AddUI.kt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
package at.xaxa.ledger.ui.add
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
package at.xaxa.ledger.ui.add
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
package at.xaxa.ledger.ui.edit
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
package at.xaxa.ledger.ui.edit
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
package at.xaxa.ledger.ui.home
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
package at.xaxa.ledger.ui.home
|
||||||
|
|
@ -8,6 +8,8 @@ espressoCore = "3.6.1"
|
|||||||
lifecycleRuntimeKtx = "2.8.7"
|
lifecycleRuntimeKtx = "2.8.7"
|
||||||
activityCompose = "1.9.3"
|
activityCompose = "1.9.3"
|
||||||
composeBom = "2024.04.01"
|
composeBom = "2024.04.01"
|
||||||
|
roomCommon = "2.6.1"
|
||||||
|
roomKtx = "2.6.1"
|
||||||
|
|
||||||
[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" }
|
||||||
@ -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-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
||||||
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
||||||
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-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "roomKtx" }
|
||||||
|
|
||||||
[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