Fix weekly view pinch zoom getting stuck (#1097)

* Fix weekly view pinch zoom getting stuck

This code fixes an issue #621 in Week view where pinch zoom could stop
responding after zooming out, especially when an event/task is placed in
the first or last time slot (around 00:00 or 23:00).

* add to fixed issue #621

* fix code for ci test
This commit is contained in:
rbrgmn
2026-04-28 12:25:45 +02:00
committed by GitHub
parent 5fc88aefc3
commit 0b35af49fc
3 changed files with 113 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
@@ -24,37 +25,54 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed event text readability on colored backgrounds ([#1065])
### Fixed
- Zoom level in weekly view locks (#621)
## [1.10.3] - 2026-02-14
### Changed
- Updated translations
### Fixed
- Fixed crash when changing orientation ([#644])
## [1.10.2] - 2026-02-04
### Fixed
- Fixed crash in event editor when CalDAV sync is disabled ([#1024])
## [1.10.1] - 2026-02-03
### Changed
- Updated holiday data
- Updated translations
### Fixed
- Fixed last used default calendar preference for new events ([#1019])
## [1.10.0] - 2026-01-30
### Added
- Added support for custom fonts
- Location suggestions in event editor using recently used locations ([#393])
### Changed
- Unified the local and synchronized calendar pickers in event editor ([#629])
- Updated holiday data ([#1003])
- Updated translations
## [1.9.0] - 2025-12-16
### Changed
- Replaced "event types" concept with "calendars" ([#629])
- Renamed built-in "Regular event" calendar to "Local calendar"
- Weekday labels now use three-letter abbreviations instead of single letters ([#103])
@@ -62,41 +80,53 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated translations
### Fixed
- Fixed crashes and freezing on some devices ([#889])
## [1.8.1] - 2025-11-09
### Changed
- Updated holiday data
- Updated translations
### Fixed
- Fixed startup crash in weekly view ([#550])
- Fixed incorrect weekly view start date in some cases ([#45])
- Fixed issue with Up/Arrow button closing the app ([#870])
- Fixed time drift when switching between views ([#590])
## [1.8.0] - 2025-10-29
### Changed
- Compatibility updates for Android 15 & 16
- Removed permission to access network state (it was added accidentally) ([#826])
- Updated holiday data
- Updated translations
## [1.7.0] - 2025-10-16
### Changed
- Events shown in adjacent months are no longer dimmed ([#808])
- Updated translations
### Fixed
- Fixed missing email notifications for attendees in some cases ([#135])
- Fixed missing attendees list when using some specific providers ([#818])
## [1.6.2] - 2025-10-09
### Changed
- Synchronized events with unspecified status are now treated as confirmed ([#761])
- Updated translations
### Fixed
- Fixed event duplication when editing instances of recurring events ([#138])
- Fixed old reminders not being removed when moving events ([#486])
- Fixed drag and drop copying events instead of moving them ([#706])
@@ -105,68 +135,89 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed synchronization issues when editing events in a recurring series ([#641])
## [1.6.1] - 2025-09-01
### Changed
- Declined events will no longer trigger notifications ([#732])
- Updated translations
### Fixed
- Fixed incorrect widget font size on foldable devices ([#337])
- Fixed missing or delayed reminders in some cases ([#217])
## [1.6.0] - 2025-08-21
### Added
- Holidays for Philippines ([#729])
### Changed
- Updated translations
## [1.5.0] - 2025-07-22
### Added
- Holidays for Guatemala ([#682])
### Changed
- Updated translations
### Fixed
- Audio stream preference now works correctly ([#394])
- Fixed "today" highlight alignment in month view ([#603])
## [1.4.0] - 2025-07-05
### Added
- Holidays for Vietnam ([#613])
- Holidays for Hong Kong ([#574])
### Changed
- Updated translations
## [1.3.0] - 2025-05-13
### Added
- Support for setting event visibility ([#148])
- Option to hide date header in event list widget ([#484])
- Holidays for Bangladesh
### Changed
- Updated some in-app icons for consistency ([#567])
- Updated translations
- Updated holiday data
### Fixed
- Addressed a glitch when long pressing in quick filter
- Fixed age calculation for birthdays from private contacts ([#196])
- Fixed incorrect time in some events imported via ICS files ([#262])
- Fixed "Go to today" button in weekly view ([#551])
## [1.2.0] - 2025-01-26
### Added
- Added ability to export event colors in ICS files (#188)
- Added ability to quickly filter calendars on long press (#309)
- Added state-specific and optional holidays (#379, #413)
### Changed
- Other minor bug fixes and improvements
- Added more translations
### Fixed
- Fixed issue with "Mark completed" notification button (#156)
- Fixed cut-off text in month view on some devices (#265)
- Fixed broken weekly repetition in some timezones (#408)
@@ -174,18 +225,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed invisible attendee suggestions (#41)
## [1.1.0] - 2024-11-15
### Added
- Added support for event status
### Changed
- Replaced checkboxes with switches
- Other minor bug fixes and improvements
- Added more translations
### Removed
- Removed support for Android 7 and older versions
### Fixed
- Resolved issue with multi-day all-day events not displaying on the top bar
- Fixed task opening functionality from widgets
- Fixed resizing issue in date widget
@@ -193,27 +249,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed spanish translation for saturday.
## [1.0.3] - 2024-03-12
### Changed
- Highlight weekends in print mode.
- Updated holidays for some countries.
- Added some translations.
### Fixed
- Fixed month view issue on Google Pixel 8 Pro.
- Fixed event color dots on monthly and daily view.
- Fixed incorrect timezone when import ICS files.
## [1.0.2] - 2024-01-02
### Fixed
- Fixed import compatibility with Simple Calendar.
- Fixed foss flavor configuration.
## [1.0.1] - 2024-01-02
### Fixed
- Fixed import compatibility with Simple Calendar.
## [1.0.0] - 2024-01-01
### Added
- Initial release
[#34]: https://github.com/FossifyOrg/Calendar/issues/34

View File

@@ -112,6 +112,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private var screenHeight = 0
private var rowHeightsAtScale = 0f
private var prevScaleFactor = 0f
private var gestureScaleFactor = 0f
private var mWasDestroyed = false
private var isFragmentVisible = false
private var wasFragmentInit = false
@@ -137,6 +138,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private lateinit var scrollView: MyScrollView
private lateinit var res: Resources
private lateinit var config: Config
private lateinit var scaleDetector: ScaleGestureDetector
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -165,16 +167,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
weekHorizontalGridHolder.layoutParams.height = fullHeight
weekEventsColumnsHolder.layoutParams.height = fullHeight
val scaleDetector = getViewScaleDetector()
scaleDetector = getViewScaleDetector()
scrollView.setOnTouchListener { _, motionEvent ->
scaleDetector.onTouchEvent(motionEvent)
if (motionEvent.action == MotionEvent.ACTION_UP && wasScaled) {
scrollView.isScrollable = true
wasScaled = false
true
} else {
false
}
handleScaleTouch(motionEvent)
}
}
@@ -328,8 +323,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
val gestureDetector = getViewGestureDetector(layout, index)
layout.setOnTouchListener { _, motionEvent ->
gestureDetector.onTouchEvent(motionEvent)
true
handleDayColumnTouch(gestureDetector, motionEvent)
}
layout.setOnDragListener { _, dragEvent ->
@@ -439,6 +433,16 @@ class WeekFragment : Fragment(), WeeklyCalendar {
}
}
private fun handleDayColumnTouch(
gestureDetector: GestureDetector,
motionEvent: MotionEvent
): Boolean {
if (!handleScaleTouch(motionEvent)) {
gestureDetector.onTouchEvent(motionEvent)
}
return true
}
private fun revertDraggedEvent() {
activity?.runOnUiThread {
currentlyDraggedView?.beVisible()
@@ -499,6 +503,25 @@ class WeekFragment : Fragment(), WeeklyCalendar {
}
}
private fun handleScaleTouch(motionEvent: MotionEvent): Boolean {
scaleDetector.onTouchEvent(motionEvent)
val action = motionEvent.actionMasked
if ((action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) && wasScaled) {
scrollView.isScrollable = true
wasScaled = false
return true
}
return scaleDetector.isInProgress || wasScaled || motionEvent.pointerCount > 1
}
@SuppressLint("ClickableViewAccessibility")
private fun attachEventScaleTouchListener(view: View) {
view.setOnTouchListener { _, motionEvent ->
handleScaleTouch(motionEvent)
}
}
private fun getViewScaleDetector(): ScaleGestureDetector {
return ScaleGestureDetector(
requireContext(),
@@ -508,12 +531,14 @@ class WeekFragment : Fragment(), WeeklyCalendar {
prevScaleSpanY = detector.currentSpanY
val wantedFactor =
config.weeklyViewItemHeightMultiplier - (SCALE_RANGE * percent)
gestureScaleFactor - (SCALE_RANGE * percent)
var newFactor = max(min(wantedFactor, MAX_SCALE_FACTOR), MIN_SCALE_FACTOR)
if (scrollView.height > defaultRowHeight * newFactor * 24) {
newFactor = scrollView.height / 24f / defaultRowHeight
}
gestureScaleFactor = newFactor
if (Math.abs(newFactor - prevScaleFactor) > MIN_SCALE_DIFFERENCE) {
prevScaleFactor = newFactor
config.weeklyViewItemHeightMultiplier = newFactor
@@ -534,10 +559,17 @@ class WeekFragment : Fragment(), WeeklyCalendar {
scrollView.isScrollable = false
prevScaleSpanY = detector.currentSpanY
prevScaleFactor = config.weeklyViewItemHeightMultiplier
gestureScaleFactor = prevScaleFactor
wasScaled = true
screenHeight = context!!.realScreenSize.y
return super.onScaleBegin(detector)
}
override fun onScaleEnd(detector: ScaleGestureDetector) {
scrollView.isScrollable = true
wasScaled = false
super.onScaleEnd(detector)
}
})
}
@@ -795,6 +827,8 @@ class WeekFragment : Fragment(), WeeklyCalendar {
}
}
attachEventScaleTouchListener(root)
root.setOnLongClickListener { view ->
currentlyDraggedView = view
val shadowBuilder = View.DragShadowBuilder(view)

View File

@@ -5,6 +5,7 @@ import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import androidx.core.content.ContextCompat
import org.fossify.calendar.extensions.config
import org.fossify.calendar.extensions.getWeeklyViewItemHeight
@@ -16,7 +17,7 @@ class WeeklyViewGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
init {
paint.color = context.resources.getColor(org.fossify.commons.R.color.divider_grey)
paint.color = ContextCompat.getColor(context, org.fossify.commons.R.color.divider_grey)
}
override fun onDraw(canvas: Canvas) {