Skip to content

Commit

Permalink
last modified date
Browse files Browse the repository at this point in the history
  • Loading branch information
seamuslowry committed Sep 9, 2024
1 parent 810c1ff commit 92707e4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/src/main/java/seamuslowry/daytracker/data/room/Converters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@ import androidx.room.TypeConverter
import seamuslowry.daytracker.models.LimitedOptionTrackingType
import seamuslowry.daytracker.models.TextEntryTrackingType
import seamuslowry.daytracker.models.TrackingType
import java.time.Instant
import java.time.LocalDate

class Converters {
// Instant conversions
@TypeConverter
fun epochMillisToInstant(value: Long?): Instant? {
return value?.let { Instant.ofEpochMilli(it) }
}

@TypeConverter
fun instantToEpochMillis(instant: Instant?): Long? {
return instant?.toEpochMilli()
}

// LocalDate conversions
@TypeConverter
fun epochDayToLocalDate(value: Long?): LocalDate? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ val MIGRATION_6_7: Migration = object : Migration(6, 7) {

val MIGRATION_7_8: Migration = object : Migration(7, 8) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE Item_Configuration ADD COLUMN orderOverride INTEGER")
db.execSQL("ALTER TABLE Item_Configuration ADD COLUMN orderOverride INTEGER;")
db.execSQL("ALTER TABLE Item_Configuration ADD COLUMN lastModifiedDate INTEGER NOT NULL DEFAULT(unixepoch('subsec') * 1000);")
// trigger to update last modified date on updates
db.execSQL("""
CREATE TRIGGER update_lastModifiedDate_trigger
AFTER UPDATE ON Item_Configuration
FOR EACH ROW
WHEN NEW.lastModifiedDate = OLD.lastModifiedDate
BEGIN
UPDATE Item_Configuration
SET lastModifiedDate = unixepoch('subsec') * 1000
WHERE id = OLD.id;
END;
""")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package seamuslowry.daytracker.models

import androidx.room.Entity
import androidx.room.PrimaryKey
import java.time.Instant

@Entity(tableName = "item_configuration")
data class ItemConfiguration(
Expand All @@ -11,6 +12,7 @@ data class ItemConfiguration(
val trackingType: TrackingType = LimitedOptionTrackingType.ONE_TO_TEN,
val active: Boolean = true,
val orderOverride: Long? = null,
val lastModifiedDate: Instant = Instant.now()
) : Comparable<ItemConfiguration> {
override fun compareTo(other: ItemConfiguration): Int = order.compareTo(other.order)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seamuslowry.daytracker.ui.screens.entry

import android.util.Log
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.animateIntAsState
Expand Down Expand Up @@ -88,6 +89,8 @@ fun EntryScreen(
val date by viewModel.date.collectAsState()
val scope = rememberCoroutineScope()

Log.d(TAG, items.toString())

val itemsUpdatedChannel = remember { Channel<Unit>() }

val lazyColumnState = rememberLazyListState()
Expand Down

0 comments on commit 92707e4

Please sign in to comment.