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 30, 2024
1 parent d939c44 commit cd7f86b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import androidx.compose.material.Switch
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -65,7 +63,6 @@ private val displayPropositionsHandler: (List<Offer>) -> Unit = { offers ->

@Composable
fun OffersView(viewModel: MainViewModel) {
val shouldBatchDisplayPropositions = remember { mutableStateOf(false) }
var listState = rememberLazyListState()
Column(
modifier = Modifier
Expand All @@ -81,15 +78,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 @@ -108,7 +105,7 @@ fun OffersView(viewModel: MainViewModel) {
TextOffers(
offers = viewModel.optimizePropositionStateMap[viewModel.textDecisionScope?.name]?.offers,
listState = listState,
shouldCallDisplayProposition = !shouldBatchDisplayPropositions.value
shouldCallDisplayProposition = !viewModel.shouldBatchDisplayPropositions
)
}

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

Expand All @@ -142,13 +139,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 @@ -178,8 +175,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 cd7f86b

Please sign in to comment.