Commit e95bdd14 authored by Filip Wiesner's avatar Filip Wiesner

Working UserNotes on events

parent 347e3f55
......@@ -7,6 +7,8 @@ import com.cvut.blackbird.extensions.withDefault
import com.cvut.blackbird.flows.BlackBirdVM
import com.cvut.blackbird.model.entities.DetailedEvent
import com.cvut.blackbird.model.entities.Event
import com.cvut.blackbird.model.entities.EventNote
import com.cvut.blackbird.model.entities.Note
import com.cvut.blackbird.model.flows.EventDetailModel
interface EventDetailVM {
......@@ -38,21 +40,14 @@ class EventDetailViewModel: BlackBirdVM(), EventDetailVM {
}
}
@Suppress("UNREACHABLE_CODE")
override fun changeEventNote(text: String) {
return //TODO
startJob("note") {
startJob("userNote") {
if (detailedEvent.dontHaveValue()) return@startJob
val note = if (detailedEvent.value?.userNotes?.firstOrNull() != null)
detailedEvent.value!!.userNotes.first()
else
model.createNote(detailedEvent.value!!.event.id)
// TODO: You will create note every time because the change in DB wont propagate here (event is not LD)
model.updateNote(note.apply { this.note = text })
val userNote = detailedEvent.value!!.userNote
model.updateNote(userNote.apply {
note = text
})
}
}
}
\ No newline at end of file
......@@ -154,7 +154,7 @@ class PinnedViewHolder(view: View, context: Context) : TaskViewHolder(view, cont
if (pinnedEvent.note?.cs != null) {
view.pin_description.setVisible()
view.pin_description.text = pinnedEvent.note.cs
view.pin_description.text = "${pinnedEvent.note.cs}\n\n"//TODO pass user note here
}
view.pin_unpinBtn.setOnClickListener { pinnedEvent.isPinned = !pinnedEvent.isPinned }
......
......@@ -3,6 +3,7 @@ package com.cvut.blackbird.model
import com.cvut.blackbird.BlackBirdAC
import com.cvut.blackbird.BlackBirdAC.Companion.log
import com.cvut.blackbird.model.database.EventDao
import com.cvut.blackbird.model.database.insertAll
import com.cvut.blackbird.model.services.AuthInfo
import com.cvut.blackbird.model.services.AuthService
import com.cvut.blackbird.model.services.SiriusService
......
......@@ -36,10 +36,10 @@ interface EventDao {
fun updateEvent(event: Event)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll(events: List<Event>)
fun insertAllEvents(events: List<Event>)
@Query("DELETE FROM Event")
fun deleteAll()
fun deleteAllEvents()
/** DETAILED EVENT */
......@@ -50,6 +50,9 @@ interface EventDao {
/** EVENT - NOTE*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAllNotes(notes: List<EventNote>)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun saveEventNote(eventNote: EventNote)
......@@ -57,6 +60,11 @@ interface EventDao {
fun deleteAllNotes()
}
fun EventDao.insertAll(events: List<Event>) {
insertAllEvents(events)
insertAllNotes(events.map { EventNote(it.id) })
}
fun EventDao.getTeachers(): List<String> {
val raw = getRawTeachers()
val convertor = DBTypeConverters()
......
......@@ -28,4 +28,6 @@ data class DetailedEvent (
if (event.linked?.teachers?.isEmpty() == true) return
teacherList = teacherDao.getTeachers(event.linked!!.teachers!!)
}
val userNote get() = userNotes.first()
}
\ No newline at end of file
......@@ -20,7 +20,7 @@ class ProfileModel: BlackBirdModel() {
}
suspend fun deleteDB() {
eventDao.deleteAll()
eventDao.deleteAllEvents()
eventDao.deleteAllNotes()
courseDao.deleteAll()
teacherDao.deleteAll()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment