cleaning up some code from the previous list views

This commit is contained in:
tibbi 2021-11-21 16:18:02 +01:00
parent 67dae16d11
commit ce3123811e
4 changed files with 10 additions and 51 deletions

View File

@ -11,8 +11,6 @@ import com.simplemobiletools.calendar.pro.extensions.eventsHelper
import com.simplemobiletools.calendar.pro.extensions.handleEventDeleting import com.simplemobiletools.calendar.pro.extensions.handleEventDeleting
import com.simplemobiletools.calendar.pro.extensions.shareEvents import com.simplemobiletools.calendar.pro.extensions.shareEvents
import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.helpers.ITEM_EVENT
import com.simplemobiletools.calendar.pro.helpers.ITEM_EVENT_SIMPLE
import com.simplemobiletools.calendar.pro.models.Event import com.simplemobiletools.calendar.pro.models.Event
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.adjustAlpha import com.simplemobiletools.commons.extensions.adjustAlpha
@ -70,26 +68,6 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
override fun getItemCount() = events.size override fun getItemCount() = events.size
override fun getItemViewType(position: Int): Int {
val event = events[position]
val detailField = if (replaceDescriptionWithLocation) event.location else event.description
return if (detailField.isNotEmpty()) {
ITEM_EVENT
} else if (event.startTS == event.endTS) {
ITEM_EVENT_SIMPLE
} else if (event.getIsAllDay()) {
val startCode = Formatter.getDayCodeFromTS(event.startTS)
val endCode = Formatter.getDayCodeFromTS(event.endTS)
if (startCode == endCode) {
ITEM_EVENT_SIMPLE
} else {
ITEM_EVENT
}
} else {
ITEM_EVENT
}
}
fun togglePrintMode() { fun togglePrintMode() {
isPrintVersion = !isPrintVersion isPrintVersion = !isPrintVersion
textColor = if (isPrintVersion) { textColor = if (isPrintVersion) {
@ -110,7 +88,7 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
event_item_time.text = "${event_item_time.text} - ${Formatter.getTimeFromTS(context, event.endTS)}" event_item_time.text = "${event_item_time.text} - ${Formatter.getTimeFromTS(context, event.endTS)}"
} }
event_item_description?.text = if (replaceDescriptionWithLocation) event.location else event.description event_item_description.text = if (replaceDescriptionWithLocation) event.location else event.description
event_item_description.beVisibleIf(event_item_description.text.isNotEmpty()) event_item_description.beVisibleIf(event_item_description.text.isNotEmpty())
event_item_color_bar.background.applyColorFilter(event.color) event_item_color_bar.background.applyColorFilter(event.color)

View File

@ -88,7 +88,7 @@ class EventListAdapter(
val listItem = listItems[position] val listItem = listItems[position]
holder.bindView(listItem, true, allowLongClick && listItem is ListEvent) { itemView, layoutPosition -> holder.bindView(listItem, true, allowLongClick && listItem is ListEvent) { itemView, layoutPosition ->
when (listItem) { when (listItem) {
is ListSectionDay -> setupListSectionDay(itemView, listItem, position) is ListSectionDay -> setupListSectionDay(itemView, listItem)
is ListEvent -> setupListEvent(itemView, listItem) is ListEvent -> setupListEvent(itemView, listItem)
is ListSectionMonth -> setupListSectionMonth(itemView, listItem) is ListSectionMonth -> setupListSectionMonth(itemView, listItem)
} }
@ -98,28 +98,10 @@ class EventListAdapter(
override fun getItemCount() = listItems.size override fun getItemCount() = listItems.size
override fun getItemViewType(position: Int) = if (listItems[position] is ListEvent) { override fun getItemViewType(position: Int) = when {
val event = listItems[position] as ListEvent listItems[position] is ListEvent -> ITEM_EVENT
val detailField = if (replaceDescription) event.location else event.description listItems[position] is ListSectionDay -> ITEM_SECTION_DAY
if (detailField.isNotEmpty()) { else -> ITEM_SECTION_MONTH
ITEM_EVENT
} else if (event.startTS == event.endTS) {
ITEM_EVENT_SIMPLE
} else if (event.isAllDay) {
val startCode = Formatter.getDayCodeFromTS(event.startTS)
val endCode = Formatter.getDayCodeFromTS(event.endTS)
if (startCode == endCode) {
ITEM_EVENT_SIMPLE
} else {
ITEM_EVENT
}
} else {
ITEM_EVENT
}
} else if (listItems[position] is ListSectionDay) {
ITEM_SECTION_DAY
} else {
ITEM_SECTION_MONTH
} }
fun toggle24HourFormat(use24HourFormat: Boolean) { fun toggle24HourFormat(use24HourFormat: Boolean) {
@ -180,7 +162,7 @@ class EventListAdapter(
} }
} }
private fun setupListSectionDay(view: View, listSectionDay: ListSectionDay, position: Int) { private fun setupListSectionDay(view: View, listSectionDay: ListSectionDay) {
view.event_section_title.apply { view.event_section_title.apply {
text = listSectionDay.title text = listSectionDay.title
var color = if (listSectionDay.isToday && !isPrintVersion) adjustedPrimaryColor else textColor var color = if (listSectionDay.isToday && !isPrintVersion) adjustedPrimaryColor else textColor

View File

@ -31,9 +31,8 @@ const val MONTHLY_DAILY_VIEW = 7
const val REMINDER_OFF = -1 const val REMINDER_OFF = -1
const val ITEM_EVENT = 0 const val ITEM_EVENT = 0
const val ITEM_EVENT_SIMPLE = 1 const val ITEM_SECTION_DAY = 1
const val ITEM_SECTION_DAY = 2 const val ITEM_SECTION_MONTH = 2
const val ITEM_SECTION_MONTH = 3
const val DEFAULT_START_TIME_NEXT_FULL_HOUR = -1 const val DEFAULT_START_TIME_NEXT_FULL_HOUR = -1
const val DEFAULT_START_TIME_CURRENT_TIME = -2 const val DEFAULT_START_TIME_CURRENT_TIME = -2

View File

@ -82,4 +82,4 @@
tools:text="Event description" /> tools:text="Event description" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout><!--</FrameLayout>--> </androidx.constraintlayout.widget.ConstraintLayout>