forked from github/szkolny
[Agenda] Implement updating event list when changed.
This commit is contained in:
parent
2d6cf50ca7
commit
98bf4f3bdc
@ -84,6 +84,8 @@ abstract class TimetableDao : BaseDao<Lesson, LessonFull> {
|
|||||||
"LIMIT 1")
|
"LIMIT 1")
|
||||||
fun getBetweenDates(dateFrom: Date, dateTo: Date) =
|
fun getBetweenDates(dateFrom: Date, dateTo: Date) =
|
||||||
getRaw("$QUERY WHERE (type != 3 AND date >= '${dateFrom.stringY_m_d}' AND date <= '${dateTo.stringY_m_d}') OR ((type = 3 OR type = 1) AND oldDate >= '${dateFrom.stringY_m_d}' AND oldDate <= '${dateTo.stringY_m_d}') $ORDER_BY")
|
getRaw("$QUERY WHERE (type != 3 AND date >= '${dateFrom.stringY_m_d}' AND date <= '${dateTo.stringY_m_d}') OR ((type = 3 OR type = 1) AND oldDate >= '${dateFrom.stringY_m_d}' AND oldDate <= '${dateTo.stringY_m_d}') $ORDER_BY")
|
||||||
|
fun getChanges(profileId: Int) =
|
||||||
|
getRaw("$QUERY WHERE timetable.profileId = $profileId AND $IS_CHANGED $ORDER_BY")
|
||||||
|
|
||||||
// GET ALL - NOW
|
// GET ALL - NOW
|
||||||
fun getAllNow(profileId: Int) =
|
fun getAllNow(profileId: Int) =
|
||||||
|
@ -20,7 +20,6 @@ import org.greenrobot.eventbus.EventBus
|
|||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
import org.greenrobot.eventbus.ThreadMode
|
import org.greenrobot.eventbus.ThreadMode
|
||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_AGENDA
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.ApiTaskAllFinishedEvent
|
import pl.szczodrzynski.edziennik.data.api.events.ApiTaskAllFinishedEvent
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.ApiTaskErrorEvent
|
import pl.szczodrzynski.edziennik.data.api.events.ApiTaskErrorEvent
|
||||||
@ -599,8 +598,6 @@ class EventManualDialog(
|
|||||||
|
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
Toast.makeText(activity, R.string.saved, Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, R.string.saved, Toast.LENGTH_SHORT).show()
|
||||||
if (activity is MainActivity && activity.navTargetId == DRAWER_ITEM_AGENDA)
|
|
||||||
activity.reloadTarget()
|
|
||||||
}
|
}
|
||||||
private fun finishRemoving() {
|
private fun finishRemoving() {
|
||||||
editingEvent ?: return
|
editingEvent ?: return
|
||||||
@ -613,7 +610,5 @@ class EventManualDialog(
|
|||||||
removeEventDialog?.dismiss()
|
removeEventDialog?.dismiss()
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
Toast.makeText(activity, R.string.removed, Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, R.string.removed, Toast.LENGTH_SHORT).show()
|
||||||
if (activity is MainActivity && activity.navTargetId == DRAWER_ITEM_AGENDA)
|
|
||||||
activity.reloadTarget()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ class AgendaFragment : Fragment(), CoroutineScope {
|
|||||||
EventManualDialog(
|
EventManualDialog(
|
||||||
activity,
|
activity,
|
||||||
app.profileId,
|
app.profileId,
|
||||||
defaultDate = agendaDefault?.selectedDate
|
defaultDate = AgendaFragmentDefault.selectedDate
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
BottomSheetPrimaryItem(true)
|
BottomSheetPrimaryItem(true)
|
||||||
@ -112,7 +112,11 @@ class AgendaFragment : Fragment(), CoroutineScope {
|
|||||||
activity.navView.bottomBar.fabExtendedText = getString(R.string.add)
|
activity.navView.bottomBar.fabExtendedText = getString(R.string.add)
|
||||||
activity.navView.bottomBar.fabIcon = CommunityMaterial.Icon3.cmd_plus
|
activity.navView.bottomBar.fabIcon = CommunityMaterial.Icon3.cmd_plus
|
||||||
activity.navView.setFabOnClickListener {
|
activity.navView.setFabOnClickListener {
|
||||||
EventManualDialog(activity, app.profileId, defaultDate = agendaDefault?.selectedDate)
|
EventManualDialog(
|
||||||
|
activity,
|
||||||
|
app.profileId,
|
||||||
|
defaultDate = AgendaFragmentDefault.selectedDate
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
activity.gainAttention()
|
activity.gainAttention()
|
||||||
|
@ -7,7 +7,10 @@ package pl.szczodrzynski.edziennik.ui.modules.agenda
|
|||||||
import android.util.SparseIntArray
|
import android.util.SparseIntArray
|
||||||
import androidx.core.util.forEach
|
import androidx.core.util.forEach
|
||||||
import androidx.core.util.set
|
import androidx.core.util.set
|
||||||
|
import com.github.tibolte.agendacalendarview.CalendarManager
|
||||||
import com.github.tibolte.agendacalendarview.CalendarPickerController
|
import com.github.tibolte.agendacalendarview.CalendarPickerController
|
||||||
|
import com.github.tibolte.agendacalendarview.agenda.AgendaAdapter
|
||||||
|
import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent
|
||||||
import com.github.tibolte.agendacalendarview.models.CalendarEvent
|
import com.github.tibolte.agendacalendarview.models.CalendarEvent
|
||||||
import com.github.tibolte.agendacalendarview.models.IDayItem
|
import com.github.tibolte.agendacalendarview.models.IDayItem
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -15,6 +18,7 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
import pl.szczodrzynski.edziennik.MainActivity
|
import pl.szczodrzynski.edziennik.MainActivity
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||||
import pl.szczodrzynski.edziennik.databinding.FragmentAgendaDefaultBinding
|
import pl.szczodrzynski.edziennik.databinding.FragmentAgendaDefaultBinding
|
||||||
import pl.szczodrzynski.edziennik.ui.dialogs.day.DayDialog
|
import pl.szczodrzynski.edziennik.ui.dialogs.day.DayDialog
|
||||||
import pl.szczodrzynski.edziennik.ui.dialogs.lessonchange.LessonChangeDialog
|
import pl.szczodrzynski.edziennik.ui.dialogs.lessonchange.LessonChangeDialog
|
||||||
@ -33,30 +37,39 @@ class AgendaFragmentDefault(
|
|||||||
private val app: App,
|
private val app: App,
|
||||||
private val b: FragmentAgendaDefaultBinding
|
private val b: FragmentAgendaDefaultBinding
|
||||||
) {
|
) {
|
||||||
|
companion object {
|
||||||
|
var selectedDate: Date = Date.getToday()
|
||||||
|
}
|
||||||
|
|
||||||
private val unreadDates = mutableSetOf<Int>()
|
private val unreadDates = mutableSetOf<Int>()
|
||||||
var selectedDate: Date = Date.getToday()
|
private val events = mutableListOf<CalendarEvent>()
|
||||||
|
private var isInitialized = false
|
||||||
|
|
||||||
suspend fun initView(fragment: AgendaFragment) {
|
suspend fun initView(fragment: AgendaFragment) {
|
||||||
val dateStart = app.profile.dateSemester1Start.asCalendar
|
isInitialized = false
|
||||||
val dateEnd = app.profile.dateYearEnd.asCalendar
|
|
||||||
|
|
||||||
val events = withContext(Dispatchers.Default) {
|
|
||||||
val events = mutableListOf<CalendarEvent>()
|
|
||||||
|
|
||||||
|
withContext(Dispatchers.Default) {
|
||||||
addLessonChanges(events)
|
addLessonChanges(events)
|
||||||
|
|
||||||
val showTeacherAbsences = app.profile.getStudentData("showTeacherAbsences", true)
|
val showTeacherAbsences = app.profile.getStudentData("showTeacherAbsences", true)
|
||||||
if (showTeacherAbsences) {
|
if (showTeacherAbsences) {
|
||||||
addTeacherAbsence(events)
|
addTeacherAbsence(events)
|
||||||
}
|
}
|
||||||
|
|
||||||
addEvents(events)
|
|
||||||
|
|
||||||
return@withContext events
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fragment.isAdded)
|
app.db.eventDao().getAll(app.profileId).observe(fragment) {
|
||||||
return
|
addEvents(events, it)
|
||||||
|
if (isInitialized)
|
||||||
|
updateView()
|
||||||
|
else
|
||||||
|
initViewPriv()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initViewPriv() {
|
||||||
|
val dateStart = app.profile.dateSemester1Start.asCalendar
|
||||||
|
val dateEnd = app.profile.dateYearEnd.asCalendar
|
||||||
|
|
||||||
b.agendaDefaultView.init(
|
b.agendaDefaultView.init(
|
||||||
events,
|
events,
|
||||||
dateStart,
|
dateStart,
|
||||||
@ -71,7 +84,11 @@ class AgendaFragmentDefault(
|
|||||||
when (event) {
|
when (event) {
|
||||||
is AgendaEvent -> DayDialog(activity, app.profileId, date)
|
is AgendaEvent -> DayDialog(activity, app.profileId, date)
|
||||||
is LessonChangesEvent -> LessonChangeDialog(activity, app.profileId, date)
|
is LessonChangesEvent -> LessonChangeDialog(activity, app.profileId, date)
|
||||||
is TeacherAbsenceEvent -> TeacherAbsenceDialog(activity, app.profileId, date)
|
is TeacherAbsenceEvent -> TeacherAbsenceDialog(
|
||||||
|
activity,
|
||||||
|
app.profileId,
|
||||||
|
date
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,10 +108,25 @@ class AgendaFragmentDefault(
|
|||||||
LessonChangesEventRenderer(),
|
LessonChangesEventRenderer(),
|
||||||
TeacherAbsenceEventRenderer()
|
TeacherAbsenceEventRenderer()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
isInitialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addEvents(events: MutableList<CalendarEvent>) {
|
private fun updateView() {
|
||||||
val eventList = app.db.eventDao().getAllNow(app.profileId)
|
val manager = CalendarManager.getInstance()
|
||||||
|
manager.events.clear()
|
||||||
|
manager.loadEvents(events, BaseCalendarEvent())
|
||||||
|
|
||||||
|
val adapter = b.agendaDefaultView.agendaView.agendaListView.adapter as? AgendaAdapter
|
||||||
|
adapter?.updateEvents(manager.events)
|
||||||
|
b.agendaDefaultView.agendaView.agendaListView.scrollToCurrentDate(selectedDate.asCalendar)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addEvents(
|
||||||
|
events: MutableList<CalendarEvent>,
|
||||||
|
eventList: List<EventFull>
|
||||||
|
) {
|
||||||
|
events.removeAll { it is AgendaEvent }
|
||||||
|
|
||||||
events += eventList.map {
|
events += eventList.map {
|
||||||
if (!it.seen)
|
if (!it.seen)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user