Skip to content

Commit 36202a2

Browse files
committed
feat(agendaPage): add the agenda page
1 parent fbe2440 commit 36202a2

File tree

12 files changed

+171
-52
lines changed

12 files changed

+171
-52
lines changed

app/src/main/java/com/xpeho/xpeapp/enums/Screens.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ enum class Screens {
77
Vacation,
88
Colleague,
99
Qvst,
10-
Profile
10+
Profile,
11+
Agenda
1112
}

app/src/main/java/com/xpeho/xpeapp/ui/Navigation.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.xpeho.xpeapp.ui.components.layout.DisabledFeaturePlaceHolder
1111
import com.xpeho.xpeapp.ui.page.HomePage
1212
import com.xpeho.xpeapp.ui.page.LoginPage
1313
import com.xpeho.xpeapp.ui.page.NewsletterPage
14+
import com.xpeho.xpeapp.ui.page.AgendaPage
1415
import com.xpeho.xpeapp.ui.page.qvst.QvstCampaignDetailPage
1516
import com.xpeho.xpeapp.ui.page.qvst.QvstPage
1617
import com.xpeho.xpeapp.ui.page.user.ProfilePage
@@ -80,4 +81,13 @@ fun NavGraphBuilder.navigationBuilder(
8081
}
8182
}
8283
}
84+
composable(route = Screens.Agenda.name) {
85+
Layout(navigationController) {
86+
if (ffManager.isFeatureEnabled(FeatureFlippingEnum.AGENDA)) {
87+
AgendaPage()
88+
} else {
89+
DisabledFeaturePlaceHolder()
90+
}
91+
}
92+
}
8393
}

app/src/main/java/com/xpeho/xpeapp/ui/Resources.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ class Resources {
6363
redirection = Screens.Vacation.name,
6464
featureFlippingId = FeatureFlippingEnum.VACATION,
6565
),
66+
Menu(
67+
idImage = XpehoRes.calendar,
68+
title = "Agenda",
69+
redirection = Screens.Agenda.name,
70+
featureFlippingId = FeatureFlippingEnum.AGENDA,
71+
)
6672
)
6773

6874
var listOfRequest: Array<RequestLeaveDetail> =

