fix #44, show an optional grid on the monthly view if selected so

This commit is contained in:
tibbi 2018-04-12 14:22:33 +02:00
parent 8bd24a5642
commit 313422637d
5 changed files with 58 additions and 1 deletions

View File

@ -52,6 +52,7 @@ class SettingsActivity : SimpleActivity() {
setupDeleteAllEvents() setupDeleteAllEvents()
setupReplaceDescription() setupReplaceDescription()
setupWeekNumbers() setupWeekNumbers()
setupShowGrid()
setupWeeklyStart() setupWeeklyStart()
setupWeeklyEnd() setupWeeklyEnd()
setupVibrate() setupVibrate()
@ -274,6 +275,14 @@ class SettingsActivity : SimpleActivity() {
} }
} }
private fun setupShowGrid() {
settings_show_grid.isChecked = config.showGrid
settings_show_grid_holder.setOnClickListener {
settings_show_grid.toggle()
config.showGrid = settings_show_grid.isChecked
}
}
private fun setupReminderSound() { private fun setupReminderSound() {
settings_reminder_sound.text = config.reminderSoundTitle settings_reminder_sound.text = config.reminderSoundTitle

View File

@ -85,6 +85,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(REPLACE_DESCRIPTION, false) get() = prefs.getBoolean(REPLACE_DESCRIPTION, false)
set(replaceDescription) = prefs.edit().putBoolean(REPLACE_DESCRIPTION, replaceDescription).apply() set(replaceDescription) = prefs.edit().putBoolean(REPLACE_DESCRIPTION, replaceDescription).apply()
var showGrid: Boolean
get() = prefs.getBoolean(SHOW_GRID, false)
set(showGrid) = prefs.edit().putBoolean(SHOW_GRID, showGrid).apply()
fun getSyncedCalendarIdsAsList() = caldavSyncedCalendarIDs.split(",").filter { it.trim().isNotEmpty() } as ArrayList<String> fun getSyncedCalendarIdsAsList() = caldavSyncedCalendarIDs.split(",").filter { it.trim().isNotEmpty() } as ArrayList<String>
fun addDisplayEventType(type: String) { fun addDisplayEventType(type: String) {

View File

@ -50,6 +50,7 @@ const val CALDAV_SYNCED_CALENDAR_IDS = "caldav_synced_calendar_ids"
const val LAST_USED_CALDAV_CALENDAR = "last_used_caldav_calendar" const val LAST_USED_CALDAV_CALENDAR = "last_used_caldav_calendar"
const val DISPLAY_PAST_EVENTS = "display_past_events" const val DISPLAY_PAST_EVENTS = "display_past_events"
const val REPLACE_DESCRIPTION = "replace_description" const val REPLACE_DESCRIPTION = "replace_description"
const val SHOW_GRID = "show_grid"
// repeat_rule for monthly repetition // repeat_rule for monthly repetition
const val REPEAT_MONTH_SAME_DAY = 1 // ie 25th every month const val REPEAT_MONTH_SAME_DAY = 1 // ie 25th every month

View File

@ -31,6 +31,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
private var paint: Paint private var paint: Paint
private var eventTitlePaint: TextPaint private var eventTitlePaint: TextPaint
private var gridPaint: Paint
private var dayWidth = 0f private var dayWidth = 0f
private var dayHeight = 0f private var dayHeight = 0f
private var primaryColor = 0 private var primaryColor = 0
@ -65,6 +66,10 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
textAlign = Paint.Align.CENTER textAlign = Paint.Align.CENTER
} }
gridPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = textColor.adjustAlpha(LOW_ALPHA)
}
val smallerTextSize = resources.getDimensionPixelSize(R.dimen.smaller_text_size) val smallerTextSize = resources.getDimensionPixelSize(R.dimen.smaller_text_size)
eventTitleHeight = smallerTextSize eventTitleHeight = smallerTextSize
eventTitlePaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply { eventTitlePaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
@ -112,6 +117,10 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
dayVerticalOffsets.clear() dayVerticalOffsets.clear()
measureDaySize(canvas) measureDaySize(canvas)
if (context.config.showGrid) {
drawGrid(canvas)
}
addWeekDayLetters(canvas) addWeekDayLetters(canvas)
if (showWeekNumbers) { if (showWeekNumbers) {
addWeekNumbers(canvas) addWeekNumbers(canvas)
@ -141,6 +150,17 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
drawEvents(canvas) drawEvents(canvas)
} }
private fun drawGrid(canvas: Canvas) {
for (i in 0..6) {
canvas.drawLine(i * dayWidth, 0f, i * dayWidth, canvas.height.toFloat(), gridPaint)
}
canvas.drawLine(0f, 0f, canvas.width.toFloat(), 0f, gridPaint)
for (i in 0..5) {
canvas.drawLine(0f, i * dayHeight + weekDaysLetterHeight, canvas.width.toFloat(), i * dayHeight + weekDaysLetterHeight, gridPaint)
}
}
private fun addWeekDayLetters(canvas: Canvas) { private fun addWeekDayLetters(canvas: Canvas) {
for (i in 0..6) { for (i in 0..6) {
val xPos = horizontalOffset + (i + 1) * dayWidth - dayWidth / 2 val xPos = horizontalOffset + (i + 1) * dayWidth - dayWidth / 2
@ -148,7 +168,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
if (i == currDayOfWeek) { if (i == currDayOfWeek) {
weekDayLetterPaint = getColoredPaint(primaryColor) weekDayLetterPaint = getColoredPaint(primaryColor)
} }
canvas.drawText(dayLetters[i], xPos, weekDaysLetterHeight / 2f, weekDayLetterPaint) canvas.drawText(dayLetters[i], xPos, weekDaysLetterHeight * 0.7f, weekDayLetterPaint)
} }
} }

View File

@ -494,6 +494,29 @@
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:id="@+id/settings_show_grid_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/activity_margin"
android:paddingLeft="@dimen/normal_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_show_grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/show_a_grid"/>
</RelativeLayout>
<View <View
android:id="@+id/events_list_view_divider" android:id="@+id/events_list_view_divider"
android:layout_width="match_parent" android:layout_width="match_parent"