-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10641 from woocommerce/issue/10589-language-selec…
…tion Blaze: Ad target languages
- Loading branch information
Showing
8 changed files
with
328 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...com/woocommerce/android/ui/blaze/creation/targets/BlazeCampaignTargetSelectionFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.woocommerce.android.ui.blaze.creation.targets | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.viewModels | ||
import androidx.navigation.fragment.findNavController | ||
import com.woocommerce.android.extensions.navigateBackWithResult | ||
import com.woocommerce.android.ui.base.BaseFragment | ||
import com.woocommerce.android.ui.compose.composeView | ||
import com.woocommerce.android.ui.main.AppBarStatus | ||
import com.woocommerce.android.viewmodel.MultiLiveEvent | ||
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.ExitWithResult | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class BlazeCampaignTargetSelectionFragment : BaseFragment() { | ||
companion object { | ||
const val BLAZE_TARGET_SELECTION_RESULT = "blaze_target_selection_result" | ||
} | ||
|
||
override val activityAppBarStatus: AppBarStatus | ||
get() = AppBarStatus.Hidden | ||
|
||
val viewModel: BlazeCampaignTargetSelectionViewModel by viewModels() | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
return composeView { | ||
BlazeCampaignTargetSelectionScreen(viewModel) | ||
} | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setupObservers() | ||
} | ||
|
||
private fun setupObservers() { | ||
viewModel.event.observe(viewLifecycleOwner) { event -> | ||
when (event) { | ||
is MultiLiveEvent.Event.Exit -> findNavController().popBackStack() | ||
is ExitWithResult<*> -> navigateBackWithResult(BLAZE_TARGET_SELECTION_RESULT, event.data) | ||
} | ||
} | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...n/com/woocommerce/android/ui/blaze/creation/targets/BlazeCampaignTargetSelectionScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.woocommerce.android.ui.blaze.creation.targets | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.material.icons.Icons.Filled | ||
import androidx.compose.material.icons.filled.ArrowBack | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.livedata.observeAsState | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import com.woocommerce.android.R.string | ||
import com.woocommerce.android.ui.blaze.creation.targets.BlazeCampaignTargetSelectionViewModel.TargetItem | ||
import com.woocommerce.android.ui.blaze.creation.targets.BlazeCampaignTargetSelectionViewModel.ViewState | ||
import com.woocommerce.android.ui.compose.component.MultiSelectAllItemsButton | ||
import com.woocommerce.android.ui.compose.component.MultiSelectList | ||
import com.woocommerce.android.ui.compose.component.Toolbar | ||
import com.woocommerce.android.ui.compose.preview.LightDarkThemePreviews | ||
|
||
@Composable | ||
fun BlazeCampaignTargetSelectionScreen(viewModel: BlazeCampaignTargetSelectionViewModel) { | ||
viewModel.viewState.observeAsState().value?.let { state -> | ||
TargetSelectionScreen( | ||
state = state, | ||
onBackPressed = viewModel::onBackPressed, | ||
onSaveTapped = viewModel::onSaveTapped, | ||
onItemTapped = viewModel::onItemTapped, | ||
onAllButtonTapped = viewModel::onAllButtonTapped | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun TargetSelectionScreen( | ||
state: ViewState, | ||
onBackPressed: () -> Unit, | ||
onSaveTapped: () -> Unit, | ||
onItemTapped: (TargetItem) -> Unit, | ||
onAllButtonTapped: () -> Unit | ||
) { | ||
Scaffold( | ||
topBar = { | ||
Toolbar( | ||
title = state.title, | ||
onNavigationButtonClick = onBackPressed, | ||
navigationIcon = Filled.ArrowBack, | ||
actionButtonText = stringResource(id = string.save).uppercase(), | ||
onActionButtonClick = onSaveTapped | ||
) | ||
}, | ||
modifier = Modifier.background(MaterialTheme.colors.surface) | ||
) { paddingValues -> | ||
MultiSelectList( | ||
items = state.items, | ||
selectedItems = state.selectedItems, | ||
itemFormatter = { value }, | ||
onItemToggled = onItemTapped, | ||
allItemsButton = MultiSelectAllItemsButton( | ||
text = stringResource(id = string.blaze_campaign_preview_target_default_value), | ||
onClicked = onAllButtonTapped | ||
), | ||
modifier = Modifier | ||
.background(MaterialTheme.colors.surface) | ||
.padding(paddingValues) | ||
) | ||
} | ||
} | ||
|
||
@LightDarkThemePreviews | ||
@Composable | ||
fun PreviewTargetSelectionScreen() { | ||
TargetSelectionScreen( | ||
state = ViewState( | ||
items = listOf( | ||
TargetItem("1", "Item 1"), | ||
TargetItem("2", "Item 2"), | ||
TargetItem("3", "Item 3"), | ||
TargetItem("4", "Item 4"), | ||
TargetItem("5", "Item 5"), | ||
TargetItem("6", "Item 6"), | ||
TargetItem("7", "Item 7"), | ||
TargetItem("8", "Item 8"), | ||
TargetItem("9", "Item 9") | ||
), | ||
selectedItems = listOf( | ||
TargetItem("4", "Item 4"), | ||
TargetItem("5", "Item 5"), | ||
TargetItem("8", "Item 8"), | ||
TargetItem("9", "Item 9") | ||
), | ||
title = "Title" | ||
), | ||
onBackPressed = { /*TODO*/ }, | ||
onSaveTapped = { /*TODO*/ }, | ||
onItemTapped = {}, | ||
onAllButtonTapped = {} | ||
) | ||
} |
Oops, something went wrong.