Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for: Clicking on a day in the monthly view and selecting the wrong day #2276

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
dayVerticalOffsets.put(day.indexOnMonthView, dayVerticalOffsets[day.indexOnMonthView] + weekDaysLetterHeight)
val verticalOffset = dayVerticalOffsets[day.indexOnMonthView]
val xPos = x * dayWidth + horizontalOffset
val yPos = y * dayHeight + verticalOffset
val yPos = y * dayHeight + verticalOffset*1.055f
val xPosCenter = xPos + dayWidth / 2
val dayNumber = day.value.toString()

Expand Down Expand Up @@ -276,7 +276,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
verticalOffset = max(verticalOffset, dayVerticalOffsets[event.startDayIndex + i])
}
val xPos = event.startDayIndex % 7 * dayWidth + horizontalOffset
val yPos = (event.startDayIndex / 7) * dayHeight
val yPos = (event.startDayIndex / 10) * dayHeight
val xPosCenter = xPos + dayWidth / 2

if (verticalOffset - eventTitleHeight * 2 > dayHeight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import com.simplemobiletools.calendar.pro.BuildConfig
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.databinding.MonthViewBackgroundBinding
import com.simplemobiletools.calendar.pro.databinding.MonthViewBinding
import com.simplemobiletools.calendar.pro.extensions.config
Expand Down Expand Up @@ -67,7 +69,7 @@ class MonthViewWrapper(context: Context, attrs: AttributeSet, defStyle: Int) : F
val childLeft = x * dayWidth + horizontalOffset - child.translationX
val childTop = y * dayHeight + weekDaysLetterHeight - child.translationY
val childWidth = child.measuredWidth
val childHeight = child.measuredHeight
val childHeight = child.measuredHeight/1.05F
val childRight = childLeft + childWidth
val childBottom = childTop + childHeight

Expand Down Expand Up @@ -106,10 +108,15 @@ class MonthViewWrapper(context: Context, attrs: AttributeSet, defStyle: Int) : F
}

private fun measureSizes() {
dayWidth = (width - horizontalOffset) / 7f
dayHeight = (height - weekDaysLetterHeight) / 6f
// Supposons que vous avez 7 colonnes et 6 lignes
val columns = 7
val rows = 6

dayWidth = ((width - horizontalOffset) / columns).toFloat()
dayHeight = ((height - weekDaysLetterHeight) / rows).toFloat()
}


private fun addClickableBackgrounds() {
removeAllViews()
binding = MonthViewBinding.inflate(inflater, this, true)
Expand All @@ -119,38 +126,54 @@ class MonthViewWrapper(context: Context, attrs: AttributeSet, defStyle: Int) : F
for (x in 0 until COLUMN_COUNT) {
val day = days.getOrNull(curId)
if (day != null) {
addViewBackground(x, y, day)
addViewBackground(x, y/2, day)
}
curId++
}
}
}

private fun addViewBackground(viewX: Int, viewY: Int, day: DayMonthly) {
val xPos = viewX * dayWidth + horizontalOffset
val yPos = viewY * dayHeight + weekDaysLetterHeight

MonthViewBackgroundBinding.inflate(inflater, this, false).root.apply {
if (isMonthDayView) {
background = null
// utilisation de dayWidth et dayHeight pour définir la taille visuelle totale du jour
val totalDayWidth = dayWidth
val totalDayHeight = dayHeight

// la zone cliquable à un pourcentage de la taille totale du jour
val clickableWidth = (totalDayWidth * 0.7).toInt() // 70% de la largeur totale
val clickableHeight = (totalDayHeight * 0.7).toInt() // 70% de la hauteur totale

// Calcule les positions x et y pour centrer la zone cliquable dans la cellule du jour
val xPos = viewX * totalDayWidth + (totalDayWidth - clickableWidth) / 2 + horizontalOffset
val yPos = viewY * totalDayHeight + (totalDayHeight - clickableHeight) / 2 + weekDaysLetterHeight

// Création des paramètres de disposition pour la vue cliquable
val clickableLayoutParams = FrameLayout.LayoutParams(clickableWidth, clickableHeight)
clickableLayoutParams.setMargins(xPos.toInt(), yPos.toInt(), 0, 0)

val dayView = MonthViewBackgroundBinding.inflate(inflater, this, false).root.apply {
this.layoutParams = clickableLayoutParams
if (BuildConfig.DEBUG) {
setBackgroundResource(R.drawable.debug_day_border) // Appliquez la bordure rouge si en mode débogage
}

layoutParams.width = dayWidth.toInt()
layoutParams.height = dayHeight.toInt()
x = xPos
y = yPos
setOnClickListener {
// gestion de clic sur la zone cliquable
dayClickCallback?.invoke(day)

if (isMonthDayView) {
binding.monthView.updateCurrentlySelectedDay(viewX, viewY)
}
}

addView(this)
}

addView(dayView) // ajout de la vue cliquable à la hiérarchie de la vue parente
}







fun togglePrintMode() {
binding.monthView.togglePrintMode()
}
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name">Agenda simple</string>
<string name="app_launcher_name">Agenda</string>
<string name="change_view">Changer de vue</string>
Expand Down Expand Up @@ -159,7 +159,7 @@
<string name="add_holidays">Ajouter des jours fériés</string>
<string name="national_holidays">Jours fériés nationaux</string>
<string name="religious_holidays">Jours fériés religieux</string>
<string name="holidays_imported_successfully">Les jours fériés ont été correctement importés dans le type d'évènement \'Jours fériés\'</string>
<string name="holidays_imported_successfully">Les jours fériés ont été correctement importés dans le type d\'évènement \'Jours fériés\'</string>
<string name="importing_some_holidays_failed">L\'importation de certains évènements a échoué</string>
<string name="importing_holidays_failed">L\'importation des jours fériés a échoué</string>
<!-- Settings -->
Expand Down Expand Up @@ -252,17 +252,17 @@
<string name="today_only">Aujourd\'hui seulement</string>
<string name="within_the_next">Au cours du prochain…</string>
<plurals name="within_the_next_days">
<item quantity="one">Au cours de la prochaine journée</item>
<item quantity="one" tools:ignore="ImpliedQuantity">Au cours de la prochaine journée</item>
<item quantity="many">Au cours des %d prochains jours</item>
<item quantity="other">Au cours des %d prochains jours</item>
</plurals>
<plurals name="within_the_next_weeks">
<item quantity="one">Au cours de la prochaine semaine</item>
<item quantity="one" tools:ignore="ImpliedQuantity">Au cours de la prochaine semaine</item>
<item quantity="many">Au cours des %d prochaines semaines</item>
<item quantity="other">Au cours des %d prochaines semaines</item>
</plurals>
<plurals name="within_the_next_months">
<item quantity="one">Au cours du prochain mois</item>
<item quantity="one" tools:ignore="ImpliedQuantity">Au cours du prochain mois</item>
<item quantity="many">Au cours des %d prochains mois</item>
<item quantity="other">Au cours des %d prochains mois</item>
</plurals>
Expand Down