-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blaze: Ad target languages #10641
Merged
Merged
Blaze: Ad target languages #10641
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
94ebe81
Add the language selection boiler plate
0nko 398393c
Merge branch 'blaze/refactor-preview-viewstate' into issue/10589-lang…
0nko ba0cb30
Add the functions to fetch & observe languages
0nko 390962f
Add BlazeTargetType enum
0nko 3925cd6
Add target selection navigation
0nko b520914
Handle language selection in the preview ViewModel
0nko 6dfb0a0
Add target selection screen UI
0nko b3c87cd
Add target selection logic
0nko 7b67888
Fix ktlint issues
0nko ec280ac
Remove unused parameters
0nko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor np, Wdyt about having a single flow for languages and add a new boolean field to the
Language
model to save theisSelected
state. I feel with this approach of 2 different flows one for all the values and one for the selected ones we are going to have an explosion of flows once we add the rest of the campaign details.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm.. 🤔 I'm not convinced this would be cleaner, in the end. We'd save 4 flows overall but updating the selection and returning results would result in copying the entire lists and mapping, like this:
languages.update { items -> items.map { it.copy(isSelected = it.language.code in selectedIds) } } }
instead ofselectedLanguages.update { selectedIds }
.Let's discuss this further, I don't feel too strongly about this.. 🙂