forked from github/wulkanowy-mirror
Fix bugs in dashboard (#1517)
This commit is contained in:
parent
037dbd792f
commit
da668f93cf
@ -53,7 +53,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView
|
|||||||
|
|
||||||
var onAttendanceTileClickListener: () -> Unit = {}
|
var onAttendanceTileClickListener: () -> Unit = {}
|
||||||
|
|
||||||
var onLessonsTileClickListener: () -> Unit = {}
|
var onLessonsTileClickListener: (LocalDate) -> Unit = {}
|
||||||
|
|
||||||
var onHomeworkTileClickListener: () -> Unit = {}
|
var onHomeworkTileClickListener: () -> Unit = {}
|
||||||
|
|
||||||
@ -275,10 +275,12 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView
|
|||||||
val item = items[position] as DashboardItem.Lessons
|
val item = items[position] as DashboardItem.Lessons
|
||||||
val timetableFull = item.lessons
|
val timetableFull = item.lessons
|
||||||
val binding = lessonsViewHolder.binding
|
val binding = lessonsViewHolder.binding
|
||||||
|
var dateToNavigate = LocalDate.now()
|
||||||
|
|
||||||
fun updateLessonState() {
|
fun updateLessonState() {
|
||||||
val currentDateTime = LocalDateTime.now()
|
val currentDateTime = LocalDateTime.now()
|
||||||
val currentDate = LocalDate.now()
|
val currentDate = LocalDate.now()
|
||||||
|
val tomorrowDate = currentDate.plusDays(1)
|
||||||
|
|
||||||
val currentTimetable = timetableFull?.lessons
|
val currentTimetable = timetableFull?.lessons
|
||||||
.orEmpty()
|
.orEmpty()
|
||||||
@ -296,22 +298,27 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView
|
|||||||
|
|
||||||
when {
|
when {
|
||||||
currentTimetable.isNotEmpty() -> {
|
currentTimetable.isNotEmpty() -> {
|
||||||
|
dateToNavigate = currentDate
|
||||||
updateLessonView(item, currentTimetable, binding)
|
updateLessonView(item, currentTimetable, binding)
|
||||||
binding.dashboardLessonsItemTitleTomorrow.isVisible = false
|
binding.dashboardLessonsItemTitleTomorrow.isVisible = false
|
||||||
}
|
}
|
||||||
tomorrowTimetable.isNotEmpty() -> {
|
tomorrowTimetable.isNotEmpty() -> {
|
||||||
|
dateToNavigate = tomorrowDate
|
||||||
updateLessonView(item, tomorrowTimetable, binding)
|
updateLessonView(item, tomorrowTimetable, binding)
|
||||||
binding.dashboardLessonsItemTitleTomorrow.isVisible = true
|
binding.dashboardLessonsItemTitleTomorrow.isVisible = true
|
||||||
}
|
}
|
||||||
currentDayHeader != null && currentDayHeader.content.isNotBlank() -> {
|
currentDayHeader != null && currentDayHeader.content.isNotBlank() -> {
|
||||||
|
dateToNavigate = currentDate
|
||||||
updateLessonView(item, emptyList(), binding, currentDayHeader)
|
updateLessonView(item, emptyList(), binding, currentDayHeader)
|
||||||
binding.dashboardLessonsItemTitleTomorrow.isVisible = false
|
binding.dashboardLessonsItemTitleTomorrow.isVisible = false
|
||||||
}
|
}
|
||||||
tomorrowDayHeader != null && tomorrowDayHeader.content.isNotBlank() -> {
|
tomorrowDayHeader != null && tomorrowDayHeader.content.isNotBlank() -> {
|
||||||
|
dateToNavigate = tomorrowDate
|
||||||
updateLessonView(item, emptyList(), binding, tomorrowDayHeader)
|
updateLessonView(item, emptyList(), binding, tomorrowDayHeader)
|
||||||
binding.dashboardLessonsItemTitleTomorrow.isVisible = true
|
binding.dashboardLessonsItemTitleTomorrow.isVisible = true
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
dateToNavigate = tomorrowDate
|
||||||
updateLessonView(item, emptyList(), binding)
|
updateLessonView(item, emptyList(), binding)
|
||||||
binding.dashboardLessonsItemTitleTomorrow.isVisible =
|
binding.dashboardLessonsItemTitleTomorrow.isVisible =
|
||||||
!(item.isLoading && item.error == null)
|
!(item.isLoading && item.error == null)
|
||||||
@ -326,7 +333,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView
|
|||||||
Handler(Looper.getMainLooper()).post { updateLessonState() }
|
Handler(Looper.getMainLooper()).post { updateLessonState() }
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.root.setOnClickListener { onLessonsTileClickListener() }
|
binding.root.setOnClickListener { onLessonsTileClickListener(dateToNavigate) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateLessonView(
|
private fun updateLessonView(
|
||||||
|
@ -70,10 +70,7 @@ class DashboardFragment : BaseFragment<FragmentDashboardBinding>(R.layout.fragme
|
|||||||
override fun initView() {
|
override fun initView() {
|
||||||
val mainActivity = requireActivity() as MainActivity
|
val mainActivity = requireActivity() as MainActivity
|
||||||
val itemTouchHelper = ItemTouchHelper(
|
val itemTouchHelper = ItemTouchHelper(
|
||||||
DashboardItemMoveCallback(
|
DashboardItemMoveCallback(dashboardAdapter, presenter::onDragAndDropEnd)
|
||||||
dashboardAdapter,
|
|
||||||
presenter::onDragAndDropEnd
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
dashboardAdapter.apply {
|
dashboardAdapter.apply {
|
||||||
@ -87,7 +84,9 @@ class DashboardFragment : BaseFragment<FragmentDashboardBinding>(R.layout.fragme
|
|||||||
onAttendanceTileClickListener = {
|
onAttendanceTileClickListener = {
|
||||||
mainActivity.pushView(AttendanceSummaryFragment.newInstance())
|
mainActivity.pushView(AttendanceSummaryFragment.newInstance())
|
||||||
}
|
}
|
||||||
onLessonsTileClickListener = { mainActivity.pushView(TimetableFragment.newInstance()) }
|
onLessonsTileClickListener = {
|
||||||
|
mainActivity.pushView(TimetableFragment.newInstance(it))
|
||||||
|
}
|
||||||
onGradeTileClickListener = { mainActivity.pushView(GradeFragment.newInstance()) }
|
onGradeTileClickListener = { mainActivity.pushView(GradeFragment.newInstance()) }
|
||||||
onHomeworkTileClickListener = { mainActivity.pushView(HomeworkFragment.newInstance()) }
|
onHomeworkTileClickListener = { mainActivity.pushView(HomeworkFragment.newInstance()) }
|
||||||
onAnnouncementsTileClickListener = {
|
onAnnouncementsTileClickListener = {
|
||||||
|
@ -492,31 +492,37 @@ class DashboardPresenter @Inject constructor(
|
|||||||
end = LocalDate.now().plusDays(7),
|
end = LocalDate.now().plusDays(7),
|
||||||
forceRefresh = forceRefresh
|
forceRefresh = forceRefresh
|
||||||
)
|
)
|
||||||
}.onEach {
|
}
|
||||||
when (it.status) {
|
.map { examResource ->
|
||||||
Status.LOADING -> {
|
val sortedExams = examResource.data?.sortedBy { it.date }
|
||||||
Timber.i("Loading dashboard exams data started")
|
|
||||||
if (forceRefresh) return@onEach
|
|
||||||
updateData(
|
|
||||||
DashboardItem.Exams(it.data.orEmpty(), isLoading = true),
|
|
||||||
forceRefresh
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!it.data.isNullOrEmpty()) {
|
examResource.copy(data = sortedExams)
|
||||||
firstLoadedItemList += DashboardItem.Type.EXAMS
|
}
|
||||||
|
.onEach {
|
||||||
|
when (it.status) {
|
||||||
|
Status.LOADING -> {
|
||||||
|
Timber.i("Loading dashboard exams data started")
|
||||||
|
if (forceRefresh) return@onEach
|
||||||
|
updateData(
|
||||||
|
DashboardItem.Exams(it.data.orEmpty(), isLoading = true),
|
||||||
|
forceRefresh
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!it.data.isNullOrEmpty()) {
|
||||||
|
firstLoadedItemList += DashboardItem.Type.EXAMS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Status.SUCCESS -> {
|
||||||
|
Timber.i("Loading dashboard exams result: Success")
|
||||||
|
updateData(DashboardItem.Exams(it.data ?: emptyList()), forceRefresh)
|
||||||
|
}
|
||||||
|
Status.ERROR -> {
|
||||||
|
Timber.i("Loading dashboard exams result: An exception occurred")
|
||||||
|
errorHandler.dispatch(it.error!!)
|
||||||
|
updateData(DashboardItem.Exams(error = it.error), forceRefresh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Status.SUCCESS -> {
|
}.launch("dashboard_exams")
|
||||||
Timber.i("Loading dashboard exams result: Success")
|
|
||||||
updateData(DashboardItem.Exams(it.data ?: emptyList()), forceRefresh)
|
|
||||||
}
|
|
||||||
Status.ERROR -> {
|
|
||||||
Timber.i("Loading dashboard exams result: An exception occurred")
|
|
||||||
errorHandler.dispatch(it.error!!)
|
|
||||||
updateData(DashboardItem.Exams(error = it.error), forceRefresh)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.launch("dashboard_exams")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadConferences(student: Student, forceRefresh: Boolean) {
|
private fun loadConferences(student: Student, forceRefresh: Boolean) {
|
||||||
|
@ -44,7 +44,13 @@ class TimetableFragment : BaseFragment<FragmentTimetableBinding>(R.layout.fragme
|
|||||||
companion object {
|
companion object {
|
||||||
private const val SAVED_DATE_KEY = "CURRENT_DATE"
|
private const val SAVED_DATE_KEY = "CURRENT_DATE"
|
||||||
|
|
||||||
fun newInstance() = TimetableFragment()
|
private const val ARGUMENT_DATE_KEY = "ARGUMENT_DATE"
|
||||||
|
|
||||||
|
fun newInstance(date: LocalDate? = null) = TimetableFragment().apply {
|
||||||
|
arguments = Bundle().apply {
|
||||||
|
date?.let { putLong(ARGUMENT_DATE_KEY, it.toEpochDay()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val titleStringId get() = R.string.timetable_title
|
override val titleStringId get() = R.string.timetable_title
|
||||||
@ -62,7 +68,11 @@ class TimetableFragment : BaseFragment<FragmentTimetableBinding>(R.layout.fragme
|
|||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
binding = FragmentTimetableBinding.bind(view)
|
binding = FragmentTimetableBinding.bind(view)
|
||||||
messageContainer = binding.timetableRecycler
|
messageContainer = binding.timetableRecycler
|
||||||
presenter.onAttachView(this, savedInstanceState?.getLong(SAVED_DATE_KEY))
|
|
||||||
|
val initDate = savedInstanceState?.getLong(SAVED_DATE_KEY)
|
||||||
|
?: arguments?.getLong(ARGUMENT_DATE_KEY)?.takeUnless { it == 0L }
|
||||||
|
|
||||||
|
presenter.onAttachView(this, initDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initView() {
|
override fun initView() {
|
||||||
|
@ -11,12 +11,13 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:includeFontPadding="false"
|
android:includeFontPadding="false"
|
||||||
|
android:maxEms="15"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:textSize="13sp"
|
android:textSize="13sp"
|
||||||
app:layout_constraintBottom_toBottomOf="@id/dashboard_grades_subitem_grade_container"
|
app:layout_constraintBottom_toBottomOf="@id/dashboard_grades_subitem_grade_container"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="@id/dashboard_grades_subitem_grade_container"
|
app:layout_constraintTop_toTopOf="@id/dashboard_grades_subitem_grade_container"
|
||||||
tools:text="Urządzenia techniki kompu..." />
|
tools:text="Urządzenia techniki komputerowych" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/dashboard_grades_subitem_grade_container"
|
android:id="@+id/dashboard_grades_subitem_grade_container"
|
||||||
@ -26,6 +27,7 @@
|
|||||||
android:layout_marginBottom="6dp"
|
android:layout_marginBottom="6dp"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toEndOf="@id/dashboard_grades_subitem_title"
|
app:layout_constraintStart_toEndOf="@id/dashboard_grades_subitem_title"
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user