Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion app/src/main/java/com/xpeho/xpeapp/data/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ enum class FeatureFlippingEnum(val value: String) {
EXPENSE_REPORT("expenseReport"),
COLLEAGUES("colleagues"),
QVST("campaign"),
PROFILE("profile")
PROFILE("profile"),
AGENDA("agenda"),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.xpeho.xpeapp.data.model.agenda

import com.google.gson.annotations.SerializedName

data class AgendaBirthday(
val id: String?,
@SerializedName("first_name") val firstName: String?,
val birthdate: String?,
val email: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.xpeho.xpeapp.data.model.agenda

import com.google.gson.annotations.SerializedName

data class AgendaEvent(
val id: String?,
val date: String,
@SerializedName("start_time") val startTime: String?,
@SerializedName("end_time") val endTime: String?,
val title: String,
val location: String?,
@SerializedName("type_id") val typeId: String,
val topic: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.xpeho.xpeapp.data.model.agenda

import com.google.gson.annotations.SerializedName

data class AgendaEventType(
val id: String?,
val label: String,
@SerializedName("color_code") val colorCode: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package com.xpeho.xpeapp.data.service

import android.util.Log
import androidx.annotation.VisibleForTesting
import com.google.api.Page
import com.xpeho.xpeapp.data.entity.AuthentificationBody
import com.xpeho.xpeapp.data.entity.QvstAnswerBody
import com.xpeho.xpeapp.data.entity.QvstCampaignEntity
import com.xpeho.xpeapp.data.entity.user.UserEditPassword
import com.xpeho.xpeapp.data.model.AuthResult
import com.xpeho.xpeapp.data.model.user.UserInfos
import com.xpeho.xpeapp.data.model.WordpressToken
import com.xpeho.xpeapp.data.model.agenda.AgendaBirthday
import com.xpeho.xpeapp.data.model.agenda.AgendaEvent
import com.xpeho.xpeapp.data.model.agenda.AgendaEventType
import com.xpeho.xpeapp.data.model.qvst.QvstCampaign
import com.xpeho.xpeapp.data.model.qvst.QvstProgress
import com.xpeho.xpeapp.data.model.qvst.QvstQuestion
Expand Down Expand Up @@ -278,6 +282,50 @@ class WordpressRepository(
)
}

// Agenda features methods

// getAllEvents

suspend fun getAllEvents(page: String): List<AgendaEvent>? {
handleServiceExceptions(
tryBody = {
return api.fetchEvents(page)
},
catchBody = { e ->
Log.e("WordpressRepository: getAllEvents", "Network error: ${e.message}")
return null
}
)
}

// getAllEventsTypes

suspend fun getAllEventsTypes(): List<AgendaEventType>? {
handleServiceExceptions(
tryBody = {
return api.fetchEventTypes()
},
catchBody = { e ->
Log.e("WordpressRepository: getAllEventsTypes", "Network error: ${e.message}")
return null
}
)
}

// getAllBirthdays

suspend fun getAllBirthdays(page: String): List<AgendaBirthday>? {
handleServiceExceptions(
tryBody = {
return api.fetchBirthdays(page)
},
catchBody = { e ->
Log.e("WordpressRepository: getAllBirthdays", "Network error: ${e.message}")
return null
}
)
}

// Exceptions handling

@Suppress("ReturnCount")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.xpeho.xpeapp.data.entity.QvstAnswerBody
import com.xpeho.xpeapp.data.entity.user.UserEditPassword
import com.xpeho.xpeapp.data.model.user.UserInfos
import com.xpeho.xpeapp.data.model.WordpressToken
import com.xpeho.xpeapp.data.model.agenda.AgendaBirthday
import com.xpeho.xpeapp.data.model.agenda.AgendaEvent
import com.xpeho.xpeapp.data.model.agenda.AgendaEventType
import com.xpeho.xpeapp.data.model.qvst.QvstCampaign
import com.xpeho.xpeapp.data.model.qvst.QvstProgress
import com.xpeho.xpeapp.data.model.qvst.QvstQuestion
Expand Down Expand Up @@ -82,5 +85,27 @@ interface WordpressService {
suspend fun submitOpenAnswer(
@Query("text") text: String,
): Response<Unit>

// Agenda Feature

// Fetch all the events
@Headers("Content-Type: application/json")
@GET ("xpeho/v1/agenda/events")
suspend fun fetchEvents(
@Query("page") page: String = "",
): List<AgendaEvent>

// Fetch all the event types
@Headers("Content-Type: application/json")
@GET ("xpeho/v1/agenda/events-types")
suspend fun fetchEventTypes(): List<AgendaEventType>

// Fetch all birthdays
@Headers("Content-Type: application/json")
@GET ("xpeho/v1/agenda/birthday")
suspend fun fetchBirthdays(
@Query("page") page: String = "",
): List<AgendaBirthday>

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.xpeho.xpeapp.ui.components.agenda

import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.xpeho.xpeapp.data.model.agenda.AgendaEvent
import com.xpeho.xpeapp.data.model.agenda.AgendaEventType
import com.xpeho.xpeho_ui_android.CollapsableCard
import com.xpeho.xpeho_ui_android.TagPill
import com.xpeho.xpeho_ui_android.foundations.Colors as XpehoColors
import com.xpeho.xpeapp.R
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import androidx.core.graphics.toColorInt
import com.xpeho.xpeapp.data.model.agenda.AgendaBirthday
import java.time.LocalDate
import java.time.LocalTime

@Composable
fun AgendaBirthdayCard(
birthday: AgendaBirthday,
collapsable: Boolean = true,
defaultOpen: Boolean = false
) {
val tagColor = Color(0xFFFF7EEA)
val eventTypeIcon = R.drawable.birthday

CollapsableCard(
label = "Anniversaire de ${birthday.firstName}",
tags = getBirthdayTagsList(birthday, tagColor),
icon = {
Icon(
painter = painterResource(id = eventTypeIcon),
contentDescription = "birthday",
tint = tagColor,
modifier = Modifier.size(22.dp)
)
},
size = 16.sp,
collapsable = collapsable,
defaultOpen = defaultOpen
)
}

@Composable
private fun getBirthdayTagsList(birthday: AgendaBirthday, color: Color): @Composable () -> Unit {
val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy")

return {
birthday.birthdate?.takeIf { it.isNotEmpty() }?.let {
val formattedDate = LocalDate.parse(it, DateTimeFormatter.ofPattern("yyyy-MM-dd")).format(formatter)
TagPill(
label = formattedDate,
backgroundColor = color,
size = 9.sp
)
}
}
}
134 changes: 134 additions & 0 deletions app/src/main/java/com/xpeho/xpeapp/ui/components/agenda/AgendaCard.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package com.xpeho.xpeapp.ui.components.agenda

import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.xpeho.xpeapp.data.model.agenda.AgendaEvent
import com.xpeho.xpeapp.data.model.agenda.AgendaEventType
import com.xpeho.xpeho_ui_android.CollapsableCard
import com.xpeho.xpeho_ui_android.TagPill
import com.xpeho.xpeho_ui_android.foundations.Colors as XpehoColors
import com.xpeho.xpeapp.R
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import androidx.core.graphics.toColorInt
import java.time.LocalTime

@Composable
fun AgendaCard(
event: AgendaEvent,
eventTypes: List<AgendaEventType>,
collapsable: Boolean = true,
defaultOpen: Boolean = false
) {
val eventTypeColor = getEventTypeColor(event, eventTypes)
val tagColor = getTagColor(eventTypeColor)
val eventTypeIcon = getEventTypeIcon(event, eventTypes)

CollapsableCard(
label = event.title,
tags = getTagsList(event, eventTypes, tagColor),
icon = {
Icon(
painter = painterResource(id = eventTypeIcon),
contentDescription = "event",
tint = eventTypeColor,
modifier = Modifier.size(22.dp)
)
},
size = 16.sp,
collapsable = collapsable,
defaultOpen = defaultOpen
)
}

@Composable
private fun getTagsList(event: AgendaEvent, eventType: List<AgendaEventType>, color: Color): @Composable () -> Unit {
val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy")
val timeFormatter = DateTimeFormatter.ofPattern("HH-mm")
val timeOfData = DateTimeFormatter.ofPattern("HH:mm:ss")

return {
if (event.date.isNotEmpty()) {
val formattedDate = LocalDateTime.parse(event.date,
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).format(formatter)
TagPill(
label = formattedDate,
backgroundColor = color,
size = 9.sp
)
}
event.startTime?.takeIf { it.isNotEmpty() }?.let {
val formattedTime = LocalTime.parse(it, timeOfData).format(timeFormatter)
TagPill(
label = formattedTime,
backgroundColor = color,
size = 9.sp
)
}
event.endTime?.takeIf { it.isNotEmpty() }?.let {
val formattedTime = LocalTime.parse(it, timeOfData).format(timeFormatter)
TagPill(
label = formattedTime,
backgroundColor = color,
size = 9.sp
)
}
eventType.firstOrNull { it.id == event.typeId }?.let {
TagPill(
label = it.label,
backgroundColor = color,
size = 9.sp
)
}
event.location?.takeIf { it.isNotEmpty() }?.let {
TagPill(
label = it,
backgroundColor = color,
size = 9.sp
)
}
event.topic?.takeIf { it.isNotEmpty() }?.let {
TagPill(
label = it,
backgroundColor = color,
size = 9.sp
)
}
}
}

private fun getEventTypeColor(event: AgendaEvent, eventTypes: List<AgendaEventType>): Color {
val eventType = eventTypes.firstOrNull { it.id == event.typeId }
return if (eventType != null) {
Color(("#" + eventType.colorCode.trimStart('#')).toColorInt())
} else {
XpehoColors.GREEN_DARK_COLOR
}
}

private const val BASE_COLOR_HEX = 0xFF7C4000
private const val ALPHA_VALUE = 0.2f

private fun getTagColor(baseColor: Color): Color {
val overlayColor = Color(BASE_COLOR_HEX).copy(alpha = ALPHA_VALUE)
return overlayColor.compositeOver(baseColor)
}

private fun getEventTypeIcon(event: AgendaEvent, eventType: List<AgendaEventType>): Int {
return when (eventType.firstOrNull { it.id == event.typeId }?.label) {
"XpeUp" -> R.drawable.birthday
"Event interne" -> R.drawable.building
"Formation" -> R.drawable.study
"RSE" -> R.drawable.leaf
"Activité" -> R.drawable.gamepad
"Event externe" -> R.drawable.outside
else -> R.drawable.building
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.xpeho.xpeapp.ui.components.agenda

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.xpeho.xpeapp.data.model.agenda.AgendaBirthday
import com.xpeho.xpeapp.data.model.agenda.AgendaEvent
import com.xpeho.xpeapp.data.model.agenda.AgendaEventType
@Composable
fun AgendaCardList(
events: List<AgendaEvent>,
birthdays: List<AgendaBirthday>,
eventsTypes: List<AgendaEventType>,
collapsable: Boolean = true
) {
Column {
for (birthday in birthdays) {
AgendaBirthdayCard(
birthday = birthday,
collapsable = collapsable,
defaultOpen = true
)
Spacer(modifier = Modifier.height(10.dp))
}
for (event in events) {
AgendaCard(
event = event,
eventTypes = eventsTypes,
collapsable = collapsable,
defaultOpen = true
)
Spacer(modifier = Modifier.height(10.dp))
}

}
}
Loading
Loading