mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
create weekly view programmatically, do not hardcode 7
This commit is contained in:
@@ -61,6 +61,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
private var allDayHolders = ArrayList<RelativeLayout>()
|
private var allDayHolders = ArrayList<RelativeLayout>()
|
||||||
private var allDayRows = ArrayList<HashSet<Int>>()
|
private var allDayRows = ArrayList<HashSet<Int>>()
|
||||||
private var currEvents = ArrayList<Event>()
|
private var currEvents = ArrayList<Event>()
|
||||||
|
private var dayColumns = ArrayList<RelativeLayout>()
|
||||||
private var eventTypeColors = LongSparseArray<Int>()
|
private var eventTypeColors = LongSparseArray<Int>()
|
||||||
private var eventTimeRanges = LinkedHashMap<String, ArrayList<EventWeeklyView>>()
|
private var eventTimeRanges = LinkedHashMap<String, ArrayList<EventWeeklyView>>()
|
||||||
|
|
||||||
@@ -105,6 +106,13 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mView.week_events_columns_holder.removeAllViews()
|
||||||
|
(0..context!!.config.weeklyViewDays).forEach {
|
||||||
|
val column = inflater.inflate(R.layout.weekly_view_day_column, mView.week_events_columns_holder, false) as RelativeLayout
|
||||||
|
mView.week_events_columns_holder.addView(column)
|
||||||
|
dayColumns.add(column)
|
||||||
|
}
|
||||||
|
|
||||||
scrollView.setOnScrollviewListener(object : MyScrollView.ScrollViewListener {
|
scrollView.setOnScrollviewListener(object : MyScrollView.ScrollViewListener {
|
||||||
override fun onScrollChanged(scrollView: MyScrollView, x: Int, y: Int, oldx: Int, oldy: Int) {
|
override fun onScrollChanged(scrollView: MyScrollView, x: Int, y: Int, oldx: Int, oldy: Int) {
|
||||||
checkScrollLimits(y)
|
checkScrollLimits(y)
|
||||||
@@ -203,7 +211,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initGrid() {
|
private fun initGrid() {
|
||||||
(0..6).map { getColumnWithId(it) }
|
(0..context!!.config.weeklyViewDays).map { dayColumns[it] }
|
||||||
.forEachIndexed { index, layout ->
|
.forEachIndexed { index, layout ->
|
||||||
layout.removeAllViews()
|
layout.removeAllViews()
|
||||||
val gestureDetector = getViewGestureDetector(layout, index)
|
val gestureDetector = getViewGestureDetector(layout, index)
|
||||||
@@ -365,7 +373,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
addAllDayEvent(event)
|
addAllDayEvent(event)
|
||||||
} else {
|
} else {
|
||||||
val dayOfWeek = startDateTime.plusDays(if (config.isSundayFirst) 1 else 0).dayOfWeek - 1
|
val dayOfWeek = startDateTime.plusDays(if (config.isSundayFirst) 1 else 0).dayOfWeek - 1
|
||||||
val layout = getColumnWithId(dayOfWeek)
|
val layout = dayColumns[dayOfWeek]
|
||||||
|
|
||||||
val startMinutes = startDateTime.minuteOfDay
|
val startMinutes = startDateTime.minuteOfDay
|
||||||
val duration = endDateTime.minuteOfDay - startMinutes
|
val duration = endDateTime.minuteOfDay - startMinutes
|
||||||
@@ -454,7 +462,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
private fun addCurrentTimeIndicator(minuteHeight: Float) {
|
private fun addCurrentTimeIndicator(minuteHeight: Float) {
|
||||||
if (todayColumnIndex != -1) {
|
if (todayColumnIndex != -1) {
|
||||||
val minutes = DateTime().minuteOfDay
|
val minutes = DateTime().minuteOfDay
|
||||||
val todayColumn = getColumnWithId(todayColumnIndex)
|
val todayColumn = dayColumns[todayColumnIndex]
|
||||||
if (currentTimeView != null) {
|
if (currentTimeView != null) {
|
||||||
mView.week_events_holder.removeView(currentTimeView)
|
mView.week_events_holder.removeView(currentTimeView)
|
||||||
}
|
}
|
||||||
@@ -548,9 +556,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
|
|
||||||
allDayHolders[drawAtLine].addView(this)
|
allDayHolders[drawAtLine].addView(this)
|
||||||
(layoutParams as RelativeLayout.LayoutParams).apply {
|
(layoutParams as RelativeLayout.LayoutParams).apply {
|
||||||
leftMargin = getColumnWithId(firstDayIndex).x.toInt()
|
leftMargin = dayColumns[firstDayIndex].x.toInt()
|
||||||
bottomMargin = 1
|
bottomMargin = 1
|
||||||
width = getColumnWithId(Math.min(firstDayIndex + daysCnt, 6)).right - leftMargin - 1
|
width = dayColumns[Math.min(firstDayIndex + daysCnt, 6)].right - leftMargin - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
calculateExtraHeight()
|
calculateExtraHeight()
|
||||||
@@ -579,8 +587,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getColumnWithId(id: Int) = mView.findViewById<ViewGroup>(res.getIdentifier("week_column_$id", "id", context!!.packageName))
|
|
||||||
|
|
||||||
fun updateScrollY(y: Int) {
|
fun updateScrollY(y: Int) {
|
||||||
if (wasFragmentInit) {
|
if (wasFragmentInit) {
|
||||||
scrollView.scrollY = y
|
scrollView.scrollY = y
|
||||||
|
@@ -6,12 +6,13 @@ import android.graphics.Paint
|
|||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.simplemobiletools.calendar.pro.R
|
import com.simplemobiletools.calendar.pro.R
|
||||||
|
import com.simplemobiletools.calendar.pro.extensions.config
|
||||||
import com.simplemobiletools.calendar.pro.extensions.getWeeklyViewItemHeight
|
import com.simplemobiletools.calendar.pro.extensions.getWeeklyViewItemHeight
|
||||||
|
|
||||||
class WeeklyViewGrid(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
|
class WeeklyViewGrid(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
|
||||||
private val ROWS_CNT = 24
|
private val ROWS_CNT = 24
|
||||||
private var paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
private var paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||||
var daysCount = 7
|
var daysCount = context.config.weeklyViewDays
|
||||||
|
|
||||||
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
||||||
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@+id/week_holder"
|
android:id="@+id/week_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
@@ -22,7 +21,7 @@
|
|||||||
<com.simplemobiletools.calendar.pro.views.WeeklyViewGrid
|
<com.simplemobiletools.calendar.pro.views.WeeklyViewGrid
|
||||||
android:id="@+id/week_horizontal_grid_holder"
|
android:id="@+id/week_horizontal_grid_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/week_events_columns_holder"
|
android:id="@+id/week_events_columns_holder"
|
||||||
@@ -31,48 +30,6 @@
|
|||||||
android:background="@android:color/transparent"
|
android:background="@android:color/transparent"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/week_column_0"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"/>
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/week_column_1"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"/>
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/week_column_2"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"/>
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/week_column_3"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"/>
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/week_column_4"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"/>
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/week_column_5"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"/>
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/week_column_6"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</com.simplemobiletools.calendar.pro.views.MyScrollView>
|
</com.simplemobiletools.calendar.pro.views.MyScrollView>
|
||||||
@@ -100,7 +57,7 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:text="@string/monday_letter"
|
android:text="@string/monday_letter"
|
||||||
android:textSize="@dimen/normal_text_size"/>
|
android:textSize="@dimen/normal_text_size" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/week_day_label_1"
|
android:id="@+id/week_day_label_1"
|
||||||
@@ -109,7 +66,7 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:text="@string/tuesday_letter"
|
android:text="@string/tuesday_letter"
|
||||||
android:textSize="@dimen/normal_text_size"/>
|
android:textSize="@dimen/normal_text_size" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/week_day_label_2"
|
android:id="@+id/week_day_label_2"
|
||||||
@@ -118,7 +75,7 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:text="@string/wednesday_letter"
|
android:text="@string/wednesday_letter"
|
||||||
android:textSize="@dimen/normal_text_size"/>
|
android:textSize="@dimen/normal_text_size" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/week_day_label_3"
|
android:id="@+id/week_day_label_3"
|
||||||
@@ -127,7 +84,7 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:text="@string/thursday_letter"
|
android:text="@string/thursday_letter"
|
||||||
android:textSize="@dimen/normal_text_size"/>
|
android:textSize="@dimen/normal_text_size" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/week_day_label_4"
|
android:id="@+id/week_day_label_4"
|
||||||
@@ -136,7 +93,7 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:text="@string/friday_letter"
|
android:text="@string/friday_letter"
|
||||||
android:textSize="@dimen/normal_text_size"/>
|
android:textSize="@dimen/normal_text_size" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/week_day_label_5"
|
android:id="@+id/week_day_label_5"
|
||||||
@@ -145,7 +102,7 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:text="@string/saturday_letter"
|
android:text="@string/saturday_letter"
|
||||||
android:textSize="@dimen/normal_text_size"/>
|
android:textSize="@dimen/normal_text_size" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/week_day_label_6"
|
android:id="@+id/week_day_label_6"
|
||||||
@@ -154,7 +111,7 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:text="@string/sunday_letter"
|
android:text="@string/sunday_letter"
|
||||||
android:textSize="@dimen/normal_text_size"/>
|
android:textSize="@dimen/normal_text_size" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
6
app/src/main/res/layout/weekly_view_day_column.xml
Normal file
6
app/src/main/res/layout/weekly_view_day_column.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/week_column"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1" />
|
Reference in New Issue
Block a user