Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,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
Expand Up @@ -9,6 +9,7 @@ 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.AgendaEvent
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 +279,22 @@ class WordpressRepository(
)
}

// Agenda features methods

// getAllEvents

suspend fun getAllAgendaEvents(): List<AgendaEvent>? {
handleServiceExceptions(
tryBody = {
return api.fetchEvents()
},
catchBody = { e ->
Log.e("WordpressRepository: getAllAgendaEvents", "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,7 @@ 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.AgendaEvent
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 +83,13 @@ 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(): List<AgendaEvent>

}

115 changes: 115 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,115 @@
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.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.xpeho_ui_android.CollapsableCard
import com.xpeho.xpeho_ui_android.TagPill
import com.xpeho.xpeho_ui_android.R.drawable as XpehoRes
import com.xpeho.xpeho_ui_android.foundations.Colors as XpehoColors

@Composable
fun AgendaCard(
event: AgendaEvent,
collapsable: Boolean = true,
defaultOpen: Boolean = false
) {
CollapsableCard(
label = event.title,
tags = getTagsList(event = event),
icon = {
Icon(
painter = painterResource(id = XpehoRes.qvst),
contentDescription = "event",
tint = XpehoColors.XPEHO_COLOR,
modifier = Modifier
.size(22.dp)
)
},
size = 16.sp,
collapsable = collapsable,
defaultOpen = defaultOpen
)
}

// Get the tag pills for a campaign
private fun getTagsList(event: AgendaEvent): @Composable() (() -> Unit) {

// Init the tagsList depending the data that we got
val tagPillTheme: @Composable() () -> Unit = {
TagPill(
label = event.topic,
backgroundColor = XpehoColors.GREEN_DARK_COLOR,
size = 9.sp
)
}

var tagPillDeadline: @Composable() () -> Unit

// If the campaign is open we indicate the days remaining
// If it end in less or equal than 3 days and it hasn't been completed -> the color is red
// Else we indicate the end date
// if (event.status == "OPEN") {
// tagPillDeadline = {
// TagPill(
// label =
// when (campaign.remainingDays) {
// 0 -> "Dernier jour"
// 1 -> "${campaign.remainingDays} jour restant"
// else -> "${campaign.remainingDays} jours restants"
// },
// backgroundColor =
// if (campaign.completed || (campaign.remainingDays > 3))
// XpehoColors.GREEN_DARK_COLOR
// else
// XpehoColors.RED_INFO_COLOR,
// size = 9.sp
// )
// }
// } else {
// val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy")
// // val endDate = LocalDate.parse(campaign.endDate, DateTimeFormatter.ISO_DATE)
// tagPillDeadline = {
// TagPill(
// label = "endDate",
// backgroundColor = XpehoColors.GREEN_DARK_COLOR,
// size = 9.sp
// )
// }
// }

val tagPillCompletion: @Composable() () -> Unit

// If campaign is completed we indicate that it has been complete
// Else if it is always open we indicate it can always be completed
// if (campaign.completed) {
// tagPillCompletion = {
// TagPill(
// label = "Complétée",
// backgroundColor = XpehoColors.XPEHO_COLOR,
// size = 9.sp
// )
// }
// } else if (campaign.status == "OPEN") {
// tagPillCompletion = {
// TagPill(
// label = "À compléter",
// backgroundColor = XpehoColors.GREEN_DARK_COLOR,
// size = 9.sp
// )
// }
// } else {
// tagPillCompletion = {}
// }

return {
tagPillTheme.invoke()
//tagPillDeadline.invoke()
//tagPillCompletion.invoke()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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.AgendaEvent
import com.xpeho.xpeapp.ui.components.layout.NoContentPlaceHolder

@Composable
fun AgendaCardList(
events: List<AgendaEvent>,
collapsable: Boolean = true
) {
if (events.isEmpty()) {
// Display a placeholder if there is no events
NoContentPlaceHolder()
} else {
// Display the list of events
Column {
for (event in events) {
AgendaCard(
event = event,
collapsable = collapsable,
defaultOpen = true
)
Spacer(modifier = Modifier.height(10.dp))
}
}
}
}
22 changes: 19 additions & 3 deletions app/src/main/java/com/xpeho/xpeapp/ui/page/HomePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ import com.xpeho.xpeapp.R
import com.xpeho.xpeapp.XpeApp
import com.xpeho.xpeapp.data.FeatureFlippingEnum
import com.xpeho.xpeapp.data.entity.QvstCampaignEntity
import com.xpeho.xpeapp.data.model.agenda.AgendaEvent
import com.xpeho.xpeapp.domain.FeatureFlippingState
import com.xpeho.xpeapp.ui.components.CustomDialog
import com.xpeho.xpeapp.ui.components.agenda.AgendaCardList
import com.xpeho.xpeapp.ui.components.layout.NoContentPlaceHolder
import com.xpeho.xpeapp.ui.components.layout.Title
import com.xpeho.xpeapp.ui.components.newsletter.NewsletterPreview
import com.xpeho.xpeapp.ui.components.qvst.QvstCardList
import com.xpeho.xpeapp.ui.sendAnalyticsEvent
import com.xpeho.xpeapp.ui.uiState.QvstActiveUiState
import com.xpeho.xpeapp.ui.viewModel.FeatureFlippingViewModel
import com.xpeho.xpeapp.ui.viewModel.agenda.AgendaViewModel
import com.xpeho.xpeapp.ui.viewModel.agenda.AgendaViewModelState
import com.xpeho.xpeapp.ui.viewModel.newsletter.NewsletterViewModel
import com.xpeho.xpeapp.ui.viewModel.qvst.QvstActiveCampaignsViewModel
import com.xpeho.xpeapp.ui.viewModel.viewModelFactory
Expand Down Expand Up @@ -59,10 +63,17 @@ fun HomePage(navigationController: NavController) {
}
)

val agendaViewModel = viewModel<AgendaViewModel>(
factory = viewModelFactory {
AgendaViewModel()
}
)

sendAnalyticsEvent("home_page")

LaunchedEffect(Unit) {
campaignActiveViewModel.updateState()
agendaViewModel.updateState()
newsletterViewModel.updateState()
ffViewModel.updateState()
}
Expand Down Expand Up @@ -120,6 +131,13 @@ fun HomePage(navigationController: NavController) {
item {
Title(label = "À ne pas manquer !")

val events: List<AgendaEvent> =
(agendaViewModel.state as AgendaViewModelState.SUCCESS).agendaEvent
AgendaCardList(
events = events,
collapsable = false
)

val campaigns: List<QvstCampaignEntity> =
(campaignActiveViewModel.state as QvstActiveUiState.SUCCESS).qvst
QvstCardList(
Expand Down Expand Up @@ -152,6 +170,4 @@ fun HomePage(navigationController: NavController) {
}
}
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.xpeho.xpeapp.ui.viewModel.agenda

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.xpeho.xpeapp.XpeApp
import com.xpeho.xpeapp.data.model.agenda.AgendaEvent

import kotlinx.coroutines.launch

class AgendaViewModel : ViewModel() {

var state: AgendaViewModelState by mutableStateOf(AgendaViewModelState.EMPTY)

private fun getAllEvents() {
viewModelScope.launch {
// Get All Events
val result = XpeApp.appModule.wordpressRepository.getAllAgendaEvents()

// Update state
state = if (result != null) {
if (result.isEmpty()) {
AgendaViewModelState.EMPTY
} else {
AgendaViewModelState.SUCCESS(
agendaEvent = result
)
}
} else {
AgendaViewModelState.ERROR("Erreur de chargement de tout les événements")
}
}
}

private fun resetState() {
state = AgendaViewModelState.EMPTY
}

fun updateState() {
resetState()
getAllEvents()
}

}

interface AgendaViewModelState {
object EMPTY : AgendaViewModelState
object LOADING : AgendaViewModelState
data class ERROR(val error: String) : AgendaViewModelState
data class SUCCESS(
val agendaEvent: List<AgendaEvent>,
) : AgendaViewModelState
}
Loading