mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-02-22 14:34:44 +01:00
[UI/Agenda] Move common code to EventManager.
This commit is contained in:
parent
73f3ba17de
commit
755b846b50
@ -46,6 +46,8 @@ class EventDetailsDialog(
|
|||||||
private var removeEventDialog: AlertDialog? = null
|
private var removeEventDialog: AlertDialog? = null
|
||||||
private val eventShared = event.sharedBy != null
|
private val eventShared = event.sharedBy != null
|
||||||
private val eventOwn = event.sharedBy == "self"
|
private val eventOwn = event.sharedBy == "self"
|
||||||
|
private val manager
|
||||||
|
get() = app.eventManager
|
||||||
|
|
||||||
private val job = Job()
|
private val job = Job()
|
||||||
override val coroutineContext: CoroutineContext
|
override val coroutineContext: CoroutineContext
|
||||||
@ -93,7 +95,7 @@ class EventDetailsDialog(
|
|||||||
b.eventOwn = eventOwn
|
b.eventOwn = eventOwn
|
||||||
|
|
||||||
if (!event.seen) {
|
if (!event.seen) {
|
||||||
app.eventManager.markAsSeen(event)
|
manager.markAsSeen(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
val bullet = " • "
|
val bullet = " • "
|
||||||
@ -104,11 +106,7 @@ class EventDetailsDialog(
|
|||||||
}
|
}
|
||||||
catch (_: Exception) {}
|
catch (_: Exception) {}
|
||||||
|
|
||||||
b.legend.text = listOfNotNull(
|
manager.setLegendText(b.legend, event)
|
||||||
if (event.addedManually) R.string.legend_event_added_manually else null,
|
|
||||||
if (event.isDone) R.string.legend_event_is_done else null
|
|
||||||
).map { activity.getString(it) }.join("\n")
|
|
||||||
b.legend.isVisible = b.legend.text.isNotBlank()
|
|
||||||
|
|
||||||
b.typeColor.background?.setTintColor(event.eventColor)
|
b.typeColor.background?.setTintColor(event.eventColor)
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@ class EventListAdapter(
|
|||||||
) : RecyclerView.Adapter<EventListAdapter.ViewHolder>(), CoroutineScope {
|
) : RecyclerView.Adapter<EventListAdapter.ViewHolder>(), CoroutineScope {
|
||||||
|
|
||||||
private val app = context.applicationContext as App
|
private val app = context.applicationContext as App
|
||||||
private val manager = app.eventManager
|
private val manager
|
||||||
|
get() = app.eventManager
|
||||||
|
|
||||||
private val job = Job()
|
private val job = Job()
|
||||||
override val coroutineContext: CoroutineContext
|
override val coroutineContext: CoroutineContext
|
||||||
@ -67,7 +68,7 @@ class EventListAdapter(
|
|||||||
|
|
||||||
b.simpleMode = simpleMode
|
b.simpleMode = simpleMode
|
||||||
|
|
||||||
b.topic.text = event.topic
|
manager.setEventTopic(b.topic, event, showType = false)
|
||||||
b.topic.maxLines = if (simpleMode) 2 else 3
|
b.topic.maxLines = if (simpleMode) 2 else 3
|
||||||
|
|
||||||
b.details.text = mutableListOf<CharSequence?>(
|
b.details.text = mutableListOf<CharSequence?>(
|
||||||
@ -102,8 +103,6 @@ class EventListAdapter(
|
|||||||
}
|
}
|
||||||
b.editButton.attachToastHint(R.string.hint_edit_event)
|
b.editButton.attachToastHint(R.string.hint_edit_event)
|
||||||
|
|
||||||
b.isDone.isVisible = event.isDone
|
|
||||||
|
|
||||||
if (event.showAsUnseen == null)
|
if (event.showAsUnseen == null)
|
||||||
event.showAsUnseen = !event.seen
|
event.showAsUnseen = !event.seen
|
||||||
|
|
||||||
|
@ -50,7 +50,8 @@ class LessonDetailsDialog(
|
|||||||
get() = job + Dispatchers.Main
|
get() = job + Dispatchers.Main
|
||||||
|
|
||||||
private lateinit var adapter: EventListAdapter
|
private lateinit var adapter: EventListAdapter
|
||||||
private val manager by lazy { app.timetableManager }
|
private val manager
|
||||||
|
get() = app.timetableManager
|
||||||
|
|
||||||
init { run {
|
init { run {
|
||||||
if (activity.isFinishing)
|
if (activity.isFinishing)
|
||||||
|
@ -136,7 +136,13 @@ class AgendaFragmentDefault(
|
|||||||
dateEnd,
|
dateEnd,
|
||||||
Locale.getDefault(),
|
Locale.getDefault(),
|
||||||
object : CalendarPickerController {
|
object : CalendarPickerController {
|
||||||
override fun onDaySelected(dayItem: IDayItem) {}
|
override fun onDaySelected(dayItem: IDayItem) {
|
||||||
|
val c = Calendar.getInstance()
|
||||||
|
c.time = dayItem.date
|
||||||
|
if (c.timeInMillis == selectedDate.inMillis) {
|
||||||
|
DayDialog(activity, app.profileId, selectedDate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onEventSelected(event: CalendarEvent) {
|
override fun onEventSelected(event: CalendarEvent) {
|
||||||
val date = Date.fromCalendar(event.instanceDay)
|
val date = Date.fromCalendar(event.instanceDay)
|
||||||
@ -180,7 +186,7 @@ class AgendaFragmentDefault(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
AgendaEventRenderer(isCompactMode),
|
AgendaEventRenderer(app.eventManager, isCompactMode),
|
||||||
AgendaEventGroupRenderer(),
|
AgendaEventGroupRenderer(),
|
||||||
LessonChangesEventRenderer(),
|
LessonChangesEventRenderer(),
|
||||||
TeacherAbsenceEventRenderer()
|
TeacherAbsenceEventRenderer()
|
||||||
@ -197,7 +203,7 @@ class AgendaFragmentDefault(
|
|||||||
manager.loadEvents(events, BaseCalendarEvent())
|
manager.loadEvents(events, BaseCalendarEvent())
|
||||||
|
|
||||||
adapter?.updateEvents(manager.events)
|
adapter?.updateEvents(manager.events)
|
||||||
listView.scrollToCurrentDate(selectedDate.asCalendar)
|
//listView.scrollToCurrentDate(selectedDate.asCalendar)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setAsRead(date: Calendar) {
|
private fun setAsRead(date: Calendar) {
|
||||||
|
@ -10,10 +10,6 @@ import android.widget.FrameLayout
|
|||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.github.tibolte.agendacalendarview.render.EventRenderer
|
import com.github.tibolte.agendacalendarview.render.EventRenderer
|
||||||
import com.mikepenz.iconics.IconicsDrawable
|
|
||||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
|
||||||
import com.mikepenz.iconics.utils.colorInt
|
|
||||||
import com.mikepenz.iconics.utils.sizeDp
|
|
||||||
import com.mikepenz.iconics.view.IconicsTextView
|
import com.mikepenz.iconics.view.IconicsTextView
|
||||||
import pl.szczodrzynski.edziennik.R
|
import pl.szczodrzynski.edziennik.R
|
||||||
import pl.szczodrzynski.edziennik.databinding.AgendaWrappedEventBinding
|
import pl.szczodrzynski.edziennik.databinding.AgendaWrappedEventBinding
|
||||||
@ -22,8 +18,10 @@ import pl.szczodrzynski.edziennik.join
|
|||||||
import pl.szczodrzynski.edziennik.resolveAttr
|
import pl.szczodrzynski.edziennik.resolveAttr
|
||||||
import pl.szczodrzynski.edziennik.setTintColor
|
import pl.szczodrzynski.edziennik.setTintColor
|
||||||
import pl.szczodrzynski.edziennik.utils.Colors
|
import pl.szczodrzynski.edziennik.utils.Colors
|
||||||
|
import pl.szczodrzynski.edziennik.utils.managers.EventManager
|
||||||
|
|
||||||
class AgendaEventRenderer(
|
class AgendaEventRenderer(
|
||||||
|
val manager: EventManager,
|
||||||
val isCompact: Boolean
|
val isCompact: Boolean
|
||||||
) : EventRenderer<AgendaEvent>() {
|
) : EventRenderer<AgendaEvent>() {
|
||||||
|
|
||||||
@ -55,8 +53,6 @@ class AgendaEventRenderer(
|
|||||||
else
|
else
|
||||||
event.time!!.stringHM
|
event.time!!.stringHM
|
||||||
|
|
||||||
var eventTitle = "${event.typeName ?: "wydarzenie"} - ${event.topic}"
|
|
||||||
|
|
||||||
val eventSubtitle = listOfNotNull(
|
val eventSubtitle = listOfNotNull(
|
||||||
timeText,
|
timeText,
|
||||||
event.subjectLongName,
|
event.subjectLongName,
|
||||||
@ -64,28 +60,13 @@ class AgendaEventRenderer(
|
|||||||
event.teamName
|
event.teamName
|
||||||
).join(", ")
|
).join(", ")
|
||||||
|
|
||||||
if (event.addedManually) {
|
|
||||||
eventTitle = "{cmd-clipboard-edit-outline} $eventTitle"
|
|
||||||
}
|
|
||||||
|
|
||||||
card.foreground.setTintColor(event.eventColor)
|
card.foreground.setTintColor(event.eventColor)
|
||||||
card.background.setTintColor(event.eventColor)
|
card.background.setTintColor(event.eventColor)
|
||||||
title.text = eventTitle
|
manager.setEventTopic(title, event, doneIconColor = textColor)
|
||||||
title.setTextColor(textColor)
|
title.setTextColor(textColor)
|
||||||
subtitle?.text = eventSubtitle
|
subtitle?.text = eventSubtitle
|
||||||
subtitle?.setTextColor(textColor)
|
subtitle?.setTextColor(textColor)
|
||||||
|
|
||||||
title.setCompoundDrawables(
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
if (event.isDone) IconicsDrawable(card.context).apply {
|
|
||||||
icon = CommunityMaterial.Icon.cmd_check
|
|
||||||
colorInt = textColor
|
|
||||||
sizeDp = 24
|
|
||||||
} else null,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
|
|
||||||
badgeBackground.isVisible = aEvent.showItemBadge
|
badgeBackground.isVisible = aEvent.showItemBadge
|
||||||
badgeBackground.background.setTintColor(
|
badgeBackground.background.setTintColor(
|
||||||
android.R.attr.colorBackground.resolveAttr(card.context)
|
android.R.attr.colorBackground.resolveAttr(card.context)
|
||||||
|
@ -41,7 +41,8 @@ class AttendanceListFragment : LazyFragment(), CoroutineScope {
|
|||||||
get() = job + Dispatchers.Main
|
get() = job + Dispatchers.Main
|
||||||
|
|
||||||
// local/private variables go here
|
// local/private variables go here
|
||||||
private val manager by lazy { app.attendanceManager }
|
private val manager
|
||||||
|
get() = app.attendanceManager
|
||||||
private var viewType = AttendanceFragment.VIEW_DAYS
|
private var viewType = AttendanceFragment.VIEW_DAYS
|
||||||
private var expandSubjectId = 0L
|
private var expandSubjectId = 0L
|
||||||
|
|
||||||
|
@ -47,7 +47,8 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope {
|
|||||||
get() = job + Dispatchers.Main
|
get() = job + Dispatchers.Main
|
||||||
|
|
||||||
// local/private variables go here
|
// local/private variables go here
|
||||||
private val manager by lazy { app.attendanceManager }
|
private val manager
|
||||||
|
get() = app.attendanceManager
|
||||||
private var expandSubjectId = 0L
|
private var expandSubjectId = 0L
|
||||||
private var attendance = listOf<AttendanceFull>()
|
private var attendance = listOf<AttendanceFull>()
|
||||||
|
|
||||||
|
@ -40,7 +40,8 @@ class GradesAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val app = activity.applicationContext as App
|
private val app = activity.applicationContext as App
|
||||||
private val manager = app.gradesManager
|
private val manager
|
||||||
|
get() = app.gradesManager
|
||||||
|
|
||||||
private val job = Job()
|
private val job = Job()
|
||||||
override val coroutineContext: CoroutineContext
|
override val coroutineContext: CoroutineContext
|
||||||
|
@ -48,9 +48,12 @@ class GradesListFragment : Fragment(), CoroutineScope {
|
|||||||
get() = job + Dispatchers.Main
|
get() = job + Dispatchers.Main
|
||||||
|
|
||||||
// local/private variables go here
|
// local/private variables go here
|
||||||
private val manager by lazy { app.gradesManager }
|
private val manager
|
||||||
private val dontCountEnabled by lazy { manager.dontCountEnabled }
|
get() = app.gradesManager
|
||||||
private val dontCountGrades by lazy { manager.dontCountGrades }
|
private val dontCountEnabled
|
||||||
|
get() = manager.dontCountEnabled
|
||||||
|
private val dontCountGrades
|
||||||
|
get() = manager.dontCountGrades
|
||||||
private var expandSubjectId = 0L
|
private var expandSubjectId = 0L
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
@ -54,7 +54,8 @@ class TimetableDayFragment : LazyFragment(), CoroutineScope {
|
|||||||
private var endHour = DEFAULT_END_HOUR
|
private var endHour = DEFAULT_END_HOUR
|
||||||
private var firstEventMinute = 24 * 60
|
private var firstEventMinute = 24 * 60
|
||||||
|
|
||||||
private val manager by lazy { app.timetableManager }
|
private val manager
|
||||||
|
get() = app.timetableManager
|
||||||
|
|
||||||
// find SwipeRefreshLayout in the hierarchy
|
// find SwipeRefreshLayout in the hierarchy
|
||||||
private val refreshLayout by lazy { view?.findParentById(R.id.refreshLayout) }
|
private val refreshLayout by lazy { view?.findParentById(R.id.refreshLayout) }
|
||||||
|
@ -4,12 +4,17 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.utils.managers
|
package pl.szczodrzynski.edziennik.utils.managers
|
||||||
|
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import com.mikepenz.iconics.IconicsDrawable
|
||||||
|
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||||
|
import com.mikepenz.iconics.utils.colorInt
|
||||||
|
import com.mikepenz.iconics.utils.sizeDp
|
||||||
|
import com.mikepenz.iconics.view.IconicsTextView
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||||
import pl.szczodrzynski.edziennik.startCoroutineTimer
|
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
class EventManager(val app: App) : CoroutineScope {
|
class EventManager(val app: App) : CoroutineScope {
|
||||||
@ -32,4 +37,41 @@ class EventManager(val app: App) : CoroutineScope {
|
|||||||
app.db.metadataDao().setSeen(event.profileId, event, true)
|
app.db.metadataDao().setSeen(event.profileId, event, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setEventTopic(
|
||||||
|
title: IconicsTextView,
|
||||||
|
event: EventFull,
|
||||||
|
showType: Boolean = true,
|
||||||
|
doneIconColor: Int? = null
|
||||||
|
) {
|
||||||
|
var eventTopic = if (showType)
|
||||||
|
"${event.typeName ?: "wydarzenie"} - ${event.topic}"
|
||||||
|
else
|
||||||
|
event.topic
|
||||||
|
|
||||||
|
if (event.addedManually) {
|
||||||
|
eventTopic = "{cmd-clipboard-edit-outline} $eventTopic"
|
||||||
|
}
|
||||||
|
|
||||||
|
title.text = eventTopic
|
||||||
|
|
||||||
|
title.setCompoundDrawables(
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
if (event.isDone) IconicsDrawable(title.context).apply {
|
||||||
|
icon = CommunityMaterial.Icon.cmd_check
|
||||||
|
colorInt = doneIconColor ?: R.color.md_green_500.resolveColor(title.context)
|
||||||
|
sizeDp = 24
|
||||||
|
} else null,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setLegendText(legend: IconicsTextView, event: EventFull) {
|
||||||
|
legend.text = listOfNotNull(
|
||||||
|
if (event.addedManually) R.string.legend_event_added_manually else null,
|
||||||
|
if (event.isDone) R.string.legend_event_is_done else null
|
||||||
|
).map { legend.context.getString(it) }.join("\n")
|
||||||
|
legend.isVisible = legend.text.isNotBlank()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<layout xmlns:tools="http://schemas.android.com/tools"
|
<layout xmlns:tools="http://schemas.android.com/tools"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
||||||
|
|
||||||
<data>
|
<data>
|
||||||
<import type="android.view.View"/>
|
<import type="android.view.View"/>
|
||||||
@ -61,12 +60,10 @@
|
|||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<com.mikepenz.iconics.view.IconicsTextView
|
||||||
android:id="@+id/topic"
|
android:id="@+id/topic"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="4dp"
|
|
||||||
android:layout_marginRight="4dp"
|
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="3"
|
android:maxLines="3"
|
||||||
@ -79,23 +76,13 @@
|
|||||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
android:layout_marginLeft="4dp"
|
||||||
android:fontFamily="@font/community_material_font_v5_8_55"
|
android:fontFamily="@font/community_material_font_v5_8_55"
|
||||||
android:minWidth="0dp"
|
android:minWidth="0dp"
|
||||||
android:text="\uf2f4"
|
android:text="\uf2f4"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
tools:visibility="gone" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<com.mikepenz.iconics.view.IconicsImageView
|
|
||||||
android:id="@+id/isDone"
|
|
||||||
android:layout_width="32dp"
|
|
||||||
android:layout_height="32dp"
|
|
||||||
android:layout_gravity="top"
|
|
||||||
android:layout_marginHorizontal="4dp"
|
|
||||||
android:visibility="gone"
|
|
||||||
app:iiv_color="@color/md_green_500"
|
|
||||||
app:iiv_icon="cmd-check"
|
|
||||||
tools:background="@sample/check" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.mikepenz.iconics.view.IconicsTextView
|
<com.mikepenz.iconics.view.IconicsTextView
|
||||||
|
Loading…
x
Reference in New Issue
Block a user