mirror of
https://github.com/mudabbir-ahmad/Kotlin-TB2P1.git
synced 2026-12-06 20:13:10 +00:00
Refactor habit tracking app: update Gradle settings, add type converters, and improve UI components
This commit is contained in:
1 parent
f838d1f628
commit
1904106d16
8 files changed
+47
-10
No files matched your search
@@ -0,0 +1 @@
|
||||
/build
|
||||
@@ -2,15 +2,12 @@ plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
alias(libs.plugins.ksp)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.example.madwellbeingapp"
|
||||
compileSdk {
|
||||
version = release(36) {
|
||||
minorApiLevel = 1
|
||||
}
|
||||
}
|
||||
compileSdk = 36
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.example.madwellbeingapp"
|
||||
@@ -32,12 +29,15 @@ android {
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
buildFeatures {
|
||||
compose = true
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -53,6 +53,7 @@ dependencies {
|
||||
// Room
|
||||
implementation(libs.androidx.room.runtime)
|
||||
implementation(libs.androidx.room.ktx)
|
||||
implementation(libs.core.ktx)
|
||||
ksp(libs.androidx.room.compiler)
|
||||
|
||||
// Navigation Compose
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.example.madwellbeingapp.data
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.example.madwellbeingapp.data.model.HabitCategory
|
||||
|
||||
class Converters {
|
||||
|
||||
@TypeConverter
|
||||
fun fromCategory(category: HabitCategory): String {
|
||||
return category.name
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toCategory(value: String): HabitCategory {
|
||||
return HabitCategory.valueOf(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import com.example.madwellbeingapp.data.dao.HabitDao
|
||||
import com.example.madwellbeingapp.data.dao.HabitLogDao
|
||||
import com.example.madwellbeingapp.data.model.Habit
|
||||
import com.example.madwellbeingapp.data.model.HabitLog
|
||||
|
||||
@Database(entities = [Habit::class, HabitLog::class], version = 1, exportSchema = false)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class HabitDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun habitDao(): HabitDao
|
||||
|
||||
@@ -16,7 +16,7 @@ interface HabitDao {
|
||||
suspend fun insert(habit: Habit): Long
|
||||
|
||||
@Update
|
||||
suspend fun update(habit: Habit)
|
||||
suspend fun update(habit: Habit): Int
|
||||
|
||||
@Delete
|
||||
suspend fun delete(habit: Habit): Int
|
||||
|
||||
@@ -22,7 +22,6 @@ import androidx.compose.material3.ExposedDropdownMenuDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.MenuAnchorType
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Switch
|
||||
@@ -132,7 +131,7 @@ fun AddEditHabitScreen(
|
||||
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = categoryExpanded) },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.menuAnchor(MenuAnchorType.PrimaryNotEditable),
|
||||
.menuAnchor(),
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
)
|
||||
ExposedDropdownMenu(
|
||||
|
||||
Reference in new issue
Block a user