adding a helper function in MonthView

This commit is contained in:
tibbi 2018-03-26 18:44:19 +02:00
parent f2bc8ba5c8
commit baa1c44bcd
4 changed files with 13 additions and 6 deletions

View File

@ -268,10 +268,10 @@ class SettingsActivity : SimpleActivity() {
} }
private fun setupWeekNumbers() { private fun setupWeekNumbers() {
settings_week_numbers.isChecked = config.displayWeekNumbers settings_week_numbers.isChecked = config.showWeekNumbers
settings_week_numbers_holder.setOnClickListener { settings_week_numbers_holder.setOnClickListener {
settings_week_numbers.toggle() settings_week_numbers.toggle()
config.displayWeekNumbers = settings_week_numbers.isChecked config.showWeekNumbers = settings_week_numbers.isChecked
} }
} }

View File

@ -12,9 +12,9 @@ class Config(context: Context) : BaseConfig(context) {
fun newInstance(context: Context) = Config(context) fun newInstance(context: Context) = Config(context)
} }
var displayWeekNumbers: Boolean var showWeekNumbers: Boolean
get() = prefs.getBoolean(WEEK_NUMBERS, false) get() = prefs.getBoolean(WEEK_NUMBERS, false)
set(displayWeekNumbers) = prefs.edit().putBoolean(WEEK_NUMBERS, displayWeekNumbers).apply() set(showWeekNumbers) = prefs.edit().putBoolean(WEEK_NUMBERS, showWeekNumbers).apply()
var startWeeklyAt: Int var startWeeklyAt: Int
get() = prefs.getInt(START_WEEKLY_AT, 7) get() = prefs.getInt(START_WEEKLY_AT, 7)

View File

@ -82,7 +82,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
} }
private fun updateDays(context: Context, views: RemoteViews, days: List<DayMonthly>) { private fun updateDays(context: Context, views: RemoteViews, days: List<DayMonthly>) {
val displayWeekNumbers = context.config.displayWeekNumbers val displayWeekNumbers = context.config.showWeekNumbers
val textColor = context.config.widgetTextColor val textColor = context.config.widgetTextColor
val smallerFontSize = context.config.getFontSize() - 3f val smallerFontSize = context.config.getFontSize() - 3f
val res = context.resources val res = context.resources

View File

@ -42,6 +42,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
private var smallPadding = 0 private var smallPadding = 0
private var availableHeightForEvents = 0 private var availableHeightForEvents = 0
private var maxEventsPerDay = 0 private var maxEventsPerDay = 0
private var showWeekNumbers = false
private var allEvents = ArrayList<MonthViewEvent>() private var allEvents = ArrayList<MonthViewEvent>()
private var bgRectF = RectF() private var bgRectF = RectF()
private var dayLetters = ArrayList<String>() private var dayLetters = ArrayList<String>()
@ -54,6 +55,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
init { init {
primaryColor = context.getAdjustedPrimaryColor() primaryColor = context.getAdjustedPrimaryColor()
textColor = context.config.textColor textColor = context.config.textColor
showWeekNumbers = context.config.showWeekNumbers
weakTextColor = textColor.adjustAlpha(LOW_ALPHA) weakTextColor = textColor.adjustAlpha(LOW_ALPHA)
smallPadding = resources.displayMetrics.density.toInt() smallPadding = resources.displayMetrics.density.toInt()
@ -82,6 +84,12 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
days = newDays days = newDays
initWeekDayLetters() initWeekDayLetters()
setupCurrentDayOfWeekIndex() setupCurrentDayOfWeekIndex()
showWeekNumbers = context.config.showWeekNumbers
groupAllEvents()
invalidate()
}
private fun groupAllEvents() {
days.forEach { days.forEach {
val day = it val day = it
day.dayEvents.forEach { day.dayEvents.forEach {
@ -99,7 +107,6 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
} }
allEvents = allEvents.sortedWith(compareBy({ -it.daysCnt }, { !it.isAllDay }, { it.startTS }, { it.startDayIndex }, { it.title })).toMutableList() as ArrayList<MonthViewEvent> allEvents = allEvents.sortedWith(compareBy({ -it.daysCnt }, { !it.isAllDay }, { it.startTS }, { it.startDayIndex }, { it.title })).toMutableList() as ArrayList<MonthViewEvent>
invalidate()
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {