Add debug statements to get/update methods in grade details adapter (#827)

This commit is contained in:
Mikołaj Pich 2020-05-24 19:33:04 +02:00 committed by GitHub
parent 9c01316178
commit f737018548
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -133,6 +133,7 @@ class GradePresenter @Inject constructor(
} }
private fun loadChild(index: Int, forceRefresh: Boolean = false) { private fun loadChild(index: Int, forceRefresh: Boolean = false) {
Timber.d("Load grade tab child. Selected semester: $selectedIndex, semesters: ${semesters.joinToString { it.semesterName.toString() }}")
semesters.first { it.semesterName == selectedIndex }.semesterId.also { semesters.first { it.semesterName == selectedIndex }.semesterId.also {
if (forceRefresh || loadedSemesterId[index] != it) { if (forceRefresh || loadedSemesterId[index] != it) {
Timber.i("Load grade child view index: $index") Timber.i("Load grade child view index: $index")

View File

@ -14,6 +14,7 @@ import io.github.wulkanowy.databinding.ItemGradeDetailsBinding
import io.github.wulkanowy.ui.base.BaseExpandableAdapter import io.github.wulkanowy.ui.base.BaseExpandableAdapter
import io.github.wulkanowy.utils.getBackgroundColor import io.github.wulkanowy.utils.getBackgroundColor
import io.github.wulkanowy.utils.toFormattedString import io.github.wulkanowy.utils.toFormattedString
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class GradeDetailsAdapter @Inject constructor() : BaseExpandableAdapter<RecyclerView.ViewHolder>() { class GradeDetailsAdapter @Inject constructor() : BaseExpandableAdapter<RecyclerView.ViewHolder>() {
@ -38,12 +39,26 @@ class GradeDetailsAdapter @Inject constructor() : BaseExpandableAdapter<Recycler
} }
fun updateDetailsItem(position: Int, grade: Grade) { fun updateDetailsItem(position: Int, grade: Grade) {
if (items.getOrNull(position)?.viewType != ViewType.ITEM) {
Timber.e("Trying to update item $position on list ${items.size} size, expanded position: $expandedPosition")
return
}
items[position] = GradeDetailsItem(grade, ViewType.ITEM) items[position] = GradeDetailsItem(grade, ViewType.ITEM)
notifyItemChanged(position) notifyItemChanged(position)
} }
fun getHeaderItem(subject: String): GradeDetailsItem { fun getHeaderItem(subject: String): GradeDetailsItem {
return headers.single { (it.value as GradeDetailsHeader).subject == subject } if (headers.any { it.value !is GradeDetailsHeader }) {
Timber.e("Headers contains no-header items! $headers")
}
val candidates = headers.filter { (it.value as GradeDetailsHeader).subject == subject }
if (candidates.size > 1) {
Timber.e("Header with subject $subject found ${candidates.size} times! Items: $candidates, expanded: $expandedPosition")
}
return candidates.first()
} }
fun updateHeaderItem(item: GradeDetailsItem) { fun updateHeaderItem(item: GradeDetailsItem) {
@ -92,7 +107,7 @@ class GradeDetailsAdapter @Inject constructor() : BaseExpandableAdapter<Recycler
is ItemViewHolder -> bindItemViewHolder( is ItemViewHolder -> bindItemViewHolder(
binding = holder.binding, binding = holder.binding,
grade = items[position].value as Grade, grade = items[position].value as Grade,
position = position position = holder.adapterPosition
) )
} }
} }

View File

@ -43,7 +43,7 @@ class GradeDetailsPresenter @Inject constructor(
} }
fun onGradeItemSelected(grade: Grade, position: Int) { fun onGradeItemSelected(grade: Grade, position: Int) {
Timber.i("Select grade item ${grade.id}") Timber.i("Select grade item ${grade.id}, position: $position")
view?.apply { view?.apply {
showGradeDialog(grade, preferencesRepository.gradeColorTheme) showGradeDialog(grade, preferencesRepository.gradeColorTheme)
if (!grade.isRead) { if (!grade.isRead) {