Skip to content

Commit

Permalink
Merge pull request #20317 from wordpress-mobile/issue/20314-show-reco…
Browse files Browse the repository at this point in the history
…mmendation-card-third-position-discover-feed

[Reader][Discover] Move first recommendation card to be card number three
  • Loading branch information
RenanLukas authored Feb 28, 2024
2 parents 2e1e697 + 2753869 commit 72f5d5c
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,31 +199,37 @@ class ReaderDiscoverLogic @Inject constructor(
*/
@Suppress("NestedBlockDepth")
private fun createSimplifiedJson(cardsJsonArray: JSONArray, discoverTasks: DiscoverTasks): JSONArray {
var index = 0
val simplifiedJson = JSONArray()
val simplifiedJsonList = mutableListOf<JSONObject>()
var firstYouMayLikeCard: JSONObject? = null
for (i in 0 until cardsJsonArray.length()) {
val cardJson = cardsJsonArray.getJSONObject(i)
when (cardJson.getString(JSON_CARD_TYPE)) {
JSON_CARD_RECOMMENDED_BLOGS -> {
cardJson.optJSONArray(JSON_CARD_DATA)?.let { recommendedBlogsCardJson ->
if (recommendedBlogsCardJson.length() > 0) {
simplifiedJson.put(index++, createSimplifiedRecommendedBlogsCardJson(cardJson))
simplifiedJsonList.add(createSimplifiedRecommendedBlogsCardJson(cardJson))
}
}
}
JSON_CARD_INTERESTS_YOU_MAY_LIKE -> {
// We should not have an interests/tags card as the first element on Discover feed.
if (i == 0 && discoverTasks == REQUEST_FIRST_PAGE) {
firstYouMayLikeCard = cardJson
continue
}
simplifiedJson.put(index++, cardJson)
simplifiedJsonList.add(cardJson)
}
JSON_CARD_POST -> {
simplifiedJson.put(index++, createSimplifiedPostJson(cardJson))
simplifiedJsonList.add(createSimplifiedPostJson(cardJson))
}
}
}
return simplifiedJson
// If we've received an interests/tags card as the first element, it should be displayed as the third card.
if (firstYouMayLikeCard != null) {
simplifiedJsonList.add(2, firstYouMayLikeCard)
}

return JSONArray(simplifiedJsonList)
}

/**
Expand Down

0 comments on commit 72f5d5c

Please sign in to comment.