mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 12:56:45 -06:00
[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")
|
||||
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")
|
||||
fun getChanges(profileId: Int) =
|
||||
getRaw("$QUERY WHERE timetable.profileId = $profileId AND $IS_CHANGED $ORDER_BY")
|
||||
|
||||
// GET ALL - NOW
|
||||
fun getAllNow(profileId: Int) =
|
||||
|
@ -20,7 +20,6 @@ import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
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.events.ApiTaskAllFinishedEvent
|
||||
import pl.szczodrzynski.edziennik.data.api.events.ApiTaskErrorEvent
|
||||
@ -599,8 +598,6 @@ class EventManualDialog(
|
||||
|
||||
dialog.dismiss()
|
||||
Toast.makeText(activity, R.string.saved, Toast.LENGTH_SHORT).show()
|
||||
if (activity is MainActivity && activity.navTargetId == DRAWER_ITEM_AGENDA)
|
||||
activity.reloadTarget()
|
||||
}
|
||||
private fun finishRemoving() {
|
||||
editingEvent ?: return
|
||||
@ -613,7 +610,5 @@ class EventManualDialog(
|
||||
removeEventDialog?.dismiss()
|
||||
dialog.dismiss()
|
||||
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(
|
||||
activity,
|
||||
app.profileId,
|
||||
defaultDate = agendaDefault?.selectedDate
|
||||
defaultDate = AgendaFragmentDefault.selectedDate
|
||||
)
|
||||
},
|
||||
BottomSheetPrimaryItem(true)
|
||||
@ -112,7 +112,11 @@ class AgendaFragment : Fragment(), CoroutineScope {
|
||||
activity.navView.bottomBar.fabExtendedText = getString(R.string.add)
|
||||
activity.navView.bottomBar.fabIcon = CommunityMaterial.Icon3.cmd_plus
|
||||
activity.navView.setFabOnClickListener {
|
||||
EventManualDialog(activity, app.profileId, defaultDate = agendaDefault?.selectedDate)
|
||||
EventManualDialog(
|
||||
activity,
|
||||
app.profileId,
|
||||
defaultDate = AgendaFragmentDefault.selectedDate
|
||||
)
|
||||
}
|
||||
|
||||
activity.gainAttention()
|
||||
|
@ -7,7 +7,10 @@ package pl.szczodrzynski.edziennik.ui.modules.agenda
|
||||
import android.util.SparseIntArray
|
||||
import androidx.core.util.forEach
|
||||
import androidx.core.util.set
|
||||
import com.github.tibolte.agendacalendarview.CalendarManager
|
||||
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.IDayItem
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -15,6 +18,7 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentAgendaDefaultBinding
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.day.DayDialog
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.lessonchange.LessonChangeDialog
|
||||
@ -33,30 +37,39 @@ class AgendaFragmentDefault(
|
||||
private val app: App,
|
||||
private val b: FragmentAgendaDefaultBinding
|
||||
) {
|
||||
companion object {
|
||||
var selectedDate: Date = Date.getToday()
|
||||
}
|
||||
|
||||
private val unreadDates = mutableSetOf<Int>()
|
||||
var selectedDate: Date = Date.getToday()
|
||||
private val events = mutableListOf<CalendarEvent>()
|
||||
private var isInitialized = false
|
||||
|
||||
suspend fun initView(fragment: AgendaFragment) {
|
||||
val dateStart = app.profile.dateSemester1Start.asCalendar
|
||||
val dateEnd = app.profile.dateYearEnd.asCalendar
|
||||
|
||||
val events = withContext(Dispatchers.Default) {
|
||||
val events = mutableListOf<CalendarEvent>()
|
||||
isInitialized = false
|
||||
|
||||
withContext(Dispatchers.Default) {
|
||||
addLessonChanges(events)
|
||||
|
||||
val showTeacherAbsences = app.profile.getStudentData("showTeacherAbsences", true)
|
||||
if (showTeacherAbsences) {
|
||||
addTeacherAbsence(events)
|
||||
}
|
||||
|
||||
addEvents(events)
|
||||
|
||||
return@withContext events
|
||||
}
|
||||
|
||||
if (!fragment.isAdded)
|
||||
return
|
||||
app.db.eventDao().getAll(app.profileId).observe(fragment) {
|
||||
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(
|
||||
events,
|
||||
dateStart,
|
||||
@ -71,7 +84,11 @@ class AgendaFragmentDefault(
|
||||
when (event) {
|
||||
is AgendaEvent -> DayDialog(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(),
|
||||
TeacherAbsenceEventRenderer()
|
||||
)
|
||||
|
||||
isInitialized = true
|
||||
}
|
||||
|
||||
private fun addEvents(events: MutableList<CalendarEvent>) {
|
||||
val eventList = app.db.eventDao().getAllNow(app.profileId)
|
||||
private fun updateView() {
|
||||
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 {
|
||||
if (!it.seen)
|
||||
|
Loading…
x
Reference in New Issue
Block a user