From 35f942eeda91a2e6961e5aa5e80fbc46b1ab4295 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Fri, 17 Jun 2022 04:55:33 +0530 Subject: [PATCH 1/5] issue_5131: take care of some missing cluster apps --- .../e/apps/api/gplay/GPlayAPIImpl.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt index f0b69d06c..c4f86bc27 100644 --- a/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt @@ -249,7 +249,8 @@ class GPlayAPIImpl @Inject constructor( return withContext(Dispatchers.IO) { val clusterSize = streamBundle.streamClusters.size if (clusterSize != 0 && pointer < clusterSize && pointer >= 0) { - streamBundle.streamClusters.values.toList()[pointer].run { + val firstCluster = streamBundle.streamClusters.values.toList()[pointer] + firstCluster.run { if (hasNext()) { /* * If zeroth StreamCluster's next url is not blank, return it. @@ -262,10 +263,19 @@ class GPlayAPIImpl @Inject constructor( */ val streamHelper = StreamHelper(authData).using(gPlayHttpClient) val browseResponse = streamHelper.getBrowseStreamResponse(this.clusterBrowseUrl) - if (browseResponse.contentsUrl.isNotEmpty()) { - return@withContext streamHelper.getNextStreamCluster(browseResponse.contentsUrl) + val adjustedCluster = if (browseResponse.contentsUrl.isNotEmpty()) { + streamHelper.getNextStreamCluster(browseResponse.contentsUrl) } else if (browseResponse.hasBrowseTab()) { - return@withContext streamHelper.getNextStreamCluster(browseResponse.browseTab.listUrl) + streamHelper.getNextStreamCluster(browseResponse.browseTab.listUrl) + } else { + StreamCluster() + } + + return@withContext adjustedCluster.apply { + /* + * Make sure to put apps found in firstCluster are added. + */ + clusterAppList.addAll(firstCluster.clusterAppList) } } } -- GitLab From 439377ddecda36ff3897ee5a9b960aa77c4f85e4 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 20 Jun 2022 16:21:30 +0530 Subject: [PATCH 2/5] issue_5131: Always adjust first cluster. --- .../e/apps/api/gplay/GPlayAPIImpl.kt | 46 +++++++------------ 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt index c4f86bc27..11296a4b5 100644 --- a/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt @@ -222,10 +222,10 @@ class GPlayAPIImpl @Inject constructor( } /** - * Get first StreamCluster of a StreamBundle. + * Get first adjusted StreamCluster of a StreamBundle. * - * Ideally it would just be streamBundle.streamClusters[[pointer]], but in case the StreamCluster - * does not have a next url, we need to get a StreamCluster which has a clusterNextPageUrl. + * Takes the clusterBrowseUrl of streamBundle.streamClusters[[pointer]], + * Populates the cluster and returns it. * * This does not always operate on zeroth StreamCluster of [streamBundle]. * A StreamBundle can have many StreamClusters, each of the individual StreamCluster can point @@ -250,33 +250,21 @@ class GPlayAPIImpl @Inject constructor( val clusterSize = streamBundle.streamClusters.size if (clusterSize != 0 && pointer < clusterSize && pointer >= 0) { val firstCluster = streamBundle.streamClusters.values.toList()[pointer] - firstCluster.run { - if (hasNext()) { - /* - * If zeroth StreamCluster's next url is not blank, return it. - */ - return@withContext this - } else { - /* - * Try fetching a StreamCluster whose next url is not blank. - * Logic taken from Aurora Store code. - */ - val streamHelper = StreamHelper(authData).using(gPlayHttpClient) - val browseResponse = streamHelper.getBrowseStreamResponse(this.clusterBrowseUrl) - val adjustedCluster = if (browseResponse.contentsUrl.isNotEmpty()) { - streamHelper.getNextStreamCluster(browseResponse.contentsUrl) - } else if (browseResponse.hasBrowseTab()) { - streamHelper.getNextStreamCluster(browseResponse.browseTab.listUrl) - } else { - StreamCluster() - } - return@withContext adjustedCluster.apply { - /* - * Make sure to put apps found in firstCluster are added. - */ - clusterAppList.addAll(firstCluster.clusterAppList) - } + val streamHelper = StreamHelper(authData).using(gPlayHttpClient) + val browseResponse = streamHelper.getBrowseStreamResponse(firstCluster.clusterBrowseUrl) + val adjustedCluster = if (browseResponse.contentsUrl.isNotEmpty()) { + streamHelper.getNextStreamCluster(browseResponse.contentsUrl) + } else if (browseResponse.hasBrowseTab()) { + streamHelper.getNextStreamCluster(browseResponse.browseTab.listUrl) + } else { + StreamCluster() + } + + return@withContext adjustedCluster.apply { + clusterAppList.addAll(firstCluster.clusterAppList) + if (!hasNext()) { + clusterNextPageUrl = firstCluster.clusterNextPageUrl } } } -- GitLab From c1064a50245811f0ec0115818f64cea7d8090db2 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 20 Jun 2022 16:40:08 +0530 Subject: [PATCH 3/5] issue_5131: Add support for ExpandedBrowseHelper --- .../e/apps/api/gplay/GPlayAPIImpl.kt | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt index 11296a4b5..6433336bb 100644 --- a/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt @@ -35,6 +35,7 @@ import com.aurora.gplayapi.helpers.CategoryHelper import com.aurora.gplayapi.helpers.PurchaseHelper import com.aurora.gplayapi.helpers.SearchHelper import com.aurora.gplayapi.helpers.StreamHelper +import com.aurora.gplayapi.helpers.ExpandedBrowseHelper import com.aurora.gplayapi.helpers.TopChartsHelper import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.apps.api.gplay.token.TokenRepository @@ -251,14 +252,29 @@ class GPlayAPIImpl @Inject constructor( if (clusterSize != 0 && pointer < clusterSize && pointer >= 0) { val firstCluster = streamBundle.streamClusters.values.toList()[pointer] - val streamHelper = StreamHelper(authData).using(gPlayHttpClient) - val browseResponse = streamHelper.getBrowseStreamResponse(firstCluster.clusterBrowseUrl) - val adjustedCluster = if (browseResponse.contentsUrl.isNotEmpty()) { - streamHelper.getNextStreamCluster(browseResponse.contentsUrl) - } else if (browseResponse.hasBrowseTab()) { - streamHelper.getNextStreamCluster(browseResponse.browseTab.listUrl) + val clusterBrowseUrl = firstCluster.clusterBrowseUrl + + /* + * Logic found in Aurora store code. + */ + val adjustedCluster = if (firstCluster.clusterBrowseUrl.contains("expanded")) { + val streamHelper = ExpandedBrowseHelper(authData).using(gPlayHttpClient) + val browseResponse = streamHelper.getBrowseStreamResponse(clusterBrowseUrl) + if (browseResponse.hasBrowseTab()) { + streamHelper.getExpandedBrowseClusters(browseResponse.browseTab.listUrl) + } else { + StreamCluster() + } } else { - StreamCluster() + val streamHelper = StreamHelper(authData).using(gPlayHttpClient) + val browseResponse = streamHelper.getBrowseStreamResponse(clusterBrowseUrl) + if (browseResponse.contentsUrl.isNotEmpty()) { + streamHelper.getNextStreamCluster(browseResponse.contentsUrl) + } else if (browseResponse.hasBrowseTab()) { + streamHelper.getNextStreamCluster(browseResponse.browseTab.listUrl) + } else { + StreamCluster() + } } return@withContext adjustedCluster.apply { @@ -288,8 +304,17 @@ class GPlayAPIImpl @Inject constructor( ): StreamCluster { return withContext(Dispatchers.IO) { if (currentStreamCluster.hasNext()) { - val streamHelper = StreamHelper(authData).using(gPlayHttpClient) - streamHelper.getNextStreamCluster(currentStreamCluster.clusterNextPageUrl) + + /* + * Logic found in Aurora store code. + */ + if (currentStreamCluster.clusterNextPageUrl.contains("expanded")) { + val streamHelper = ExpandedBrowseHelper(authData).using(gPlayHttpClient) + streamHelper.getExpandedBrowseClusters(currentStreamCluster.clusterNextPageUrl) + } else { + val streamHelper = StreamHelper(authData).using(gPlayHttpClient) + streamHelper.getNextStreamCluster(currentStreamCluster.clusterNextPageUrl) + } } else { StreamCluster() } -- GitLab From 869ad3feae6d2163fe70356502227365945752b9 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 20 Jun 2022 17:54:23 +0530 Subject: [PATCH 4/5] issue_5131: improve readability by moving code to functions. --- .../e/apps/api/gplay/GPlayAPIImpl.kt | 68 +++++++++++-------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt index 6433336bb..5e6a9f281 100644 --- a/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt @@ -222,6 +222,32 @@ class GPlayAPIImpl @Inject constructor( } } + private fun getStreamCluster(url: String, authData: AuthData): StreamCluster { + StreamHelper(authData).using(gPlayHttpClient).run { + val browseResponse = getBrowseStreamResponse(url) + + if (browseResponse.contentsUrl.isNotEmpty()) { + return getNextStreamCluster(browseResponse.contentsUrl) + } + + if (browseResponse.hasBrowseTab()) { + return getNextStreamCluster(browseResponse.browseTab.listUrl) + } + } + return StreamCluster() + } + + private fun getExpandedStreamCluster(url: String, authData: AuthData): StreamCluster { + ExpandedBrowseHelper(authData).using(gPlayHttpClient).run { + val browseResponse = getBrowseStreamResponse(url) + + if (browseResponse.hasBrowseTab()) { + return getExpandedBrowseClusters(browseResponse.browseTab.listUrl) + } + } + return StreamCluster() + } + /** * Get first adjusted StreamCluster of a StreamBundle. * @@ -258,23 +284,9 @@ class GPlayAPIImpl @Inject constructor( * Logic found in Aurora store code. */ val adjustedCluster = if (firstCluster.clusterBrowseUrl.contains("expanded")) { - val streamHelper = ExpandedBrowseHelper(authData).using(gPlayHttpClient) - val browseResponse = streamHelper.getBrowseStreamResponse(clusterBrowseUrl) - if (browseResponse.hasBrowseTab()) { - streamHelper.getExpandedBrowseClusters(browseResponse.browseTab.listUrl) - } else { - StreamCluster() - } + getExpandedStreamCluster(clusterBrowseUrl, authData) } else { - val streamHelper = StreamHelper(authData).using(gPlayHttpClient) - val browseResponse = streamHelper.getBrowseStreamResponse(clusterBrowseUrl) - if (browseResponse.contentsUrl.isNotEmpty()) { - streamHelper.getNextStreamCluster(browseResponse.contentsUrl) - } else if (browseResponse.hasBrowseTab()) { - streamHelper.getNextStreamCluster(browseResponse.browseTab.listUrl) - } else { - StreamCluster() - } + getStreamCluster(clusterBrowseUrl, authData) } return@withContext adjustedCluster.apply { @@ -303,20 +315,20 @@ class GPlayAPIImpl @Inject constructor( currentStreamCluster: StreamCluster, ): StreamCluster { return withContext(Dispatchers.IO) { - if (currentStreamCluster.hasNext()) { + if (!currentStreamCluster.hasNext()) { + return@withContext StreamCluster() + } - /* - * Logic found in Aurora store code. - */ - if (currentStreamCluster.clusterNextPageUrl.contains("expanded")) { - val streamHelper = ExpandedBrowseHelper(authData).using(gPlayHttpClient) - streamHelper.getExpandedBrowseClusters(currentStreamCluster.clusterNextPageUrl) - } else { - val streamHelper = StreamHelper(authData).using(gPlayHttpClient) - streamHelper.getNextStreamCluster(currentStreamCluster.clusterNextPageUrl) - } + /* + * Logic found in Aurora store code. + */ + return@withContext if (currentStreamCluster.clusterNextPageUrl.contains("expanded")) { + getStreamCluster(currentStreamCluster.clusterNextPageUrl, authData) } else { - StreamCluster() + getExpandedStreamCluster( + currentStreamCluster.clusterNextPageUrl, + authData + ) } } } -- GitLab From 0a0eef960bef1f5cf2a285cb4c19d5a0018c11f5 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 20 Jun 2022 18:11:46 +0530 Subject: [PATCH 5/5] issue_5131: minor corrections --- .../e/apps/api/gplay/GPlayAPIImpl.kt | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt index 5e6a9f281..27bc73754 100644 --- a/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/gplay/GPlayAPIImpl.kt @@ -222,8 +222,17 @@ class GPlayAPIImpl @Inject constructor( } } - private fun getStreamCluster(url: String, authData: AuthData): StreamCluster { + private fun getStreamCluster( + url: String, + authData: AuthData, + checkStartUrl: Boolean = false + ): StreamCluster { StreamHelper(authData).using(gPlayHttpClient).run { + + if (!checkStartUrl) { + return getNextStreamCluster(url) + } + val browseResponse = getBrowseStreamResponse(url) if (browseResponse.contentsUrl.isNotEmpty()) { @@ -237,8 +246,17 @@ class GPlayAPIImpl @Inject constructor( return StreamCluster() } - private fun getExpandedStreamCluster(url: String, authData: AuthData): StreamCluster { + private fun getExpandedStreamCluster( + url: String, + authData: AuthData, + checkStartUrl: Boolean = false + ): StreamCluster { ExpandedBrowseHelper(authData).using(gPlayHttpClient).run { + + if (!checkStartUrl) { + return getExpandedBrowseClusters(url) + } + val browseResponse = getBrowseStreamResponse(url) if (browseResponse.hasBrowseTab()) { @@ -284,9 +302,9 @@ class GPlayAPIImpl @Inject constructor( * Logic found in Aurora store code. */ val adjustedCluster = if (firstCluster.clusterBrowseUrl.contains("expanded")) { - getExpandedStreamCluster(clusterBrowseUrl, authData) + getExpandedStreamCluster(clusterBrowseUrl, authData, true) } else { - getStreamCluster(clusterBrowseUrl, authData) + getStreamCluster(clusterBrowseUrl, authData, true) } return@withContext adjustedCluster.apply { @@ -323,12 +341,12 @@ class GPlayAPIImpl @Inject constructor( * Logic found in Aurora store code. */ return@withContext if (currentStreamCluster.clusterNextPageUrl.contains("expanded")) { - getStreamCluster(currentStreamCluster.clusterNextPageUrl, authData) - } else { getExpandedStreamCluster( currentStreamCluster.clusterNextPageUrl, authData ) + } else { + getStreamCluster(currentStreamCluster.clusterNextPageUrl, authData) } } } -- GitLab