From 927d11e767b1b45e2bb04c571e0c05fbe438d570 Mon Sep 17 00:00:00 2001 From: saquib-adobe Date: Mon, 21 Oct 2024 12:00:54 +0530 Subject: [PATCH] shouldBatchDisplayPropositions state moved to viewmodel --- .../marketing/optimizeapp/OffersScreen.kt | 19 +++++++++---------- .../optimizeapp/viewmodels/MainViewModel.kt | 2 ++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt index 23d82272..75a34552 100644 --- a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt +++ b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt @@ -66,7 +66,6 @@ private val displayPropositionsHandler: (List) -> Unit = { @Composable fun OffersView(viewModel: MainViewModel) { - val shouldBatchDisplayPropositions = remember { mutableStateOf(false) } var listState = rememberLazyListState() Column( modifier = Modifier @@ -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( @@ -109,7 +108,7 @@ fun OffersView(viewModel: MainViewModel) { TextOffers( offers = viewModel.optimizePropositionStateMap[viewModel.textDecisionScope?.name]?.offers, listState = listState, - shouldCallDisplayProposition = !shouldBatchDisplayPropositions.value + shouldCallDisplayProposition = !viewModel.shouldBatchDisplayPropositions ) } @@ -134,7 +133,7 @@ fun OffersView(viewModel: MainViewModel) { JSONOffers( offers = viewModel.optimizePropositionStateMap[viewModel.jsonDecisionScope?.name]?.offers, listState = listState, - shouldCallDisplayProposition = !shouldBatchDisplayPropositions.value + shouldCallDisplayProposition = !viewModel.shouldBatchDisplayPropositions ) } @@ -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()) } } @@ -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 diff --git a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt index a7832f5e..cde388d0 100644 --- a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt +++ b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt @@ -44,6 +44,8 @@ class MainViewModel: ViewModel() { var optimizePropositionStateMap = mutableStateMapOf() + var shouldBatchDisplayPropositions by mutableStateOf(false) + private val optimizePropositionUpdateCallback = object : AdobeCallbackWithError> { override fun call(propositions: Map?) { propositions?.forEach {