mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
add sections with dates to the events list
This commit is contained in:
@ -38,6 +38,7 @@ class EventsAdapter(context: Context, private val mEvents: List<Event>) : BaseAd
|
|||||||
end.visibility = View.INVISIBLE
|
end.visibility = View.INVISIBLE
|
||||||
} else {
|
} else {
|
||||||
end.text = Formatter.getTime(event.endTS)
|
end.text = Formatter.getTime(event.endTS)
|
||||||
|
end.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,12 +30,11 @@ class EventsListAdapter(context: Context, private val mEvents: List<ListItem>) :
|
|||||||
|
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
if (type == ITEM_EVENT) {
|
if (type == ITEM_EVENT) {
|
||||||
view = mInflater.inflate(R.layout.event_item, parent, false)
|
view = mInflater.inflate(R.layout.event_list_item, parent, false)
|
||||||
viewHolder = ViewHolder(view)
|
|
||||||
} else {
|
} else {
|
||||||
view = mInflater.inflate(R.layout.event_section, parent, false)
|
view = mInflater.inflate(R.layout.event_list_section, parent, false)
|
||||||
viewHolder = ViewHolder(view)
|
|
||||||
}
|
}
|
||||||
|
viewHolder = ViewHolder(view)
|
||||||
view!!.tag = viewHolder
|
view!!.tag = viewHolder
|
||||||
} else {
|
} else {
|
||||||
viewHolder = view.tag as ViewHolder
|
viewHolder = view.tag as ViewHolder
|
||||||
@ -52,6 +51,7 @@ class EventsListAdapter(context: Context, private val mEvents: List<ListItem>) :
|
|||||||
end?.visibility = View.INVISIBLE
|
end?.visibility = View.INVISIBLE
|
||||||
} else {
|
} else {
|
||||||
end?.text = Formatter.getTime(item.endTS)
|
end?.text = Formatter.getTime(item.endTS)
|
||||||
|
end?.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -79,10 +79,10 @@ class EventsListAdapter(context: Context, private val mEvents: List<ListItem>) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemId(position: Int): Long {
|
override fun getItemId(position: Int): Long {
|
||||||
return position.toLong()
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
class ViewHolder(view: View) {
|
internal class ViewHolder(view: View) {
|
||||||
val title = view.event_item_title
|
val title = view.event_item_title
|
||||||
val description: TextView? = view.event_item_description
|
val description: TextView? = view.event_item_description
|
||||||
val start: TextView? = view.event_item_start
|
val start: TextView? = view.event_item_start
|
||||||
|
@ -6,11 +6,13 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.simplemobiletools.calendar.DBHelper
|
import com.simplemobiletools.calendar.DBHelper
|
||||||
|
import com.simplemobiletools.calendar.Formatter
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.adapters.EventsListAdapter
|
import com.simplemobiletools.calendar.adapters.EventsListAdapter
|
||||||
import com.simplemobiletools.calendar.models.Event
|
import com.simplemobiletools.calendar.models.Event
|
||||||
import com.simplemobiletools.calendar.models.ListEvent
|
import com.simplemobiletools.calendar.models.ListEvent
|
||||||
import com.simplemobiletools.calendar.models.ListItem
|
import com.simplemobiletools.calendar.models.ListItem
|
||||||
|
import com.simplemobiletools.calendar.models.ListSection
|
||||||
import kotlinx.android.synthetic.main.fragment_event_list.view.*
|
import kotlinx.android.synthetic.main.fragment_event_list.view.*
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -34,7 +36,16 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener {
|
|||||||
override fun gotEvents(events: MutableList<Event>) {
|
override fun gotEvents(events: MutableList<Event>) {
|
||||||
val listItems = ArrayList<ListItem>(events.size)
|
val listItems = ArrayList<ListItem>(events.size)
|
||||||
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }))
|
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }))
|
||||||
sorted.forEach { listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description)) }
|
var prevCode = ""
|
||||||
|
sorted.forEach {
|
||||||
|
val code = Formatter.getDayCodeFromTS(it.startTS)
|
||||||
|
if (code != prevCode) {
|
||||||
|
val day = Formatter.getEventDate(context, code)
|
||||||
|
listItems.add(ListSection(day, false))
|
||||||
|
prevCode = code
|
||||||
|
}
|
||||||
|
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description))
|
||||||
|
}
|
||||||
|
|
||||||
val eventsAdapter = EventsListAdapter(context, listItems)
|
val eventsAdapter = EventsListAdapter(context, listItems)
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
|
9
app/src/main/res/drawable/divider.xml
Normal file
9
app/src/main/res/drawable/divider.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<size
|
||||||
|
android:width="10000dp"
|
||||||
|
android:height="1dp"/>
|
||||||
|
|
||||||
|
<solid android:color="@color/mediumGrey"/>
|
||||||
|
</shape>
|
49
app/src/main/res/layout/event_list_item.xml
Normal file
49
app/src/main/res/layout/event_list_item.xml
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/event_item_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/event_item_background"
|
||||||
|
android:paddingBottom="@dimen/event_padding"
|
||||||
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
|
android:paddingTop="@dimen/small_padding">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/event_item_start"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="13:00"
|
||||||
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/event_item_end"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/event_item_start"
|
||||||
|
android:text="15:00"
|
||||||
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/event_item_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="@dimen/activity_margin"
|
||||||
|
android:layout_toRightOf="@+id/event_item_start"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:text="Event title"
|
||||||
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/event_item_description"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/event_item_title"
|
||||||
|
android:layout_marginLeft="@dimen/activity_margin"
|
||||||
|
android:layout_toRightOf="@+id/event_item_start"
|
||||||
|
android:alpha=".4"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:text="Event description"
|
||||||
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
10
app/src/main/res/layout/event_list_section.xml
Normal file
10
app/src/main/res/layout/event_list_section.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<TextView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/event_item_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:drawablePadding="1dp"
|
||||||
|
android:drawableTop="@drawable/divider"
|
||||||
|
android:textSize="@dimen/normal_text_size"
|
||||||
|
android:textStyle="bold"/>
|
@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<TextView
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@+id/event_item_title"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="@dimen/day_text_size"/>
|
|
@ -6,4 +6,5 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:choiceMode="multipleChoiceModal"
|
android:choiceMode="multipleChoiceModal"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
|
android:divider="@null"
|
||||||
android:paddingLeft="@dimen/activity_margin"/>
|
android:paddingLeft="@dimen/activity_margin"/>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<dimen name="activity_margin">16dp</dimen>
|
<dimen name="activity_margin">16dp</dimen>
|
||||||
|
<dimen name="small_padding">4dp</dimen>
|
||||||
<dimen name="medium_padding">8dp</dimen>
|
<dimen name="medium_padding">8dp</dimen>
|
||||||
<dimen name="social_padding">8dp</dimen>
|
<dimen name="social_padding">8dp</dimen>
|
||||||
<dimen name="social_logo">40dp</dimen>
|
<dimen name="social_logo">40dp</dimen>
|
||||||
|
Reference in New Issue
Block a user