From ba07fbcfd32717129d2639c6efeeef0dc302b475 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 24 Mar 2018 11:06:22 +0100 Subject: [PATCH] start rewriting the monthly view into a custom view for better performance --- .../WidgetMonthlyConfigureActivity.kt | 4 +- .../calendar/fragments/MonthFragment.kt | 14 +- .../calendar/views/MonthView.kt | 51 ++ .../calendar/views/SmallMonthView.kt | 1 + app/src/main/res/layout/fragment_month.xml | 488 +----------------- 5 files changed, 65 insertions(+), 493 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/views/MonthView.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/WidgetMonthlyConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/WidgetMonthlyConfigureActivity.kt index 311976787..76aa6fcaf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/WidgetMonthlyConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/WidgetMonthlyConfigureActivity.kt @@ -152,7 +152,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar { } private fun updateDays() { - val len = mDays!!.size + /*val len = mDays!!.size if (applicationContext.config.displayWeekNumbers) { week_num.setTextColor(mTextColor) @@ -176,7 +176,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar { context.addDayNumber(mTextColor, day, this, dayLabelHeight) { dayLabelHeight = it } context.addDayEvents(day, this, mRes, dividerMargin) } - } + }*/ } private val bgSeekbarChangeListener = object : SeekBar.OnSeekBarChangeListener { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt index 6c43546d5..d809ccc17 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt @@ -9,13 +9,9 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.DatePicker -import android.widget.LinearLayout import android.widget.RelativeLayout import android.widget.TextView import com.simplemobiletools.calendar.R -import com.simplemobiletools.calendar.activities.MainActivity -import com.simplemobiletools.calendar.extensions.addDayEvents -import com.simplemobiletools.calendar.extensions.addDayNumber import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.helpers.Config import com.simplemobiletools.calendar.helpers.DAY_CODE @@ -24,8 +20,10 @@ import com.simplemobiletools.calendar.helpers.MonthlyCalendarImpl import com.simplemobiletools.calendar.interfaces.MonthlyCalendar import com.simplemobiletools.calendar.interfaces.NavigationListener import com.simplemobiletools.calendar.models.DayMonthly -import com.simplemobiletools.commons.extensions.* -import kotlinx.android.synthetic.main.first_row.* +import com.simplemobiletools.commons.extensions.applyColorFilter +import com.simplemobiletools.commons.extensions.beGone +import com.simplemobiletools.commons.extensions.getDialogTheme +import com.simplemobiletools.commons.extensions.setupDialogStuff import kotlinx.android.synthetic.main.fragment_month.view.* import kotlinx.android.synthetic.main.top_navigation.view.* import org.joda.time.DateTime @@ -169,7 +167,7 @@ class MonthFragment : Fragment(), MonthlyCalendar { } private fun updateDays(days: List) { - val displayWeekNumbers = mConfig.displayWeekNumbers + /*val displayWeekNumbers = mConfig.displayWeekNumbers val len = days.size if (week_num == null) @@ -198,6 +196,6 @@ class MonthFragment : Fragment(), MonthlyCalendar { context.addDayNumber(mTextColor, day, this, mDayLabelHeight) { mDayLabelHeight = it } context.addDayEvents(day, this, mRes, dividerMargin) } - } + }*/ } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/views/MonthView.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/views/MonthView.kt new file mode 100644 index 000000000..5a5b65655 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/views/MonthView.kt @@ -0,0 +1,51 @@ +package com.simplemobiletools.calendar.views + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Paint +import android.util.AttributeSet +import android.view.View +import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.extensions.config + +// used in the Monthly view fragment, 1 view per screen +class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) { + private var paint: Paint + private var dayWidth = 0f + private var dayHeight = 0f + private var textColor = 0 + private var days = 42 + + constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0) + + init { + textColor = context.config.textColor + + paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { + color = textColor + textSize = resources.getDimensionPixelSize(R.dimen.normal_text_size).toFloat() + textAlign = Paint.Align.CENTER + } + } + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + if (dayWidth == 0f) { + dayWidth = (canvas.width / 7).toFloat() + } + + if (dayHeight == 0f) { + dayHeight = (canvas.height / 6).toFloat() + } + + var curId = 1 + for (y in 0..5) { + for (x in 1..7) { + if (curId in 1..days) { + canvas.drawText(curId.toString(), x * dayWidth - dayWidth / 2, y * dayHeight + paint.textSize, paint) + } + curId++ + } + } + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/views/SmallMonthView.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/views/SmallMonthView.kt index 9ba798b32..af53d3b8c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/views/SmallMonthView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/views/SmallMonthView.kt @@ -14,6 +14,7 @@ import com.simplemobiletools.commons.extensions.adjustAlpha import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor import java.util.* +// used for displaying months at Yearly view class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) { private var paint: Paint private var todayCirclePaint: Paint diff --git a/app/src/main/res/layout/fragment_month.xml b/app/src/main/res/layout/fragment_month.xml index a7c627fdb..71db5cb06 100644 --- a/app/src/main/res/layout/fragment_month.xml +++ b/app/src/main/res/layout/fragment_month.xml @@ -17,489 +17,11 @@ android:layout_below="@+id/top_value" tools:ignore="UnknownIdInLayout"/> - + android:layout_centerInParent="true"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -