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

View File

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

View File

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

View File

@ -47,15 +47,12 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@android:color/white"
android:textSize="15sp"
tools:text="Sieci komputerowe" />
<TextView
android:id="@+id/timetableWidgetItemRoom"
android:layout_width="wrap_content"
@ -73,19 +70,27 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@android:color/white"
android:textSize="15sp"
tools:text="Agata Kowalska - Błaszczyk" />
tools:text="Agata" />
<TextView
android:id="@+id/timetableWidgetItemDescription"
android:layout_width="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>
<FrameLayout