forked from github/wulkanowy-mirror
Add admin message to error view in dashboard (#2400)
This commit is contained in:
parent
9dfb282e88
commit
7cdac6ede1
@ -193,7 +193,7 @@ ext {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'io.github.wulkanowy:sdk:2.3.6'
|
||||
implementation 'io.github.wulkanowy:sdk:2.3.7-SNAPSHOT'
|
||||
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
|
||||
|
||||
|
@ -21,6 +21,7 @@ import io.github.wulkanowy.ui.modules.attendance.summary.AttendanceSummaryFragme
|
||||
import io.github.wulkanowy.ui.modules.captcha.CaptchaDialog.Companion.CAPTCHA_SUCCESS
|
||||
import io.github.wulkanowy.ui.modules.conference.ConferenceFragment
|
||||
import io.github.wulkanowy.ui.modules.dashboard.adapters.DashboardAdapter
|
||||
import io.github.wulkanowy.ui.modules.dashboard.viewholders.AdminMessageViewHolder
|
||||
import io.github.wulkanowy.ui.modules.exam.ExamFragment
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeFragment
|
||||
import io.github.wulkanowy.ui.modules.homework.HomeworkFragment
|
||||
@ -37,7 +38,6 @@ import io.github.wulkanowy.utils.getErrorString
|
||||
import io.github.wulkanowy.utils.getThemeAttrColor
|
||||
import io.github.wulkanowy.utils.openInternetBrowser
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import timber.log.Timber
|
||||
import java.time.LocalDate
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -199,8 +199,17 @@ class DashboardFragment : BaseFragment<FragmentDashboardBinding>(R.layout.fragme
|
||||
binding.dashboardRecycler.isVisible = show
|
||||
}
|
||||
|
||||
override fun showErrorView(show: Boolean) {
|
||||
override fun showErrorView(show: Boolean, adminMessageItem: DashboardItem.AdminMessages?) {
|
||||
binding.dashboardErrorContainer.isVisible = show
|
||||
binding.dashboardErrorAdminMessage.root.isVisible = adminMessageItem != null
|
||||
|
||||
if (adminMessageItem != null) {
|
||||
AdminMessageViewHolder(
|
||||
binding = binding.dashboardErrorAdminMessage,
|
||||
onAdminMessageDismissClickListener = presenter::onAdminMessageDismissed,
|
||||
onAdminMessageClickListener = presenter::onAdminMessageSelected,
|
||||
).bind(adminMessageItem.adminMessage)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setErrorDetails(error: Throwable) {
|
||||
|
@ -403,7 +403,7 @@ class DashboardPresenter @Inject constructor(
|
||||
subjectWithGrades = it.dataOrNull,
|
||||
gradeTheme = preferencesRepository.gradeColorTheme,
|
||||
isLoading = true
|
||||
), forceRefresh
|
||||
), false
|
||||
)
|
||||
|
||||
if (!it.dataOrNull.isNullOrEmpty()) {
|
||||
@ -452,7 +452,7 @@ class DashboardPresenter @Inject constructor(
|
||||
if (forceRefresh) return@onEach
|
||||
updateData(
|
||||
DashboardItem.Lessons(it.dataOrNull, isLoading = true),
|
||||
forceRefresh
|
||||
false
|
||||
)
|
||||
|
||||
if (!it.dataOrNull?.lessons.isNullOrEmpty()) {
|
||||
@ -509,7 +509,7 @@ class DashboardPresenter @Inject constructor(
|
||||
val data = it.dataOrNull.orEmpty()
|
||||
updateData(
|
||||
DashboardItem.Homework(data, isLoading = true),
|
||||
forceRefresh
|
||||
false
|
||||
)
|
||||
|
||||
if (data.isNotEmpty()) {
|
||||
@ -543,7 +543,7 @@ class DashboardPresenter @Inject constructor(
|
||||
if (forceRefresh) return@onEach
|
||||
updateData(
|
||||
DashboardItem.Announcements(it.dataOrNull.orEmpty(), isLoading = true),
|
||||
forceRefresh
|
||||
false
|
||||
)
|
||||
|
||||
if (!it.dataOrNull.isNullOrEmpty()) {
|
||||
@ -586,7 +586,7 @@ class DashboardPresenter @Inject constructor(
|
||||
if (forceRefresh) return@onEach
|
||||
updateData(
|
||||
DashboardItem.Exams(it.dataOrNull.orEmpty(), isLoading = true),
|
||||
forceRefresh
|
||||
false
|
||||
)
|
||||
|
||||
if (!it.dataOrNull.isNullOrEmpty()) {
|
||||
@ -627,7 +627,7 @@ class DashboardPresenter @Inject constructor(
|
||||
if (forceRefresh) return@onEach
|
||||
updateData(
|
||||
DashboardItem.Conferences(it.dataOrNull.orEmpty(), isLoading = true),
|
||||
forceRefresh
|
||||
false
|
||||
)
|
||||
|
||||
if (!it.dataOrNull.isNullOrEmpty()) {
|
||||
@ -662,7 +662,7 @@ class DashboardPresenter @Inject constructor(
|
||||
is Resource.Loading -> {
|
||||
Timber.i("Loading dashboard admin message data started")
|
||||
if (forceRefresh) return@onEach
|
||||
updateData(DashboardItem.AdminMessages(), forceRefresh)
|
||||
updateData(DashboardItem.AdminMessages(), false)
|
||||
}
|
||||
|
||||
is Resource.Success -> {
|
||||
@ -692,7 +692,7 @@ class DashboardPresenter @Inject constructor(
|
||||
private fun loadAds(forceRefresh: Boolean) {
|
||||
presenterScope.launch {
|
||||
if (!forceRefresh) {
|
||||
updateData(DashboardItem.Ads(), forceRefresh)
|
||||
updateData(DashboardItem.Ads(), false)
|
||||
}
|
||||
|
||||
val dashboardAdItem =
|
||||
@ -813,6 +813,8 @@ class DashboardPresenter @Inject constructor(
|
||||
val filteredItems = itemsLoadedList.filterNot {
|
||||
it.type == DashboardItem.Type.ACCOUNT || it.type == DashboardItem.Type.ADMIN_MESSAGE
|
||||
}
|
||||
val dataLoadedAdminMessageItem =
|
||||
itemsLoadedList.find { it.type == DashboardItem.Type.ADMIN_MESSAGE && it.isDataLoaded } as DashboardItem.AdminMessages?
|
||||
val isAccountItemError =
|
||||
itemsLoadedList.find { it.type == DashboardItem.Type.ACCOUNT }?.error != null
|
||||
val isGeneralError =
|
||||
@ -834,7 +836,7 @@ class DashboardPresenter @Inject constructor(
|
||||
showRefresh(false)
|
||||
if ((forceRefresh && wasGeneralError) || !forceRefresh) {
|
||||
showContent(false)
|
||||
showErrorView(true)
|
||||
showErrorView(true, dataLoadedAdminMessageItem)
|
||||
setErrorDetails(lastError)
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ interface DashboardView : BaseView {
|
||||
|
||||
fun showRefresh(show: Boolean)
|
||||
|
||||
fun showErrorView(show: Boolean)
|
||||
fun showErrorView(show: Boolean, adminMessageItem: DashboardItem.AdminMessages? = null)
|
||||
|
||||
fun setErrorDetails(error: Throwable)
|
||||
|
||||
@ -29,5 +29,6 @@ interface DashboardView : BaseView {
|
||||
fun popViewToRoot()
|
||||
|
||||
fun openNotificationsCenterView()
|
||||
|
||||
fun openInternetBrowser(url: String)
|
||||
}
|
||||
|
@ -18,7 +18,8 @@
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/dashboard_swipe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
tools:visibility="gone">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/dashboard_recycler"
|
||||
@ -30,19 +31,33 @@
|
||||
tools:listitem="@layout/item_dashboard_grades" />
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
<LinearLayout
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/dashboard_error_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
tools:ignore="UseCompoundDrawables"
|
||||
tools:visibility="visible">
|
||||
|
||||
<include
|
||||
android:id="@+id/dashboard_error_admin_message"
|
||||
layout="@layout/item_dashboard_admin_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_chainStyle="packed" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dashboard_error_image"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/dashboard_error_message"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/dashboard_error_admin_message"
|
||||
app:layout_constraintVertical_chainStyle="packed"
|
||||
app:srcCompat="@drawable/ic_error"
|
||||
app:tint="?colorOnBackground"
|
||||
tools:ignore="contentDescription" />
|
||||
@ -55,14 +70,21 @@
|
||||
android:gravity="center"
|
||||
android:padding="8dp"
|
||||
android:text="@string/error_unknown"
|
||||
android:textSize="20sp" />
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toTopOf="@id/dashboard_error_buttons"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/dashboard_error_image" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/dashboard_error_buttons"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/dashboard_error_message">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/dashboard_error_details"
|
||||
@ -79,5 +101,5 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/all_retry" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user