update the weekly view grid so it scales better on different densities
This commit is contained in:
parent
b701883438
commit
0a46941b9c
|
@ -41,7 +41,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
private var isFragmentVisible = false
|
||||
private var wasFragmentInit = false
|
||||
private var wasExtraHeightAdded = false
|
||||
private var oneDP = 1
|
||||
|
||||
lateinit var mView: View
|
||||
lateinit var mCalendar: WeeklyCalendarImpl
|
||||
|
@ -53,7 +52,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
mWeekTimestamp = arguments.getInt(WEEK_START_TIMESTAMP)
|
||||
primaryColor = context.config.primaryColor
|
||||
mRes = resources
|
||||
oneDP = mRes.displayMetrics.density.toInt()
|
||||
|
||||
mView = inflater.inflate(R.layout.fragment_week, container, false).apply {
|
||||
week_events_scrollview.setOnScrollviewListener(object : MyScrollView.ScrollViewListener {
|
||||
|
@ -171,9 +169,11 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
|
||||
activity.runOnUiThread { mView.week_all_day_holder.removeAllViews() }
|
||||
|
||||
var hadAllDayEvent = false
|
||||
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
|
||||
for (event in sorted) {
|
||||
if (event.isAllDay() || Formatter.getDayCodeFromTS(event.startTS) != Formatter.getDayCodeFromTS(event.endTS)) {
|
||||
hadAllDayEvent = true
|
||||
addAllDayEvent(event)
|
||||
} else {
|
||||
val startDateTime = Formatter.getDateTimeFromTS(event.startTS)
|
||||
|
@ -190,10 +190,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
activity.runOnUiThread {
|
||||
layout.addView(this)
|
||||
(layoutParams as RelativeLayout.LayoutParams).apply {
|
||||
rightMargin = oneDP
|
||||
topMargin = (startMinutes * minuteHeight).toInt()
|
||||
width = layout.width
|
||||
minHeight = if (event.startTS == event.endTS) minimalHeight else (duration * minuteHeight).toInt() - oneDP
|
||||
width = layout.width - 1
|
||||
minHeight = if (event.startTS == event.endTS) minimalHeight else (duration * minuteHeight).toInt() - 1
|
||||
}
|
||||
}
|
||||
setOnClickListener {
|
||||
|
@ -205,6 +204,17 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hadAllDayEvent) {
|
||||
mView.week_top_holder.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
mView.week_top_holder.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
if (isFragmentVisible) {
|
||||
(activity as MainActivity).updateHoursTopMargin(mView.week_top_holder.height)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun addAllDayEvent(event: Event) {
|
||||
|
@ -226,9 +236,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
mView.week_all_day_holder.addView(this)
|
||||
(layoutParams as LinearLayout.LayoutParams).apply {
|
||||
topMargin = mRes.getDimension(R.dimen.tiny_margin).toInt()
|
||||
bottomMargin = oneDP
|
||||
leftMargin = firstDayIndex % 7 * dayColumnWidth
|
||||
width = (daysCnt + 1) * dayColumnWidth - oneDP
|
||||
leftMargin = getColumnWithId(firstDayIndex).x.toInt()
|
||||
bottomMargin = 1
|
||||
width = getColumnWithId(firstDayIndex + daysCnt).right - leftMargin - 1
|
||||
}
|
||||
|
||||
mView.week_top_holder.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:bottom="0dp"
|
||||
android:left="-2dp"
|
||||
android:right="-2dp"
|
||||
android:top="-2dp">
|
||||
android:bottom="0px"
|
||||
android:left="-2px"
|
||||
android:right="-2px"
|
||||
android:top="-2px">
|
||||
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:width="1px"
|
||||
android:color="@color/divider_grey"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:bottom="0px"
|
||||
android:left="-2px"
|
||||
android:right="0px"
|
||||
android:top="-2px">
|
||||
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
<stroke
|
||||
android:width="1px"
|
||||
android:color="@color/divider_grey"/>
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
|
@ -1,15 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:bottom="-2dp"
|
||||
android:left="-2dp"
|
||||
android:right="0dp"
|
||||
android:top="-2dp">
|
||||
android:bottom="-2px"
|
||||
android:left="-2px"
|
||||
android:right="0px"
|
||||
android:top="-2px">
|
||||
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:width="1px"
|
||||
android:color="@color/divider_grey"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
|
|
@ -24,13 +24,14 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignRight="@+id/week_view_hours_scrollview"
|
||||
android:background="@drawable/stroke_bottom"/>
|
||||
android:background="@drawable/stroke_bottom_right"/>
|
||||
|
||||
<com.simplemobiletools.calendar.views.MyScrollView
|
||||
android:id="@+id/week_view_hours_scrollview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/week_view_hours_divider"
|
||||
android:background="@drawable/stroke_right"
|
||||
android:overScrollMode="never"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:scrollbars="none">
|
||||
|
@ -41,6 +42,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/weekly_view_row_height"/>
|
||||
|
||||
</com.simplemobiletools.calendar.views.MyScrollView>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyViewPager
|
||||
|
@ -49,12 +51,6 @@
|
|||
android:layout_height="match_parent"
|
||||
android:layout_toRightOf="@+id/week_view_hours_scrollview"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_toRightOf="@+id/week_view_hours_scrollview"
|
||||
android:foreground="@drawable/stroke_right"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -1,16 +1,137 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/week_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.simplemobiletools.calendar.views.MyScrollView
|
||||
android:id="@+id/week_events_scrollview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/week_top_holder"
|
||||
android:fillViewport="true"
|
||||
android:overScrollMode="never"
|
||||
android:scrollbars="none">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_events_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<GridView
|
||||
android:id="@+id/week_events_grid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/weekly_view_events_height"
|
||||
android:numColumns="7"
|
||||
android:verticalSpacing="1px"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/week_events_columns_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/weekly_view_events_height"
|
||||
android:layout_alignLeft="@+id/week_events_grid"
|
||||
android:background="@android:color/transparent"
|
||||
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>
|
||||
</RelativeLayout>
|
||||
</com.simplemobiletools.calendar.views.MyScrollView>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_top_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:foreground="@drawable/stroke_bottom"
|
||||
android:background="@drawable/stroke_bottom"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<LinearLayout
|
||||
|
@ -18,8 +139,8 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingBottom="@dimen/small_margin"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="@dimen/small_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/week_day_label_0"
|
||||
|
@ -86,55 +207,6 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignBottom="@+id/week_all_day_holder">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/stroke_right"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/week_all_day_holder"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -143,87 +215,4 @@
|
|||
android:orientation="vertical"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<com.simplemobiletools.calendar.views.MyScrollView
|
||||
android:id="@+id/week_events_scrollview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true"
|
||||
android:overScrollMode="never"
|
||||
android:scrollbars="none">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_events_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<GridView
|
||||
android:id="@+id/week_events_grid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/weekly_view_events_height"
|
||||
android:background="@color/divider_grey"
|
||||
android:foreground="@drawable/stroke_right"
|
||||
android:horizontalSpacing="1dp"
|
||||
android:numColumns="7"
|
||||
android:verticalSpacing="1dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/week_events_columns_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/weekly_view_events_height"
|
||||
android:background="@android:color/transparent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_0"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_5"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_6"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</com.simplemobiletools.calendar.views.MyScrollView>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in New Issue