draw the weekly view grid more efficiently, in a custom view
This commit is contained in:
parent
50ac99334a
commit
1d277a143a
|
@ -93,9 +93,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
updateScrollY(Math.max(mListener?.getCurrScrollY() ?: 0, minScrollY))
|
||||
}
|
||||
|
||||
(0..6).map { inflater.inflate(R.layout.stroke_vertical_divider, mView.week_vertical_grid_holder) }
|
||||
(0..23).map { inflater.inflate(R.layout.stroke_horizontal_divider, mView.week_horizontal_grid_holder) }
|
||||
|
||||
wasFragmentInit = true
|
||||
return mView
|
||||
}
|
||||
|
@ -239,7 +236,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
}
|
||||
|
||||
activity!!.runOnUiThread {
|
||||
if (context != null && isAdded) {
|
||||
if (context != null && activity != null && isAdded) {
|
||||
addEvents()
|
||||
}
|
||||
}
|
||||
|
@ -347,9 +344,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
|
||||
private fun addAllDayEvent(event: Event) {
|
||||
(inflater.inflate(R.layout.week_all_day_event_marker, null, false) as TextView).apply {
|
||||
if (activity == null)
|
||||
return
|
||||
|
||||
var backgroundColor = eventTypeColors.get(event.eventType, primaryColor)
|
||||
var textColor = backgroundColor.getContrastColor()
|
||||
if (dimPastEvents && event.isPastEvent) {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
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
|
||||
|
||||
class WeeklyViewGrid(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
|
||||
private val ROWS_CNT = 24
|
||||
private val COLS_CNT = 7
|
||||
private var paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
||||
|
||||
init {
|
||||
paint.color = context.resources.getColor(R.color.divider_grey)
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
super.onDraw(canvas)
|
||||
val rowHeight = height / ROWS_CNT
|
||||
for (i in 0 until ROWS_CNT) {
|
||||
val y = rowHeight * i.toFloat()
|
||||
canvas.drawLine(0f, y, width.toFloat(), y, paint)
|
||||
}
|
||||
|
||||
val rowWidth = width / COLS_CNT
|
||||
for (i in 0 until COLS_CNT) {
|
||||
val x = rowWidth * i.toFloat()
|
||||
canvas.drawLine(x, 0f, x, height.toFloat(), paint)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,9 +2,9 @@
|
|||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:bottom="0px"
|
||||
android:left="-2px"
|
||||
android:right="-2px"
|
||||
android:top="-2px">
|
||||
android:left="-1px"
|
||||
android:right="-1px"
|
||||
android:top="-1px">
|
||||
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:bottom="0px"
|
||||
android:left="-2px"
|
||||
android:left="-1px"
|
||||
android:right="0px"
|
||||
android:top="-2px">
|
||||
android:top="-1px">
|
||||
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:bottom="-2px"
|
||||
android:left="-2px"
|
||||
android:bottom="-1px"
|
||||
android:left="-1px"
|
||||
android:right="0px"
|
||||
android:top="-2px">
|
||||
android:top="-1px">
|
||||
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
|
|
|
@ -5,12 +5,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/week_vertical_grid_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"/>
|
||||
|
||||
<com.simplemobiletools.calendar.views.MyScrollView
|
||||
android:id="@+id/week_events_scrollview"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -25,11 +19,10 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
<com.simplemobiletools.calendar.views.WeeklyViewGrid
|
||||
android:id="@+id/week_horizontal_grid_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/weekly_view_events_height"
|
||||
android:orientation="vertical"/>
|
||||
android:layout_height="@dimen/weekly_view_events_height"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/week_events_columns_holder"
|
||||
|
@ -88,13 +81,13 @@
|
|||
android:id="@+id/week_top_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/stroke_bottom"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/week_letters_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/stroke_bottom"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="@dimen/small_margin">
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ImageView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_bottom"/>
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ImageView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
Loading…
Reference in New Issue