diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Event.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Event.kt index 0dcaa83e..a3f44585 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Event.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Event.kt @@ -116,14 +116,7 @@ open class Event( var showAsUnseen: Boolean? = null val startTimeCalendar: Calendar - get() = Calendar.getInstance().also { it.set( - date.year, - date.month - 1, - date.day, - time?.hour ?: 0, - time?.minute ?: 0, - time?.second ?: 0 - ) } + get() = date.getAsCalendar(time) val endTimeCalendar: Calendar get() = startTimeCalendar.also { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.kt index 367b00da..dd3fbbbc 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.kt @@ -12,10 +12,6 @@ import android.widget.Toast import androidx.databinding.ViewDataBinding import androidx.fragment.app.Fragment import com.applandeo.materialcalendarview.EventDay -import com.github.tibolte.agendacalendarview.CalendarPickerController -import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent -import com.github.tibolte.agendacalendarview.models.CalendarEvent -import com.github.tibolte.agendacalendarview.models.IDayItem import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial import com.mikepenz.iconics.utils.colorInt @@ -31,15 +27,6 @@ import pl.szczodrzynski.edziennik.databinding.FragmentAgendaCalendarBinding import pl.szczodrzynski.edziennik.databinding.FragmentAgendaDefaultBinding import pl.szczodrzynski.edziennik.ui.dialogs.day.DayDialog import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog -import pl.szczodrzynski.edziennik.ui.dialogs.lessonchange.LessonChangeDialog -import pl.szczodrzynski.edziennik.ui.dialogs.teacherabsence.TeacherAbsenceDialog -import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange.LessonChangeCounter -import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange.LessonChangeEvent -import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange.LessonChangeEventRenderer -import pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence.TeacherAbsenceCounter -import pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence.TeacherAbsenceEvent -import pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence.TeacherAbsenceEventRenderer -import pl.szczodrzynski.edziennik.utils.Colors import pl.szczodrzynski.edziennik.utils.Themes import pl.szczodrzynski.edziennik.utils.models.Date import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem @@ -59,7 +46,8 @@ class AgendaFragment : Fragment(), CoroutineScope { get() = job + Dispatchers.Main private var type: Int = Profile.AGENDA_DEFAULT - private var actualDate: Date? = null + + private var agendaDefault: AgendaFragmentDefault? = null override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { if (getActivity() == null || context == null) return null @@ -82,38 +70,50 @@ class AgendaFragment : Fragment(), CoroutineScope { .withTitle(R.string.menu_add_event) .withDescription(R.string.menu_add_event_desc) .withIcon(SzkolnyFont.Icon.szf_calendar_plus_outline) - .withOnClickListener(View.OnClickListener { + .withOnClickListener { activity.bottomSheet.close() - EventManualDialog(activity, app.profileId, defaultDate = actualDate) - }), + EventManualDialog( + activity, + app.profileId, + defaultDate = agendaDefault?.selectedDate + ) + }, BottomSheetPrimaryItem(true) .withTitle(R.string.menu_agenda_change_view) .withIcon(if (type == Profile.AGENDA_DEFAULT) CommunityMaterial.Icon.cmd_calendar_outline else CommunityMaterial.Icon2.cmd_format_list_bulleted_square) - .withOnClickListener(View.OnClickListener { + .withOnClickListener { activity.bottomSheet.close() - type = if (type == Profile.AGENDA_DEFAULT) Profile.AGENDA_CALENDAR else Profile.AGENDA_DEFAULT + type = + if (type == Profile.AGENDA_DEFAULT) Profile.AGENDA_CALENDAR else Profile.AGENDA_DEFAULT app.config.forProfile().ui.agendaViewType = type activity.reloadTarget() - }), + }, BottomSheetSeparatorItem(true), BottomSheetPrimaryItem(true) .withTitle(R.string.menu_mark_as_read) .withIcon(CommunityMaterial.Icon.cmd_eye_check_outline) - .withOnClickListener(View.OnClickListener { launch { - activity.bottomSheet.close() - withContext(Dispatchers.Default) { - App.db.metadataDao().setAllSeen(app.profileId, Metadata.TYPE_EVENT, true) + .withOnClickListener { + launch { + activity.bottomSheet.close() + withContext(Dispatchers.Default) { + App.db.metadataDao() + .setAllSeen(app.profileId, Metadata.TYPE_EVENT, true) + } + Toast.makeText( + activity, + R.string.main_menu_mark_as_read_success, + Toast.LENGTH_SHORT + ).show() } - Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show() - }}) + } ) activity.navView.bottomBar.fabEnable = true activity.navView.bottomBar.fabExtendedText = getString(R.string.add) activity.navView.bottomBar.fabIcon = CommunityMaterial.Icon3.cmd_plus - activity.navView.setFabOnClickListener(View.OnClickListener { - EventManualDialog(activity, app.profileId, defaultDate = actualDate) - }) + activity.navView.setFabOnClickListener { + EventManualDialog(activity, app.profileId, defaultDate = agendaDefault?.selectedDate) + } activity.gainAttention() activity.gainAttentionFAB() @@ -129,141 +129,8 @@ class AgendaFragment : Fragment(), CoroutineScope { return@launch delay(500) - val eventList = mutableListOf() - - val minDate = Calendar.getInstance().apply { - add(Calendar.MONTH, -2) - set(Calendar.DAY_OF_MONTH, 1) - } - val maxDate = Calendar.getInstance().apply { add(Calendar.MONTH, 2) } - - /** - * LESSON CHANGES - */ - if (!isAdded) - return@launch - - val lessons = withContext(Dispatchers.Default) { app.db.timetableDao().getChangesNow(app.profileId) } - val lessonChangeCounters = mutableListOf() - - lessons.forEach { lesson -> - lessonChangeCounters.firstOrNull { it.lessonChangeDate == lesson.displayDate }?.let { - it.lessonChangeCount += 1 - } ?: run { - lessonChangeCounters.add(LessonChangeCounter( - lesson.displayDate ?: return@forEach, - 1 - )) - } - } - - lessonChangeCounters.forEach { counter -> - eventList.add(LessonChangeEvent( - counter.lessonChangeDate.inMillis, - 0xff78909c.toInt(), - Colors.legibleTextColor(0xff78909c.toInt()), - counter.startTime, - counter.endTime, - app.profileId, - counter.lessonChangeDate, - counter.lessonChangeCount - )) - } - - /** - * TEACHER ABSENCES - */ - if (!isAdded) - return@launch - - val showTeacherAbsences = app.profile.getStudentData("showTeacherAbsences", true) - - if (showTeacherAbsences) { - val teacherAbsenceList = withContext(Dispatchers.Default) { app.db.teacherAbsenceDao().getAllNow(app.profileId) } - val teacherAbsenceCounters = mutableListOf() - - teacherAbsenceList.forEach { absence -> - val date = absence.dateFrom.clone() - - while (date <= absence.dateTo) { - teacherAbsenceCounters.firstOrNull { it.teacherAbsenceDate == date }?.let { - it.teacherAbsenceCount += 1 - } ?: run { - teacherAbsenceCounters.add(TeacherAbsenceCounter(date.clone(), 1)) - } - - date.stepForward(0, 0, 1) - } - } - - teacherAbsenceCounters.forEach { counter -> - eventList.add(TeacherAbsenceEvent( - counter.teacherAbsenceDate.inMillis, - 0xffff1744.toInt(), - Colors.legibleTextColor(0xffff1744.toInt()), - counter.startTime, - counter.endTime, - app.profileId, - counter.teacherAbsenceDate, - counter.teacherAbsenceCount - )) - } - } - - /** - * EVENTS - */ - if (!isAdded) - return@launch - - val events = withContext(Dispatchers.Default) { app.db.eventDao().getAllNow(app.profileId) } - val unreadEventDates = mutableSetOf() - - events.forEach { event -> - eventList.add(BaseCalendarEvent( - "${event.typeName ?: "wydarzenie"} - ${event.topic}", - "", - (if (event.time == null) getString(R.string.agenda_event_all_day) else event.time!!.stringHM) + - (event.subjectLongName?.let { ", $it" } ?: "") + - (event.teacherName?.let { ", $it" } ?: "") + - (event.teamName?.let { ", $it" } ?: ""), - event.eventColor, - Colors.legibleTextColor(event.eventColor), - event.startTimeCalendar, - event.endTimeCalendar, - event.time == null, - event.id, - !event.seen - )) - - if (!event.seen) unreadEventDates.add(event.date.value) - } - - b.agendaDefaultView.init(eventList, minDate, maxDate, Locale.getDefault(), object : CalendarPickerController { - override fun onDaySelected(dayItem: IDayItem?) {} - - override fun onScrollToDate(calendar: Calendar) { this@AgendaFragment.launch { - val date = Date.fromCalendar(calendar) - actualDate = date - - // Mark as read scrolled date - if (date.value in unreadEventDates) { - withContext(Dispatchers.Default) { app.db.eventDao().setSeenByDate(app.profileId, date, true) } - unreadEventDates.remove(date.value) - } - }} - - override fun onEventSelected(event: CalendarEvent) { - val date = Date.fromCalendar(event.instanceDay) - - when (event) { - is BaseCalendarEvent -> DayDialog(activity, app.profileId, date) - is LessonChangeEvent -> LessonChangeDialog(activity, app.profileId, date) - is TeacherAbsenceEvent -> TeacherAbsenceDialog(activity, app.profileId, date) - } - } - - }, LessonChangeEventRenderer(), TeacherAbsenceEventRenderer()) + agendaDefault = AgendaFragmentDefault(activity, app, b) + agendaDefault?.initView(this@AgendaFragment) b.progressBar.visibility = View.GONE }}} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragmentDefault.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragmentDefault.kt new file mode 100644 index 00000000..9e4e31ab --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragmentDefault.kt @@ -0,0 +1,142 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2021-4-8. + */ + +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.CalendarPickerController +import com.github.tibolte.agendacalendarview.models.CalendarEvent +import com.github.tibolte.agendacalendarview.models.IDayItem +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import pl.szczodrzynski.edziennik.App +import pl.szczodrzynski.edziennik.MainActivity +import pl.szczodrzynski.edziennik.databinding.FragmentAgendaDefaultBinding +import pl.szczodrzynski.edziennik.ui.dialogs.day.DayDialog +import pl.szczodrzynski.edziennik.ui.dialogs.lessonchange.LessonChangeDialog +import pl.szczodrzynski.edziennik.ui.dialogs.teacherabsence.TeacherAbsenceDialog +import pl.szczodrzynski.edziennik.ui.modules.agenda.event.AgendaEvent +import pl.szczodrzynski.edziennik.ui.modules.agenda.event.AgendaEventRenderer +import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchanges.LessonChangesEvent +import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchanges.LessonChangesEventRenderer +import pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence.TeacherAbsenceEvent +import pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence.TeacherAbsenceEventRenderer +import pl.szczodrzynski.edziennik.utils.models.Date +import java.util.* + +class AgendaFragmentDefault( + private val activity: MainActivity, + private val app: App, + private val b: FragmentAgendaDefaultBinding +) { + private val unreadDates = mutableSetOf() + var selectedDate: Date = Date.getToday() + + 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() + + addLessonChanges(events) + + val showTeacherAbsences = app.profile.getStudentData("showTeacherAbsences", true) + if (showTeacherAbsences) { + addTeacherAbsence(events) + } + + addEvents(events) + + return@withContext events + } + + if (!fragment.isAdded) + return + b.agendaDefaultView.init( + events, + dateStart, + dateEnd, + Locale.getDefault(), + object : CalendarPickerController { + override fun onDaySelected(dayItem: IDayItem) {} + + override fun onEventSelected(event: CalendarEvent) { + val date = Date.fromCalendar(event.instanceDay) + + when (event) { + is AgendaEvent -> DayDialog(activity, app.profileId, date) + is LessonChangesEvent -> LessonChangeDialog(activity, app.profileId, date) + is TeacherAbsenceEvent -> TeacherAbsenceDialog(activity, app.profileId, date) + } + } + + override fun onScrollToDate(calendar: Calendar) { + selectedDate = Date.fromCalendar(calendar) + + // Mark as read scrolled date + if (selectedDate.value in unreadDates) { + activity.launch(Dispatchers.Default) { + app.db.eventDao().setSeenByDate(app.profileId, selectedDate, true) + } + unreadDates.remove(selectedDate.value) + } + } + }, + AgendaEventRenderer(), + LessonChangesEventRenderer(), + TeacherAbsenceEventRenderer() + ) + } + + private fun addEvents(events: MutableList) { + val eventList = app.db.eventDao().getAllNow(app.profileId) + + events += eventList.map { + if (!it.seen) + unreadDates.add(it.date.value) + AgendaEvent(it) + } + } + + private fun addLessonChanges(events: MutableList) { + val lessons = app.db.timetableDao().getChangesNow(app.profileId) + + val grouped = lessons.groupBy { + it.displayDate + } + + events += grouped.mapNotNull { (date, changes) -> + LessonChangesEvent( + app.profileId, + date = date ?: return@mapNotNull null, + changeCount = changes.size + ) + } + } + + private fun addTeacherAbsence(events: MutableList) { + val teacherAbsence = app.db.teacherAbsenceDao().getAllNow(app.profileId) + + val countMap = SparseIntArray() + + for (absence in teacherAbsence) { + while (absence.dateFrom <= absence.dateTo) { + countMap[absence.dateFrom.value] += 1 + absence.dateFrom.stepForward(0, 0, 1) + } + } + + countMap.forEach { dateInt, count -> + events += TeacherAbsenceEvent( + app.profileId, + date = Date.fromValue(dateInt), + absenceCount = count + ) + } + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/BaseEvent.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/BaseEvent.kt new file mode 100644 index 00000000..f183485b --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/BaseEvent.kt @@ -0,0 +1,61 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2021-4-9. + */ + +package pl.szczodrzynski.edziennik.ui.modules.agenda + +import com.github.tibolte.agendacalendarview.models.CalendarEvent +import com.github.tibolte.agendacalendarview.models.IDayItem +import com.github.tibolte.agendacalendarview.models.IWeekItem +import java.util.* + +open class BaseEvent( + private val id: Long, + private val time: Calendar, + private val color: Int, + private val showBadge: Boolean +) : CalendarEvent { + + override fun copy() = BaseEvent(id, time, color, showBadge) + + private lateinit var date: Calendar + override fun getInstanceDay() = date + override fun setInstanceDay(value: Calendar) { + date = value + } + + private lateinit var dayReference: IDayItem + override fun getDayReference() = dayReference + override fun setDayReference(value: IDayItem) { + dayReference = value + } + + private lateinit var weekReference: IWeekItem + override fun getWeekReference() = weekReference + override fun setWeekReference(value: IWeekItem) { + weekReference = value + } + + override fun getId() = id + override fun getStartTime() = time + override fun getEndTime() = time + override fun getTitle() = "" + override fun getDescription() = "" + override fun getLocation() = "" + override fun getColor() = color + override fun getTextColor() = 0 + override fun getShowBadge() = showBadge + override fun isPlaceholder() = false + override fun isAllDay() = false + + override fun setId(value: Long) = Unit + override fun setStartTime(value: Calendar) = Unit + override fun setEndTime(value: Calendar) = Unit + override fun setTitle(value: String) = Unit + override fun setDescription(value: String) = Unit + override fun setLocation(value: String) = Unit + override fun setTextColor(value: Int) = Unit + override fun setShowBadge(value: Boolean) = Unit + override fun setPlaceholder(value: Boolean) = Unit + override fun setAllDay(value: Boolean) = Unit +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/event/AgendaEvent.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/event/AgendaEvent.kt new file mode 100644 index 00000000..3cd05727 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/event/AgendaEvent.kt @@ -0,0 +1,19 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2021-4-8. + */ + +package pl.szczodrzynski.edziennik.ui.modules.agenda.event + +import pl.szczodrzynski.edziennik.data.db.full.EventFull +import pl.szczodrzynski.edziennik.ui.modules.agenda.BaseEvent + +class AgendaEvent( + val event: EventFull +) : BaseEvent( + id = event.id, + time = event.startTimeCalendar, + color = event.eventColor, + showBadge = !event.seen +) { + override fun copy() = AgendaEvent(event) +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/event/AgendaEventRenderer.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/event/AgendaEventRenderer.kt new file mode 100644 index 00000000..da28ffd5 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/event/AgendaEventRenderer.kt @@ -0,0 +1,37 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2021-4-8. + */ + +package pl.szczodrzynski.edziennik.ui.modules.agenda.event + +import android.annotation.SuppressLint +import android.view.View +import com.github.tibolte.agendacalendarview.render.EventRenderer +import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.databinding.AgendaWrappedEventBinding +import pl.szczodrzynski.edziennik.utils.Colors + +class AgendaEventRenderer : EventRenderer() { + + @SuppressLint("SetTextI18n") + override fun render(view: View, aEvent: AgendaEvent) { + val b = AgendaWrappedEventBinding.bind(view).item + val event = aEvent.event + + b.card.setCardBackgroundColor(event.eventColor) + b.eventTitle.setTextColor(Colors.legibleTextColor(event.eventColor)) + b.eventSubtitle.setTextColor(Colors.legibleTextColor(event.eventColor)) + + b.eventTitle.text = "${event.typeName ?: "wydarzenie"} - ${event.topic}" + b.eventSubtitle.text = + (if (event.time == null) + view.context.getString(R.string.agenda_event_all_day) + else + event.time!!.stringHM) + + (event.subjectLongName?.let { ", $it" } ?: "") + + (event.teacherName?.let { ", $it" } ?: "") + + (event.teamName?.let { ", $it" } ?: "") + } + + override fun getEventLayout(): Int = R.layout.agenda_wrapped_event +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchange/LessonChangeCounter.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchange/LessonChangeCounter.kt deleted file mode 100644 index 2b264ede..00000000 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchange/LessonChangeCounter.kt +++ /dev/null @@ -1,19 +0,0 @@ -package pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange - -import pl.szczodrzynski.edziennik.utils.models.Date -import java.util.* - -class LessonChangeCounter( - val lessonChangeDate: Date, - var lessonChangeCount: Int -) { - val startTime: Calendar - get() = Calendar.getInstance().apply { - set(lessonChangeDate.year, lessonChangeDate.month - 1, lessonChangeDate.day, 10, 0, 0) - } - - val endTime: Calendar - get() = Calendar.getInstance().apply { - timeInMillis = startTime.timeInMillis + (45 * 60 * 1000) - } -} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchange/LessonChangeEvent.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchange/LessonChangeEvent.java deleted file mode 100644 index 077c2206..00000000 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchange/LessonChangeEvent.java +++ /dev/null @@ -1,243 +0,0 @@ -package pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange; - -import com.github.tibolte.agendacalendarview.models.CalendarEvent; -import com.github.tibolte.agendacalendarview.models.IDayItem; -import com.github.tibolte.agendacalendarview.models.IWeekItem; - -import java.util.Calendar; - -import pl.szczodrzynski.edziennik.utils.models.Date; - -public class LessonChangeEvent implements CalendarEvent { - - /** - * Id of the event. - */ - private long mId; - /** - * Color to be displayed in the agenda view. - */ - private int mColor; - /** - * Text color displayed on the background color - */ - private int mTextColor; - /** - * Calendar instance helping sorting the events per section in the agenda view. - */ - private Calendar mInstanceDay; - /** - * Start time of the event. - */ - private Calendar mStartTime; - /** - * End time of the event. - */ - private Calendar mEndTime; - /** - * References to a DayItem instance for that event, used to link interaction between the - * calendar view and the agenda view. - */ - private IDayItem mDayReference; - /** - * References to a WeekItem instance for that event, used to link interaction between the - * calendar view and the agenda view. - */ - private IWeekItem mWeekReference; - - - private int profileId; - private Date lessonChangeDate; - private int lessonChangeCount; - - public LessonChangeEvent(LessonChangeEvent calendarEvent) { - this.mId = calendarEvent.getId(); - this.mColor = calendarEvent.getColor(); - this.mTextColor = calendarEvent.getTextColor(); - this.mStartTime = calendarEvent.getStartTime(); - this.mEndTime = calendarEvent.getEndTime(); - this.profileId = calendarEvent.getProfileId(); - this.lessonChangeDate = calendarEvent.getLessonChangeDate(); - this.lessonChangeCount = calendarEvent.getLessonChangeCount(); - } - - public LessonChangeEvent(long mId, int mColor, int mTextColor, Calendar mStartTime, Calendar mEndTime, int profileId, Date lessonChangeDate, int lessonChangeCount) { - this.mId = mId; - this.mColor = mColor; - this.mTextColor = mTextColor; - this.mStartTime = mStartTime; - this.mEndTime = mEndTime; - this.profileId = profileId; - this.lessonChangeDate = lessonChangeDate; - this.lessonChangeCount = lessonChangeCount; - } - - public int getProfileId() { - return profileId; - } - - public Date getLessonChangeDate() { - return lessonChangeDate; - } - - public int getLessonChangeCount() { - return lessonChangeCount; - } - - public void setProfileId(int profileId) { - this.profileId = profileId; - } - - public void setLessonChangeDate(Date lessonChangeDate) { - this.lessonChangeDate = lessonChangeDate; - } - - public void setLessonChangeCount(int lessonChangeCount) { - this.lessonChangeCount = lessonChangeCount; - } - - @Override - public void setPlaceholder(boolean placeholder) { - - } - - @Override - public boolean isPlaceholder() { - return false; - } - - @Override - public String getLocation() { - return null; - } - - @Override - public void setLocation(String mLocation) { - - } - - @Override - public long getId() { - return mId; - } - - @Override - public void setId(long mId) { - this.mId = mId; - } - - @Override - public boolean getShowBadge() { - return false; - } - - @Override - public void setShowBadge(boolean mShowBadge) { - - } - - @Override - public int getTextColor() { - return mTextColor; - } - - @Override - public void setTextColor(int mTextColor) { - this.mTextColor = mTextColor; - } - - @Override - public String getDescription() { - return null; - } - - @Override - public void setDescription(String mDescription) { - - } - - @Override - public boolean isAllDay() { - return false; - } - - @Override - public void setAllDay(boolean allDay) { - - } - - @Override - public Calendar getStartTime() { - return mStartTime; - } - - @Override - public void setStartTime(Calendar mStartTime) { - this.mStartTime = mStartTime; - } - - @Override - public Calendar getEndTime() { - return mEndTime; - } - - @Override - public void setEndTime(Calendar mEndTime) { - this.mEndTime = mEndTime; - } - - @Override - public String getTitle() { - return null; - } - - @Override - public void setTitle(String mTitle) { - - } - - @Override - public Calendar getInstanceDay() { - return mInstanceDay; - } - - @Override - public void setInstanceDay(Calendar mInstanceDay) { - this.mInstanceDay = mInstanceDay; - this.mInstanceDay.set(Calendar.HOUR, 0); - this.mInstanceDay.set(Calendar.MINUTE, 0); - this.mInstanceDay.set(Calendar.SECOND, 0); - this.mInstanceDay.set(Calendar.MILLISECOND, 0); - this.mInstanceDay.set(Calendar.AM_PM, 0); - } - - @Override - public IDayItem getDayReference() { - return mDayReference; - } - - @Override - public void setDayReference(IDayItem mDayReference) { - this.mDayReference = mDayReference; - } - - @Override - public IWeekItem getWeekReference() { - return mWeekReference; - } - - @Override - public void setWeekReference(IWeekItem mWeekReference) { - this.mWeekReference = mWeekReference; - } - - @Override - public CalendarEvent copy() { - return new LessonChangeEvent(this); - } - - @Override - public int getColor() { - return mColor; - } -} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchange/LessonChangeEventRenderer.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchange/LessonChangeEventRenderer.kt deleted file mode 100644 index e2306039..00000000 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchange/LessonChangeEventRenderer.kt +++ /dev/null @@ -1,21 +0,0 @@ -package pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange - -import android.view.View -import android.widget.TextView -import androidx.cardview.widget.CardView -import com.github.tibolte.agendacalendarview.render.EventRenderer -import pl.szczodrzynski.edziennik.R - -class LessonChangeEventRenderer : EventRenderer() { - override fun render(view: View?, event: LessonChangeEvent) { - val card = view?.findViewById(R.id.lesson_change_card) - val changeText = view?.findViewById(R.id.lesson_change_text) - val changeCount = view?.findViewById(R.id.lessonChangeCount) - card?.setCardBackgroundColor(event.color) - changeText?.setTextColor(event.textColor) - changeCount?.setTextColor(event.textColor) - changeCount?.text = event.lessonChangeCount.toString() - } - - override fun getEventLayout(): Int = R.layout.agenda_event_lesson_change -} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchanges/LessonChangesEvent.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchanges/LessonChangesEvent.kt new file mode 100644 index 00000000..e65c82bd --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchanges/LessonChangesEvent.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2021-4-8. + */ + +package pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchanges + +import pl.szczodrzynski.edziennik.ui.modules.agenda.BaseEvent +import pl.szczodrzynski.edziennik.utils.models.Date + +class LessonChangesEvent( + val profileId: Int, + val date: Date, + val changeCount: Int +) : BaseEvent( + id = date.value.toLong(), + time = date.asCalendar, + color = 0xff78909c.toInt(), + showBadge = false +) { + override fun copy() = LessonChangesEvent(profileId, date, changeCount) +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchanges/LessonChangesEventRenderer.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchanges/LessonChangesEventRenderer.kt new file mode 100644 index 00000000..5ffc788c --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchanges/LessonChangesEventRenderer.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2021-4-8. + */ + +package pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchanges + +import android.view.View +import com.github.tibolte.agendacalendarview.render.EventRenderer +import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.databinding.AgendaWrappedLessonChangesBinding + +class LessonChangesEventRenderer : EventRenderer() { + + override fun render(view: View, event: LessonChangesEvent) { + val b = AgendaWrappedLessonChangesBinding.bind(view).item + + b.lessonChangeCount.text = event.changeCount.toString() + } + + override fun getEventLayout(): Int = R.layout.agenda_wrapped_lesson_changes +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceCounter.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceCounter.kt deleted file mode 100644 index 71dea025..00000000 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceCounter.kt +++ /dev/null @@ -1,19 +0,0 @@ -package pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence - -import pl.szczodrzynski.edziennik.utils.models.Date -import java.util.* - -class TeacherAbsenceCounter ( - val teacherAbsenceDate: Date, - var teacherAbsenceCount: Int = 0 -) { - val startTime: Calendar - get() = Calendar.getInstance().apply { - set(teacherAbsenceDate.year, teacherAbsenceDate.month - 1, teacherAbsenceDate.day, 10, 0, 0) - } - - val endTime: Calendar - get() = Calendar.getInstance().apply { - timeInMillis = startTime.timeInMillis + (45 * 60 * 1000) - } -} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceEvent.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceEvent.kt index fc1c28db..4208814b 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceEvent.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceEvent.kt @@ -1,188 +1,21 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2021-4-8. + */ + package pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence -import com.github.tibolte.agendacalendarview.models.CalendarEvent -import com.github.tibolte.agendacalendarview.models.IDayItem -import com.github.tibolte.agendacalendarview.models.IWeekItem +import pl.szczodrzynski.edziennik.ui.modules.agenda.BaseEvent import pl.szczodrzynski.edziennik.utils.models.Date -import java.util.* -class TeacherAbsenceEvent : CalendarEvent { - /** - * Id of the event. - */ - private var mId: Long = 0 - /** - * Color to be displayed in the agenda view. - */ - private var mColor: Int = 0 - /** - * Text color displayed on the background color - */ - private var mTextColor: Int = 0 - /** - * Calendar instance helping sorting the events per section in the agenda view. - */ - private var mInstanceDay: Calendar? = null - /** - * Start time of the event. - */ - private var mStartTime: Calendar? = null - /** - * End time of the event. - */ - private var mEndTime: Calendar? = null - /** - * References to a DayItem instance for that event, used to link interaction between the - * calendar view and the agenda view. - */ - private var mDayReference: IDayItem? = null - /** - * References to a WeekItem instance for that event, used to link interaction between the - * calendar view and the agenda view. - */ - private var mWeekReference: IWeekItem? = null - - - private var profileId: Int = 0 - var teacherAbsenceDate: Date? = null - var teacherAbsenceCount: Int = 0 - - constructor(calendarEvent: TeacherAbsenceEvent) { - this.mId = calendarEvent.id - this.mColor = calendarEvent.color - this.mTextColor = calendarEvent.textColor - this.mStartTime = calendarEvent.startTime - this.mEndTime = calendarEvent.endTime - this.profileId = calendarEvent.profileId - this.teacherAbsenceDate = calendarEvent.teacherAbsenceDate - this.teacherAbsenceCount = calendarEvent.teacherAbsenceCount - } - - constructor(mId: Long, mColor: Int, mTextColor: Int, mStartTime: Calendar, mEndTime: Calendar, profileId: Int, teacherAbsenceDate: Date, teacherAbsenceCount: Int) { - this.mId = mId - this.mColor = mColor - this.mTextColor = mTextColor - this.mStartTime = mStartTime - this.mEndTime = mEndTime - this.profileId = profileId - this.teacherAbsenceDate = teacherAbsenceDate - this.teacherAbsenceCount = teacherAbsenceCount - } - - override fun setPlaceholder(placeholder: Boolean) { - - } - - override fun isPlaceholder(): Boolean { - return false - } - - override fun getLocation(): String? { - return null - } - - override fun setLocation(mLocation: String) { - - } - - override fun getId(): Long { - return mId - } - - override fun setId(mId: Long) { - this.mId = mId - } - - override fun getShowBadge(): Boolean { - return false - } - - override fun setShowBadge(mShowBadge: Boolean) { - - } - - override fun getTextColor(): Int { - return mTextColor - } - - override fun setTextColor(mTextColor: Int) { - this.mTextColor = mTextColor - } - - override fun getDescription(): String? { - return null - } - - override fun setDescription(mDescription: String) { - - } - - override fun isAllDay(): Boolean { - return false - } - - override fun setAllDay(allDay: Boolean) { - - } - - override fun getStartTime(): Calendar? { - return mStartTime - } - - override fun setStartTime(mStartTime: Calendar) { - this.mStartTime = mStartTime - } - - override fun getEndTime(): Calendar? { - return mEndTime - } - - override fun setEndTime(mEndTime: Calendar) { - this.mEndTime = mEndTime - } - - override fun getTitle(): String? { - return null - } - - override fun setTitle(mTitle: String) { - - } - - override fun getInstanceDay(): Calendar? { - return mInstanceDay - } - - override fun setInstanceDay(mInstanceDay: Calendar) { - this.mInstanceDay = mInstanceDay - this.mInstanceDay!!.set(Calendar.HOUR, 0) - this.mInstanceDay!!.set(Calendar.MINUTE, 0) - this.mInstanceDay!!.set(Calendar.SECOND, 0) - this.mInstanceDay!!.set(Calendar.MILLISECOND, 0) - this.mInstanceDay!!.set(Calendar.AM_PM, 0) - } - - override fun getDayReference(): IDayItem? { - return mDayReference - } - - override fun setDayReference(mDayReference: IDayItem) { - this.mDayReference = mDayReference - } - - override fun getWeekReference(): IWeekItem? { - return mWeekReference - } - - override fun setWeekReference(mWeekReference: IWeekItem) { - this.mWeekReference = mWeekReference - } - - override fun copy(): CalendarEvent { - return TeacherAbsenceEvent(this) - } - - override fun getColor(): Int { - return mColor - } +class TeacherAbsenceEvent( + val profileId: Int, + val date: Date, + val absenceCount: Int +) : BaseEvent( + id = date.value.toLong(), + time = date.asCalendar, + color = 0xffff1744.toInt(), + showBadge = false +) { + override fun copy() = TeacherAbsenceEvent(profileId, date, absenceCount) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceEventRenderer.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceEventRenderer.kt index b437769b..756c60c9 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceEventRenderer.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceEventRenderer.kt @@ -1,21 +1,21 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2021-4-8. + */ + package pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence import android.view.View -import android.widget.TextView -import androidx.cardview.widget.CardView import com.github.tibolte.agendacalendarview.render.EventRenderer import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.databinding.AgendaWrappedTeacherAbsenceBinding class TeacherAbsenceEventRenderer : EventRenderer() { - override fun render(view: View?, event: TeacherAbsenceEvent) { - val card = view?.findViewById(R.id.teacherAbsenceCard) - val changeText = view?.findViewById(R.id.teacherAbsenceText) - val changeCount = view?.findViewById(R.id.teacherAbsenceCount) - card?.setCardBackgroundColor(event.color) - changeText?.setTextColor(event.textColor) - changeCount?.setTextColor(event.textColor) - changeCount?.text = event.teacherAbsenceCount.toString() + + override fun render(view: View, event: TeacherAbsenceEvent) { + val b = AgendaWrappedTeacherAbsenceBinding.bind(view).item + + b.teacherAbsenceCount.text = event.absenceCount.toString() } - override fun getEventLayout(): Int = R.layout.agenda_event_teacher_absence + override fun getEventLayout(): Int = R.layout.agenda_wrapped_teacher_absence } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/utils/models/Date.java b/app/src/main/java/pl/szczodrzynski/edziennik/utils/models/Date.java index b39d0298..ebc4570c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/utils/models/Date.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/utils/models/Date.java @@ -94,17 +94,29 @@ public class Date implements Comparable { } } - public long getInMillis() { + public Calendar getAsCalendar() { Calendar c = Calendar.getInstance(); c.set(year, month - 1, day, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); + return c; + } + + public Calendar getAsCalendar(Time time) { + if (time == null) + return getAsCalendar(); + Calendar c = Calendar.getInstance(); + c.set(year, month - 1, day, time.hour, time.minute, time.second); + c.set(Calendar.MILLISECOND, 0); + return c; + } + + public long getInMillis() { + Calendar c = getAsCalendar(); return c.getTimeInMillis(); } public long getInMillisUtc() { - Calendar c = Calendar.getInstance(); - c.set(year, month - 1, day, 0, 0, 0); - c.set(Calendar.MILLISECOND, 0); + Calendar c = getAsCalendar(); c.setTimeZone(TimeZone.getTimeZone("UTC")); return c.getTimeInMillis(); } @@ -179,13 +191,7 @@ public class Date implements Comparable { } public long combineWith(Time time) { - if (time == null) { - return getInMillis(); - } - Calendar c = Calendar.getInstance(); - c.set(this.year, this.month - 1, this.day, time.hour, time.minute, time.second); - c.set(Calendar.MILLISECOND, 0); - return c.getTimeInMillis(); + return getAsCalendar(time).getTimeInMillis(); } public int getWeekDay() { diff --git a/app/src/main/res/layout/agenda_event_item.xml b/app/src/main/res/layout/agenda_event_item.xml new file mode 100644 index 00000000..b07106f5 --- /dev/null +++ b/app/src/main/res/layout/agenda_event_item.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/layout/row_lesson_change_item.xml b/app/src/main/res/layout/agenda_lesson_changes_item.xml similarity index 72% rename from app/src/main/res/layout/row_lesson_change_item.xml rename to app/src/main/res/layout/agenda_lesson_changes_item.xml index 33515e89..8700a575 100644 --- a/app/src/main/res/layout/row_lesson_change_item.xml +++ b/app/src/main/res/layout/agenda_lesson_changes_item.xml @@ -1,11 +1,10 @@ - + app:cardCornerRadius="5dp"> + android:textColor="@color/md_white_1000" /> - - diff --git a/app/src/main/res/layout/row_teacher_absence_item.xml b/app/src/main/res/layout/agenda_teacher_absence_item.xml similarity index 72% rename from app/src/main/res/layout/row_teacher_absence_item.xml rename to app/src/main/res/layout/agenda_teacher_absence_item.xml index da78c625..4b749e8c 100644 --- a/app/src/main/res/layout/row_teacher_absence_item.xml +++ b/app/src/main/res/layout/agenda_teacher_absence_item.xml @@ -1,11 +1,10 @@ - + app:cardCornerRadius="5dp"> + android:textColor="@color/md_white_1000" /> - - diff --git a/app/src/main/res/layout/agenda_event_lesson_change.xml b/app/src/main/res/layout/agenda_wrapped_event.xml similarity index 77% rename from app/src/main/res/layout/agenda_event_lesson_change.xml rename to app/src/main/res/layout/agenda_wrapped_event.xml index c51f9b35..2ca38528 100644 --- a/app/src/main/res/layout/agenda_event_lesson_change.xml +++ b/app/src/main/res/layout/agenda_wrapped_event.xml @@ -1,15 +1,17 @@ + + - diff --git a/app/src/main/res/layout/agenda_event_teacher_absence.xml b/app/src/main/res/layout/agenda_wrapped_lesson_changes.xml similarity index 86% rename from app/src/main/res/layout/agenda_event_teacher_absence.xml rename to app/src/main/res/layout/agenda_wrapped_lesson_changes.xml index 785256d0..834d2ddd 100644 --- a/app/src/main/res/layout/agenda_event_teacher_absence.xml +++ b/app/src/main/res/layout/agenda_wrapped_lesson_changes.xml @@ -5,9 +5,9 @@ android:gravity="center_vertical" android:orientation="horizontal"> - diff --git a/app/src/main/res/layout/agenda_wrapped_teacher_absence.xml b/app/src/main/res/layout/agenda_wrapped_teacher_absence.xml new file mode 100644 index 00000000..4793b0d8 --- /dev/null +++ b/app/src/main/res/layout/agenda_wrapped_teacher_absence.xml @@ -0,0 +1,14 @@ + + + + + diff --git a/app/src/main/res/layout/dialog_day.xml b/app/src/main/res/layout/dialog_day.xml index 59fd7f8c..f1544f59 100644 --- a/app/src/main/res/layout/dialog_day.xml +++ b/app/src/main/res/layout/dialog_day.xml @@ -49,7 +49,7 @@