diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt index 836e6d84..49afa827 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt @@ -43,7 +43,7 @@ import pl.szczodrzynski.edziennik.data.db.migration.* LibrusLesson::class, TimetableManual::class, Metadata::class -], version = 81) +], version = 82) @TypeConverters( ConverterTime::class, ConverterDate::class, @@ -166,7 +166,8 @@ abstract class AppDb : RoomDatabase() { Migration78(), Migration79(), Migration80(), - Migration81() + Migration81(), + Migration82() ).allowMainThreadQueries().build() } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/EventDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/EventDao.kt index fbaccf30..c2efdf2c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/EventDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/EventDao.kt @@ -40,6 +40,7 @@ abstract class EventDao : BaseDao { private const val ORDER_BY = """GROUP BY eventId ORDER BY eventDate, eventTime, addedDate ASC""" private const val NOT_BLACKLISTED = """events.eventBlacklisted = 0""" + private const val NOT_DONE = """events.eventIsDone = 0""" } private val selective by lazy { EventDaoSelective(App.db) } @@ -48,7 +49,7 @@ abstract class EventDao : BaseDao { abstract override fun getRaw(query: SupportSQLiteQuery): LiveData> // SELECTIVE UPDATE - @UpdateSelective(primaryKeys = ["profileId", "eventId"], skippedColumns = ["homeworkBody", "attachmentIds", "attachmentNames"]) + @UpdateSelective(primaryKeys = ["profileId", "eventId"], skippedColumns = ["eventIsDone", "eventBlacklisted", "homeworkBody", "attachmentIds", "attachmentNames"]) override fun update(item: Event) = selective.update(item) override fun updateAll(items: List) = selective.updateAll(items) @@ -65,8 +66,8 @@ abstract class EventDao : BaseDao { getRaw("$QUERY WHERE $NOT_BLACKLISTED AND events.profileId = $profileId AND eventDate = '${date.stringY_m_d}' $ORDER_BY") fun getAllByDateTime(profileId: Int, date: Date, time: Time) = getRaw("$QUERY WHERE $NOT_BLACKLISTED AND events.profileId = $profileId AND eventDate = '${date.stringY_m_d}' AND eventTime = ${time.stringValue}") - fun getAllNearest(profileId: Int, today: Date, limit: Int) = - getRaw("$QUERY WHERE $NOT_BLACKLISTED AND events.profileId = $profileId AND eventDate >= '${today.stringY_m_d}' $ORDER_BY LIMIT $limit") + fun getNearestNotDone(profileId: Int, today: Date, limit: Int) = + getRaw("$QUERY WHERE $NOT_BLACKLISTED AND $NOT_DONE AND events.profileId = $profileId AND eventDate >= '${today.stringY_m_d}' $ORDER_BY LIMIT $limit") // GET ALL - NOW fun getAllNow(profileId: Int) = diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Event.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Event.kt index 64c6de8e..f14ac32e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Event.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Event.kt @@ -79,6 +79,8 @@ open class Event( var sharedByName: String? = null @ColumnInfo(name = "eventBlacklisted") var blacklisted: Boolean = false + @ColumnInfo(name = "eventIsDone") + var isDone: Boolean = false var homeworkBody: String? = null var attachmentIds: List? = null diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration82.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration82.kt new file mode 100644 index 00000000..b0e1c769 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration82.kt @@ -0,0 +1,10 @@ +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration82 : Migration(81, 82) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE events ADD COLUMN eventIsDone INTEGER DEFAULT 0 NOT NULL") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt index a5a682c6..cea275ea 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt @@ -161,6 +161,14 @@ class EventDetailsDialog( true } + b.checkDoneButton.isChecked = event.isDone + b.checkDoneButton.addOnCheckedChangeListener { _, isChecked -> + event.isDone = isChecked + launch(Dispatchers.Default) { + app.db.eventDao().replace(event) + } + } + b.topic.text = event.topic BetterLink.attach(b.topic) { dialog.dismiss() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeEventsCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeEventsCard.kt index e6b2b23b..bcff527a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeEventsCard.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeEventsCard.kt @@ -77,7 +77,7 @@ class HomeEventsCard( } ) - app.db.eventDao().getAllNearest(profile.id, Date.getToday(), 4).observe(activity, Observer { events -> + app.db.eventDao().getNearestNotDone(profile.id, Date.getToday(), 4).observe(activity, Observer { events -> adapter.items = events if (b.eventsView.adapter == null) { b.eventsView.adapter = adapter diff --git a/app/src/main/res/layout/dialog_event_details.xml b/app/src/main/res/layout/dialog_event_details.xml index f6df2154..d06c71bb 100644 --- a/app/src/main/res/layout/dialog_event_details.xml +++ b/app/src/main/res/layout/dialog_event_details.xml @@ -195,6 +195,18 @@ android:text="\uFCDA" android:textSize="20sp" android:fontFamily="@font/community_material_font_v3_5_95_1" /> + +