diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesAdapter.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesAdapter.kt index 137dc265..46c75d8d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesAdapter.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesAdapter.kt @@ -99,10 +99,31 @@ class GradesAdapter( } } if (model is GradesSubject) { + // hide the preview, show summary val preview = view?.findViewById(R.id.previewContainer) val summary = view?.findViewById(R.id.yearSummary) preview?.visibility = if (model.state == STATE_CLOSED) View.INVISIBLE else View.VISIBLE summary?.visibility = if (model.state == STATE_CLOSED) View.VISIBLE else View.INVISIBLE + + // expanding a subject - mark proposed & final grade as seen + var unseenChanged = false + if (model.proposedGrade?.seen == false) { + manager.markAsSeen(model.proposedGrade!!) + unseenChanged = true + } + if (model.finalGrade?.seen == false) { + manager.markAsSeen(model.finalGrade!!) + unseenChanged = true + } + // remove the override flag + model.hasUnseen = false + + if (unseenChanged) { + // check if the unseen status has changed + if (!model.hasUnseen) { + notifyItemChanged(model) + } + } } if (model.state == STATE_CLOSED) { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesListFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesListFragment.kt index b80e5539..901ad0cf 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesListFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesListFragment.kt @@ -204,7 +204,10 @@ class GradesListFragment : Fragment(), CoroutineScope { grade.showAsUnseen = !grade.seen if (!grade.seen) { - semester.hasUnseen = true + if (grade.type == Grade.TYPE_YEAR_PROPOSED || grade.type == Grade.TYPE_YEAR_FINAL) + subject.hasUnseen = true // set an override flag + else + semester.hasUnseen = true } when (grade.type) { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/models/GradesSubject.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/models/GradesSubject.kt index 89b07e6f..a61abc0d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/models/GradesSubject.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/models/GradesSubject.kt @@ -16,8 +16,8 @@ data class GradesSubject( var lastAddedDate = 0L var semester: Int = 1 - val hasUnseen - get() = semesters.any { it.hasUnseen } + var hasUnseen: Boolean = false + get() = field || semesters.any { it.hasUnseen } val averages = GradesAverages() var proposedGrade: GradeFull? = null diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/viewholder/SubjectViewHolder.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/viewholder/SubjectViewHolder.kt index a8ccabd2..0dce6297 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/viewholder/SubjectViewHolder.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/viewholder/SubjectViewHolder.kt @@ -96,6 +96,7 @@ class SubjectViewHolder( ellipsize = TextUtils.TruncateAt.END }) + // add the topmost semester's grades to preview container (collapsed) firstSemester.proposedGrade?.let { b.previewContainer.addView(GradeView( contextWrapper, @@ -111,6 +112,23 @@ class SubjectViewHolder( )) } + // add the yearly grades to summary container (expanded) + item.proposedGrade?.let { + b.yearContainer.addView(GradeView( + contextWrapper, + it, + manager + )) + } + item.finalGrade?.let { + b.yearContainer.addView(GradeView( + contextWrapper, + it, + manager + )) + } + + // if showing semester 2, add yearly grades to preview container (collapsed) if (firstSemester.number == item.semester) { b.previewContainer.addView(TextView(contextWrapper).apply { text = manager.getAverageString(app, item.averages, nameSemester = true) diff --git a/app/src/main/res/layout/grades_item_subject.xml b/app/src/main/res/layout/grades_item_subject.xml index 8d4f47f3..440857e8 100644 --- a/app/src/main/res/layout/grades_item_subject.xml +++ b/app/src/main/res/layout/grades_item_subject.xml @@ -65,39 +65,52 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="8dp" - android:layout_marginBottom="8dp" - android:layout_marginLeft="8dp"> + android:layout_marginLeft="8dp" + android:layout_marginBottom="8dp"> + tools:visibility="visible"> - + android:baselineAligned="false" + android:orientation="horizontal" + tools:visibility="visible"> + + + +