add a sample event in week view

This commit is contained in:
tibbi 2017-01-16 23:41:06 +01:00
parent f64212eb79
commit a3b614862d
4 changed files with 29 additions and 10 deletions

View File

@ -10,7 +10,7 @@ import com.simplemobiletools.calendar.fragments.WeekFragment
class MyWeekPagerAdapter(fm: FragmentManager, private val mListener: WeekFragment.WeekScrollListener) : FragmentStatePagerAdapter(fm) {
private val mFragments = SparseArray<WeekFragment>()
override fun getCount() = 3
override fun getCount() = 1
override fun getItem(position: Int): Fragment {
val bundle = Bundle()

View File

@ -1,14 +1,18 @@
package com.simplemobiletools.calendar.fragments
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.widget.LinearLayout
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.MainActivity
import com.simplemobiletools.calendar.adapters.WeekEventsAdapter
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.helpers.WeeklyCalendarImpl
import com.simplemobiletools.calendar.interfaces.WeeklyCalendar
import com.simplemobiletools.calendar.models.Event
@ -48,7 +52,17 @@ class WeekFragment : Fragment(), WeeklyCalendar {
}
override fun updateWeeklyCalendar(events: List<Event>) {
val res = resources
val eventColor = context.config.primaryColor
for (event in events) {
val dateTime = Formatter.getDateTimeFromTS(event.startTS)
val dayOfWeek = dateTime.dayOfWeek - if (context.config.isSundayFirst) 0 else 1
val layout = mView.findViewById(res.getIdentifier("week_column_$dayOfWeek", "id", context.packageName)) as LinearLayout
LayoutInflater.from(context).inflate(R.layout.week_event_marker, null, false).apply {
background = ColorDrawable(eventColor)
layout.addView(this)
}
}
}
fun setListener(listener: WeekScrollListener) {

View File

@ -93,6 +93,14 @@
android:background="@android:color/transparent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/week_column_0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/week_column_1"
android:layout_width="match_parent"
@ -141,14 +149,6 @@
android:background="@android:color/transparent"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/week_column_7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:orientation="vertical"/>
</LinearLayout>
</RelativeLayout>
</com.simplemobiletools.calendar.views.MyScrollView>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="10dp"/>