Set missing styles to small lesson items (#707)

This commit is contained in:
Mikołaj Pich 2020-03-02 22:45:56 +01:00 committed by GitHub
parent 79bd2fccdf
commit 2634c270b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 142 additions and 80 deletions

View File

@ -5,6 +5,7 @@ import android.graphics.Paint
import android.view.View import android.view.View
import android.view.View.GONE import android.view.View.GONE
import android.view.View.VISIBLE import android.view.View.VISIBLE
import android.widget.TextView
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.flexibleadapter.items.IFlexible
@ -32,31 +33,26 @@ class TimetableItem(val lesson: Timetable, private val showWholeClassPlan: Strin
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<*>>, holder: ViewHolder, position: Int, payloads: MutableList<Any>?) { override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<*>>, holder: ViewHolder, position: Int, payloads: MutableList<Any>?) {
when (itemViewType) { when (itemViewType) {
R.layout.item_timetable_small -> { R.layout.item_timetable_small -> bindSmallView(holder)
R.layout.item_timetable -> bindNormalView(holder)
}
}
private fun bindSmallView(holder: ViewHolder) {
with(holder) { with(holder) {
timetableSmallItemNumber.text = lesson.number.toString() timetableSmallItemNumber.text = lesson.number.toString()
timetableSmallItemSubject.text = lesson.subject timetableSmallItemSubject.text = lesson.subject
timetableSmallItemTimeStart.text = lesson.start.toFormattedString("HH:mm") timetableSmallItemTimeStart.text = lesson.start.toFormattedString("HH:mm")
timetableSmallItemRoom.text = lesson.room timetableSmallItemRoom.text = lesson.room
timetableSmallItemTeacher.text = lesson.teacher timetableSmallItemTeacher.text = lesson.teacher
}
}
R.layout.item_timetable -> {
updateFields(holder)
with(holder) { updateSubjectStyle(timetableSmallItemSubject)
timetableItemSubject.paintFlags = updateSmallDescription(this)
if (lesson.canceled) timetableItemSubject.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG updateSmallColors(this)
else timetableItemSubject.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
}
updateDescription(holder)
updateColors(holder)
}
} }
} }
private fun updateFields(holder: ViewHolder) { private fun bindNormalView(holder: ViewHolder) {
with(holder) { with(holder) {
timetableItemNumber.text = lesson.number.toString() timetableItemNumber.text = lesson.number.toString()
timetableItemSubject.text = lesson.subject timetableItemSubject.text = lesson.subject
@ -64,24 +60,42 @@ class TimetableItem(val lesson: Timetable, private val showWholeClassPlan: Strin
timetableItemTeacher.text = lesson.teacher timetableItemTeacher.text = lesson.teacher
timetableItemTimeStart.text = lesson.start.toFormattedString("HH:mm") timetableItemTimeStart.text = lesson.start.toFormattedString("HH:mm")
timetableItemTimeFinish.text = lesson.end.toFormattedString("HH:mm") timetableItemTimeFinish.text = lesson.end.toFormattedString("HH:mm")
updateSubjectStyle(timetableItemSubject)
updateNormalDescription(this)
updateNormalColors(this)
} }
} }
private fun updateDescription(holder: ViewHolder) { private fun updateSubjectStyle(subjectView: TextView) {
subjectView.paintFlags = if (lesson.canceled) subjectView.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
else subjectView.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
}
private fun updateSmallDescription(holder: ViewHolder) {
with(holder) { with(holder) {
if (lesson.info.isNotBlank() && !lesson.changes) { if (lesson.info.isNotBlank() && !lesson.changes) {
updateDescriptionNoChanges(this) timetableSmallItemDescription.visibility = VISIBLE
timetableSmallItemDescription.text = lesson.info
timetableSmallItemRoom.visibility = GONE
timetableSmallItemTeacher.visibility = GONE
timetableSmallItemDescription.setTextColor(holder.view.context.getThemeAttrColor(
if (lesson.canceled) R.attr.colorPrimary
else R.attr.colorTimetableChange
))
} else { } else {
timetableItemDescription.visibility = GONE timetableSmallItemDescription.visibility = GONE
timetableSmallItemRoom.visibility = VISIBLE
timetableItemRoom.visibility = VISIBLE timetableSmallItemTeacher.visibility = VISIBLE
timetableItemTeacher.visibility = VISIBLE
} }
} }
} }
private fun updateDescriptionNoChanges(holder: ViewHolder) { private fun updateNormalDescription(holder: ViewHolder) {
with(holder) { with(holder) {
if (lesson.info.isNotBlank() && !lesson.changes) {
timetableItemDescription.visibility = VISIBLE timetableItemDescription.visibility = VISIBLE
timetableItemDescription.text = lesson.info timetableItemDescription.text = lesson.info
@ -92,46 +106,68 @@ class TimetableItem(val lesson: Timetable, private val showWholeClassPlan: Strin
if (lesson.canceled) R.attr.colorPrimary if (lesson.canceled) R.attr.colorPrimary
else R.attr.colorTimetableChange else R.attr.colorTimetableChange
)) ))
} else {
timetableItemDescription.visibility = GONE
timetableItemRoom.visibility = VISIBLE
timetableItemTeacher.visibility = VISIBLE
}
} }
} }
private fun updateColors(holder: ViewHolder) { private fun updateSmallColors(holder: ViewHolder) {
with(holder) { with(holder) {
if (lesson.canceled) { if (lesson.canceled) {
timetableItemNumber.setTextColor(holder.view.context.getThemeAttrColor(R.attr.colorPrimary)) updateNumberAndSubjectCanceledColor(timetableSmallItemNumber, timetableSmallItemSubject)
timetableItemSubject.setTextColor(holder.view.context.getThemeAttrColor(R.attr.colorPrimary))
} else { } else {
updateNumberColor(this) updateNumberColor(timetableSmallItemNumber)
updateSubjectColor(this) updateSubjectColor(timetableSmallItemSubject)
updateRoomColor(this) updateRoomColor(timetableSmallItemRoom)
updateTeacherColor(this) updateTeacherColor(timetableSmallItemTeacher)
} }
} }
} }
private fun updateNumberColor(holder: ViewHolder) { private fun updateNormalColors(holder: ViewHolder) {
holder.timetableItemNumber.setTextColor(holder.view.context.getThemeAttrColor( with(holder) {
if (lesson.canceled) {
updateNumberAndSubjectCanceledColor(timetableItemNumber, timetableItemSubject)
} else {
updateNumberColor(timetableItemNumber)
updateSubjectColor(timetableItemSubject)
updateRoomColor(timetableItemRoom)
updateTeacherColor(timetableItemTeacher)
}
}
}
private fun updateNumberAndSubjectCanceledColor(numberView: TextView, subjectView: TextView) {
numberView.setTextColor(numberView.context.getThemeAttrColor(R.attr.colorPrimary))
subjectView.setTextColor(subjectView.context.getThemeAttrColor(R.attr.colorPrimary))
}
private fun updateNumberColor(numberView: TextView) {
numberView.setTextColor(numberView.context.getThemeAttrColor(
if (lesson.changes || lesson.info.isNotBlank()) R.attr.colorTimetableChange if (lesson.changes || lesson.info.isNotBlank()) R.attr.colorTimetableChange
else android.R.attr.textColorPrimary else android.R.attr.textColorPrimary
)) ))
} }
private fun updateSubjectColor(holder: ViewHolder) { private fun updateSubjectColor(subjectView: TextView) {
holder.timetableItemSubject.setTextColor(holder.view.context.getThemeAttrColor( subjectView.setTextColor(subjectView.context.getThemeAttrColor(
if (lesson.subjectOld.isNotBlank() && lesson.subjectOld != lesson.subject) R.attr.colorTimetableChange if (lesson.subjectOld.isNotBlank() && lesson.subjectOld != lesson.subject) R.attr.colorTimetableChange
else android.R.attr.textColorPrimary else android.R.attr.textColorPrimary
)) ))
} }
private fun updateRoomColor(holder: ViewHolder) { private fun updateRoomColor(roomView: TextView) {
holder.timetableItemRoom.setTextColor(holder.view.context.getThemeAttrColor( roomView.setTextColor(roomView.context.getThemeAttrColor(
if (lesson.roomOld.isNotBlank() && lesson.roomOld != lesson.room) R.attr.colorTimetableChange if (lesson.roomOld.isNotBlank() && lesson.roomOld != lesson.room) R.attr.colorTimetableChange
else android.R.attr.textColorSecondary else android.R.attr.textColorSecondary
)) ))
} }
private fun updateTeacherColor(holder: ViewHolder) { private fun updateTeacherColor(teacherTextView: TextView) {
holder.timetableItemTeacher.setTextColor(holder.view.context.getThemeAttrColor( teacherTextView.setTextColor(teacherTextView.context.getThemeAttrColor(
if (lesson.teacherOld.isNotBlank() && lesson.teacherOld != lesson.teacher) R.attr.colorTimetableChange if (lesson.teacherOld.isNotBlank() && lesson.teacherOld != lesson.teacher) R.attr.colorTimetableChange
else android.R.attr.textColorSecondary else android.R.attr.textColorSecondary
)) ))
@ -153,7 +189,8 @@ class TimetableItem(val lesson: Timetable, private val showWholeClassPlan: Strin
return result return result
} }
class ViewHolder(val view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { class ViewHolder(val view: View, adapter: FlexibleAdapter<*>) :
FlexibleViewHolder(view, adapter), LayoutContainer {
override val containerView: View override val containerView: View
get() = contentView get() = contentView
} }

View File

@ -24,11 +24,11 @@
android:layout_alignTop="@id/timetableSmallItemNumber" android:layout_alignTop="@id/timetableSmallItemNumber"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
android:layout_marginTop="1dp"
android:layout_toEndOf="@id/timetableSmallItemNumber" android:layout_toEndOf="@id/timetableSmallItemNumber"
android:layout_toRightOf="@id/timetableSmallItemNumber" android:layout_toRightOf="@id/timetableSmallItemNumber"
android:maxLines="1"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"
android:textSize="15sp" android:textSize="13sp"
tools:text="11:11" /> tools:text="11:11" />
<TextView <TextView
@ -38,8 +38,6 @@
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_toEndOf="@+id/timetableSmallItemTimeStart" android:layout_toEndOf="@+id/timetableSmallItemTimeStart"
android:layout_toRightOf="@+id/timetableSmallItemTimeStart" android:layout_toRightOf="@+id/timetableSmallItemTimeStart"
android:ellipsize="end" android:ellipsize="end"
@ -48,18 +46,18 @@
android:textSize="15sp" android:textSize="15sp"
tools:text="Sieci komputerowe" /> tools:text="Sieci komputerowe" />
<TextView <TextView
android:id="@+id/timetableSmallItemRoom" android:id="@+id/timetableSmallItemRoom"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:layout_toEndOf="@+id/timetableSmallItemSubject" android:layout_toEndOf="@+id/timetableSmallItemSubject"
android:layout_toRightOf="@+id/timetableSmallItemSubject" android:layout_toRightOf="@+id/timetableSmallItemSubject"
android:maxLines="1" android:maxLines="1"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"
android:textSize="15sp" android:textSize="13sp"
tools:text="22" /> tools:text="22" />
<TextView <TextView
@ -68,14 +66,30 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginEnd="16dp" android:layout_marginTop="1dp"
android:layout_marginRight="16dp"
android:layout_toEndOf="@id/timetableSmallItemRoom" android:layout_toEndOf="@id/timetableSmallItemRoom"
android:layout_toRightOf="@id/timetableSmallItemRoom" android:layout_toRightOf="@id/timetableSmallItemRoom"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"
android:textSize="15sp" android:textSize="13sp"
tools:text="Agata Kowalska - Błaszczyk" /> tools:text="Agata" />
<TextView
android:id="@+id/timetableSmallItemDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_toEndOf="@id/timetableSmallItemTeacher"
android:layout_toRightOf="@id/timetableSmallItemTeacher"
android:ellipsize="end"
android:singleLine="true"
android:textColor="?android:textColorSecondary"
android:textSize="13sp"
tools:text="zastępstwo jakieś tam gdzieś tam" />
</RelativeLayout> </RelativeLayout>

View File

@ -13,6 +13,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/timetableWidgetItemNumber" android:id="@+id/timetableWidgetItemNumber"
android:layout_width="40dp" android:layout_width="40dp"
@ -46,8 +47,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:textColor="@android:color/black" android:textColor="@android:color/black"
@ -72,19 +71,26 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:textColor="@android:color/black" android:textColor="@android:color/black"
android:textSize="15sp" android:textSize="15sp"
tools:text="Agata Kowalska - Błaszczyk" /> tools:text="Agata" />
<TextView <TextView
android:id="@+id/timetableWidgetItemDescription" android:id="@+id/timetableWidgetItemDescription"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone" /> android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:maxLines="1"
android:singleLine="true"
android:textColor="@android:color/black"
android:textSize="15sp"
android:visibility="visible"
tools:text="@tools:sample/lorem/random" />
</LinearLayout> </LinearLayout>
<FrameLayout <FrameLayout

View File

@ -47,15 +47,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textSize="15sp" android:textSize="15sp"
tools:text="Sieci komputerowe" /> tools:text="Sieci komputerowe" />
<TextView <TextView
android:id="@+id/timetableWidgetItemRoom" android:id="@+id/timetableWidgetItemRoom"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -73,19 +70,27 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textSize="15sp" android:textSize="15sp"
tools:text="Agata Kowalska - Błaszczyk" /> tools:text="Agata" />
<TextView <TextView
android:id="@+id/timetableWidgetItemDescription" android:id="@+id/timetableWidgetItemDescription"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone" /> android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:maxLines="1"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="15sp"
android:visibility="visible"
tools:text="@tools:sample/lorem/random" />
</LinearLayout> </LinearLayout>
<FrameLayout <FrameLayout