Skip to content

Commit

Permalink
update stage item ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal committed Feb 21, 2024
1 parent 2007139 commit 5172858
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import io.reactivex.processors.FlowableProcessor
import io.reactivex.processors.PublishProcessor
import org.dhis2.R
import org.dhis2.commons.data.EventViewModel
import org.dhis2.commons.data.EventViewModelType
import org.dhis2.commons.data.EventViewModelType.EVENT
import org.dhis2.commons.data.EventViewModelType.STAGE
import org.dhis2.commons.data.EventViewModelType.TOGGLE_BUTTON
import org.dhis2.commons.data.EventViewModelType.values
import org.dhis2.commons.data.StageSection
import org.dhis2.commons.resources.ColorUtils
import org.dhis2.databinding.ItemEventBinding
import org.dhis2.databinding.ItemStageSectionBinding
import org.dhis2.usescases.teiDashboard.dashboardfragments.teidata.TEIDataPresenter
import org.hisp.dhis.android.core.enrollment.Enrollment
import org.hisp.dhis.android.core.program.Program
Expand Down Expand Up @@ -59,15 +59,10 @@ class EventAdapter(
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return when (values()[viewType]) {
return when (EventViewModelType.entries[viewType]) {
STAGE -> {
val binding = ItemStageSectionBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false,
)
StageViewHolder(
binding,
ComposeView(parent.context),
stageSelector,
presenter,
colorUtils,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
package org.dhis2.usescases.teiDashboard.dashboardfragments.teidata.teievents

import android.view.View
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.LocalTextStyle
import androidx.compose.material.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.composethemeadapter.MdcTheme
import io.reactivex.processors.FlowableProcessor
import org.dhis2.R
import org.dhis2.commons.data.EventViewModel
import org.dhis2.commons.data.StageSection
import org.dhis2.commons.resources.ColorType
import org.dhis2.commons.resources.ColorUtils
import org.dhis2.commons.resources.ResourceManager
import org.dhis2.databinding.ItemStageSectionBinding
import org.dhis2.ui.MetadataIcon
import org.dhis2.ui.MetadataIconData
import org.dhis2.ui.setUpMetadataIcon
import org.dhis2.usescases.teiDashboard.dashboardfragments.teidata.TEIDataPresenter
import org.dhis2.usescases.teiDashboard.ui.NewEventOptions

internal class StageViewHolder(
private val binding: ItemStageSectionBinding,
val composeView: ComposeView,
private val stageSelector: FlowableProcessor<StageSection>,
private val presenter: TEIDataPresenter,
private val colorUtils: ColorUtils,
) : RecyclerView.ViewHolder(binding.root) {

init {
binding.composeProgramStageIcon.setViewCompositionStrategy(
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed,
)
}
) : RecyclerView.ViewHolder(composeView) {

fun bind(eventItem: EventViewModel) {
val stage = eventItem.stage!!

binding.programStageName.text = stage.displayName()
binding.programStageName.post {
binding.programStageName.isSelected = true
}

val color = colorUtils.getColorFrom(
stage.style().color(),
colorUtils.getPrimaryColor(
Expand All @@ -54,48 +60,62 @@ internal class StageViewHolder(
R.drawable.ic_default_outline,
)

binding.composeProgramStageIcon.setUpMetadataIcon(
MetadataIconData(
programColor = color,
iconResource = iconResource,
sizeInDp = 40,
),
false,
)

binding.addStageButton.visibility =
if (eventItem.canShowAddButton()) {
View.VISIBLE
} else {
View.GONE
}

binding.addStageButton.setContent {
MdcTheme {
NewEventOptions(presenter.getNewEventOptionsByStages(stage)) {
presenter.onAddNewEventOptionSelected(it, stage)
composeView.setContent {
Row(
modifier = Modifier
.fillMaxWidth()
.background(color = Color.White)
.padding(horizontal = 16.dp, vertical = 12.dp),
verticalAlignment = Alignment.CenterVertically,
) {
MetadataIcon(
metadataIconData = MetadataIconData(
programColor = color,
iconResource = iconResource,
sizeInDp = 40,
)
)
Spacer(modifier = Modifier.width(16.dp))
Column(
modifier = Modifier
.weight(1f)
) {
Text(
text = stage.displayName() ?: "",
color = colorResource(id = R.color.textPrimary),
fontSize = 14.sp,
style = LocalTextStyle.current.copy(
fontFamily = FontFamily(Font(R.font.rubik_regular)),
),
)
if (eventItem.eventCount < 1) {
Text(
text = stringResource(R.string.no_data),
color = colorResource(id = R.color.textSecondary),
fontSize = 12.sp,
style = LocalTextStyle.current.copy(
fontFamily = FontFamily(Font(R.font.rubik_regular)),
),
)
}
}
if (eventItem.canShowAddButton()) {
Box(modifier = Modifier
.clickable {
stageSelector.onNext(
StageSection(
stageUid = stage.uid(),
showOptions = true,
showAllEvents = false,
),
)
}) {
NewEventOptions(presenter.getNewEventOptionsByStages(stage)) {
presenter.onAddNewEventOptionSelected(it, stage)
}
}
}
}
}
binding.addStageButton.setOnClickListener {
stageSelector.onNext(
StageSection(
stageUid = stage.uid(),
showOptions = true,
showAllEvents = false,
),
)
}

binding.programNoStageText.visibility =
if (eventItem.eventCount < 1) {
View.VISIBLE
} else {
View.GONE
}

if (eventItem.isSelected) {
eventItem.isSelected = false
}
}
}
87 changes: 0 additions & 87 deletions app/src/main/res/layout/item_stage_section.xml

This file was deleted.

0 comments on commit 5172858

Please sign in to comment.