Skip to content

Commit affbe0a

Browse files
LunarXKevinBoulongne
authored andcommitted
Clean code
1 parent adbe182 commit affbe0a

File tree

6 files changed

+20
-17
lines changed

6 files changed

+20
-17
lines changed

app/src/main/java/com/infomaniak/mail/data/models/Attachment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Infomaniak Mail - Android
3-
* Copyright (C) 2022-2024 Infomaniak Network SA
3+
* Copyright (C) 2022-2023 Infomaniak Network SA
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by

app/src/main/java/com/infomaniak/mail/data/models/calendar/CalendarEventResponse.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class CalendarEventResponse : EmbeddedRealmObject {
4141
fun hasUserStoredEvent() = userStoredEvent != null
4242

4343
fun hasAttachmentEvent() = attachmentEvent != null
44-
4544
override fun equals(other: Any?): Boolean {
4645
if (this === other) return true
4746
if (javaClass != other?.javaClass) return false
@@ -50,13 +49,15 @@ class CalendarEventResponse : EmbeddedRealmObject {
5049

5150
if (userStoredEvent != other.userStoredEvent) return false
5251
if (userStoredEventDeleted != other.userStoredEventDeleted) return false
53-
return attachmentEvent == other.attachmentEvent
52+
if (attachmentEvent != other.attachmentEvent) return false
53+
return _attachmentEventMethod == other._attachmentEventMethod
5454
}
5555

5656
override fun hashCode(): Int {
5757
var result = userStoredEvent?.hashCode() ?: 0
5858
result = 31 * result + userStoredEventDeleted.hashCode()
5959
result = 31 * result + (attachmentEvent?.hashCode() ?: 0)
60+
result = 31 * result + (_attachmentEventMethod?.hashCode() ?: 0)
6061
return result
6162
}
6263

app/src/main/java/com/infomaniak/mail/data/models/message/Message.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class Message : RealmObject {
124124
@Transient
125125
var isDeletedOnApi: Boolean = false
126126
@Transient
127-
var latestCalendarEventResponse: CalendarEventResponse? = null // TODO : Migration? If message already exists set it to null
127+
var latestCalendarEventResponse: CalendarEventResponse? = null
128128
//endregion
129129

130130
//region UI data (Transient & Ignore)

app/src/main/java/com/infomaniak/mail/ui/main/thread/ThreadFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class ThreadFragment : Fragment() {
331331

332332
threadViewModel.fetchMessagesHeavyData(messages)
333333

334-
val currentMailboxUuid = mainViewModel.currentMailbox.value!!.uuid // TODO : What do we do if value is null?
334+
val currentMailboxUuid = mainViewModel.currentMailbox.value!!.uuid
335335
if (threadViewModel.getCalendarEventTreatedMessageCount() != messages.count()) {
336336
threadViewModel.fetchCalendarEvents(messages, currentMailboxUuid)
337337
}

app/src/main/java/com/infomaniak/mail/ui/main/thread/calendar/CalendarEventBannerView.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.infomaniak.mail.data.models.calendar.CalendarEvent
3232
import com.infomaniak.mail.databinding.ViewCalendarEventBannerBinding
3333
import com.infomaniak.mail.utils.UiUtils.getPrettyNameAndEmail
3434
import com.infomaniak.mail.utils.toDate
35+
import io.realm.kotlin.types.RealmList
3536
import io.sentry.Sentry
3637
import java.time.format.FormatStyle
3738
import java.util.Date
@@ -72,14 +73,7 @@ class CalendarEventBannerView @JvmOverloads constructor(
7273
text = calendarEvent.location
7374
}
7475

75-
val iAmPartOfAttendees = calendarEvent.attendees.any { it.isMe() }
76-
notPartOfAttendeesWarning.isGone = iAmPartOfAttendees
77-
participationButtons.isVisible = iAmPartOfAttendees
78-
attendeesLayout.isGone = calendarEvent.attendees.isEmpty()
79-
80-
displayOrganizer(calendarEvent.attendees)
81-
allAttendeesButton.setOnClickListener { navigateToAttendeesBottomSheet?.invoke(calendarEvent.attendees) }
82-
manyAvatarsView.setAttendees(calendarEvent.attendees)
76+
setAttendees(calendarEvent.attendees)
8377
}
8478

8579
private fun setWarnings(startDate: Date, hasBeenDeleted: Boolean) = with(binding) {
@@ -117,6 +111,17 @@ class CalendarEventBannerView @JvmOverloads constructor(
117111
}
118112
}
119113

114+
private fun setAttendees(attendees: RealmList<Attendee>) = with(binding) {
115+
val iAmPartOfAttendees = attendees.any { it.isMe() }
116+
notPartOfAttendeesWarning.isGone = iAmPartOfAttendees
117+
participationButtons.isVisible = iAmPartOfAttendees
118+
attendeesLayout.isGone = attendees.isEmpty()
119+
120+
displayOrganizer(attendees)
121+
allAttendeesButton.setOnClickListener { navigateToAttendeesBottomSheet?.invoke(attendees) }
122+
manyAvatarsView.setAttendees(attendees)
123+
}
124+
120125
fun initCallback(navigateToAttendeesBottomSheet: (List<Attendee>) -> Unit) {
121126
this.navigateToAttendeesBottomSheet = navigateToAttendeesBottomSheet
122127
}
@@ -142,7 +147,7 @@ class CalendarEventBannerView @JvmOverloads constructor(
142147
scope.setExtra("amount of organizer", organizers.count().toString())
143148
scope.setExtra("have same email", organizers.all { it.email == organizers[0].email }.toString())
144149
scope.setExtra("have same name", organizers.all { it.name == organizers[0].name }.toString())
145-
Sentry.captureMessage("Found more than one organizer for this event")
150+
Sentry.captureMessage("Found more than one organizer for an event")
146151
}
147152
}
148153

app/src/main/java/com/infomaniak/mail/utils/Extensions.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,9 @@ import io.realm.kotlin.types.RealmObject
104104
import kotlinx.serialization.encodeToString
105105
import org.jsoup.Jsoup
106106
import org.jsoup.nodes.Document
107-
import java.lang.IllegalArgumentException
108-
import java.text.SimpleDateFormat
109107
import java.time.*
110108
import java.util.Calendar
111109
import java.util.Date
112-
import java.util.Objects
113110
import java.util.Scanner
114111
import kotlin.math.roundToInt
115112

0 commit comments

Comments
 (0)