@@ -16,7 +16,6 @@ import android.view.MotionEvent
1616import android.view.ScaleGestureDetector
1717import android.view.View
1818import android.view.ViewGroup
19- import android.widget.ImageView
2019import android.widget.RelativeLayout
2120import androidx.collection.LongSparseArray
2221import androidx.fragment.app.Fragment
@@ -61,6 +60,7 @@ import org.fossify.calendar.interfaces.WeekFragmentListener
6160import org.fossify.calendar.interfaces.WeeklyCalendar
6261import org.fossify.calendar.models.Event
6362import org.fossify.calendar.models.EventWeeklyView
63+ import org.fossify.calendar.views.CurrentTimeIndicatorView
6464import org.fossify.calendar.views.MyScrollView
6565import org.fossify.commons.dialogs.RadioGroupDialog
6666import org.fossify.commons.extensions.adjustAlpha
@@ -72,6 +72,7 @@ import org.fossify.commons.extensions.getContrastColor
7272import org.fossify.commons.extensions.getProperPrimaryColor
7373import org.fossify.commons.extensions.getProperTextColor
7474import org.fossify.commons.extensions.hideKeyboard
75+ import org.fossify.commons.extensions.isRTLLayout
7576import org.fossify.commons.extensions.onGlobalLayout
7677import org.fossify.commons.extensions.realScreenSize
7778import org.fossify.commons.extensions.removeBit
@@ -123,7 +124,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
123124 private var wasScaled = false
124125 private var isPrintVersion = false
125126 private var selectedGrid: View ? = null
126- private var currentTimeView: ImageView ? = null
127+ private var currentTimeView: CurrentTimeIndicatorView ? = null
127128 private var fadeOutHandler = Handler ()
128129 private var allDayHolders = ArrayList <RelativeLayout >()
129130 private var allDayRows = ArrayList <HashSet <Int >>()
@@ -863,43 +864,45 @@ class WeekFragment : Fragment(), WeeklyCalendar {
863864 }
864865
865866 private fun addCurrentTimeIndicator () {
866- if (todayColumnIndex != - 1 ) {
867- val calendar = Calendar .getInstance()
868- val minutes = calendar.get(Calendar .HOUR_OF_DAY ) * 60 + calendar.get(Calendar .MINUTE )
869- if (todayColumnIndex >= dayColumns.size) {
870- currentTimeView?.alpha = 0f
871- return
872- }
873-
874- if (currentTimeView != null ) {
875- binding.weekEventsHolder.removeView(currentTimeView)
876- }
867+ if (todayColumnIndex == - 1 ) {
868+ return
869+ }
877870
878- if (isPrintVersion) {
879- return
880- }
871+ val calendar = Calendar .getInstance()
872+ val minutes = calendar.get(Calendar .HOUR_OF_DAY ) * 60 + calendar.get(Calendar .MINUTE )
873+ if (todayColumnIndex >= dayColumns.size) {
874+ currentTimeView?.alpha = 0f
875+ return
876+ }
881877
882- val weeklyViewDays = config.weeklyViewDays
883- currentTimeView = WeekNowMarkerBinding .inflate(layoutInflater).root.apply {
884- applyColorFilter(primaryColor)
885- binding.weekEventsHolder.addView(this )
886- val extraWidth =
887- res.getDimension(org.fossify.commons.R .dimen.activity_margin).toInt()
888- val markerHeight = res.getDimension(R .dimen.weekly_view_now_height).toInt()
889- val minuteHeight = rowHeight / 60
890- (layoutParams as RelativeLayout .LayoutParams ).apply {
891- width = (binding.root.width / weeklyViewDays) + extraWidth
892- height = markerHeight
893- }
878+ if (currentTimeView != null ) {
879+ binding.weekEventsHolder.removeView(currentTimeView)
880+ }
894881
895- x = if (weeklyViewDays == 1 ) {
896- 0f
897- } else {
898- (binding.root.width / weeklyViewDays * todayColumnIndex).toFloat() - extraWidth / 2f
899- }
882+ if (isPrintVersion) {
883+ return
884+ }
900885
901- y = minutes * minuteHeight - markerHeight / 2
886+ currentTimeView = WeekNowMarkerBinding .inflate(layoutInflater).root.apply {
887+ binding.weekEventsHolder.addView(this )
888+ val todayColumn = dayColumns[todayColumnIndex]
889+ val dotSize = res.getDimension(R .dimen.weekly_view_now_dot_size)
890+ val dotRadius = dotSize / 2f
891+ val isRtl = requireContext().isRTLLayout
892+ val leftOverflow = if (isRtl) dotRadius else dotSize
893+ val rightOverflow = if (isRtl) dotSize else dotRadius
894+ val markerLeft = (todayColumn.left - leftOverflow).coerceAtLeast(0f )
895+ val markerRight = (todayColumn.right + rightOverflow).coerceAtMost(binding.weekEventsHolder.width.toFloat())
896+ val markerHeight = res.getDimensionPixelSize(R .dimen.weekly_view_now_height)
897+ val minuteHeight = rowHeight / 60
898+ (layoutParams as RelativeLayout .LayoutParams ).apply {
899+ addRule(RelativeLayout .ALIGN_PARENT_LEFT )
900+ width = (markerRight - markerLeft).roundToInt()
901+ height = markerHeight
902902 }
903+
904+ x = markerLeft
905+ y = minutes * minuteHeight - markerHeight / 2
903906 }
904907 }
905908
0 commit comments