diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/GradeRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/GradeRepository.kt index 0b8a0e71..d8417f8a 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/GradeRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/GradeRepository.kt @@ -33,10 +33,16 @@ class GradeRepository @Inject constructor( private val cacheKey = "grade" - fun getGrades(student: Student, semester: Semester, forceRefresh: Boolean, notify: Boolean = false) = networkBoundResource( + fun getGrades( + student: Student, + semester: Semester, + forceRefresh: Boolean, + notify: Boolean = false + ) = networkBoundResource( mutex = saveFetchResultMutex, shouldFetch = { (details, summaries) -> - val isShouldBeRefreshed = refreshHelper.isShouldBeRefreshed(getRefreshKey(cacheKey, semester)) + val isShouldBeRefreshed = + refreshHelper.isShouldBeRefreshed(getRefreshKey(cacheKey, semester)) details.isEmpty() || summaries.isEmpty() || forceRefresh || isShouldBeRefreshed }, query = { @@ -59,8 +65,14 @@ class GradeRepository @Inject constructor( } ) - private suspend fun refreshGradeDetails(student: Student, oldGrades: List, newDetails: List, notify: Boolean) { - val notifyBreakDate = oldGrades.maxByOrNull { it.date }?.date ?: student.registrationDate.toLocalDate() + private suspend fun refreshGradeDetails( + student: Student, + oldGrades: List, + newDetails: List, + notify: Boolean + ) { + val notifyBreakDate = + oldGrades.maxByOrNull { it.date }?.date ?: student.registrationDate.toLocalDate() gradeDb.deleteAll(oldGrades uniqueSubtract newDetails) gradeDb.insertAll((newDetails uniqueSubtract oldGrades).onEach { if (it.date >= notifyBreakDate) it.apply { @@ -70,10 +82,15 @@ class GradeRepository @Inject constructor( }) } - private suspend fun refreshGradeSummaries(oldSummaries: List, newSummary: List, notify: Boolean) { + private suspend fun refreshGradeSummaries( + oldSummaries: List, + newSummary: List, + notify: Boolean + ) { gradeSummaryDb.deleteAll(oldSummaries uniqueSubtract newSummary) gradeSummaryDb.insertAll((newSummary uniqueSubtract oldSummaries).onEach { summary -> - val oldSummary = oldSummaries.find { oldSummary -> oldSummary.subject == summary.subject } + val oldSummary = + oldSummaries.find { oldSummary -> oldSummary.subject == summary.subject } summary.isPredictedGradeNotified = when { summary.predictedGrade.isEmpty() -> true notify && oldSummary?.predictedGrade != summary.predictedGrade -> false diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/SemesterRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/SemesterRepository.kt index 8942391c..4336877a 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/SemesterRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/SemesterRepository.kt @@ -22,7 +22,11 @@ class SemesterRepository @Inject constructor( private val dispatchers: DispatchersProvider ) { - suspend fun getSemesters(student: Student, forceRefresh: Boolean = false, refreshOnNoCurrent: Boolean = false) = withContext(dispatchers.backgroundThread) { + suspend fun getSemesters( + student: Student, + forceRefresh: Boolean = false, + refreshOnNoCurrent: Boolean = false + ) = withContext(dispatchers.backgroundThread) { val semesters = semesterDb.loadAll(student.studentId, student.classId) if (isShouldFetch(student, semesters, forceRefresh, refreshOnNoCurrent)) { @@ -31,14 +35,21 @@ class SemesterRepository @Inject constructor( } else semesters } - private fun isShouldFetch(student: Student, semesters: List, forceRefresh: Boolean, refreshOnNoCurrent: Boolean): Boolean { + private fun isShouldFetch( + student: Student, + semesters: List, + forceRefresh: Boolean, + refreshOnNoCurrent: Boolean + ): Boolean { val isNoSemesters = semesters.isEmpty() - val isRefreshOnModeChangeRequired = if (Sdk.Mode.valueOf(student.loginMode) != Sdk.Mode.API) { - semesters.firstOrNull { it.isCurrent }?.diaryId == 0 - } else false + val isRefreshOnModeChangeRequired = + if (Sdk.Mode.valueOf(student.loginMode) != Sdk.Mode.API) { + semesters.firstOrNull { it.isCurrent }?.diaryId == 0 + } else false - val isRefreshOnNoCurrentAppropriate = refreshOnNoCurrent && !semesters.any { semester -> semester.isCurrent } + val isRefreshOnNoCurrentAppropriate = + refreshOnNoCurrent && !semesters.any { semester -> semester.isCurrent } return forceRefresh || isNoSemesters || isRefreshOnModeChangeRequired || isRefreshOnNoCurrentAppropriate } @@ -52,7 +63,8 @@ class SemesterRepository @Inject constructor( semesterDb.insertSemesters(new.uniqueSubtract(old)) } - suspend fun getCurrentSemester(student: Student, forceRefresh: Boolean = false) = withContext(dispatchers.backgroundThread) { - getSemesters(student, forceRefresh).getCurrentOrLast() - } + suspend fun getCurrentSemester(student: Student, forceRefresh: Boolean = false) = + withContext(dispatchers.backgroundThread) { + getSemesters(student, forceRefresh).getCurrentOrLast() + } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/base/BasePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/base/BasePresenter.kt index be530049..6f363bfc 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/base/BasePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/base/BasePresenter.kt @@ -18,7 +18,7 @@ open class BasePresenter( protected val studentRepository: StudentRepository ) : CoroutineScope { - private var job: Job = Job() + private var job = Job() private val jobs = mutableMapOf() diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountFragment.kt index 7a8f8585..051c93c9 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountFragment.kt @@ -8,7 +8,7 @@ import androidx.core.view.get import androidx.recyclerview.widget.LinearLayoutManager import dagger.hilt.android.AndroidEntryPoint import io.github.wulkanowy.R -import io.github.wulkanowy.data.db.entities.StudentWithSemesters +import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.databinding.FragmentAccountBinding import io.github.wulkanowy.ui.base.BaseFragment import io.github.wulkanowy.ui.modules.account.accountdetails.AccountDetailsFragment @@ -75,9 +75,7 @@ class AccountFragment : BaseFragment(R.layout.fragment_a } } - override fun openAccountDetailsView(studentWithSemesters: StudentWithSemesters) { - (activity as? MainActivity)?.pushView( - AccountDetailsFragment.newInstance(studentWithSemesters) - ) + override fun openAccountDetailsView(student: Student) { + (activity as? MainActivity)?.pushView(AccountDetailsFragment.newInstance(student)) } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountPresenter.kt index 8d165139..7fe77ca7 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountPresenter.kt @@ -28,7 +28,7 @@ class AccountPresenter @Inject constructor( } fun onItemSelected(studentWithSemesters: StudentWithSemesters) { - view?.openAccountDetailsView(studentWithSemesters) + view?.openAccountDetailsView(studentWithSemesters.student) } private fun loadData() { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountView.kt index d7deefaf..56fcb0a3 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountView.kt @@ -1,6 +1,6 @@ package io.github.wulkanowy.ui.modules.account -import io.github.wulkanowy.data.db.entities.StudentWithSemesters +import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.ui.base.BaseView interface AccountView : BaseView { @@ -11,5 +11,5 @@ interface AccountView : BaseView { fun openLoginView() - fun openAccountDetailsView(studentWithSemesters: StudentWithSemesters) + fun openAccountDetailsView(student: Student) } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/account/accountdetails/AccountDetailsFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/account/accountdetails/AccountDetailsFragment.kt index f1c7f7bd..a9890ad9 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/account/accountdetails/AccountDetailsFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/account/accountdetails/AccountDetailsFragment.kt @@ -37,9 +37,9 @@ class AccountDetailsFragment : private const val ARGUMENT_KEY = "Data" - fun newInstance(studentWithSemesters: StudentWithSemesters) = + fun newInstance(student: Student) = AccountDetailsFragment().apply { - arguments = Bundle().apply { putSerializable(ARGUMENT_KEY, studentWithSemesters) } + arguments = Bundle().apply { putSerializable(ARGUMENT_KEY, student) } } } @@ -51,7 +51,7 @@ class AccountDetailsFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding = FragmentAccountDetailsBinding.bind(view) - presenter.onAttachView(this, requireArguments()[ARGUMENT_KEY] as StudentWithSemesters) + presenter.onAttachView(this, requireArguments()[ARGUMENT_KEY] as Student) } override fun initView() { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/account/accountdetails/AccountDetailsPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/account/accountdetails/AccountDetailsPresenter.kt index cc53c9b6..d4cba580 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/account/accountdetails/AccountDetailsPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/account/accountdetails/AccountDetailsPresenter.kt @@ -2,6 +2,7 @@ package io.github.wulkanowy.ui.modules.account.accountdetails import io.github.wulkanowy.data.Resource import io.github.wulkanowy.data.Status +import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.StudentWithSemesters import io.github.wulkanowy.data.repositories.StudentRepository import io.github.wulkanowy.services.sync.SyncManager @@ -27,9 +28,9 @@ class AccountDetailsPresenter @Inject constructor( private var studentId: Long? = null - fun onAttachView(view: AccountDetailsView, studentWithSemesters: StudentWithSemesters) { + fun onAttachView(view: AccountDetailsView, student: Student) { super.onAttachView(view) - studentId = studentWithSemesters.student.id + studentId = student.id view.initView() errorHandler.showErrorMessage = ::showErrorViewOnError diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardAdapter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardAdapter.kt index fa081ce7..56503d02 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardAdapter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardAdapter.kt @@ -14,6 +14,7 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.github.wulkanowy.R +import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.Timetable import io.github.wulkanowy.data.db.entities.TimetableHeader import io.github.wulkanowy.databinding.ItemDashboardAccountBinding @@ -41,7 +42,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter Unit = {} + var onAccountTileClickListener: (Student) -> Unit = {} var onLuckyNumberTileClickListener: () -> Unit = {} @@ -152,7 +153,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter { + attendancePercentage == null || attendancePercentage == .0 -> { + context.getThemeAttrColor(R.attr.colorOnSurface) + } + attendancePercentage <= ATTENDANCE_SECOND_WARNING_THRESHOLD -> { context.getThemeAttrColor(R.attr.colorPrimary) } - attendancePercentage ?: 0.0 <= ATTENDANCE_FIRST_WARNING_THRESHOLD -> { + attendancePercentage <= ATTENDANCE_FIRST_WARNING_THRESHOLD -> { context.getThemeAttrColor(R.attr.colorTimetableChange) } else -> context.getThemeAttrColor(R.attr.colorOnSurface) } + val attendanceString = if (attendancePercentage == null || attendancePercentage == .0) { + context.getString(R.string.dashboard_horizontal_group_no_data) + } else { + "%.2f%%".format(attendancePercentage) + } with(binding.dashboardHorizontalGroupItemAttendanceValue) { - text = "%.2f%%".format(attendancePercentage) + text = attendanceString setTextColor(attendanceColor) } with(binding) { dashboardHorizontalGroupItemMessageValue.text = unreadMessagesCount.toString() - dashboardHorizontalGroupItemLuckyValue.text = if (luckyNumber == -1) { - context.getString(R.string.dashboard_horizontal_group_no_lukcy_number) + dashboardHorizontalGroupItemLuckyValue.text = if (luckyNumber == 0) { + context.getString(R.string.dashboard_horizontal_group_no_data) } else luckyNumber?.toString() - if (dashboardHorizontalGroupItemInfoContainer.isVisible != (error != null || isLoading)) { - dashboardHorizontalGroupItemInfoContainer.isVisible = error != null || isLoading - } - - if (dashboardHorizontalGroupItemInfoProgress.isVisible != isLoading) { - dashboardHorizontalGroupItemInfoProgress.isVisible = isLoading - } - + dashboardHorizontalGroupItemInfoContainer.isVisible = error != null || isLoading + dashboardHorizontalGroupItemInfoProgress.isVisible = + (isLoading && !item.isDataLoaded) || (isLoading && !item.isFullDataLoaded) dashboardHorizontalGroupItemInfoErrorText.isVisible = error != null with(dashboardHorizontalGroupItemLuckyContainer) { - isVisible = error == null && !isLoading && luckyNumber != null + isVisible = luckyNumber != null && luckyNumber != -1 setOnClickListener { onLuckyNumberTileClickListener() } updateLayoutParams { @@ -216,7 +220,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter { matchConstraintPercentWidth = when { luckyNumber == null && unreadMessagesCount == null -> 1.0f @@ -228,7 +232,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter { - updateLessonView(item, emptyList(), binding, currentDayHeader) - binding.dashboardLessonsItemTitleTomorrow.isVisible = false - } tomorrowTimetable.isNotEmpty() -> { updateLessonView(item, tomorrowTimetable, binding) binding.dashboardLessonsItemTitleTomorrow.isVisible = true } + currentDayHeader != null && currentDayHeader.content.isNotBlank() -> { + updateLessonView(item, emptyList(), binding, currentDayHeader) + binding.dashboardLessonsItemTitleTomorrow.isVisible = false + } tomorrowDayHeader != null && tomorrowDayHeader.content.isNotBlank() -> { updateLessonView(item, emptyList(), binding, tomorrowDayHeader) binding.dashboardLessonsItemTitleTomorrow.isVisible = true @@ -348,6 +352,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter 60) { val formattedStartTime = firstLesson.start.toFormattedString("HH:mm") val formattedEndTime = firstLesson.end.toFormattedString("HH:mm") - firstTimeRangeText = "${formattedStartTime}-${formattedEndTime}" + firstTimeRangeText = "$formattedStartTime - $formattedEndTime" firstTimeText = "" isFirstTimeRangeVisible = true @@ -421,7 +426,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter(R.layout.fragme ) dashboardAdapter.apply { - onAccountTileClickListener = { mainActivity.pushView(AccountFragment.newInstance()) } + onAccountTileClickListener = { + mainActivity.pushView(AccountDetailsFragment.newInstance(it)) + } onLuckyNumberTileClickListener = { mainActivity.pushView(LuckyNumberFragment.newInstance()) } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardItem.kt index 2948b42f..cf99f0c9 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardItem.kt @@ -35,6 +35,9 @@ sealed class DashboardItem(val type: Type) { override val isDataLoaded get() = unreadMessagesCount != null || attendancePercentage != null || luckyNumber != null + + val isFullDataLoaded + get() = luckyNumber != -1 && attendancePercentage != -1.0 && unreadMessagesCount != -1 } data class Grades( diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardPresenter.kt index 0e24f0a1..027bcc05 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardPresenter.kt @@ -2,6 +2,8 @@ package io.github.wulkanowy.ui.modules.dashboard import io.github.wulkanowy.data.Resource import io.github.wulkanowy.data.Status +import io.github.wulkanowy.data.db.entities.LuckyNumber +import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.enums.MessageFolder import io.github.wulkanowy.data.repositories.AttendanceSummaryRepository import io.github.wulkanowy.data.repositories.ConferenceRepository @@ -18,11 +20,18 @@ import io.github.wulkanowy.data.repositories.TimetableRepository import io.github.wulkanowy.ui.base.BasePresenter import io.github.wulkanowy.ui.base.ErrorHandler import io.github.wulkanowy.utils.calculatePercentage -import io.github.wulkanowy.utils.flowWithResource import io.github.wulkanowy.utils.flowWithResourceIn import io.github.wulkanowy.utils.nextOrSameSchoolDay +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.emitAll +import kotlinx.coroutines.flow.filterNot +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.launch import timber.log.Timber import java.time.LocalDate import java.time.LocalDateTime @@ -48,9 +57,11 @@ class DashboardPresenter @Inject constructor( private val dashboardItemRefreshLoadedList = mutableListOf() - private lateinit var dashboardItemsToLoad: Set + private var dashboardItemsToLoad = emptySet() - private var dashboardTilesToLoad: Set = emptySet() + private var dashboardTileLoadedList = emptySet() + + private val firstLoadedItemList = mutableListOf() private lateinit var lastError: Throwable @@ -69,8 +80,10 @@ class DashboardPresenter @Inject constructor( } fun onDragAndDropEnd(list: List) { - dashboardItemLoadedList.clear() - dashboardItemLoadedList.addAll(list) + with(dashboardItemLoadedList) { + clear() + addAll(list) + } val positionList = list.mapIndexed { index, dashboardItem -> Pair(dashboardItem.type, index) }.toMap() @@ -78,87 +91,102 @@ class DashboardPresenter @Inject constructor( preferencesRepository.dashboardItemsPosition = positionList } - fun loadData(forceRefresh: Boolean = false, tilesToLoad: Set) { - val oldDashboardDataToLoad = dashboardTilesToLoad + fun loadData( + tilesToLoad: Set, + forceRefresh: Boolean = false, + ) { + val oldDashboardTileLoadedList = dashboardTileLoadedList + dashboardItemsToLoad = tilesToLoad.map { it.toDashboardItemType() }.toSet() + dashboardTileLoadedList = tilesToLoad - dashboardTilesToLoad = tilesToLoad - dashboardItemsToLoad = dashboardTilesToLoad.map { it.toDashboardItemType() }.toSet() + val itemsToLoad = generateDashboardTileListToLoad( + dashboardTilesToLoad = tilesToLoad, + dashboardLoadedTiles = oldDashboardTileLoadedList, + forceRefresh = forceRefresh + ).map { it.toDashboardItemType() } - removeUnselectedTiles() - - val newTileList = generateTileListToLoad(oldDashboardDataToLoad, forceRefresh) - loadTiles(forceRefresh, newTileList) + removeUnselectedTiles(tilesToLoad.toList()) + loadTiles(tileList = itemsToLoad, forceRefresh = forceRefresh) } - private fun removeUnselectedTiles() { - val isLuckyNumberToLoad = - dashboardTilesToLoad.any { it == DashboardItem.Tile.LUCKY_NUMBER } - val isMessagesToLoad = - dashboardTilesToLoad.any { it == DashboardItem.Tile.MESSAGES } - val isAttendanceToLoad = - dashboardTilesToLoad.any { it == DashboardItem.Tile.ATTENDANCE } + private fun generateDashboardTileListToLoad( + dashboardTilesToLoad: Set, + dashboardLoadedTiles: Set, + forceRefresh: Boolean + ) = dashboardTilesToLoad.filter { newItemToLoad -> + dashboardLoadedTiles.none { it == newItemToLoad } || forceRefresh + } + private fun removeUnselectedTiles(tilesToLoad: List) { dashboardItemLoadedList.removeAll { loadedTile -> dashboardItemsToLoad.none { it == loadedTile.type } } val horizontalGroup = dashboardItemLoadedList.find { it is DashboardItem.HorizontalGroup } as DashboardItem.HorizontalGroup? if (horizontalGroup != null) { - val horizontalIndex = dashboardItemLoadedList.indexOf(horizontalGroup) - dashboardItemLoadedList.remove(horizontalGroup) + val isLuckyNumberToLoad = DashboardItem.Tile.LUCKY_NUMBER in tilesToLoad + val isMessagesToLoad = DashboardItem.Tile.MESSAGES in tilesToLoad + val isAttendanceToLoad = DashboardItem.Tile.ATTENDANCE in tilesToLoad - var updatedHorizontalGroup = horizontalGroup + val horizontalGroupIndex = dashboardItemLoadedList.indexOf(horizontalGroup) - if (horizontalGroup.luckyNumber != null && !isLuckyNumberToLoad) { - updatedHorizontalGroup = updatedHorizontalGroup.copy(luckyNumber = null) + val newHorizontalGroup = horizontalGroup.copy( + attendancePercentage = horizontalGroup.attendancePercentage.takeIf { isAttendanceToLoad }, + unreadMessagesCount = horizontalGroup.unreadMessagesCount.takeIf { isMessagesToLoad }, + luckyNumber = horizontalGroup.luckyNumber.takeIf { isLuckyNumberToLoad } + ) + + with(dashboardItemLoadedList) { + removeAt(horizontalGroupIndex) + add(horizontalGroupIndex, newHorizontalGroup) } - - if (horizontalGroup.attendancePercentage != null && !isAttendanceToLoad) { - updatedHorizontalGroup = updatedHorizontalGroup.copy(attendancePercentage = null) - } - - if (horizontalGroup.unreadMessagesCount != null && !isMessagesToLoad) { - updatedHorizontalGroup = updatedHorizontalGroup.copy(unreadMessagesCount = null) - } - - if (horizontalGroup.error != null) { - updatedHorizontalGroup = updatedHorizontalGroup.copy(error = null, isLoading = true) - } - - dashboardItemLoadedList.add(horizontalIndex, updatedHorizontalGroup) } view?.updateData(dashboardItemLoadedList) } - private fun loadTiles(forceRefresh: Boolean, tileList: List) { - tileList.forEach { - when (it) { - DashboardItem.Tile.ACCOUNT -> loadCurrentAccount(forceRefresh) - DashboardItem.Tile.LUCKY_NUMBER -> loadLuckyNumber(forceRefresh) - DashboardItem.Tile.MESSAGES -> loadMessages(forceRefresh) - DashboardItem.Tile.ATTENDANCE -> loadAttendance(forceRefresh) - DashboardItem.Tile.LESSONS -> loadLessons(forceRefresh) - DashboardItem.Tile.GRADES -> loadGrades(forceRefresh) - DashboardItem.Tile.HOMEWORK -> loadHomework(forceRefresh) - DashboardItem.Tile.ANNOUNCEMENTS -> loadSchoolAnnouncements(forceRefresh) - DashboardItem.Tile.EXAMS -> loadExams(forceRefresh) - DashboardItem.Tile.CONFERENCES -> loadConferences(forceRefresh) - DashboardItem.Tile.ADS -> TODO() + private fun loadTiles( + tileList: List, + forceRefresh: Boolean + ) { + launch { + Timber.i("Loading dashboard account data started") + val student = runCatching { studentRepository.getCurrentStudent(true) } + .onFailure { + Timber.i("Loading dashboard account result: An exception occurred") + errorHandler.dispatch(it) + updateData(DashboardItem.Account(error = it), forceRefresh) + } + .onSuccess { Timber.i("Loading dashboard account result: Success") } + .getOrNull() ?: return@launch + + tileList.forEach { + when (it) { + DashboardItem.Type.ACCOUNT -> { + updateData(DashboardItem.Account(student), forceRefresh) + } + DashboardItem.Type.HORIZONTAL_GROUP -> { + loadHorizontalGroup(student, forceRefresh) + } + DashboardItem.Type.LESSONS -> loadLessons(student, forceRefresh) + DashboardItem.Type.GRADES -> loadGrades(student, forceRefresh) + DashboardItem.Type.HOMEWORK -> loadHomework(student, forceRefresh) + DashboardItem.Type.ANNOUNCEMENTS -> { + loadSchoolAnnouncements(student, forceRefresh) + } + DashboardItem.Type.EXAMS -> loadExams(student, forceRefresh) + DashboardItem.Type.CONFERENCES -> { + loadConferences(student, forceRefresh) + } + DashboardItem.Type.ADS -> TODO() + } } } } - private fun generateTileListToLoad( - oldDashboardTileToLoad: Set, - forceRefresh: Boolean - ) = dashboardTilesToLoad.filter { newTileToLoad -> - oldDashboardTileToLoad.none { it == newTileToLoad } || forceRefresh - } - fun onSwipeRefresh() { Timber.i("Force refreshing the dashboard") - loadData(true, preferencesRepository.selectedDashboardTiles) + loadData(preferencesRepository.selectedDashboardTiles, forceRefresh = true) } fun onRetry() { @@ -166,7 +194,7 @@ class DashboardPresenter @Inject constructor( showErrorView(false) showProgress(true) } - loadData(true, preferencesRepository.selectedDashboardTiles) + loadData(preferencesRepository.selectedDashboardTiles, forceRefresh = true) } fun onViewReselected() { @@ -192,139 +220,86 @@ class DashboardPresenter @Inject constructor( }.toSet() } - private fun loadCurrentAccount(forceRefresh: Boolean) { - flowWithResource { studentRepository.getCurrentStudent(false) } + private fun loadHorizontalGroup(student: Student, forceRefresh: Boolean) { + flow { + val semester = semesterRepository.getCurrentSemester(student) + val selectedTiles = preferencesRepository.selectedDashboardTiles + + val luckyNumberFlow = luckyNumberRepository.getLuckyNumber(student, forceRefresh) + .map { + if (it.data == null) { + it.copy(data = LuckyNumber(0, LocalDate.now(), 0)) + } else it + } + .takeIf { DashboardItem.Tile.LUCKY_NUMBER in selectedTiles } ?: flowOf(null) + + val messageFLow = messageRepository.getMessages( + student = student, + semester = semester, + folder = MessageFolder.RECEIVED, + forceRefresh = forceRefresh + ).takeIf { DashboardItem.Tile.MESSAGES in selectedTiles } ?: flowOf(null) + + val attendanceFlow = attendanceSummaryRepository.getAttendanceSummary( + student = student, + semester = semester, + subjectId = -1, + forceRefresh = forceRefresh + ).takeIf { DashboardItem.Tile.ATTENDANCE in selectedTiles } ?: flowOf(null) + + emitAll( + combine( + luckyNumberFlow, + messageFLow, + attendanceFlow + ) { luckyNumberResource, messageResource, attendanceResource -> + val error = + luckyNumberResource?.error ?: messageResource?.error ?: attendanceResource?.error + error?.let { throw it } + + val luckyNumber = luckyNumberResource?.data?.luckyNumber + val messageCount = messageResource?.data?.count { it.unread } + val attendancePercentage = attendanceResource?.data?.calculatePercentage() + + val isLoading = + luckyNumberResource?.status == Status.LOADING || messageResource?.status == Status.LOADING || attendanceResource?.status == Status.LOADING + + DashboardItem.HorizontalGroup( + isLoading = isLoading, + attendancePercentage = if (attendancePercentage == 0.0 && isLoading) -1.0 else attendancePercentage, + unreadMessagesCount = if (messageCount == 0 && isLoading) -1 else messageCount, + luckyNumber = if (luckyNumber == 0 && isLoading) -1 else luckyNumber + ) + }) + } + .filterNot { it.isLoading && forceRefresh } + .distinctUntilChanged() .onEach { - when (it.status) { - Status.LOADING -> { - Timber.i("Loading dashboard account data started") - if (forceRefresh) return@onEach - updateData(DashboardItem.Account(it.data, isLoading = true), forceRefresh) - } - Status.SUCCESS -> { - Timber.i("Loading dashboard account result: Success") - updateData(DashboardItem.Account(it.data), forceRefresh) - } - Status.ERROR -> { - Timber.i("Loading dashboard account result: An exception occurred") - errorHandler.dispatch(it.error!!) - updateData(DashboardItem.Account(error = it.error), forceRefresh) + updateData(it, forceRefresh) + + if (it.isLoading) { + Timber.i("Loading horizontal group data started") + + if (it.isFullDataLoaded) { + firstLoadedItemList += DashboardItem.Type.HORIZONTAL_GROUP } + } else { + Timber.i("Loading horizontal group result: Success") } } - .launch("dashboard_account") - } - - private fun loadLuckyNumber(forceRefresh: Boolean) { - flowWithResourceIn { - val student = studentRepository.getCurrentStudent(true) - - luckyNumberRepository.getLuckyNumber(student, forceRefresh) - }.onEach { - when (it.status) { - Status.LOADING -> { - Timber.i("Loading dashboard lucky number data started") - if (forceRefresh) return@onEach - processHorizontalGroupData( - luckyNumber = it.data?.luckyNumber, - isLoading = true, - forceRefresh = forceRefresh - ) - } - Status.SUCCESS -> { - Timber.i("Loading dashboard lucky number result: Success") - processHorizontalGroupData( - luckyNumber = it.data?.luckyNumber ?: -1, - forceRefresh = forceRefresh - ) - } - Status.ERROR -> { - Timber.i("Loading dashboard lucky number result: An exception occurred") - errorHandler.dispatch(it.error!!) - processHorizontalGroupData(error = it.error, forceRefresh = forceRefresh) - } + .catch { + Timber.i("Loading horizontal group result: An exception occurred") + updateData( + DashboardItem.HorizontalGroup(error = it), + forceRefresh, + ) + errorHandler.dispatch(it) } - }.launch("dashboard_lucky_number") + .launch("horizontal_group") } - private fun loadMessages(forceRefresh: Boolean) { + private fun loadGrades(student: Student, forceRefresh: Boolean) { flowWithResourceIn { - val student = studentRepository.getCurrentStudent(true) - val semester = semesterRepository.getCurrentSemester(student) - - messageRepository.getMessages(student, semester, MessageFolder.RECEIVED, forceRefresh) - }.onEach { - when (it.status) { - Status.LOADING -> { - Timber.i("Loading dashboard messages data started") - if (forceRefresh) return@onEach - val unreadMessagesCount = it.data?.count { message -> message.unread } - - processHorizontalGroupData( - unreadMessagesCount = unreadMessagesCount, - isLoading = true, - forceRefresh = forceRefresh - ) - } - Status.SUCCESS -> { - Timber.i("Loading dashboard messages result: Success") - val unreadMessagesCount = it.data?.count { message -> message.unread } - - processHorizontalGroupData( - unreadMessagesCount = unreadMessagesCount, - forceRefresh = forceRefresh - ) - } - Status.ERROR -> { - Timber.i("Loading dashboard messages result: An exception occurred") - errorHandler.dispatch(it.error!!) - processHorizontalGroupData(error = it.error, forceRefresh = forceRefresh) - } - } - }.launch("dashboard_messages") - } - - private fun loadAttendance(forceRefresh: Boolean) { - flowWithResourceIn { - val student = studentRepository.getCurrentStudent(true) - val semester = semesterRepository.getCurrentSemester(student) - - attendanceSummaryRepository.getAttendanceSummary(student, semester, -1, forceRefresh) - }.onEach { - when (it.status) { - Status.LOADING -> { - Timber.i("Loading dashboard attendance data started") - if (forceRefresh) return@onEach - val attendancePercentage = it.data?.calculatePercentage() - - processHorizontalGroupData( - attendancePercentage = attendancePercentage, - isLoading = true, - forceRefresh = forceRefresh - ) - } - Status.SUCCESS -> { - Timber.i("Loading dashboard attendance result: Success") - val attendancePercentage = it.data?.calculatePercentage() - - processHorizontalGroupData( - attendancePercentage = attendancePercentage, - forceRefresh = forceRefresh - ) - } - Status.ERROR -> { - Timber.i("Loading dashboard attendance result: An exception occurred") - errorHandler.dispatch(it.error!!) - - processHorizontalGroupData(error = it.error, forceRefresh = forceRefresh) - } - } - }.launch("dashboard_attendance") - } - - private fun loadGrades(forceRefresh: Boolean) { - flowWithResourceIn { - val student = studentRepository.getCurrentStudent(true) val semester = semesterRepository.getCurrentSemester(student) gradeRepository.getGrades(student, semester, forceRefresh) @@ -353,6 +328,7 @@ class DashboardPresenter @Inject constructor( Status.LOADING -> { Timber.i("Loading dashboard grades data started") if (forceRefresh) return@onEach + updateData( DashboardItem.Grades( subjectWithGrades = it.data, @@ -360,6 +336,10 @@ class DashboardPresenter @Inject constructor( isLoading = true ), forceRefresh ) + + if (!it.data.isNullOrEmpty()) { + firstLoadedItemList += DashboardItem.Type.GRADES + } } Status.SUCCESS -> { Timber.i("Loading dashboard grades result: Success") @@ -367,7 +347,8 @@ class DashboardPresenter @Inject constructor( DashboardItem.Grades( subjectWithGrades = it.data, gradeTheme = preferencesRepository.gradeColorTheme - ), forceRefresh + ), + forceRefresh ) } Status.ERROR -> { @@ -379,9 +360,8 @@ class DashboardPresenter @Inject constructor( }.launch("dashboard_grades") } - private fun loadLessons(forceRefresh: Boolean) { + private fun loadLessons(student: Student, forceRefresh: Boolean) { flowWithResourceIn { - val student = studentRepository.getCurrentStudent(true) val semester = semesterRepository.getCurrentSemester(student) val date = LocalDate.now().nextOrSameSchoolDay @@ -398,24 +378,34 @@ class DashboardPresenter @Inject constructor( Status.LOADING -> { Timber.i("Loading dashboard lessons data started") if (forceRefresh) return@onEach - updateData(DashboardItem.Lessons(it.data, isLoading = true), forceRefresh) + updateData( + DashboardItem.Lessons(it.data, isLoading = true), + forceRefresh + ) + + if (!it.data?.lessons.isNullOrEmpty()) { + firstLoadedItemList += DashboardItem.Type.LESSONS + } } Status.SUCCESS -> { Timber.i("Loading dashboard lessons result: Success") - updateData(DashboardItem.Lessons(it.data), forceRefresh) + updateData( + DashboardItem.Lessons(it.data), forceRefresh + ) } Status.ERROR -> { Timber.i("Loading dashboard lessons result: An exception occurred") errorHandler.dispatch(it.error!!) - updateData(DashboardItem.Lessons(error = it.error), forceRefresh) + updateData( + DashboardItem.Lessons(error = it.error), forceRefresh + ) } } }.launch("dashboard_lessons") } - private fun loadHomework(forceRefresh: Boolean) { + private fun loadHomework(student: Student, forceRefresh: Boolean) { flowWithResourceIn { - val student = studentRepository.getCurrentStudent(true) val semester = semesterRepository.getCurrentSemester(student) val date = LocalDate.now().nextOrSameSchoolDay @@ -443,6 +433,10 @@ class DashboardPresenter @Inject constructor( DashboardItem.Homework(it.data ?: emptyList(), isLoading = true), forceRefresh ) + + if (!it.data.isNullOrEmpty()) { + firstLoadedItemList += DashboardItem.Type.HOMEWORK + } } Status.SUCCESS -> { Timber.i("Loading dashboard homework result: Success") @@ -457,10 +451,8 @@ class DashboardPresenter @Inject constructor( }.launch("dashboard_homework") } - private fun loadSchoolAnnouncements(forceRefresh: Boolean) { + private fun loadSchoolAnnouncements(student: Student, forceRefresh: Boolean) { flowWithResourceIn { - val student = studentRepository.getCurrentStudent(true) - schoolAnnouncementRepository.getSchoolAnnouncements(student, forceRefresh) }.onEach { when (it.status) { @@ -468,11 +460,13 @@ class DashboardPresenter @Inject constructor( Timber.i("Loading dashboard announcements data started") if (forceRefresh) return@onEach updateData( - DashboardItem.Announcements( - it.data ?: emptyList(), - isLoading = true - ), forceRefresh + DashboardItem.Announcements(it.data ?: emptyList(), isLoading = true), + forceRefresh ) + + if (!it.data.isNullOrEmpty()) { + firstLoadedItemList += DashboardItem.Type.ANNOUNCEMENTS + } } Status.SUCCESS -> { Timber.i("Loading dashboard announcements result: Success") @@ -487,9 +481,8 @@ class DashboardPresenter @Inject constructor( }.launch("dashboard_announcements") } - private fun loadExams(forceRefresh: Boolean) { + private fun loadExams(student: Student, forceRefresh: Boolean) { flowWithResourceIn { - val student = studentRepository.getCurrentStudent(true) val semester = semesterRepository.getCurrentSemester(student) examRepository.getExams( @@ -508,6 +501,10 @@ class DashboardPresenter @Inject constructor( 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") @@ -522,9 +519,8 @@ class DashboardPresenter @Inject constructor( }.launch("dashboard_exams") } - private fun loadConferences(forceRefresh: Boolean) { + private fun loadConferences(student: Student, forceRefresh: Boolean) { flowWithResourceIn { - val student = studentRepository.getCurrentStudent(true) val semester = semesterRepository.getCurrentSemester(student) conferenceRepository.getConferences( @@ -542,6 +538,10 @@ class DashboardPresenter @Inject constructor( DashboardItem.Conferences(it.data ?: emptyList(), isLoading = true), forceRefresh ) + + if (!it.data.isNullOrEmpty()) { + firstLoadedItemList += DashboardItem.Type.CONFERENCES + } } Status.SUCCESS -> { Timber.i("Loading dashboard conferences result: Success") @@ -556,145 +556,119 @@ class DashboardPresenter @Inject constructor( }.launch("dashboard_conferences") } - private fun processHorizontalGroupData( - luckyNumber: Int? = null, - unreadMessagesCount: Int? = null, - attendancePercentage: Double? = null, - error: Throwable? = null, - isLoading: Boolean = false, - forceRefresh: Boolean - ) { - val isLuckyNumberToLoad = - dashboardTilesToLoad.any { it == DashboardItem.Tile.LUCKY_NUMBER } - val isMessagesToLoad = - dashboardTilesToLoad.any { it == DashboardItem.Tile.MESSAGES } - val isAttendanceToLoad = - dashboardTilesToLoad.any { it == DashboardItem.Tile.ATTENDANCE } - val isPushedToList = - dashboardItemLoadedList.any { it.type == DashboardItem.Type.HORIZONTAL_GROUP } + private fun updateData(dashboardItem: DashboardItem, forceRefresh: Boolean) { + val isForceRefreshError = forceRefresh && dashboardItem.error != null + val isFirstRunDataLoadedError = + dashboardItem.type in firstLoadedItemList && dashboardItem.error != null - if (error != null) { - updateData(DashboardItem.HorizontalGroup(error = error), forceRefresh) - return + with(dashboardItemLoadedList) { + removeAll { it.type == dashboardItem.type && !isForceRefreshError && !isFirstRunDataLoadedError } + if (!isForceRefreshError && !isFirstRunDataLoadedError) add(dashboardItem) } - if (isLoading) { - val horizontalGroup = - dashboardItemLoadedList.find { it is DashboardItem.HorizontalGroup } as DashboardItem.HorizontalGroup? - val updatedHorizontalGroup = - horizontalGroup?.copy(isLoading = true) ?: DashboardItem.HorizontalGroup(isLoading = true) + sortDashboardItems() - updateData(updatedHorizontalGroup, forceRefresh) - } - - if (forceRefresh && !isPushedToList) { - updateData(DashboardItem.HorizontalGroup(), forceRefresh) - } - - val horizontalGroup = - dashboardItemLoadedList.single { it is DashboardItem.HorizontalGroup } as DashboardItem.HorizontalGroup - - when { - luckyNumber != null -> { - updateData(horizontalGroup.copy(luckyNumber = luckyNumber), forceRefresh) - } - unreadMessagesCount != null -> { - updateData( - horizontalGroup.copy(unreadMessagesCount = unreadMessagesCount), - forceRefresh - ) - } - attendancePercentage != null -> { - updateData( - horizontalGroup.copy(attendancePercentage = attendancePercentage), - forceRefresh - ) - } - } - - val isHorizontalGroupLoaded = dashboardItemLoadedList.any { - if (it !is DashboardItem.HorizontalGroup) return@any false - - val isLuckyNumberStateCorrect = (it.luckyNumber != null) == isLuckyNumberToLoad - val isMessagesStateCorrect = (it.unreadMessagesCount != null) == isMessagesToLoad - val isAttendanceStateCorrect = (it.attendancePercentage != null) == isAttendanceToLoad - - isLuckyNumberStateCorrect && isAttendanceStateCorrect && isMessagesStateCorrect - } - - if (isHorizontalGroupLoaded) { - val updatedHorizontalGroup = - dashboardItemLoadedList.single { it is DashboardItem.HorizontalGroup } as DashboardItem.HorizontalGroup - - updateData(updatedHorizontalGroup.copy(isLoading = false, error = null), forceRefresh) + if (forceRefresh) { + updateForceRefreshData(dashboardItem) + } else { + updateNormalData() } } - private fun updateData(dashboardItem: DashboardItem, forceRefresh: Boolean) { - val isForceRefreshError = forceRefresh && dashboardItem.error != null - val dashboardItemsPosition = preferencesRepository.dashboardItemsPosition - - with(dashboardItemLoadedList) { - removeAll { it.type == dashboardItem.type && !isForceRefreshError } - if (!isForceRefreshError) add(dashboardItem) - sortBy { tile -> dashboardItemsToLoad.single { it == tile.type }.ordinal } + private fun updateNormalData() { + val isItemsLoaded = + dashboardItemsToLoad.all { type -> dashboardItemLoadedList.any { it.type == type } } + val isItemsDataLoaded = isItemsLoaded && dashboardItemLoadedList.all { + it.isDataLoaded || it.error != null } - if (forceRefresh) { - with(dashboardItemRefreshLoadedList) { - removeAll { it.type == dashboardItem.type } - add(dashboardItem) + if (isItemsDataLoaded) { + view?.run { + showProgress(false) + showErrorView(false) + showContent(true) + updateData(dashboardItemLoadedList.toList()) } } + showErrorIfExists( + isItemsLoaded = isItemsLoaded, + itemsLoadedList = dashboardItemLoadedList, + forceRefresh = false + ) + } + + private fun updateForceRefreshData(dashboardItem: DashboardItem) { + with(dashboardItemRefreshLoadedList) { + removeAll { it.type == dashboardItem.type } + add(dashboardItem) + } + + val isRefreshItemLoaded = + dashboardItemsToLoad.all { type -> dashboardItemRefreshLoadedList.any { it.type == type } } + val isRefreshItemsDataLoaded = isRefreshItemLoaded && dashboardItemRefreshLoadedList.all { + it.isDataLoaded || it.error != null + } + + if (isRefreshItemsDataLoaded) { + view?.run { + showRefresh(false) + showErrorView(false) + showContent(true) + updateData(dashboardItemLoadedList.toList()) + } + } + + showErrorIfExists( + isItemsLoaded = isRefreshItemLoaded, + itemsLoadedList = dashboardItemRefreshLoadedList, + forceRefresh = true + ) + + if (isRefreshItemsDataLoaded) dashboardItemRefreshLoadedList.clear() + } + + private fun showErrorIfExists( + isItemsLoaded: Boolean, + itemsLoadedList: List, + forceRefresh: Boolean + ) { + val filteredItems = itemsLoadedList.filterNot { it.type == DashboardItem.Type.ACCOUNT } + val isAccountItemError = + itemsLoadedList.find { it.type == DashboardItem.Type.ACCOUNT }?.error != null + val isGeneralError = + filteredItems.none { it.error == null } && filteredItems.isNotEmpty() || isAccountItemError + val errorMessage = itemsLoadedList.map { it.error?.stackTraceToString() }.toString() + + val filteredOriginalLoadedList = + dashboardItemLoadedList.filterNot { it.type == DashboardItem.Type.ACCOUNT } + val wasAccountItemError = + dashboardItemLoadedList.find { it.type == DashboardItem.Type.ACCOUNT }?.error != null + val wasGeneralError = + filteredOriginalLoadedList.none { it.error == null } && filteredOriginalLoadedList.isNotEmpty() || wasAccountItemError + + if (isGeneralError && isItemsLoaded) { + lastError = Exception(errorMessage) + + view?.run { + showProgress(false) + showRefresh(false) + if ((forceRefresh && wasGeneralError) || !forceRefresh) { + showContent(false) + showErrorView(true) + } + } + } + } + + private fun sortDashboardItems() { + val dashboardItemsPosition = preferencesRepository.dashboardItemsPosition + dashboardItemLoadedList.sortBy { tile -> dashboardItemsPosition?.getOrDefault( tile.type, tile.type.ordinal + 100 ) ?: tile.type.ordinal } - - val isItemsLoaded = - dashboardItemsToLoad.all { type -> dashboardItemLoadedList.any { it.type == type } } - val isRefreshItemLoaded = - dashboardItemsToLoad.all { type -> dashboardItemRefreshLoadedList.any { it.type == type } } - val isItemsDataLoaded = isItemsLoaded && dashboardItemLoadedList.all { - it.isDataLoaded || it.error != null - } - val isRefreshItemsDataLoaded = isRefreshItemLoaded && dashboardItemRefreshLoadedList.all { - it.isDataLoaded || it.error != null - } - - if (isRefreshItemsDataLoaded) { - view?.showRefresh(false) - dashboardItemRefreshLoadedList.clear() - } - - view?.run { - if (!forceRefresh) { - showProgress(!isItemsDataLoaded) - showContent(isItemsDataLoaded) - } - updateData(dashboardItemLoadedList.toList()) - } - - if (isItemsLoaded) { - val filteredItems = - dashboardItemLoadedList.filterNot { it.type == DashboardItem.Type.ACCOUNT } - val isAccountItemError = - dashboardItemLoadedList.single { it.type == DashboardItem.Type.ACCOUNT }.error != null - val isGeneralError = - filteredItems.all { it.error != null } && filteredItems.isNotEmpty() || isAccountItemError - - val errorMessage = filteredItems.map { it.error?.stackTraceToString() }.toString() - - lastError = Exception(errorMessage) - - view?.run { - showProgress(false) - showContent(!isGeneralError) - showErrorView(isGeneralError) - } - } } } \ No newline at end of file diff --git a/app/src/main/java/io/github/wulkanowy/utils/TimetableExtension.kt b/app/src/main/java/io/github/wulkanowy/utils/TimetableExtension.kt index f3591306..9d15216c 100644 --- a/app/src/main/java/io/github/wulkanowy/utils/TimetableExtension.kt +++ b/app/src/main/java/io/github/wulkanowy/utils/TimetableExtension.kt @@ -18,7 +18,7 @@ inline val Timetable.left: Duration? get() = when { canceled -> null !isStudentPlan -> null - end.isAfter(now()) && start.isBefore(now()) -> between(now(), end) + end >= now() && start <= now() -> between(now(), end) else -> null } diff --git a/app/src/main/res/layout/item_dashboard_horizontal_group.xml b/app/src/main/res/layout/item_dashboard_horizontal_group.xml index bbd8f351..1d43d511 100644 --- a/app/src/main/res/layout/item_dashboard_horizontal_group.xml +++ b/app/src/main/res/layout/item_dashboard_horizontal_group.xml @@ -4,14 +4,14 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingHorizontal="12dp" android:layout_marginVertical="2dp" - android:clipToPadding="false"> + android:clipToPadding="false" + android:paddingHorizontal="12dp"> Lekce (Zítra) - %1$s (%2$s) Za chvíli: Brzy: První: @@ -566,7 +565,7 @@ Ještě %1$d dalších setkání Při načítání dat došlo k chybě - Žádné + Žádné Zkontrolovat aktualizace Před hlášením chyby zkontrolujte, zda je k dispozici aktualizace s opravou chyb diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 29d5c763..5f14a425 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -432,7 +432,6 @@ Lektionen (Morgen) - %1$s (%2$s) Gleich: Bald: Erstens: @@ -488,7 +487,7 @@ %1$d weitere Konferenzen Fehler beim Laden der Daten - Keine + Keine Auf Updates prüfen Bevor Sie einen Fehler melden, prüfen Sie zuerst, ob ein Update mit der Fehlerbehebung verfügbar ist diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 2a0f3cb7..14f23cd2 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -496,7 +496,6 @@ Lekcje (Jutro) - %1$s (%2$s) Za chwilę: Wkrótce: Pierwsza: @@ -566,7 +565,7 @@ Jeszcze %1$d dodatkowych zebrań Wystąpił błąd podczas ładowania danych - Brak + Brak Sprawdź dostępność aktualizacji Przed zgłoszeniem błędu sprawdź wcześniej, czy dostępna jest już aktualizacja z poprawką błędu diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index db78f595..09b8a146 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -496,7 +496,6 @@ Уроки (Завтра) - %1$s (%2$s) Сейчас: Скоро: Первый: @@ -566,7 +565,7 @@ Еще %1$d конференций Произошла ошибка при загрузке данных - Отсутствует + Отсутствует Проверить наличие обновлений Прежде чем сообщать об ошибке, проверьте наличие обновлений diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 72899b78..ad078e33 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -496,7 +496,6 @@ Lekcie (Zajtra) - %1$s (%2$s) Za chvíľu: Čoskoro: Prvá: @@ -566,7 +565,7 @@ Ešte %1$d ďalších stretnutí Pri načítaní dát došlo k chybe - Žiadne + Žiadne Skontrolovať aktualizácie Pred hlásením chyby skontrolujte, či je k dispozícii aktualizácia s opravou chýb diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 4850e239..41f1c300 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -496,7 +496,6 @@ Уроки (Завтра) - %1$s (%2$s) Через мить: Незабаром: Перше: @@ -566,7 +565,7 @@ %1$d більше конференцій Помилка при завантаженні даних - Нічого + Нічого Провірити наявність оновлень Перед тим, як повідомлювати о помілці, перевірте наявність оновлень diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 08776c1a..cf8a0760 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -495,7 +495,6 @@ Lessons (Tomorrow) - %1$s (%2$s) In a moment: Soon: First: @@ -557,7 +556,7 @@ An error occurred while loading data - None + None diff --git a/app/src/test/java/io/github/wulkanowy/utils/TimetableExtensionTest.kt b/app/src/test/java/io/github/wulkanowy/utils/TimetableExtensionTest.kt index 84b61a90..b7fa58c6 100644 --- a/app/src/test/java/io/github/wulkanowy/utils/TimetableExtensionTest.kt +++ b/app/src/test/java/io/github/wulkanowy/utils/TimetableExtensionTest.kt @@ -32,7 +32,22 @@ class TimetableExtensionTest { assertEquals(null, getTimetableEntity(canceled = true).left) assertEquals(null, getTimetableEntity(start = now().plusMinutes(5), end = now().plusMinutes(50)).left) assertEquals(null, getTimetableEntity(start = now().minusMinutes(1), end = now().plusMinutes(44), isStudentPlan = false).left) - assertNotEquals(null, getTimetableEntity(start = now().minusMinutes(1), end = now().plusMinutes(44), isStudentPlan = true).left) + assertNotEquals( + null, + getTimetableEntity( + start = now().minusMinutes(1), + end = now().plusMinutes(44), + isStudentPlan = true + ).left + ) + assertNotEquals( + null, + getTimetableEntity( + start = now(), + end = now().plusMinutes(45), + isStudentPlan = true + ).left + ) } @Test