1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-19 09:17:07 -06:00

Fix broken grade summary view (#208)

This commit is contained in:
Mikołaj Pich 2019-01-07 00:55:39 +01:00 committed by Rafał Borcz
parent 450ae4e124
commit b9ac592ea9
5 changed files with 115 additions and 132 deletions

View File

@ -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<GradeSummaryHeader.ViewHolder>() {
override fun getLayoutRes() = R.layout.header_grade_summary
override fun createViewHolder(view: View?, adapter: FlexibleAdapter<IFlexible<*>>?): ViewHolder {
return ViewHolder(view, adapter)
}
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<*>>?, holder: ViewHolder?,
position: Int, payloads: MutableList<Any>?) {
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<IFlexible<*>>?) :
FlexibleViewHolder(view, adapter), LayoutContainer {
override val containerView: View?
get() = contentView
}
}

View File

@ -2,16 +2,19 @@ package io.github.wulkanowy.ui.modules.grade.summary
import android.view.View import android.view.View
import eu.davidea.flexibleadapter.FlexibleAdapter 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.flexibleadapter.items.IFlexible
import eu.davidea.viewholders.FlexibleViewHolder import eu.davidea.viewholders.FlexibleViewHolder
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.GradeSummary
import kotlinx.android.extensions.LayoutContainer import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.item_grade_summary.* import kotlinx.android.synthetic.main.item_grade_summary.*
class GradeSummaryItem(header: GradeSummaryHeader, private val grade: String, private val title: String) : class GradeSummaryItem(
AbstractSectionableItem<GradeSummaryItem.ViewHolder, GradeSummaryHeader>(header) { private val title: String,
private val average: String,
private val predictedGrade: String,
private val finalGrade: String
) : AbstractFlexibleItem<GradeSummaryItem.ViewHolder>() {
override fun getLayoutRes() = R.layout.item_grade_summary 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<Any>? position: Int, payloads: MutableList<Any>?
) { ) {
holder?.run { holder?.run {
gradeSummaryItemGrade.text = grade
gradeSummaryItemTitle.text = title 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 other as GradeSummaryItem
if (grade != other.grade) return false if (average != other.average) return false
if (title != other.title) 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 return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {
var result = header.hashCode() var result = title.hashCode()
result = 31 * result + grade.hashCode() result = 31 * result + average.hashCode()
result = 31 * result + title.hashCode() result = 31 * result + predictedGrade.hashCode()
result = 31 * result + finalGrade.hashCode()
return result return result
} }

View File

@ -99,22 +99,13 @@ class GradeSummaryPresenter @Inject constructor(
private fun createGradeSummaryItems(gradesSummary: List<GradeSummary>, averages: Map<String, Double>) private fun createGradeSummaryItems(gradesSummary: List<GradeSummary>, averages: Map<String, Double>)
: List<GradeSummaryItem> { : List<GradeSummaryItem> {
return gradesSummary.filter { !checkEmpty(it, averages) } return gradesSummary.filter { !checkEmpty(it, averages) }.map { it ->
.flatMap { gradeSummary -> GradeSummaryItem(
GradeSummaryHeader( title = it.subject,
name = gradeSummary.subject, average = formatAverage(averages.getOrElse(it.subject) { 0.0 }, ""),
average = formatAverage(averages.getOrElse(gradeSummary.subject) { 0.0 }, "") predictedGrade = it.predictedGrade,
).let { finalGrade = it.finalGrade
listOf(GradeSummaryItem( )
header = it,
title = view?.predictedString.orEmpty(),
grade = gradeSummary.predictedGrade
), GradeSummaryItem(
header = it,
title = view?.finalString.orEmpty(),
grade = gradeSummary.finalGrade
))
}
} }
} }

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorControlHighlight"
android:orientation="horizontal"
android:paddingLeft="20dp"
android:paddingTop="7dp"
android:paddingRight="20dp"
android:paddingBottom="7dp">
<TextView
android:id="@+id/gradeSummaryHeaderName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:layout_weight="1"
android:text="@string/app_name"
android:textSize="17sp" />
<TextView
android:id="@+id/gradeSummaryHeaderAverage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:text="@string/app_name"
android:textSize="12sp" />
</LinearLayout>

View File

@ -1,4 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorControlHighlight"
android:orientation="horizontal"
android:paddingLeft="20dp"
android:paddingTop="7dp"
android:paddingRight="20dp"
android:paddingBottom="7dp">
<TextView
android:id="@+id/gradeSummaryItemTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:layout_weight="1"
android:textSize="17sp"
tools:text="@tools:sample/lorem" />
<TextView
android:id="@+id/gradeSummaryItemAverage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:textSize="12sp"
tools:text="@string/aboutlibrary_lib_version" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/ic_all_divider" android:background="@drawable/ic_all_divider"
@ -6,7 +42,6 @@
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <TextView
android:id="@+id/gradeSummaryItemTitle"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
@ -17,7 +52,7 @@
android:textSize="14sp" /> android:textSize="14sp" />
<TextView <TextView
android:id="@+id/gradeSummaryItemGrade" android:id="@+id/gradeSummaryItemPredicted"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
@ -26,6 +61,38 @@
android:layout_marginEnd="25dp" android:layout_marginEnd="25dp"
android:layout_marginRight="25dp" android:layout_marginRight="25dp"
android:gravity="end" android:gravity="end"
android:text="@string/app_name" android:textSize="12sp"
android:textSize="12sp" /> tools:text="@string/aboutlibrary_lib_version" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_all_divider"
android:minHeight="35dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:text="@string/grade_summary_final_average"
android:textSize="14sp" />
<TextView
android:id="@+id/gradeSummaryItemFinal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:gravity="end"
android:textSize="12sp"
tools:text="@string/aboutlibrary_lib_version" />
</LinearLayout>
</LinearLayout> </LinearLayout>