mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 04:10:45 +01:00
fix #62, allow highlighting the weekend on some views
This commit is contained in:
parent
e939b302dc
commit
d49bfeace0
@ -46,6 +46,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
setupManageEventTypes()
|
||||
setupHourFormat()
|
||||
setupSundayFirst()
|
||||
setupHighlightWeekends()
|
||||
setupDeleteAllEvents()
|
||||
setupReplaceDescription()
|
||||
setupWeekNumbers()
|
||||
@ -275,6 +276,14 @@ class SettingsActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupHighlightWeekends() {
|
||||
settings_highlight_weekends.isChecked = config.highlightWeekends
|
||||
settings_highlight_weekends_holder.setOnClickListener {
|
||||
settings_highlight_weekends.toggle()
|
||||
config.highlightWeekends = settings_highlight_weekends.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupDeleteAllEvents() {
|
||||
settings_delete_all_events_holder.setOnClickListener {
|
||||
ConfirmationDialog(this, messageId = R.string.delete_all_events_confirmation) {
|
||||
|
@ -57,6 +57,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
private var wasFragmentInit = false
|
||||
private var wasExtraHeightAdded = false
|
||||
private var dimPastEvents = true
|
||||
private var highlightWeekends = false
|
||||
private var wasScaled = false
|
||||
private var isPrintVersion = false
|
||||
private var selectedGrid: View? = null
|
||||
@ -83,6 +84,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
defaultRowHeight = res.getDimension(R.dimen.weekly_view_row_height)
|
||||
weekTimestamp = arguments!!.getLong(WEEK_START_TIMESTAMP)
|
||||
dimPastEvents = config.dimPastEvents
|
||||
highlightWeekends = config.highlightWeekends
|
||||
primaryColor = context!!.getAdjustedPrimaryColor()
|
||||
allDayRows.add(HashSet())
|
||||
}
|
||||
@ -209,7 +211,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
|
||||
private fun setupDayLabels() {
|
||||
var curDay = Formatter.getUTCDateTimeFromTS(weekTimestamp)
|
||||
val textColor = if (isPrintVersion) resources.getColor(R.color.theme_light_text_color) else config.textColor
|
||||
val todayCode = Formatter.getDayCodeFromDateTime(DateTime())
|
||||
val screenWidth = context?.usableScreenSize?.x ?: return
|
||||
val dayWidth = screenWidth / config.weeklyViewDays
|
||||
@ -227,9 +228,19 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
val dayLetters = res.getStringArray(labelIDs).toMutableList() as ArrayList<String>
|
||||
val dayLetter = dayLetters[curDay.dayOfWeek - 1]
|
||||
|
||||
val textColor = if (isPrintVersion) {
|
||||
resources.getColor(R.color.theme_light_text_color)
|
||||
} else if (todayCode == dayCode) {
|
||||
primaryColor
|
||||
} else if (highlightWeekends && isWeekend(i, config.isSundayFirst)) {
|
||||
resources.getColor(R.color.red_text)
|
||||
} else {
|
||||
config.textColor
|
||||
}
|
||||
|
||||
val label = inflater.inflate(R.layout.weekly_view_day_letter, mView.week_letters_holder, false) as MyTextView
|
||||
label.text = "$dayLetter\n${curDay.dayOfMonth}"
|
||||
label.setTextColor(if (todayCode == dayCode && !isPrintVersion) primaryColor else textColor)
|
||||
label.setTextColor(textColor)
|
||||
if (todayCode == dayCode) {
|
||||
todayColumnIndex = i
|
||||
}
|
||||
|
@ -186,4 +186,8 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
var weeklyViewDays: Int
|
||||
get() = prefs.getInt(WEEKLY_VIEW_DAYS, 7)
|
||||
set(weeklyViewDays) = prefs.edit().putInt(WEEKLY_VIEW_DAYS, weeklyViewDays).apply()
|
||||
|
||||
var highlightWeekends: Boolean
|
||||
get() = prefs.getBoolean(HIGHLIGHT_WEEKENDS, false)
|
||||
set(highlightWeekends) = prefs.edit().putBoolean(HIGHLIGHT_WEEKENDS, highlightWeekends).apply()
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ const val LAST_EXPORT_PATH = "last_export_path"
|
||||
const val EXPORT_PAST_EVENTS = "export_past_events"
|
||||
const val WEEKLY_VIEW_ITEM_HEIGHT_MULTIPLIER = "weekly_view_item_height_multiplier"
|
||||
const val WEEKLY_VIEW_DAYS = "weekly_view_days"
|
||||
const val HIGHLIGHT_WEEKENDS = "highlight_weekends"
|
||||
|
||||
// repeat_rule for monthly and yearly repetition
|
||||
const val REPEAT_SAME_DAY = 1 // i.e. 25th every month, or 3rd june (if yearly repetition)
|
||||
@ -157,3 +158,11 @@ const val REMINDER_NOTIFICATION = 0
|
||||
const val REMINDER_EMAIL = 1
|
||||
|
||||
fun getNowSeconds() = System.currentTimeMillis() / 1000L
|
||||
|
||||
fun isWeekend(i: Int, isSundayFirst: Boolean): Boolean {
|
||||
return if (isSundayFirst) {
|
||||
i == 0 || i == 6
|
||||
} else {
|
||||
i == 5 || i == 6
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,11 @@ class MonthlyCalendarImpl(val callback: MonthlyCalendar, val context: Context) {
|
||||
val days = ArrayList<DayMonthly>(DAYS_CNT)
|
||||
val currMonthDays = mTargetDate.dayOfMonth().maximumValue
|
||||
var firstDayIndex = mTargetDate.withDayOfMonth(1).dayOfWeek
|
||||
if (!context.config.isSundayFirst)
|
||||
val isSundayFirst = context.config.isSundayFirst
|
||||
if (!isSundayFirst) {
|
||||
firstDayIndex -= 1
|
||||
}
|
||||
|
||||
val prevMonthDays = mTargetDate.minusMonths(1).dayOfMonth().maximumValue
|
||||
|
||||
var isThisMonth = false
|
||||
@ -68,7 +71,7 @@ class MonthlyCalendarImpl(val callback: MonthlyCalendar, val context: Context) {
|
||||
|
||||
val newDay = curDay.withDayOfMonth(value)
|
||||
val dayCode = Formatter.getDayCodeFromDateTime(newDay)
|
||||
val day = DayMonthly(value, isThisMonth, isToday, dayCode, newDay.weekOfWeekyear, ArrayList(), i)
|
||||
val day = DayMonthly(value, isThisMonth, isToday, dayCode, newDay.weekOfWeekyear, ArrayList(), i, isWeekend(i % 7, isSundayFirst))
|
||||
days.add(day)
|
||||
value++
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.simplemobiletools.calendar.pro.models
|
||||
|
||||
data class DayMonthly(val value: Int, val isThisMonth: Boolean, val isToday: Boolean, val code: String, val weekOfYear: Int, var dayEvents: ArrayList<Event>,
|
||||
var indexOnMonthView: Int)
|
||||
var indexOnMonthView: Int, var isWeekend: Boolean)
|
||||
|
@ -15,6 +15,7 @@ import com.simplemobiletools.calendar.pro.extensions.seconds
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.pro.helpers.LOW_ALPHA
|
||||
import com.simplemobiletools.calendar.pro.helpers.MEDIUM_ALPHA
|
||||
import com.simplemobiletools.calendar.pro.helpers.isWeekend
|
||||
import com.simplemobiletools.calendar.pro.models.DayMonthly
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.calendar.pro.models.MonthViewEvent
|
||||
@ -30,7 +31,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
||||
private val BG_CORNER_RADIUS = 8f
|
||||
private val ROW_COUNT = 6
|
||||
|
||||
private var paint: Paint
|
||||
private var textPaint: Paint
|
||||
private var eventTitlePaint: TextPaint
|
||||
private var gridPaint: Paint
|
||||
private var config = context.config
|
||||
@ -38,6 +39,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
||||
private var dayHeight = 0f
|
||||
private var primaryColor = 0
|
||||
private var textColor = 0
|
||||
private var redTextColor = 0
|
||||
private var weekDaysLetterHeight = 0
|
||||
private var eventTitleHeight = 0
|
||||
private var currDayOfWeek = 0
|
||||
@ -46,6 +48,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
||||
private var horizontalOffset = 0
|
||||
private var showWeekNumbers = false
|
||||
private var dimPastEvents = true
|
||||
private var highlightWeekends = false
|
||||
private var isPrintVersion = false
|
||||
private var allEvents = ArrayList<MonthViewEvent>()
|
||||
private var bgRectF = RectF()
|
||||
@ -58,14 +61,16 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
||||
init {
|
||||
primaryColor = context.getAdjustedPrimaryColor()
|
||||
textColor = config.textColor
|
||||
redTextColor = context.resources.getColor(R.color.red_text)
|
||||
showWeekNumbers = config.showWeekNumbers
|
||||
dimPastEvents = config.dimPastEvents
|
||||
highlightWeekends = config.highlightWeekends
|
||||
|
||||
smallPadding = resources.displayMetrics.density.toInt()
|
||||
val normalTextSize = resources.getDimensionPixelSize(R.dimen.normal_text_size)
|
||||
weekDaysLetterHeight = normalTextSize * 2
|
||||
|
||||
paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
textPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = textColor
|
||||
textSize = normalTextSize.toFloat()
|
||||
textAlign = Paint.Align.CENTER
|
||||
@ -144,11 +149,11 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
||||
val yPos = y * dayHeight + verticalOffset
|
||||
val xPosCenter = xPos + dayWidth / 2
|
||||
if (day.isToday && !isPrintVersion) {
|
||||
canvas.drawCircle(xPosCenter, yPos + paint.textSize * 0.7f, paint.textSize * 0.75f, getCirclePaint(day))
|
||||
canvas.drawCircle(xPosCenter, yPos + textPaint.textSize * 0.7f, textPaint.textSize * 0.75f, getCirclePaint(day))
|
||||
}
|
||||
|
||||
canvas.drawText(day.value.toString(), xPosCenter, yPos + paint.textSize, getTextPaint(day))
|
||||
dayVerticalOffsets.put(day.indexOnMonthView, (verticalOffset + paint.textSize * 2).toInt())
|
||||
canvas.drawText(day.value.toString(), xPosCenter, yPos + textPaint.textSize, getTextPaint(day))
|
||||
dayVerticalOffsets.put(day.indexOnMonthView, (verticalOffset + textPaint.textSize * 2).toInt())
|
||||
}
|
||||
curId++
|
||||
}
|
||||
@ -179,16 +184,18 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
||||
private fun addWeekDayLetters(canvas: Canvas) {
|
||||
for (i in 0..6) {
|
||||
val xPos = horizontalOffset + (i + 1) * dayWidth - dayWidth / 2
|
||||
var weekDayLetterPaint = paint
|
||||
var weekDayLetterPaint = textPaint
|
||||
if (i == currDayOfWeek && !isPrintVersion) {
|
||||
weekDayLetterPaint = getColoredPaint(primaryColor)
|
||||
} else if (highlightWeekends && isWeekend(i, config.isSundayFirst)) {
|
||||
weekDayLetterPaint = getColoredPaint(redTextColor)
|
||||
}
|
||||
canvas.drawText(dayLetters[i], xPos, weekDaysLetterHeight * 0.7f, weekDayLetterPaint)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addWeekNumbers(canvas: Canvas) {
|
||||
val weekNumberPaint = Paint(paint)
|
||||
val weekNumberPaint = Paint(textPaint)
|
||||
weekNumberPaint.textAlign = Paint.Align.RIGHT
|
||||
|
||||
for (i in 0 until ROW_COUNT) {
|
||||
@ -199,7 +206,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
||||
val weekOfYear = days.getOrNull(i * 7 + 3)?.weekOfYear ?: 1
|
||||
val id = "$weekOfYear:"
|
||||
val yPos = i * dayHeight + weekDaysLetterHeight
|
||||
canvas.drawText(id, horizontalOffset.toFloat() * 0.9f, yPos + paint.textSize, weekNumberPaint)
|
||||
canvas.drawText(id, horizontalOffset.toFloat() * 0.9f, yPos + textPaint.textSize, weekNumberPaint)
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,8 +265,12 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
||||
|
||||
private fun getTextPaint(startDay: DayMonthly): Paint {
|
||||
var paintColor = textColor
|
||||
if (startDay.isToday && !isPrintVersion) {
|
||||
paintColor = primaryColor.getContrastColor()
|
||||
if (!isPrintVersion) {
|
||||
if (startDay.isToday) {
|
||||
paintColor = primaryColor.getContrastColor()
|
||||
} else if (startDay.isWeekend) {
|
||||
paintColor = redTextColor
|
||||
}
|
||||
}
|
||||
|
||||
if (!startDay.isThisMonth) {
|
||||
@ -270,7 +281,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
||||
}
|
||||
|
||||
private fun getColoredPaint(color: Int): Paint {
|
||||
val curPaint = Paint(paint)
|
||||
val curPaint = Paint(textPaint)
|
||||
curPaint.color = color
|
||||
return curPaint
|
||||
}
|
||||
@ -296,7 +307,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
||||
}
|
||||
|
||||
private fun getCirclePaint(day: DayMonthly): Paint {
|
||||
val curPaint = Paint(paint)
|
||||
val curPaint = Paint(textPaint)
|
||||
var paintColor = primaryColor
|
||||
if (!day.isThisMonth) {
|
||||
paintColor = paintColor.adjustAlpha(MEDIUM_ALPHA)
|
||||
@ -358,7 +369,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
||||
config.textColor
|
||||
}
|
||||
|
||||
paint.color = textColor
|
||||
textPaint.color = textColor
|
||||
gridPaint.color = textColor.adjustAlpha(LOW_ALPHA)
|
||||
invalidate()
|
||||
initWeekDayLetters()
|
||||
|
@ -9,6 +9,7 @@ import android.view.View
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.helpers.MEDIUM_ALPHA
|
||||
import com.simplemobiletools.calendar.pro.helpers.isWeekend
|
||||
import com.simplemobiletools.calendar.pro.models.DayYearly
|
||||
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
@ -20,8 +21,11 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||
private var todayCirclePaint: Paint
|
||||
private var dayWidth = 0f
|
||||
private var textColor = 0
|
||||
private var redTextColor = 0
|
||||
private var days = 31
|
||||
private var isLandscape = false
|
||||
private var highlightWeekends = false
|
||||
private var isSundayFirst = false
|
||||
private var isPrintVersion = false
|
||||
private var mEvents: ArrayList<DayYearly>? = null
|
||||
|
||||
@ -54,6 +58,9 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||
|
||||
val baseColor = context.config.textColor
|
||||
textColor = baseColor.adjustAlpha(MEDIUM_ALPHA)
|
||||
redTextColor = context.resources.getColor(R.color.red_text).adjustAlpha(MEDIUM_ALPHA)
|
||||
highlightWeekends = context.config.highlightWeekends
|
||||
isSundayFirst = context.config.isSundayFirst
|
||||
|
||||
paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = textColor
|
||||
@ -80,7 +87,8 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||
for (y in 1..6) {
|
||||
for (x in 1..7) {
|
||||
if (curId in 1..days) {
|
||||
canvas.drawText(curId.toString(), x * dayWidth - (dayWidth / 4), y * dayWidth, getPaint(curId))
|
||||
val paint = getPaint(curId, x, highlightWeekends)
|
||||
canvas.drawText(curId.toString(), x * dayWidth - (dayWidth / 4), y * dayWidth, paint)
|
||||
|
||||
if (curId == todaysId && !isPrintVersion) {
|
||||
val dividerConstant = if (isLandscape) 6 else 4
|
||||
@ -92,12 +100,16 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPaint(curId: Int): Paint {
|
||||
private fun getPaint(curId: Int, weekDay: Int, highlightWeekends: Boolean): Paint {
|
||||
val colors = mEvents?.get(curId)?.eventColors ?: HashSet()
|
||||
if (colors.isNotEmpty()) {
|
||||
val curPaint = Paint(paint)
|
||||
curPaint.color = colors.first()
|
||||
return curPaint
|
||||
} else if (highlightWeekends && isWeekend(weekDay - 1, isSundayFirst)) {
|
||||
val curPaint = Paint(paint)
|
||||
curPaint.color = redTextColor
|
||||
return curPaint
|
||||
}
|
||||
|
||||
return paint
|
||||
|
@ -119,6 +119,28 @@
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_highlight_weekends_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingStart="@dimen/normal_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:paddingEnd="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MySwitchCompat
|
||||
android:id="@+id/settings_highlight_weekends"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/highlight_weekends" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/reminders_label"
|
||||
android:layout_width="wrap_content"
|
||||
|
Loading…
x
Reference in New Issue
Block a user