use more compact listview at inapp event listview too

This commit is contained in:
tibbi 2018-05-27 13:07:25 +02:00
parent ed0d974e00
commit c36d360776
3 changed files with 83 additions and 11 deletions

View File

@ -29,11 +29,12 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
private val ITEM_EVENT = 0
private val ITEM_HEADER = 1
private val ITEM_EVENT_SIMPLE = 1
private val ITEM_HEADER = 2
private val topDivider = resources.getDrawable(R.drawable.divider_width)
private val allDayString = resources.getString(R.string.all_day)
private val replaceDescriptionWithLocation = activity.config.replaceDescription
private val replaceDescription = activity.config.replaceDescription
private val dimPastEvents = activity.config.dimPastEvents
private val now = getNowSeconds()
private var use24HourFormat = activity.config.use24HourFormat
@ -76,7 +77,11 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
override fun getSelectableItemCount() = listItems.filter { it is ListEvent }.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyRecyclerViewAdapter.ViewHolder {
val layoutId = if (viewType == ITEM_EVENT) R.layout.event_list_item else R.layout.event_list_section
val layoutId = when (viewType) {
ITEM_EVENT -> R.layout.event_list_item
ITEM_EVENT_SIMPLE -> R.layout.event_list_item_simple
else -> R.layout.event_list_section
}
return createViewHolder(layoutId, parent)
}
@ -94,7 +99,17 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
override fun getItemCount() = listItems.size
override fun getItemViewType(position: Int) = if (listItems[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
override fun getItemViewType(position: Int) = if (listItems[position] is ListEvent) {
val event = listItems[position] as ListEvent
val detailField = if (replaceDescription) event.location else event.description
if (event.startTS == event.endTS && detailField.isEmpty()) {
ITEM_EVENT_SIMPLE
} else {
ITEM_EVENT
}
} else {
ITEM_HEADER
}
fun toggle24HourFormat(use24HourFormat: Boolean) {
this.use24HourFormat = use24HourFormat
@ -114,16 +129,16 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
private fun setupListEvent(view: View, listEvent: ListEvent) {
view.apply {
event_section_title.text = listEvent.title
event_item_description.text = if (replaceDescriptionWithLocation) listEvent.location else listEvent.description
event_item_description?.text = if (replaceDescription) listEvent.location else listEvent.description
event_item_start.text = if (listEvent.isAllDay) allDayString else Formatter.getTimeFromTS(context, listEvent.startTS)
event_item_end.beInvisibleIf(listEvent.startTS == listEvent.endTS)
event_item_end?.beInvisibleIf(listEvent.startTS == listEvent.endTS)
event_item_color.applyColorFilter(listEvent.color)
if (listEvent.startTS != listEvent.endTS) {
val startCode = Formatter.getDayCodeFromTS(listEvent.startTS)
val endCode = Formatter.getDayCodeFromTS(listEvent.endTS)
event_item_end?.apply {
val startCode = Formatter.getDayCodeFromTS(listEvent.startTS)
val endCode = Formatter.getDayCodeFromTS(listEvent.endTS)
event_item_end.apply {
text = Formatter.getTimeFromTS(context, listEvent.endTS)
if (startCode != endCode) {
if (listEvent.isAllDay) {
@ -155,9 +170,9 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
}
event_item_start.setTextColor(startTextColor)
event_item_end.setTextColor(endTextColor)
event_item_end?.setTextColor(endTextColor)
event_section_title.setTextColor(startTextColor)
event_item_description.setTextColor(startTextColor)
event_item_description?.setTextColor(startTextColor)
}
}

View File

@ -32,6 +32,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/event_item_start"
android:includeFontPadding="false"
android:text="15:00"
android:textSize="@dimen/day_text_size"/>
@ -57,6 +58,7 @@
android:layout_toLeftOf="@+id/event_item_color"
android:layout_toRightOf="@+id/event_item_end"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
android:paddingRight="@dimen/activity_margin"
android:textSize="@dimen/day_text_size"

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/event_item_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:foreground="@drawable/selector"
android:paddingLeft="@dimen/activity_margin">
<RelativeLayout
android:id="@+id/event_item_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/medium_margin"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/small_margin">
<TextView
android:id="@+id/event_item_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/day_text_size"
tools:text="13:00"/>
<TextView
android:id="@+id/event_section_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_toLeftOf="@+id/event_item_color"
android:layout_toRightOf="@+id/event_item_start"
android:ellipsize="end"
android:maxLines="1"
android:paddingRight="@dimen/activity_margin"
android:textSize="@dimen/day_text_size"
tools:text="Event title"/>
<ImageView
android:id="@+id/event_item_color"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/event_section_title"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/event_section_title"
android:paddingRight="@dimen/medium_margin"
android:src="@drawable/monthly_event_dot"/>
</RelativeLayout>
</FrameLayout>