Fix grade header item object comparision (#999)

This commit is contained in:
Mikołaj Pich 2020-10-25 12:16:19 +01:00 committed by GitHub
parent c00b5edaf7
commit bf92c6b2e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 12 deletions

View File

@ -40,10 +40,6 @@ 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)
} }
@ -62,10 +58,6 @@ class GradeDetailsAdapter @Inject constructor() : BaseExpandableAdapter<Recycler
val headerPosition = headers.indexOf(item) val headerPosition = headers.indexOf(item)
val itemPosition = items.indexOf(item) val itemPosition = items.indexOf(item)
if (headerPosition == NO_POSITION || itemPosition == NO_POSITION) {
Timber.e("Invalid update header positions! Header: $headerPosition, item: $itemPosition")
}
headers[headerPosition] = item headers[headerPosition] = item
items[itemPosition] = item items[itemPosition] = item
notifyItemChanged(itemPosition) notifyItemChanged(itemPosition)

View File

@ -14,6 +14,7 @@ data class GradeDetailsHeader(
val subject: String, val subject: String,
val average: Double?, val average: Double?,
val pointsSum: String?, val pointsSum: String?,
var newGrades: Int,
val grades: List<GradeDetailsItem> val grades: List<GradeDetailsItem>
) ) {
var newGrades = 0
}

View File

@ -213,9 +213,10 @@ class GradeDetailsPresenter @Inject constructor(
subject = subject, subject = subject,
average = average, average = average,
pointsSum = points, pointsSum = points,
newGrades = grades.filter { grade -> !grade.isRead }.size,
grades = subItems grades = subItems
), ViewType.HEADER)) + if (preferencesRepository.isGradeExpandable) emptyList() else subItems ).apply {
newGrades = grades.filter { grade -> !grade.isRead }.size
}, ViewType.HEADER)) + if (preferencesRepository.isGradeExpandable) emptyList() else subItems
}.flatten() }.flatten()
} }