From 192dd0c4c7a6773e77991f11a7d8ff483fda2a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Fri, 8 May 2020 22:19:55 +0200 Subject: [PATCH] [UI] Add listing attendance by type. --- .../data/web/MobidziennikWebAttendance.kt | 13 ++- .../szczodrzynski/edziennik/data/db/AppDb.kt | 5 +- .../edziennik/data/db/entity/Attendance.kt | 2 + .../data/db/migration/Migration87.kt | 14 +++ .../modules/attendance/AttendanceAdapter.kt | 14 ++- .../modules/attendance/AttendanceFragment.kt | 13 ++- .../attendance/AttendanceListFragment.kt | 24 +++- .../attendance/AttendanceSummaryFragment.kt | 5 +- .../attendance/models/AttendanceTypeGroup.kt | 25 +++++ .../viewholder/AttendanceViewHolder.kt | 2 + .../viewholder/DayRangeViewHolder.kt | 4 +- .../attendance/viewholder/MonthViewHolder.kt | 6 +- .../viewholder/SubjectViewHolder.kt | 4 +- .../attendance/viewholder/TypeViewHolder.kt | 64 +++++++++++ ...iner.xml => attendance_item_day_range.xml} | 0 ...iner_bar.xml => attendance_item_month.xml} | 3 +- ...ubject.xml => attendance_item_subject.xml} | 0 .../main/res/layout/attendance_item_type.xml | 106 ++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 19 files changed, 280 insertions(+), 25 deletions(-) create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration87.kt create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/models/AttendanceTypeGroup.kt create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/TypeViewHolder.kt rename app/src/main/res/layout/{attendance_item_container.xml => attendance_item_day_range.xml} (100%) rename app/src/main/res/layout/{attendance_item_container_bar.xml => attendance_item_month.xml} (98%) rename app/src/main/res/layout/{attendance_item_container_subject.xml => attendance_item_subject.xml} (100%) create mode 100644 app/src/main/res/layout/attendance_item_type.xml diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebAttendance.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebAttendance.kt index 3389bf8e..498f6fbf 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebAttendance.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebAttendance.kt @@ -15,6 +15,7 @@ import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_ABSEN import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_ABSENT_EXCUSED import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_BELATED import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_PRESENT +import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_PRESENT_CUSTOM import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_RELEASED import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_UNKNOWN import pl.szczodrzynski.edziennik.data.db.entity.Metadata @@ -132,13 +133,22 @@ class MobidziennikWebAttendance(override val data: DataMobidziennik, } entry = entry.removePrefix(typeSymbol) + var isCounted = true val baseType = when (typeSymbol) { "." -> TYPE_PRESENT "|" -> TYPE_ABSENT "+" -> TYPE_ABSENT_EXCUSED "s" -> TYPE_BELATED "z" -> TYPE_RELEASED - else -> TYPE_UNKNOWN + else -> { + isCounted = false + when (typeSymbol) { + "e" -> TYPE_PRESENT_CUSTOM + "en" -> TYPE_ABSENT + "ep" -> TYPE_PRESENT_CUSTOM + else -> TYPE_UNKNOWN + } + } } val typeName = types?.get(typeSymbol) ?: "" @@ -166,6 +176,7 @@ class MobidziennikWebAttendance(override val data: DataMobidziennik, subjectId = subjectId ).also { it.lessonTopic = topic + it.isCounted = isCounted } data.attendanceList.add(attendanceObject) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt index 0cd2fe26..b92f0e4a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt @@ -43,7 +43,7 @@ import pl.szczodrzynski.edziennik.data.db.migration.* LibrusLesson::class, TimetableManual::class, Metadata::class -], version = 86) +], version = 87) @TypeConverters( ConverterTime::class, ConverterDate::class, @@ -171,7 +171,8 @@ abstract class AppDb : RoomDatabase() { Migration83(), Migration84(), Migration85(), - Migration86() + Migration86(), + Migration87() ).allowMainThreadQueries().build() } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Attendance.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Attendance.kt index 525c2b39..700b9682 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Attendance.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Attendance.kt @@ -65,6 +65,8 @@ open class Attendance( var lessonTopic: String? = null @ColumnInfo(name = "attendanceLessonNumber") var lessonNumber: Int? = null + @ColumnInfo(name = "attendanceIsCounted") + var isCounted: Boolean = true @Ignore var showAsUnseen: Boolean? = null diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration87.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration87.kt new file mode 100644 index 00000000..524cb559 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration87.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2020-5-8. + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration87 : Migration(86, 87) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE attendances ADD COLUMN attendanceIsCounted INTEGER NOT NULL DEFAULT 1") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceAdapter.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceAdapter.kt index 812e8465..0dcae97e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceAdapter.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceAdapter.kt @@ -19,10 +19,7 @@ import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.data.db.full.AttendanceFull import pl.szczodrzynski.edziennik.startCoroutineTimer -import pl.szczodrzynski.edziennik.ui.modules.attendance.models.AttendanceDayRange -import pl.szczodrzynski.edziennik.ui.modules.attendance.models.AttendanceEmpty -import pl.szczodrzynski.edziennik.ui.modules.attendance.models.AttendanceMonth -import pl.szczodrzynski.edziennik.ui.modules.attendance.models.AttendanceSubject +import pl.szczodrzynski.edziennik.ui.modules.attendance.models.* import pl.szczodrzynski.edziennik.ui.modules.attendance.viewholder.* import pl.szczodrzynski.edziennik.ui.modules.grades.models.ExpandableItemModel import pl.szczodrzynski.edziennik.ui.modules.grades.viewholder.BindableViewHolder @@ -39,7 +36,8 @@ class AttendanceAdapter( private const val ITEM_TYPE_DAY_RANGE = 1 private const val ITEM_TYPE_MONTH = 2 private const val ITEM_TYPE_SUBJECT = 3 - private const val ITEM_TYPE_EMPTY = 4 + private const val ITEM_TYPE_TYPE = 4 + private const val ITEM_TYPE_EMPTY = 5 const val STATE_CLOSED = 0 const val STATE_OPENED = 1 } @@ -60,6 +58,7 @@ class AttendanceAdapter( ITEM_TYPE_DAY_RANGE -> DayRangeViewHolder(inflater, parent) ITEM_TYPE_MONTH -> MonthViewHolder(inflater, parent) ITEM_TYPE_SUBJECT -> SubjectViewHolder(inflater, parent) + ITEM_TYPE_TYPE -> TypeViewHolder(inflater, parent) ITEM_TYPE_EMPTY -> EmptyViewHolder(inflater, parent) else -> throw IllegalArgumentException("Incorrect viewType") } @@ -71,6 +70,7 @@ class AttendanceAdapter( is AttendanceDayRange -> ITEM_TYPE_DAY_RANGE is AttendanceMonth -> ITEM_TYPE_MONTH is AttendanceSubject -> ITEM_TYPE_SUBJECT + is AttendanceTypeGroup -> ITEM_TYPE_TYPE is AttendanceEmpty -> ITEM_TYPE_EMPTY else -> throw IllegalArgumentException("Incorrect viewType") } @@ -102,7 +102,7 @@ class AttendanceAdapter( ).setDuration(200).start(); } - if (model is AttendanceDayRange || model is AttendanceMonth) { + if (model is AttendanceDayRange || model is AttendanceMonth || model is AttendanceTypeGroup) { // hide the preview, show summary val preview = view?.findViewById(R.id.previewContainer) val summary = view?.findViewById(R.id.summaryContainer) @@ -158,6 +158,7 @@ class AttendanceAdapter( is DayRangeViewHolder -> ITEM_TYPE_DAY_RANGE is MonthViewHolder -> ITEM_TYPE_MONTH is SubjectViewHolder -> ITEM_TYPE_SUBJECT + is TypeViewHolder -> ITEM_TYPE_TYPE is EmptyViewHolder -> ITEM_TYPE_EMPTY else -> throw IllegalArgumentException("Incorrect viewType") } @@ -170,6 +171,7 @@ class AttendanceAdapter( holder is DayRangeViewHolder && item is AttendanceDayRange -> holder.onBind(activity, app, item, position, this) holder is MonthViewHolder && item is AttendanceMonth -> holder.onBind(activity, app, item, position, this) holder is SubjectViewHolder && item is AttendanceSubject -> holder.onBind(activity, app, item, position, this) + holder is TypeViewHolder && item is AttendanceTypeGroup -> holder.onBind(activity, app, item, position, this) holder is EmptyViewHolder && item is AttendanceEmpty -> holder.onBind(activity, app, item, position, this) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceFragment.kt index e3d43c7e..0af177f9 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceFragment.kt @@ -27,10 +27,11 @@ import kotlin.coroutines.CoroutineContext class AttendanceFragment : Fragment(), CoroutineScope { companion object { private const val TAG = "AttendanceFragment" - const val VIEW_DAYS = 0 - const val VIEW_MONTHS = 1 - const val VIEW_SUMMARY = 2 - const val VIEW_LIST = 3 + const val VIEW_SUMMARY = 0 + const val VIEW_DAYS = 1 + const val VIEW_MONTHS = 2 + const val VIEW_TYPES = 3 + const val VIEW_LIST = 4 var pageSelection = 1 } @@ -93,6 +94,10 @@ class AttendanceFragment : Fragment(), CoroutineScope { arguments = Bundle("viewType" to VIEW_MONTHS) } to getString(R.string.attendance_tab_months), + AttendanceListFragment().apply { + arguments = Bundle("viewType" to VIEW_TYPES) + } to getString(R.string.attendance_tab_types), + AttendanceListFragment().apply { arguments = Bundle("viewType" to VIEW_LIST) } to getString(R.string.attendance_tab_list) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceListFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceListFragment.kt index 2f800bb0..d317f4e9 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceListFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceListFragment.kt @@ -21,6 +21,7 @@ import pl.szczodrzynski.edziennik.isNotNullNorEmpty import pl.szczodrzynski.edziennik.startCoroutineTimer import pl.szczodrzynski.edziennik.ui.modules.attendance.models.AttendanceDayRange import pl.szczodrzynski.edziennik.ui.modules.attendance.models.AttendanceMonth +import pl.szczodrzynski.edziennik.ui.modules.attendance.models.AttendanceTypeGroup import pl.szczodrzynski.edziennik.ui.modules.base.lazypager.LazyFragment import pl.szczodrzynski.edziennik.ui.modules.grades.models.GradesSubject import pl.szczodrzynski.edziennik.utils.models.Date @@ -146,7 +147,7 @@ class AttendanceListFragment : LazyFragment(), CoroutineScope { var element = iterator.next() while (iterator.hasNext()) { var nextElement = iterator.next() - while (Date.diffDays(element.rangeStart, nextElement.rangeStart) <= 1) { + while (Date.diffDays(element.rangeStart, nextElement.rangeStart) <= 1 && iterator.hasNext()) { if (element.rangeEnd == null) element.rangeEnd = element.rangeStart @@ -173,7 +174,7 @@ class AttendanceListFragment : LazyFragment(), CoroutineScope { items.forEach { month -> month.typeCountMap = month.items .groupBy { it.typeObject } - .map { it.key to it.value.size } + .map { it.key to it.value.count { a -> a.isCounted } } .sortedBy { it.first } .toMap() @@ -205,6 +206,25 @@ class AttendanceListFragment : LazyFragment(), CoroutineScope { return items.toMutableList() } + else if (viewType == AttendanceFragment.VIEW_TYPES) { + val items = attendance + .groupBy { it.typeObject } + .map { AttendanceTypeGroup( + type = it.key, + items = it.value.toMutableList() + ) } + + items.forEach { type -> + type.percentage = if (attendance.isEmpty()) + 0f + else + type.items.size.toFloat() / attendance.size.toFloat() * 100f + + type.semesterCount = type.items.count { it.semester == app.profile.currentSemester } + } + + return items.toMutableList() + } return attendance.filter { it.baseType != Attendance.TYPE_PRESENT }.toMutableList() } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceSummaryFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceSummaryFragment.kt index 2e4378c8..9e610cda 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceSummaryFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceSummaryFragment.kt @@ -78,6 +78,7 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope { b.list.apply { setHasFixedSize(true) layoutManager = LinearLayoutManager(context) + isNestedScrollingEnabled = false } } adapter.notifyDataSetChanged() @@ -183,7 +184,7 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope { items.forEach { subject -> subject.typeCountMap = subject.items .groupBy { it.typeObject } - .map { it.key to it.value.size } + .map { it.key to it.value.count { a -> a.isCounted } } .sortedBy { it.first } .toMap() @@ -217,7 +218,7 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope { val typeCountMap = attendance .groupBy { it.typeObject } - .map { it.key to it.value.size } + .map { it.key to it.value.count { a -> a.isCounted } } .sortedBy { it.first } .toMap() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/models/AttendanceTypeGroup.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/models/AttendanceTypeGroup.kt new file mode 100644 index 00000000..d6b431ec --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/models/AttendanceTypeGroup.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2020-5-8. + */ + +package pl.szczodrzynski.edziennik.ui.modules.attendance.models + +import pl.szczodrzynski.edziennik.data.db.entity.Attendance +import pl.szczodrzynski.edziennik.data.db.entity.AttendanceType +import pl.szczodrzynski.edziennik.data.db.full.AttendanceFull +import pl.szczodrzynski.edziennik.ui.modules.grades.models.ExpandableItemModel + +data class AttendanceTypeGroup( + val type: AttendanceType, + override val items: MutableList = mutableListOf() +) : ExpandableItemModel(items) { + override var level = 1 + + var lastAddedDate = 0L + + var hasUnseen: Boolean = false + get() = field || items.any { it.baseType != Attendance.TYPE_PRESENT && !it.seen } + + var percentage: Float = 0f + var semesterCount: Int = 0 +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/AttendanceViewHolder.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/AttendanceViewHolder.kt index e67c68b7..3e7a1d32 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/AttendanceViewHolder.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/AttendanceViewHolder.kt @@ -21,6 +21,7 @@ import pl.szczodrzynski.edziennik.ui.modules.attendance.models.AttendanceMonth import pl.szczodrzynski.edziennik.ui.modules.grades.models.ExpandableItemModel import pl.szczodrzynski.edziennik.ui.modules.grades.viewholder.BindableViewHolder import pl.szczodrzynski.edziennik.utils.Themes +import pl.szczodrzynski.edziennik.utils.models.Week class AttendanceViewHolder( inflater: LayoutInflater, @@ -42,6 +43,7 @@ class AttendanceViewHolder( b.type.text = item.typeName b.subjectName.text = item.subjectLongName ?: item.lessonTopic b.dateTime.text = listOf( + Week.getFullDayName(item.date.weekDay), item.date.formattedStringShort, item.startTime?.stringHM, item.lessonNumber?.let { app.getString(R.string.attendance_lesson_number_format, it) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/DayRangeViewHolder.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/DayRangeViewHolder.kt index 11a5005c..b42d5e16 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/DayRangeViewHolder.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/DayRangeViewHolder.kt @@ -16,7 +16,7 @@ import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.concat import pl.szczodrzynski.edziennik.data.db.entity.Attendance -import pl.szczodrzynski.edziennik.databinding.AttendanceItemContainerBinding +import pl.szczodrzynski.edziennik.databinding.AttendanceItemDayRangeBinding import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceAdapter import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceAdapter.Companion.STATE_CLOSED import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceView @@ -27,7 +27,7 @@ import pl.szczodrzynski.edziennik.utils.Themes class DayRangeViewHolder( inflater: LayoutInflater, parent: ViewGroup, - val b: AttendanceItemContainerBinding = AttendanceItemContainerBinding.inflate(inflater, parent, false) + val b: AttendanceItemDayRangeBinding = AttendanceItemDayRangeBinding.inflate(inflater, parent, false) ) : RecyclerView.ViewHolder(b.root), BindableViewHolder { companion object { private const val TAG = "DayRangeViewHolder" diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/MonthViewHolder.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/MonthViewHolder.kt index 8c010f81..08d2acec 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/MonthViewHolder.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/MonthViewHolder.kt @@ -15,7 +15,7 @@ import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.data.db.entity.Attendance -import pl.szczodrzynski.edziennik.databinding.AttendanceItemContainerBarBinding +import pl.szczodrzynski.edziennik.databinding.AttendanceItemMonthBinding import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceAdapter import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceAdapter.Companion.STATE_CLOSED import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceView @@ -27,7 +27,7 @@ import pl.szczodrzynski.edziennik.utils.models.Date class MonthViewHolder( inflater: LayoutInflater, parent: ViewGroup, - val b: AttendanceItemContainerBarBinding = AttendanceItemContainerBarBinding.inflate(inflater, parent, false) + val b: AttendanceItemMonthBinding = AttendanceItemMonthBinding.inflate(inflater, parent, false) ) : RecyclerView.ViewHolder(b.root), BindableViewHolder { companion object { private const val TAG = "MonthViewHolder" @@ -80,7 +80,7 @@ class MonthViewHolder( it.setText(R.string.attendance_percentage_format, count/sum*100f) it.setPadding(0, 0, 5.dp, 0) }) - layout.setPadding(0, 8.dp, 0, 8.dp) + layout.setPadding(0, 8.dp, 0, 0) b.previewContainer.addView(layout) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/SubjectViewHolder.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/SubjectViewHolder.kt index bea33ed4..9a8e56a0 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/SubjectViewHolder.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/SubjectViewHolder.kt @@ -12,7 +12,7 @@ import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.R -import pl.szczodrzynski.edziennik.databinding.AttendanceItemContainerSubjectBinding +import pl.szczodrzynski.edziennik.databinding.AttendanceItemSubjectBinding import pl.szczodrzynski.edziennik.setText import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceAdapter import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceAdapter.Companion.STATE_CLOSED @@ -23,7 +23,7 @@ import pl.szczodrzynski.edziennik.utils.Themes class SubjectViewHolder( inflater: LayoutInflater, parent: ViewGroup, - val b: AttendanceItemContainerSubjectBinding = AttendanceItemContainerSubjectBinding.inflate(inflater, parent, false) + val b: AttendanceItemSubjectBinding = AttendanceItemSubjectBinding.inflate(inflater, parent, false) ) : RecyclerView.ViewHolder(b.root), BindableViewHolder { companion object { private const val TAG = "SubjectViewHolder" diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/TypeViewHolder.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/TypeViewHolder.kt new file mode 100644 index 00000000..62465e8b --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/viewholder/TypeViewHolder.kt @@ -0,0 +1,64 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2020-5-8. + */ + +package pl.szczodrzynski.edziennik.ui.modules.attendance.viewholder + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.view.ContextThemeWrapper +import androidx.core.view.isVisible +import androidx.recyclerview.widget.RecyclerView +import pl.szczodrzynski.edziennik.App +import pl.szczodrzynski.edziennik.data.db.entity.Attendance +import pl.szczodrzynski.edziennik.databinding.AttendanceItemTypeBinding +import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceAdapter +import pl.szczodrzynski.edziennik.ui.modules.attendance.models.AttendanceTypeGroup +import pl.szczodrzynski.edziennik.ui.modules.grades.viewholder.BindableViewHolder +import pl.szczodrzynski.edziennik.utils.Themes +import pl.szczodrzynski.edziennik.utils.models.Date + +class TypeViewHolder( + inflater: LayoutInflater, + parent: ViewGroup, + val b: AttendanceItemTypeBinding = AttendanceItemTypeBinding.inflate(inflater, parent, false) +) : RecyclerView.ViewHolder(b.root), BindableViewHolder { + companion object { + private const val TAG = "TypeViewHolder" + } + + override fun onBind(activity: AppCompatActivity, app: App, item: AttendanceTypeGroup, position: Int, adapter: AttendanceAdapter) { + val manager = app.attendanceManager + val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme) + + val type = item.type + b.title.text = type.typeName + + b.dropdownIcon.rotation = when (item.state) { + AttendanceAdapter.STATE_CLOSED -> 0f + else -> 180f + } + + b.unread.isVisible = item.hasUnseen + + b.previewContainer.visibility = if (item.state == AttendanceAdapter.STATE_CLOSED) View.VISIBLE else View.INVISIBLE + + b.type.setAttendance(Attendance( + profileId = 0, + id = 0, + baseType = type.baseType, + typeName = "", + typeShort = type.typeShort, + typeSymbol = type.typeSymbol, + typeColor = type.typeColor, + date = Date(0, 0, 0), + startTime = null, + semester = 0, + teacherId = 0, + subjectId = 0, + addedDate = 0 + ), manager, bigView = false) + } +} diff --git a/app/src/main/res/layout/attendance_item_container.xml b/app/src/main/res/layout/attendance_item_day_range.xml similarity index 100% rename from app/src/main/res/layout/attendance_item_container.xml rename to app/src/main/res/layout/attendance_item_day_range.xml diff --git a/app/src/main/res/layout/attendance_item_container_bar.xml b/app/src/main/res/layout/attendance_item_month.xml similarity index 98% rename from app/src/main/res/layout/attendance_item_container_bar.xml rename to app/src/main/res/layout/attendance_item_month.xml index 63ff39ed..6016a81c 100644 --- a/app/src/main/res/layout/attendance_item_container_bar.xml +++ b/app/src/main/res/layout/attendance_item_month.xml @@ -86,6 +86,7 @@ android:layout_height="wrap_content" android:layout_marginHorizontal="8dp" android:orientation="horizontal" + android:paddingBottom="8dp" android:visibility="gone" app:flexWrap="wrap" tools:visibility="visible"> @@ -93,7 +94,7 @@ + android:paddingTop="8dp"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6f97b5d0..bc603679 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1304,4 +1304,5 @@ wczoraj Jesteś offline. Spróbuj włączyć Wi-Fi lub dane komórkowe. Połączenie sieciowe + Wg typu