inflate the events list as a fragment

This commit is contained in:
tibbi 2016-10-22 23:44:30 +02:00
parent 7fd1907b3e
commit 8b85ed656c
5 changed files with 104 additions and 9 deletions

View File

@ -13,6 +13,7 @@ import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.adapters.MyMonthPagerAdapter
import com.simplemobiletools.calendar.adapters.MyYearPagerAdapter
import com.simplemobiletools.calendar.extensions.updateWidget
import com.simplemobiletools.calendar.fragments.EventListFragment
import com.simplemobiletools.calendar.views.dialogs.ChangeViewDialog
import kotlinx.android.synthetic.main.activity_main.*
import org.joda.time.DateTime
@ -118,7 +119,7 @@ class MainActivity : SimpleActivity(), NavigationListener, ChangeViewDialog.Chan
visibility = View.VISIBLE
}
title = getString(R.string.app_launcher_name)
calendar_events_list.visibility = View.GONE
calendar_event_list_holder.visibility = View.GONE
}
private fun getMonths(code: String): List<String> {
@ -154,7 +155,7 @@ class MainActivity : SimpleActivity(), NavigationListener, ChangeViewDialog.Chan
visibility = View.VISIBLE
}
title = "${getString(R.string.app_launcher_name)} - ${years[years.size / 2]}"
calendar_events_list.visibility = View.GONE
calendar_event_list_holder.visibility = View.GONE
}
private fun getYears(targetYear: Int): List<Int> {
@ -169,7 +170,8 @@ class MainActivity : SimpleActivity(), NavigationListener, ChangeViewDialog.Chan
title = getString(R.string.app_launcher_name)
view_pager.adapter = null
view_pager.visibility = View.GONE
calendar_events_list.visibility = View.VISIBLE
calendar_event_list_holder.visibility = View.VISIBLE
supportFragmentManager.beginTransaction().replace(R.id.calendar_event_list_holder, EventListFragment(), "").commit()
}
override fun goLeft() {

View File

@ -0,0 +1,65 @@
package com.simplemobiletools.calendar.adapters
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.simplemobiletools.calendar.Formatter
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.models.Event
import kotlinx.android.synthetic.main.event_item.view.*
class EventsListAdapter(context: Context, private val mEvents: List<Event>) : BaseAdapter() {
private val mInflater: LayoutInflater
init {
mInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
var view = convertView
val viewHolder: ViewHolder
if (view == null) {
view = mInflater.inflate(R.layout.event_item, parent, false)
viewHolder = ViewHolder(view)
view!!.tag = viewHolder
} else {
viewHolder = view.tag as ViewHolder
}
val event = mEvents[position]
viewHolder.apply {
title.text = event.title
description.text = event.description
start.text = Formatter.getTime(event.startTS)
if (event.startTS == event.endTS) {
end.visibility = View.INVISIBLE
} else {
end.text = Formatter.getTime(event.endTS)
}
}
return view
}
override fun getCount(): Int {
return mEvents.size
}
override fun getItem(position: Int): Any {
return mEvents[position]
}
override fun getItemId(position: Int): Long {
return 0
}
class ViewHolder(view: View) {
val title = view.event_item_title
val description = view.event_item_description
val start = view.event_item_start
val end = view.event_item_end
}
}

View File

@ -0,0 +1,22 @@
package com.simplemobiletools.calendar.fragments
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.calendar.DBHelper
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.models.Event
class EventListFragment : Fragment(), DBHelper.GetEventsListener {
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater!!.inflate(R.layout.fragment_event_list, container, false)
return view
}
override fun gotEvents(events: MutableList<Event>) {
}
}

View File

@ -11,13 +11,10 @@
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ListView
android:id="@+id/calendar_events_list"
<FrameLayout
android:id="@+id/calendar_event_list_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoiceModal"
android:clipToPadding="false"
android:paddingLeft="@dimen/activity_margin"
android:layout_height="match_parent"
android:visibility="gone"/>
<android.support.design.widget.FloatingActionButton

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/calendar_events_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoiceModal"
android:clipToPadding="false"
android:paddingLeft="@dimen/activity_margin"/>