Skip to content

Commit

Permalink
shouldBatchDisplayPropositions state moved to viewmodel
Browse files Browse the repository at this point in the history
  • Loading branch information
siddique-adobe committed Oct 21, 2024
1 parent ce2c652 commit 927d11e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ private val displayPropositionsHandler: (List<OptimizeProposition>) -> Unit = {

@Composable
fun OffersView(viewModel: MainViewModel) {
val shouldBatchDisplayPropositions = remember { mutableStateOf(false) }
var listState = rememberLazyListState()
Column(
modifier = Modifier
Expand All @@ -82,15 +81,15 @@ fun OffersView(viewModel: MainViewModel) {
) {

OffersSectionText(sectionName = "Text Offers")
TextOffers(shouldCallDisplayProposition = !shouldBatchDisplayPropositions.value)
TextOffers(shouldCallDisplayProposition = !viewModel.shouldBatchDisplayPropositions)
OffersSectionText(sectionName = "Image Offers")
ImageOffers()
OffersSectionText(sectionName = "HTML Offers")
HTMLOffers()
OffersSectionText(sectionName = "JSON Offers")
JSONOffers(shouldCallDisplayProposition = !shouldBatchDisplayPropositions.value)
JSONOffers(shouldCallDisplayProposition = !viewModel.shouldBatchDisplayPropositions)
OffersSectionText(sectionName = "Target Offers")
TargetOffersView(shouldCallDisplayProposition = !shouldBatchDisplayPropositions.value)
TargetOffersView(shouldCallDisplayProposition = !viewModel.shouldBatchDisplayPropositions)
}
} else {
LazyColumn(
Expand All @@ -109,7 +108,7 @@ fun OffersView(viewModel: MainViewModel) {
TextOffers(
offers = viewModel.optimizePropositionStateMap[viewModel.textDecisionScope?.name]?.offers,
listState = listState,
shouldCallDisplayProposition = !shouldBatchDisplayPropositions.value
shouldCallDisplayProposition = !viewModel.shouldBatchDisplayPropositions
)
}

Expand All @@ -134,7 +133,7 @@ fun OffersView(viewModel: MainViewModel) {
JSONOffers(
offers = viewModel.optimizePropositionStateMap[viewModel.jsonDecisionScope?.name]?.offers,
listState = listState,
shouldCallDisplayProposition = !shouldBatchDisplayPropositions.value
shouldCallDisplayProposition = !viewModel.shouldBatchDisplayPropositions
)
}

Expand All @@ -143,13 +142,13 @@ fun OffersView(viewModel: MainViewModel) {
TargetOffersView(
offers = viewModel.optimizePropositionStateMap[viewModel.targetMboxDecisionScope?.name]?.offers,
listState = listState,
shouldCallDisplayProposition = !shouldBatchDisplayPropositions.value
shouldCallDisplayProposition = !viewModel.shouldBatchDisplayPropositions
)
}
}
})
}.also {
if (shouldBatchDisplayPropositions.value) {
if (viewModel.shouldBatchDisplayPropositions) {
displayPropositionsHandler(viewModel.optimizePropositionStateMap.values.toList())
}
}
Expand Down Expand Up @@ -179,8 +178,8 @@ fun OffersView(viewModel: MainViewModel) {
)

Switch(
checked = shouldBatchDisplayPropositions.value,
onCheckedChange = { shouldBatchDisplayPropositions.value = it })
checked = viewModel.shouldBatchDisplayPropositions,
onCheckedChange = { viewModel.shouldBatchDisplayPropositions = it })
}
Spacer(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class MainViewModel: ViewModel() {

var optimizePropositionStateMap = mutableStateMapOf<String, OptimizeProposition>()

var shouldBatchDisplayPropositions by mutableStateOf(false)

private val optimizePropositionUpdateCallback = object : AdobeCallbackWithError<Map<DecisionScope, OptimizeProposition>> {
override fun call(propositions: Map<DecisionScope, OptimizeProposition>?) {
propositions?.forEach {
Expand Down

0 comments on commit 927d11e

Please sign in to comment.