[Event] Add isDone attribute and marking events as done.

This commit is contained in:
Kacper Ziubryniewicz 2020-03-30 18:19:03 +02:00
parent 8c869d082b
commit b9f83875a0
7 changed files with 40 additions and 6 deletions

View File

@ -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()
}
}

View File

@ -40,6 +40,7 @@ abstract class EventDao : BaseDao<Event, EventFull> {
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<Event, EventFull> {
abstract override fun getRaw(query: SupportSQLiteQuery): LiveData<List<EventFull>>
// 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<Event>) = selective.updateAll(items)
@ -65,8 +66,8 @@ abstract class EventDao : BaseDao<Event, EventFull> {
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) =

View File

@ -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<Long>? = null

View File

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

View File

@ -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()

View File

@ -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

View File

@ -195,6 +195,18 @@
android:text="\uFCDA"
android:textSize="20sp"
android:fontFamily="@font/community_material_font_v3_5_95_1" />
<com.google.android.material.button.MaterialButton
android:id="@+id/checkDoneButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:minWidth="0dp"
android:checkable="true"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:text="\uFCE1"
android:textSize="20sp"
android:fontFamily="@font/community_material_font_v3_5_95_1" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>