diff --git a/app/src/main/java/com/kickstarter/features/pledgedprojectsoverview/ui/PledgedProjectsOverviewActivity.kt b/app/src/main/java/com/kickstarter/features/pledgedprojectsoverview/ui/PledgedProjectsOverviewActivity.kt index a29f37d47f..4b8da00908 100644 --- a/app/src/main/java/com/kickstarter/features/pledgedprojectsoverview/ui/PledgedProjectsOverviewActivity.kt +++ b/app/src/main/java/com/kickstarter/features/pledgedprojectsoverview/ui/PledgedProjectsOverviewActivity.kt @@ -71,6 +71,7 @@ class PledgedProjectsOverviewActivity : AppCompatActivity() { errorSnackBarHostState = snackbarHostState, ppoCards = ppoCardPagingSource, totalAlerts = totalAlerts.value, + onAddressConfirmed = { viewModel.showSnackbarAndRefreshCardsList() }, onSendMessageClick = { projectName -> viewModel.onMessageCreatorClicked(projectName) } ) } diff --git a/app/src/main/java/com/kickstarter/features/pledgedprojectsoverview/ui/PledgedProjectsOverviewScreen.kt b/app/src/main/java/com/kickstarter/features/pledgedprojectsoverview/ui/PledgedProjectsOverviewScreen.kt index 80e0f845f0..2e19f11107 100644 --- a/app/src/main/java/com/kickstarter/features/pledgedprojectsoverview/ui/PledgedProjectsOverviewScreen.kt +++ b/app/src/main/java/com/kickstarter/features/pledgedprojectsoverview/ui/PledgedProjectsOverviewScreen.kt @@ -16,6 +16,10 @@ import androidx.compose.material.SnackbarHost import androidx.compose.material.SnackbarHostState import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag @@ -25,6 +29,7 @@ import androidx.paging.PagingData import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems import com.kickstarter.R +import com.kickstarter.ui.compose.designsystem.KSAlertDialog import com.kickstarter.ui.compose.designsystem.KSTheme import com.kickstarter.ui.compose.designsystem.KSTheme.colors import com.kickstarter.ui.compose.designsystem.KSTheme.dimensions @@ -50,6 +55,7 @@ private fun PledgedProjectsOverviewScreenPreview() { ppoCards = ppoCardList, totalAlerts = 10, onBackPressed = {}, + onAddressConfirmed = {}, onSendMessageClick = {}, errorSnackBarHostState = SnackbarHostState() ) @@ -61,12 +67,16 @@ private fun PledgedProjectsOverviewScreenPreview() { fun PledgedProjectsOverviewScreen( modifier: Modifier, onBackPressed: () -> Unit, + onAddressConfirmed: () -> Unit, lazyColumnListState: LazyListState, errorSnackBarHostState: SnackbarHostState, ppoCards: LazyPagingItems, totalAlerts: Int = 0, onSendMessageClick: (projectName: String) -> Unit ) { + val openConfirmAddressAlertDialog = remember { mutableStateOf(false) } + var confirmedAddress by remember { mutableStateOf("") } // TODO: This is either the original shipping address or the user-edited address + Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center @@ -128,7 +138,10 @@ fun PledgedProjectsOverviewScreen( shippingAddress = it.shippingAddress, showBadge = it.showBadge, onActionButtonClicked = { }, - onSecondaryActionButtonClicked = { }, + onSecondaryActionButtonClicked = { + confirmedAddress = it.shippingAddress + openConfirmAddressAlertDialog.value = true + }, timeNumberForAction = it.timeNumberForAction ) } @@ -140,6 +153,28 @@ fun PledgedProjectsOverviewScreen( } } } + + when { + openConfirmAddressAlertDialog.value -> { + KSAlertDialog( + setShowDialog = { openConfirmAddressAlertDialog.value = it }, + headlineText = "Confirm your address:", + bodyText = confirmedAddress, + leftButtonText = "Cancel", + leftButtonAction = { openConfirmAddressAlertDialog.value = false }, + rightButtonText = "Confirm", + rightButtonAction = { + openConfirmAddressAlertDialog.value = false + + // Call confirm address API + // TODO: MBL-1556 Add network call to confirm address + + // Show snackbar and refresh list + onAddressConfirmed() + } + ) + } + } } enum class PledgedProjectsOverviewScreenTestTag { diff --git a/app/src/main/java/com/kickstarter/features/pledgedprojectsoverview/viewmodel/PledgedProjectsOverviewViewModel.kt b/app/src/main/java/com/kickstarter/features/pledgedprojectsoverview/viewmodel/PledgedProjectsOverviewViewModel.kt index cbc11f85d6..7d67218019 100644 --- a/app/src/main/java/com/kickstarter/features/pledgedprojectsoverview/viewmodel/PledgedProjectsOverviewViewModel.kt +++ b/app/src/main/java/com/kickstarter/features/pledgedprojectsoverview/viewmodel/PledgedProjectsOverviewViewModel.kt @@ -34,6 +34,12 @@ class PledgedProjectsOverviewViewModel(environment: Environment) : ViewModel() { val ppoCardsState: StateFlow> = ppoCards.asStateFlow() val totalAlertsState: StateFlow = totalAlerts.asStateFlow() + fun showSnackbarAndRefreshCardsList() { + snackbarMessage.invoke(R.string.address_confirmed_snackbar_text) + + // TODO: MBL-1556 refresh the PPO list (i.e. requery the PPO list). + } + val projectFlow: SharedFlow get() = mutableProjectFlow .asSharedFlow() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d62390b71e..27ef5fe6c0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -91,5 +91,6 @@ Project Alerts Alerts (%1$s) + Address confirmed! Need to change your address before it locks? Visit your backing details on our website. diff --git a/app/src/test/java/com/kickstarter/features/pledgedprojectsoverview/ui/PledgedProjectsOverviewScreenTest.kt b/app/src/test/java/com/kickstarter/features/pledgedprojectsoverview/ui/PledgedProjectsOverviewScreenTest.kt index 7f82dc9d4d..4475473018 100644 --- a/app/src/test/java/com/kickstarter/features/pledgedprojectsoverview/ui/PledgedProjectsOverviewScreenTest.kt +++ b/app/src/test/java/com/kickstarter/features/pledgedprojectsoverview/ui/PledgedProjectsOverviewScreenTest.kt @@ -32,7 +32,8 @@ class PledgedProjectsOverviewScreenTest : KSRobolectricTestCase() { lazyColumnListState = rememberLazyListState(), ppoCards = ppoCardList, errorSnackBarHostState = SnackbarHostState(), - onSendMessageClick = {} + onSendMessageClick = {}, + onAddressConfirmed = {} ) } } diff --git a/app/src/test/java/com/kickstarter/features/pledgedprojectsoverview/viewmodel/PledgedProjectsOverviewViewModelTest.kt b/app/src/test/java/com/kickstarter/features/pledgedprojectsoverview/viewmodel/PledgedProjectsOverviewViewModelTest.kt index 869176dcf9..029f294b8d 100644 --- a/app/src/test/java/com/kickstarter/features/pledgedprojectsoverview/viewmodel/PledgedProjectsOverviewViewModelTest.kt +++ b/app/src/test/java/com/kickstarter/features/pledgedprojectsoverview/viewmodel/PledgedProjectsOverviewViewModelTest.kt @@ -71,4 +71,18 @@ class PledgedProjectsOverviewViewModelTest : KSRobolectricTestCase() { R.string.Something_went_wrong_please_try_again ) } + + @Test + fun `emits_snackbar_when_confirms_address`() = + runTest { + var snackbarAction = 0 + viewModel.provideSnackbarMessage { snackbarAction = it } + viewModel.showSnackbarAndRefreshCardsList() + + // Should equal address confirmed string id + assertEquals( + snackbarAction, + R.string.address_confirmed_snackbar_text + ) + } }