app/src/main/java/com/xpeho/xpeapp/ui/components/agenda/AgendaBirthdayCard.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fun AgendaBirthdayCard(
4343

4444
@Composable
4545
private fun getBirthdayTagsList(birthday: AgendaBirthday, color: Color): @Composable () -> Unit {
46-
val dateFormat = SimpleDateFormat("dd/MM/yyyy", Locale.FRENCH)
46+
val dateFormat = SimpleDateFormat("dd/MM", Locale.FRENCH)
4747

4848
return {
4949
TagPill(

app/src/main/java/com/xpeho/xpeapp/ui/components/agenda/AgendaCard.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fun AgendaCard(
4949

5050
@Composable
5151
private fun getTagsList(event: AgendaEvent, eventType: List<AgendaEventType>, color: Color): @Composable () -> Unit {
52-
val dateFormat = SimpleDateFormat("dd/MM/yyyy", Locale.FRENCH)
52+
val dateFormat = SimpleDateFormat("dd/MM", Locale.FRENCH)
5353
return {
5454
TagPill(
5555
label = dateFormat.format(event.date),

app/src/main/java/com/xpeho/xpeapp/ui/components/agenda/AgendaCardList.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,34 @@ import androidx.compose.foundation.layout.height
66
import androidx.compose.runtime.Composable
77
import androidx.compose.ui.Modifier
88
import androidx.compose.ui.unit.dp
9-
import com.xpeho.xpeapp.data.model.agenda.AgendaBirthday
10-
import com.xpeho.xpeapp.data.model.agenda.AgendaEvent
119
import com.xpeho.xpeapp.data.model.agenda.AgendaEventType
10+
1211
@Composable
1312
fun AgendaCardList(
14-
events: List<AgendaEvent>,
15-
birthdays: List<AgendaBirthday>,
13+
items: List<AgendaItem>,
1614
eventsTypes: List<AgendaEventType>,
1715
collapsable: Boolean = true
1816
) {
1917
Column {
20-
for (birthday in birthdays) {
21-
AgendaBirthdayCard(
22-
birthday = birthday,
23-
collapsable = collapsable,
24-
defaultOpen = true
25-
)
26-
Spacer(modifier = Modifier.height(10.dp))
27-
}
28-
for (event in events) {
29-
AgendaCard(
30-
event = event,
31-
eventTypes = eventsTypes,
32-
collapsable = collapsable,
33-
defaultOpen = true
34-
)
18+
for (item in items) {
19+
when (item) {
20+
is AgendaBirthdayItem -> {
21+
AgendaBirthdayCard(
22+
birthday = item.birthday,
23+
collapsable = collapsable,
24+
defaultOpen = true
25+
)
26+
}
27+
is AgendaEventItem -> {
28+
AgendaCard(
29+
event = item.event,
30+
eventTypes = eventsTypes,
31+
collapsable = collapsable,
32+
defaultOpen = true
33+
)
34+
}
35+
}
3536
Spacer(modifier = Modifier.height(10.dp))
3637
}
37-
3838
}
3939
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.xpeho.xpeapp.ui.components.agenda
2+
3+
import com.xpeho.xpeapp.data.model.agenda.AgendaBirthday
4+
import com.xpeho.xpeapp.data.model.agenda.AgendaEvent
5+
import java.util.Date
6+
7+
// Common base class to sort the global display by the dates
8+
// of each event and birthday in ascending order
9+
sealed class AgendaItem(val date: Date)
10+
11+
data class AgendaBirthdayItem(val birthday: AgendaBirthday) : AgendaItem(birthday.birthdate)
12+
data class AgendaEventItem(val event: AgendaEvent) : AgendaItem(event.date)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.xpeho.xpeapp.ui.page
2+
3+
import androidx.compose.foundation.layout.fillMaxSize
4+
import androidx.compose.foundation.layout.padding
5+
import androidx.compose.foundation.lazy.LazyColumn
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.runtime.LaunchedEffect
8+
import androidx.compose.ui.Modifier
9+
import androidx.compose.ui.res.stringResource
10+
import androidx.compose.ui.unit.dp
11+
import androidx.lifecycle.viewmodel.compose.viewModel
12+
import com.xpeho.xpeapp.R
13+
import com.xpeho.xpeapp.ui.components.CustomDialog
14+
import com.xpeho.xpeapp.ui.components.agenda.AgendaBirthdayItem
15+
import com.xpeho.xpeapp.ui.components.agenda.AgendaCardList
16+
import com.xpeho.xpeapp.ui.components.agenda.AgendaEventItem
17+
import com.xpeho.xpeapp.ui.components.layout.Title
18+
import com.xpeho.xpeapp.ui.sendAnalyticsEvent
19+
import com.xpeho.xpeapp.ui.uiState.AgendaUiState
20+
import com.xpeho.xpeapp.ui.uiState.QvstUiState
21+
import com.xpeho.xpeapp.ui.viewModel.agenda.AgendaViewModel
22+
import com.xpeho.xpeapp.ui.viewModel.viewModelFactory
23+
24+
@Composable
25+
fun AgendaPage() {
26+
val agendaViewModel = viewModel<AgendaViewModel>(
27+
factory = viewModelFactory {
28+
AgendaViewModel()
29+
}
30+
)
31+
32+
sendAnalyticsEvent("agenda_page")
33+
34+
LaunchedEffect(Unit) {
35+
agendaViewModel.updateState()
36+
}
37+
38+
LazyColumn(
39+
modifier = Modifier
40+
.padding(horizontal = 24.dp, vertical = 10.dp)
41+
.fillMaxSize(),
42+
) {
43+
when (agendaViewModel.state) {
44+
is AgendaUiState.SUCCESS -> {
45+
item {
46+
Title(label = "Agenda")
47+
val state = agendaViewModel.state as AgendaUiState.SUCCESS
48+
val events = state.agendaEvent.map { AgendaEventItem(it) }
49+
val birthdays = state.agendaBirthday.map { AgendaBirthdayItem(it) }
50+
val items = (events + birthdays).sortedBy { it.date }
51+
AgendaCardList(
52+
items = items,
53+
eventsTypes = state.agendaEventType,
54+
collapsable = true
55+
)
56+
}
57+
}
58+
is AgendaUiState.ERROR -> {
59+
item {
60+
CustomDialog(
61+
title = stringResource(id = R.string.login_page_error_title),
62+
message = (agendaViewModel.state as QvstUiState.ERROR).error,
63+
) {
64+
agendaViewModel.resetState()
65+
}
66+
}
67+
}
68+
}
69+
}
70+
}

app/src/main/java/com/xpeho/xpeapp/ui/page/HomePage.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import com.xpeho.xpeapp.data.model.agenda.AgendaEvent
2323
import com.xpeho.xpeapp.data.model.agenda.AgendaEventType
2424
import com.xpeho.xpeapp.domain.FeatureFlippingState
2525
import com.xpeho.xpeapp.ui.components.CustomDialog
26+
import com.xpeho.xpeapp.ui.components.agenda.AgendaBirthdayItem
2627
import com.xpeho.xpeapp.ui.components.agenda.AgendaCardList
28+
import com.xpeho.xpeapp.ui.components.agenda.AgendaEventItem
2729
import com.xpeho.xpeapp.ui.components.layout.NoContentPlaceHolder
2830
import com.xpeho.xpeapp.ui.components.layout.Title
2931
import com.xpeho.xpeapp.ui.components.newsletter.NewsletterPreview
@@ -163,16 +165,14 @@ fun HomePage(navigationController: NavController) {
163165
// If we successfully loaded the events
164166
is AgendaViewModelState.SUCCESS -> {
165167
item {
166-
val events: List<AgendaEvent> =
167-
(agendaViewModel.state as AgendaViewModelState.SUCCESS).agendaEvent
168-
val eventsTypes: List<AgendaEventType> =
169-
(agendaViewModel.state as AgendaViewModelState.SUCCESS).agendaEventType
170-
val birthdays: List<AgendaBirthday> =
171-
(agendaViewModel.state as AgendaViewModelState.SUCCESS).agendaBirthday
168+
val state = agendaViewModel.state as AgendaViewModelState.SUCCESS
169+
val events = state.agendaEvent.map { AgendaEventItem(it) }
170+
val birthdays = state.agendaBirthday.map { AgendaBirthdayItem(it) }
171+
val items = (events + birthdays).sortedBy { it.date }
172+
val eventsTypes = state.agendaEventType
172173
AgendaCardList(
173-
events = events,
174+
items = items,
174175
eventsTypes = eventsTypes,
175-
birthdays = birthdays,
176176
collapsable = false
177177
)
178178
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.xpeho.xpeapp.ui.uiState
2+
3+
import com.xpeho.xpeapp.data.model.agenda.AgendaBirthday
4+
import com.xpeho.xpeapp.data.model.agenda.AgendaEvent
5+
import com.xpeho.xpeapp.data.model.agenda.AgendaEventType
6+
7+
interface AgendaUiState {
8+
object EMPTY : AgendaUiState
9+
object LOADING : AgendaUiState
10+
data class ERROR(val error: String) : AgendaUiState
11+
data class SUCCESS(
12+
val agendaEvent: List<AgendaEvent> = emptyList(),
13+
val agendaEventType: List<AgendaEventType> = emptyList(),
14+
val agendaBirthday: List<AgendaBirthday> = emptyList()
15+
) : AgendaUiState
16+
}

0 commit comments

Comments
 (0)