From 4c411075e7cf9d4310ec17834ec2642662aad814 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Wed, 28 Feb 2024 16:21:23 -0300 Subject: [PATCH 1/2] Move first recommendation card to be card number three --- .../services/discover/ReaderDiscoverLogic.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt index 17a833495dcf..a77a08adb3b6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt @@ -200,30 +200,37 @@ class ReaderDiscoverLogic @Inject constructor( @Suppress("NestedBlockDepth") private fun createSimplifiedJson(cardsJsonArray: JSONArray, discoverTasks: DiscoverTasks): JSONArray { var index = 0 - val simplifiedJson = JSONArray() + val simplifiedJsonList = mutableListOf() + 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(index++, 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(index++, cardJson) } JSON_CARD_POST -> { - simplifiedJson.put(index++, createSimplifiedPostJson(cardJson)) + simplifiedJsonList.add(index++, 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) } /** From 275386982437ada3f26f720f21e84efc613c12ad Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Wed, 28 Feb 2024 16:55:51 -0300 Subject: [PATCH 2/2] Apply PR suggestion: remove useless index variable --- .../ui/reader/services/discover/ReaderDiscoverLogic.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt index a77a08adb3b6..9eee7c0d18bf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt @@ -199,7 +199,6 @@ class ReaderDiscoverLogic @Inject constructor( */ @Suppress("NestedBlockDepth") private fun createSimplifiedJson(cardsJsonArray: JSONArray, discoverTasks: DiscoverTasks): JSONArray { - var index = 0 val simplifiedJsonList = mutableListOf() var firstYouMayLikeCard: JSONObject? = null for (i in 0 until cardsJsonArray.length()) { @@ -208,7 +207,7 @@ class ReaderDiscoverLogic @Inject constructor( JSON_CARD_RECOMMENDED_BLOGS -> { cardJson.optJSONArray(JSON_CARD_DATA)?.let { recommendedBlogsCardJson -> if (recommendedBlogsCardJson.length() > 0) { - simplifiedJsonList.add(index++, createSimplifiedRecommendedBlogsCardJson(cardJson)) + simplifiedJsonList.add(createSimplifiedRecommendedBlogsCardJson(cardJson)) } } } @@ -218,10 +217,10 @@ class ReaderDiscoverLogic @Inject constructor( firstYouMayLikeCard = cardJson continue } - simplifiedJsonList.add(index++, cardJson) + simplifiedJsonList.add(cardJson) } JSON_CARD_POST -> { - simplifiedJsonList.add(index++, createSimplifiedPostJson(cardJson)) + simplifiedJsonList.add(createSimplifiedPostJson(cardJson)) } } }