From b9ac592ea94494ee87bcb640ad378dcbf7607cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Mon, 7 Jan 2019 00:55:39 +0100 Subject: [PATCH] Fix broken grade summary view (#208) --- .../grade/summary/GradeSummaryHeader.kt | 52 -------- .../modules/grade/summary/GradeSummaryItem.kt | 27 +++-- .../grade/summary/GradeSummaryPresenter.kt | 25 ++-- .../main/res/layout/header_grade_summary.xml | 30 ----- .../main/res/layout/item_grade_summary.xml | 113 ++++++++++++++---- 5 files changed, 115 insertions(+), 132 deletions(-) delete mode 100644 app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryHeader.kt delete mode 100644 app/src/main/res/layout/header_grade_summary.xml diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryHeader.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryHeader.kt deleted file mode 100644 index fba3fde6..00000000 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryHeader.kt +++ /dev/null @@ -1,52 +0,0 @@ -package io.github.wulkanowy.ui.modules.grade.summary - -import android.view.View -import eu.davidea.flexibleadapter.FlexibleAdapter -import eu.davidea.flexibleadapter.items.AbstractHeaderItem -import eu.davidea.flexibleadapter.items.IFlexible -import eu.davidea.viewholders.FlexibleViewHolder -import io.github.wulkanowy.R -import kotlinx.android.extensions.LayoutContainer -import kotlinx.android.synthetic.main.header_grade_summary.* - -class GradeSummaryHeader(private val name: String, private val average: String) : AbstractHeaderItem() { - - override fun getLayoutRes() = R.layout.header_grade_summary - - override fun createViewHolder(view: View?, adapter: FlexibleAdapter>?): ViewHolder { - return ViewHolder(view, adapter) - } - - override fun bindViewHolder(adapter: FlexibleAdapter>?, holder: ViewHolder?, - position: Int, payloads: MutableList?) { - holder?.run { - gradeSummaryHeaderName.text = name - gradeSummaryHeaderAverage.text = average - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as GradeSummaryHeader - - if (name != other.name) return false - if (average != other.average) return false - - return true - } - - override fun hashCode(): Int { - var result = name.hashCode() - result = 31 * result + average.hashCode() - return result - } - - class ViewHolder(view: View?, adapter: FlexibleAdapter>?) : - FlexibleViewHolder(view, adapter), LayoutContainer { - - override val containerView: View? - get() = contentView - } -} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryItem.kt index 54302fa6..0daf0665 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryItem.kt @@ -2,16 +2,19 @@ package io.github.wulkanowy.ui.modules.grade.summary import android.view.View import eu.davidea.flexibleadapter.FlexibleAdapter -import eu.davidea.flexibleadapter.items.AbstractSectionableItem +import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.viewholders.FlexibleViewHolder import io.github.wulkanowy.R -import io.github.wulkanowy.data.db.entities.GradeSummary import kotlinx.android.extensions.LayoutContainer import kotlinx.android.synthetic.main.item_grade_summary.* -class GradeSummaryItem(header: GradeSummaryHeader, private val grade: String, private val title: String) : - AbstractSectionableItem(header) { +class GradeSummaryItem( + private val title: String, + private val average: String, + private val predictedGrade: String, + private val finalGrade: String +) : AbstractFlexibleItem() { override fun getLayoutRes() = R.layout.item_grade_summary @@ -24,8 +27,10 @@ class GradeSummaryItem(header: GradeSummaryHeader, private val grade: String, pr position: Int, payloads: MutableList? ) { holder?.run { - gradeSummaryItemGrade.text = grade gradeSummaryItemTitle.text = title + gradeSummaryItemAverage.text = average + gradeSummaryItemPredicted.text = predictedGrade + gradeSummaryItemFinal.text = finalGrade } } @@ -35,17 +40,19 @@ class GradeSummaryItem(header: GradeSummaryHeader, private val grade: String, pr other as GradeSummaryItem - if (grade != other.grade) return false + if (average != other.average) return false if (title != other.title) return false - if (header != other.header) return false + if (predictedGrade != other.predictedGrade) return false + if (finalGrade != other.finalGrade) return false return true } override fun hashCode(): Int { - var result = header.hashCode() - result = 31 * result + grade.hashCode() - result = 31 * result + title.hashCode() + var result = title.hashCode() + result = 31 * result + average.hashCode() + result = 31 * result + predictedGrade.hashCode() + result = 31 * result + finalGrade.hashCode() return result } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryPresenter.kt index a67ad894..7920ca28 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryPresenter.kt @@ -99,23 +99,14 @@ class GradeSummaryPresenter @Inject constructor( private fun createGradeSummaryItems(gradesSummary: List, averages: Map) : List { - return gradesSummary.filter { !checkEmpty(it, averages) } - .flatMap { gradeSummary -> - GradeSummaryHeader( - name = gradeSummary.subject, - average = formatAverage(averages.getOrElse(gradeSummary.subject) { 0.0 }, "") - ).let { - listOf(GradeSummaryItem( - header = it, - title = view?.predictedString.orEmpty(), - grade = gradeSummary.predictedGrade - ), GradeSummaryItem( - header = it, - title = view?.finalString.orEmpty(), - grade = gradeSummary.finalGrade - )) - } - } + return gradesSummary.filter { !checkEmpty(it, averages) }.map { it -> + GradeSummaryItem( + title = it.subject, + average = formatAverage(averages.getOrElse(it.subject) { 0.0 }, ""), + predictedGrade = it.predictedGrade, + finalGrade = it.finalGrade + ) + } } private fun checkEmpty(gradeSummary: GradeSummary, averages: Map): Boolean { diff --git a/app/src/main/res/layout/header_grade_summary.xml b/app/src/main/res/layout/header_grade_summary.xml deleted file mode 100644 index 3dca71e7..00000000 --- a/app/src/main/res/layout/header_grade_summary.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - diff --git a/app/src/main/res/layout/item_grade_summary.xml b/app/src/main/res/layout/item_grade_summary.xml index 81d7693e..a650e9dc 100644 --- a/app/src/main/res/layout/item_grade_summary.xml +++ b/app/src/main/res/layout/item_grade_summary.xml @@ -1,31 +1,98 @@ + + android:orientation="vertical"> - + android:background="?colorControlHighlight" + android:orientation="horizontal" + android:paddingLeft="20dp" + android:paddingTop="7dp" + android:paddingRight="20dp" + android:paddingBottom="7dp"> - + + + + + + android:background="@drawable/ic_all_divider" + android:minHeight="35dp" + android:orientation="horizontal"> + + + + + + + + + + + +