mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
add a top indicator for all-day events
This commit is contained in:
@ -181,7 +181,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
||||
description = newDescription
|
||||
reminderMinutes = mReminderMinutes
|
||||
repeatInterval = mRepeatInterval
|
||||
flags = if (event_all_day.isChecked) (mEvent.flags or FLAG_ALL_DAY) else (mEvent.flags xor FLAG_ALL_DAY)
|
||||
flags = if (event_all_day.isChecked) (mEvent.flags or FLAG_ALL_DAY) else (mEvent.flags.removeFlag(FLAG_ALL_DAY))
|
||||
}
|
||||
|
||||
if (mEvent.id == 0) {
|
||||
|
@ -14,7 +14,7 @@ import android.widget.SeekBar
|
||||
import android.widget.TextView
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.extensions.removeUnderlineFlag
|
||||
import com.simplemobiletools.calendar.extensions.removeFlag
|
||||
import com.simplemobiletools.calendar.helpers.LOW_ALPHA
|
||||
import com.simplemobiletools.calendar.helpers.MonthlyCalendarImpl
|
||||
import com.simplemobiletools.calendar.helpers.MyWidgetMonthlyProvider
|
||||
@ -171,7 +171,7 @@ class WidgetMonthlyConfigureActivity : AppCompatActivity(), MonthlyCalendar {
|
||||
text = day.value.toString()
|
||||
setTextColor(curTextColor)
|
||||
|
||||
paintFlags = if (day.hasEvent) (paintFlags or Paint.UNDERLINE_TEXT_FLAG) else (paintFlags.removeUnderlineFlag())
|
||||
paintFlags = if (day.hasEvent) (paintFlags or Paint.UNDERLINE_TEXT_FLAG) else (paintFlags.removeFlag(Paint.UNDERLINE_TEXT_FLAG))
|
||||
background = if (day.isToday) todayCircle else null
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,4 @@
|
||||
package com.simplemobiletools.calendar.extensions
|
||||
|
||||
import android.graphics.Paint
|
||||
|
||||
// TODO: how to do "flags & ~Paint.UNDERLINE_TEXT_FLAG" in kotlin?
|
||||
fun Int.removeUnderlineFlag(): Int {
|
||||
return this - (if (this and Paint.UNDERLINE_TEXT_FLAG == Paint.UNDERLINE_TEXT_FLAG) Paint.UNDERLINE_TEXT_FLAG else 0)
|
||||
}
|
||||
// TODO: how to do "flags & ~flag" in kotlin?
|
||||
fun Int.removeFlag(flag: Int) = this - (if (this and flag != 0) flag else 0)
|
||||
|
@ -17,7 +17,7 @@ import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.activities.DayActivity
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.extensions.getAppropriateTheme
|
||||
import com.simplemobiletools.calendar.extensions.removeUnderlineFlag
|
||||
import com.simplemobiletools.calendar.extensions.removeFlag
|
||||
import com.simplemobiletools.calendar.helpers.*
|
||||
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
|
||||
import com.simplemobiletools.calendar.interfaces.NavigationListener
|
||||
@ -187,7 +187,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
|
||||
setTextColor(curTextColor)
|
||||
setOnClickListener { openDay(day.code) }
|
||||
|
||||
paintFlags = if (day.hasEvent) (paintFlags or Paint.UNDERLINE_TEXT_FLAG) else (paintFlags.removeUnderlineFlag())
|
||||
paintFlags = if (day.hasEvent) (paintFlags or Paint.UNDERLINE_TEXT_FLAG) else (paintFlags.removeFlag(Paint.UNDERLINE_TEXT_FLAG))
|
||||
background = if (day.isToday) todayCircle else null
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewTreeObserver
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import com.simplemobiletools.calendar.R
|
||||
@ -24,6 +25,7 @@ import com.simplemobiletools.calendar.views.MyScrollView
|
||||
import kotlinx.android.synthetic.main.fragment_week.*
|
||||
import kotlinx.android.synthetic.main.fragment_week.view.*
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.Days
|
||||
import kotlin.comparisons.compareBy
|
||||
|
||||
class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
@ -33,6 +35,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
private var minScrollY = -1
|
||||
private var maxScrollY = -1
|
||||
private var mWasDestroyed = false
|
||||
private var primaryColor = 0
|
||||
lateinit var mView: View
|
||||
lateinit var mCalendar: WeeklyCalendarImpl
|
||||
lateinit var mRes: Resources
|
||||
@ -41,6 +44,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
mRowHeight = (context.resources.getDimension(R.dimen.weekly_view_row_height)).toInt()
|
||||
minScrollY = mRowHeight * context.config.startWeeklyAt
|
||||
mWeekTimestamp = arguments.getInt(WEEK_START_TIMESTAMP)
|
||||
primaryColor = context.config.primaryColor
|
||||
|
||||
mView = inflater.inflate(R.layout.fragment_week, container, false).apply {
|
||||
week_events_scrollview.setOnScrollviewListener(object : MyScrollView.ScrollViewListener {
|
||||
@ -104,7 +108,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
val dayLetter = getDayLetter(curDay.dayOfWeek)
|
||||
(mView.findViewById(mRes.getIdentifier("week_day_label_$i", "id", context.packageName)) as TextView).apply {
|
||||
text = "$dayLetter\n${curDay.dayOfMonth}"
|
||||
setTextColor(if (todayCode == dayCode) context.config.primaryColor else textColor)
|
||||
setTextColor(if (todayCode == dayCode) primaryColor else textColor)
|
||||
}
|
||||
curDay = curDay.plusDays(1)
|
||||
}
|
||||
@ -139,13 +143,17 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
val fullHeight = mRes.getDimension(R.dimen.weekly_view_events_height)
|
||||
val minuteHeight = fullHeight / (24 * 60)
|
||||
val minimalHeight = mRes.getDimension(R.dimen.weekly_view_minimal_event_height).toInt()
|
||||
val eventColor = context.config.primaryColor
|
||||
val sideMargin = mRes.displayMetrics.density.toInt()
|
||||
(0..6).map { getColumnWithId(it) }
|
||||
.forEach { activity.runOnUiThread { it.removeAllViews() } }
|
||||
|
||||
activity.runOnUiThread { mView.week_all_day_holder.removeAllViews() }
|
||||
|
||||
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
|
||||
for (event in sorted) {
|
||||
if (event.isAllDay()) {
|
||||
addAllDayEvent(event)
|
||||
} else {
|
||||
val startDateTime = Formatter.getDateTimeFromTS(event.startTS).plusDays(if (context.config.isSundayFirst) 1 else 0)
|
||||
val endDateTime = Formatter.getDateTimeFromTS(event.endTS)
|
||||
val dayOfWeek = startDateTime.dayOfWeek - 1
|
||||
@ -155,7 +163,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
val duration = endDateTime.minuteOfDay - startMinutes
|
||||
|
||||
(LayoutInflater.from(context).inflate(R.layout.week_event_marker, null, false) as TextView).apply {
|
||||
background = ColorDrawable(eventColor)
|
||||
background = ColorDrawable(primaryColor)
|
||||
text = event.title
|
||||
activity.runOnUiThread {
|
||||
layout.addView(this)
|
||||
@ -175,6 +183,37 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addAllDayEvent(event: Event) {
|
||||
(LayoutInflater.from(context).inflate(R.layout.week_all_day_event_marker, null, false) as TextView).apply {
|
||||
background = ColorDrawable(primaryColor)
|
||||
text = event.title
|
||||
|
||||
val startDateTime = Formatter.getDateTimeFromTS(event.startTS)
|
||||
val endDateTime = Formatter.getDateTimeFromTS(event.endTS)
|
||||
|
||||
val firstDayIndex = startDateTime.dayOfWeek - if (context.config.isSundayFirst) 0 else 1
|
||||
val daysCnt = Days.daysBetween(startDateTime.withTimeAtStartOfDay(), endDateTime.withTimeAtStartOfDay()).days
|
||||
|
||||
activity.runOnUiThread {
|
||||
val dayColumnWidth = getColumnWithId(1).width
|
||||
mView.week_all_day_holder.addView(this)
|
||||
(layoutParams as LinearLayout.LayoutParams).apply {
|
||||
topMargin = mRes.getDimension(R.dimen.tiny_margin).toInt()
|
||||
bottomMargin = mRes.getDimension(R.dimen.tiny_margin).toInt()
|
||||
leftMargin = firstDayIndex * dayColumnWidth
|
||||
width = (daysCnt + 1) * dayColumnWidth - mRes.displayMetrics.density.toInt()
|
||||
}
|
||||
}
|
||||
setOnClickListener {
|
||||
Intent(activity.applicationContext, EventActivity::class.java).apply {
|
||||
putExtra(EVENT_ID, event.id)
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
|
@ -27,4 +27,6 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
|
||||
startTS = newStartTS
|
||||
endTS = newEndTS
|
||||
}
|
||||
|
||||
fun isAllDay() = flags and FLAG_ALL_DAY != 0
|
||||
}
|
||||
|
@ -85,12 +85,12 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
<LinearLayout
|
||||
android:id="@+id/week_all_day_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<com.simplemobiletools.calendar.views.MyScrollView
|
||||
|
10
app/src/main/res/layout/week_all_day_event_marker.xml
Normal file
10
app/src/main/res/layout/week_all_day_event_marker.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:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:padding="@dimen/tiny_margin"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="@dimen/small_text_size"/>
|
Reference in New Issue
Block a user