mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[Event] Add isDone
attribute and marking events as done.
This commit is contained in:
parent
8c869d082b
commit
b9f83875a0
@ -43,7 +43,7 @@ import pl.szczodrzynski.edziennik.data.db.migration.*
|
|||||||
LibrusLesson::class,
|
LibrusLesson::class,
|
||||||
TimetableManual::class,
|
TimetableManual::class,
|
||||||
Metadata::class
|
Metadata::class
|
||||||
], version = 81)
|
], version = 82)
|
||||||
@TypeConverters(
|
@TypeConverters(
|
||||||
ConverterTime::class,
|
ConverterTime::class,
|
||||||
ConverterDate::class,
|
ConverterDate::class,
|
||||||
@ -166,7 +166,8 @@ abstract class AppDb : RoomDatabase() {
|
|||||||
Migration78(),
|
Migration78(),
|
||||||
Migration79(),
|
Migration79(),
|
||||||
Migration80(),
|
Migration80(),
|
||||||
Migration81()
|
Migration81(),
|
||||||
|
Migration82()
|
||||||
).allowMainThreadQueries().build()
|
).allowMainThreadQueries().build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 ORDER_BY = """GROUP BY eventId ORDER BY eventDate, eventTime, addedDate ASC"""
|
||||||
private const val NOT_BLACKLISTED = """events.eventBlacklisted = 0"""
|
private const val NOT_BLACKLISTED = """events.eventBlacklisted = 0"""
|
||||||
|
private const val NOT_DONE = """events.eventIsDone = 0"""
|
||||||
}
|
}
|
||||||
|
|
||||||
private val selective by lazy { EventDaoSelective(App.db) }
|
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>>
|
abstract override fun getRaw(query: SupportSQLiteQuery): LiveData<List<EventFull>>
|
||||||
|
|
||||||
// SELECTIVE UPDATE
|
// 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 update(item: Event) = selective.update(item)
|
||||||
override fun updateAll(items: List<Event>) = selective.updateAll(items)
|
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")
|
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) =
|
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}")
|
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) =
|
fun getNearestNotDone(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")
|
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
|
// GET ALL - NOW
|
||||||
fun getAllNow(profileId: Int) =
|
fun getAllNow(profileId: Int) =
|
||||||
|
@ -79,6 +79,8 @@ open class Event(
|
|||||||
var sharedByName: String? = null
|
var sharedByName: String? = null
|
||||||
@ColumnInfo(name = "eventBlacklisted")
|
@ColumnInfo(name = "eventBlacklisted")
|
||||||
var blacklisted: Boolean = false
|
var blacklisted: Boolean = false
|
||||||
|
@ColumnInfo(name = "eventIsDone")
|
||||||
|
var isDone: Boolean = false
|
||||||
|
|
||||||
var homeworkBody: String? = null
|
var homeworkBody: String? = null
|
||||||
var attachmentIds: List<Long>? = null
|
var attachmentIds: List<Long>? = null
|
||||||
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
@ -161,6 +161,14 @@ class EventDetailsDialog(
|
|||||||
true
|
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
|
b.topic.text = event.topic
|
||||||
BetterLink.attach(b.topic) {
|
BetterLink.attach(b.topic) {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
|
@ -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
|
adapter.items = events
|
||||||
if (b.eventsView.adapter == null) {
|
if (b.eventsView.adapter == null) {
|
||||||
b.eventsView.adapter = adapter
|
b.eventsView.adapter = adapter
|
||||||
|
@ -195,6 +195,18 @@
|
|||||||
android:text="\uFCDA"
|
android:text="\uFCDA"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:fontFamily="@font/community_material_font_v3_5_95_1" />
|
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>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user