Skip to content

Commit

Permalink
fix event card item margins (#3536)
Browse files Browse the repository at this point in the history
* fix event card item margins

* fix lint error

---------

Co-authored-by: Siddharth Agarwal <[email protected]>
  • Loading branch information
siddh1004 and Siddharth Agarwal authored Mar 15, 2024
1 parent 79e5e8c commit c86e8e1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org.dhis2.usescases.programEventDetail
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.testTag
Expand All @@ -19,6 +21,7 @@ import org.dhis2.usescases.teiDashboard.dashboardfragments.teidata.teievents.Eve
import org.hisp.dhis.android.core.program.Program
import org.hisp.dhis.mobile.ui.designsystem.component.ListCard
import org.hisp.dhis.mobile.ui.designsystem.component.ListCardTitleModel
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing

class ProgramEventDetailLiveAdapter(
private val program: Program,
Expand Down Expand Up @@ -67,17 +70,26 @@ class ProgramEventDetailLiveAdapter(
}
},
)
ListCard(
modifier = Modifier.testTag("EVENT_ITEM"),
listAvatar = card.avatar,
title = ListCardTitleModel(text = card.title),
lastUpdated = card.lastUpdated,
additionalInfoList = card.additionalInfo,
actionButton = card.actionButton,
expandLabelText = card.expandLabelText,
shrinkLabelText = card.shrinkLabelText,
onCardClick = card.onCardCLick,
)
Box(
modifier = Modifier
.padding(
start = Spacing.Spacing8,
end = Spacing.Spacing8,
bottom = Spacing.Spacing8,
),
) {
ListCard(
modifier = Modifier.testTag("EVENT_ITEM"),
listAvatar = card.avatar,
title = ListCardTitleModel(text = card.title),
lastUpdated = card.lastUpdated,
additionalInfoList = card.additionalInfo,
actionButton = card.actionButton,
expandLabelText = card.expandLabelText,
shrinkLabelText = card.shrinkLabelText,
onCardClick = card.onCardCLick,
)
}
}

holder.bind(it, null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ class EventAdapter(
materialView.visibility = View.GONE
val composeView = holder.itemView.findViewById<ComposeView>(R.id.composeView)
composeView.setContent {
val spacing = if (it.groupedByStage == true) Spacing.Spacing56 else Spacing.Spacing8
val leftSpacing = if (it.groupedByStage == true) Spacing.Spacing64 else Spacing.Spacing16
val bottomSpacing = if (it.showBottomShadow) {
Spacing.Spacing16
} else {
Spacing.Spacing4
}
val card = cardMapper.map(
event = it,
editable = it.event?.uid()
Expand Down Expand Up @@ -154,7 +159,9 @@ class EventAdapter(
Box(
modifier = Modifier
.padding(
start = spacing,
start = leftSpacing,
end = Spacing.Spacing16,
bottom = bottomSpacing,
),
) {
ListCard(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.hisp.dhis.mobile.ui.designsystem.component.Avatar
import org.hisp.dhis.mobile.ui.designsystem.component.AvatarStyle
import org.hisp.dhis.mobile.ui.designsystem.component.Description
import org.hisp.dhis.mobile.ui.designsystem.component.Title
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing
import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor

internal class StageViewHolder(
Expand All @@ -49,7 +50,16 @@ internal class StageViewHolder(
modifier = Modifier
.fillMaxWidth()
.background(color = Color.White)
.padding(horizontal = 16.dp, vertical = 12.dp),
.padding(
start = Spacing.Spacing16,
end = Spacing.Spacing16,
top = Spacing.Spacing16,
bottom = if (eventItem.eventCount < 1) {
Spacing.Spacing16
} else {
Spacing.Spacing8
},
),
verticalAlignment = Alignment.CenterVertically,
) {
ProvideAvatar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ class TEIEventCardMapper(
onCardClick: () -> Unit,
): ListCardUiModel {
return ListCardUiModel(
avatar = { ProvideAvatar(event) },
avatar = if (event.groupedByStage != true) {
{
ProvideAvatar(eventItem = event)
}
} else {
null
},
title = getTitle(event),
description = getDescription(event),
additionalInfo = getAdditionalInfoList(event, editable, displayOrgUnit),
Expand All @@ -61,14 +67,12 @@ class TEIEventCardMapper(

@Composable
private fun ProvideAvatar(eventItem: EventViewModel) {
if (eventItem.groupedByStage != true) {
Avatar(
metadataAvatar = {
MetadataIcon(metadataIconData = eventItem.metadataIconData)
},
style = AvatarStyle.METADATA,
)
}
Avatar(
metadataAvatar = {
MetadataIcon(metadataIconData = eventItem.metadataIconData)
},
style = AvatarStyle.METADATA,
)
}

private fun getTitle(event: EventViewModel): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.dhis2.usescases.teiDashboard.ui.model.TimelineEventsHeaderModel
import org.hisp.dhis.mobile.ui.designsystem.component.CardDetail
import org.hisp.dhis.mobile.ui.designsystem.component.InfoBar
import org.hisp.dhis.mobile.ui.designsystem.component.InfoBarData
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing

@Composable
fun TeiDetailDashboard(
Expand Down Expand Up @@ -99,11 +100,12 @@ fun TeiDetailDashboard(
}

if (!isGrouped) {
Spacer(modifier = Modifier.size(16.dp))
Spacer(modifier = Modifier.size(Spacing.Spacing16))
TimelineEventsHeader(
timelineEventsHeaderModel = timelineEventHeaderModel,
onOptionSelected = timelineOnEventCreationOptionSelected,
)
Spacer(modifier = Modifier.size(Spacing.Spacing8))
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/res/layout/item_event.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
<androidx.compose.ui.platform.ComposeView
android:id="@+id/composeView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/dp_8"
android:paddingRight="@dimen/dp_8"
android:paddingBottom="@dimen/dp_8" />
android:layout_height="wrap_content" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/materialView"
Expand Down

0 comments on commit c86e8e1

Please sign in to comment.