-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Site Design Revamp] Recommends designs based on chosen vertical #16510
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
Merged
ovitrif
merged 21 commits into
feature/site-design-revamp
from
task/16503-recommend-vertical-designs
May 13, 2022
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f502a2a
Updates FluxC reference
antonis a6f506f
Pass selected vertical to the design picker
antonis 85d9074
Recommend designs based on the selected vertical
antonis 7142471
Merge branch 'feature/site-design-revamp' into task/16503-recommend-v…
antonis 9677bb9
Extracts the recommendation logic to a separate file
antonis fe387f4
Tests the recommended designs logic
antonis 0052838
Adds a mechanism for randomising the order of layouts in specific cat…
antonis 29060b9
Randomises the order of site designs except for the recommended category
antonis 69d9798
Also save the ordered layouts per category for efficiency
antonis 9daa723
Unit tests for which categories should be randomised
antonis c349fca
Merge branch 'feature/site-design-revamp' into task/16503-recommend-v…
antonis 11ff1a1
Merge branch 'task/16503-recommend-vertical-designs' into task/16506-…
antonis e0980a7
Unselect the layout after the choose action if fired
antonis 2fa545a
Merge branch 'task/16503-recommend-vertical-designs' into task/16506-…
antonis 3ddba5e
Adds recommended property in the enhanced_site_creation_site_design_s…
antonis e80ad38
Merge branch 'feature/site-design-revamp' into task/16503-recommend-v…
antonis 319e4c5
Merge branch 'task/16503-recommend-vertical-designs' into task/16506-…
antonis 62812e7
Merge branch 'task/16503-recommend-vertical-designs' into task/16528-…
antonis 91c1cab
Hides keyboard on back
antonis 1020c4d
Merge pull request #16531 from wordpress-mobile/task/16506-randomise-…
ovitrif 8a16b16
Merge pull request #16538 from wordpress-mobile/task/16528-track-reco…
ovitrif 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
76 changes: 76 additions & 0 deletions
76
...main/java/org/wordpress/android/ui/sitecreation/theme/SiteDesignRecommendationProvider.kt
This file contains hidden or 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,76 @@ | ||
| package org.wordpress.android.ui.sitecreation.theme | ||
|
|
||
| import org.wordpress.android.R | ||
| import org.wordpress.android.fluxc.network.rest.wpcom.theme.StarterDesign | ||
| import org.wordpress.android.fluxc.network.rest.wpcom.theme.StarterDesignCategory | ||
| import org.wordpress.android.ui.layoutpicker.LayoutCategoryModel | ||
| import org.wordpress.android.ui.layoutpicker.LayoutModel | ||
| import org.wordpress.android.ui.layoutpicker.toLayoutCategories | ||
| import org.wordpress.android.ui.layoutpicker.toLayoutModels | ||
| import org.wordpress.android.viewmodel.ResourceProvider | ||
| import javax.inject.Inject | ||
|
|
||
| class SiteDesignRecommendationProvider @Inject constructor(private val resourceProvider: ResourceProvider) { | ||
| fun handleResponse( | ||
| vertical: String, | ||
| designs: List<StarterDesign>, | ||
| categories: List<StarterDesignCategory>, | ||
| responseHandler: (layouts: List<LayoutModel>, categories: List<LayoutCategoryModel>) -> Unit | ||
| ) { | ||
| val verticalSlug: String? = if (vertical.isNullOrEmpty()) null else getVerticalSlug(vertical) | ||
| val hasRecommendations = !verticalSlug.isNullOrEmpty() && | ||
| designs.any { it.group != null && it.group.contains(verticalSlug) } | ||
|
|
||
| if (hasRecommendations) { | ||
| val recommendedTitle = resourceProvider.getString(R.string.hpp_recommended_title, vertical) | ||
| // Create a new category for the recommendations | ||
| val recommendedCategory = StarterDesignCategory( | ||
| slug = "recommended_$verticalSlug", // The slug is not used but should not already exist | ||
| title = recommendedTitle, | ||
| description = recommendedTitle, | ||
| emoji = "" | ||
| ) | ||
| val designsWithRecommendations = designs.map { | ||
| // Add the new category to the recommended designs so that they are filtered correctly | ||
| // in the `LayoutPickerViewModel.loadLayouts()` method | ||
| if (it.group.contains(verticalSlug)) { | ||
| it.copy(categories = it.categories + recommendedCategory) | ||
| } else { | ||
| it | ||
| } | ||
| }.toLayoutModels() | ||
| val categoriesWithRecommendations = | ||
| listOf(recommendedCategory).toLayoutCategories(recommended = true) + | ||
| categories.toLayoutCategories(randomizeOrder = true) | ||
| responseHandler(designsWithRecommendations, categoriesWithRecommendations) | ||
| } else { | ||
| // If no designs are recommended for the selected vertical recommend the blog category | ||
| val recommendedTitle = resourceProvider.getString( | ||
| R.string.hpp_recommended_title, | ||
| resourceProvider.getString(R.string.hpp_recommended_default_vertical) | ||
| ) | ||
| val recommendedCategory = categories.firstOrNull { it.slug == "blog" }?.copy( | ||
| title = recommendedTitle, | ||
| description = recommendedTitle | ||
| ) | ||
| if (recommendedCategory == null) { | ||
| // If there is no blog category do not show a recommendation | ||
| responseHandler(designs.toLayoutModels(), categories.toLayoutCategories(randomizeOrder = true)) | ||
| } else { | ||
| val categoriesWithRecommendations = | ||
| listOf(recommendedCategory).toLayoutCategories(recommended = true, randomizeOrder = true) + | ||
| categories.toLayoutCategories(randomizeOrder = true) | ||
| responseHandler(designs.toLayoutModels(), categoriesWithRecommendations) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun getVerticalSlug(vertical: String): String? { | ||
| val slugsArray = resourceProvider.getStringArray(R.array.site_creation_intents_slugs) | ||
| val verticalArray = resourceProvider.getStringArray(R.array.site_creation_intents_strings) | ||
| if (slugsArray.size != verticalArray.size) { | ||
| throw IllegalStateException("Intents arrays size mismatch") | ||
| } | ||
| return slugsArray.getOrNull(verticalArray.indexOf(vertical)) | ||
| } | ||
| } |
This file contains hidden or 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
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.
@mkevins Delaying the super call that dismisses the preview screen and unselects the layout seems to fix the flow.
I removed the TODO but I'll be happy to put it back if there is more to it 🙏
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.
Fwiw, I added this comment before removing the bottom action buttons, and I left it in case anything else would need to be wired up when adding the new behavior. Delaying it sounds good to me (an alternative might be to pass it as a parameter, but I think this is simpler 🤷♂️ ).
One other consideration I had at the time was with regard to the tracks events, and whether we are differentiating between the user choosing from the main screen and the preview screen (in the old flow). In the new flow there is only one path to choose a theme, so maybe we just need to update the tracks description to reflect this?
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.
Thank you for the feedback @mkevins 🙇
That's a good point. I think with the old flow we do not differentiate between choosing directly or choosing in the preview screen and emit the same event
enhanced_site_creation_site_design_selected. Despite that I think it's a good idea to make clear in the description of what we track when we update it to add the newrecommendedproperty.ps. I added a draft issue
[Site Design Revamp] Update Tracks event (non-blocking)on the board (cc @twstokes)