Skip to content

Commit 2566c38

Browse files
committed
New getFilteredReviews function
1 parent c686f87 commit 2566c38

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed
Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
11
package com.jdroid.android.googleplay.publisher
22

33
import com.google.api.services.androidpublisher.model.Review
4+
import com.google.api.services.androidpublisher.model.ReviewsListResponse
45

56
class ReviewsService : AbstractGooglePlayPublisher() {
67

7-
fun getReviews(app: App, maxResults: Long? = null, paginationToken: String? = null, startIndex: Long? = null, translationLanguage: String? = null): List<Review> {
8+
fun getReviews(app: App, maxResults: Long? = null, paginationToken: String? = null, startIndex: Long? = null, translationLanguage: String? = null): ReviewsListResponse {
89
val list = init(app.appContext).reviews().list(app.applicationId)
910
list.maxResults = maxResults
1011
list.token = paginationToken
1112
list.startIndex = startIndex
1213
list.translationLanguage = translationLanguage
13-
return list.execute().reviews
14+
return list.execute()
15+
}
16+
17+
fun getFilteredReviews(app: App, appVersionCode: Int? = null, maxRating: Int = 5, translationLanguage: String? = null): List<Review> {
18+
return internalGetFilteredReviews(app, appVersionCode, maxRating, null, null, null, translationLanguage)
19+
}
20+
21+
private fun internalGetFilteredReviews(app: App, appVersionCode: Int?, maxRating: Int, maxResults: Long?, paginationToken: String?, startIndex: Long?, translationLanguage: String?): List<Review> {
22+
val reviews = mutableListOf<Review>()
23+
val reviewsListResponse = getReviews(app, maxResults, paginationToken, startIndex, translationLanguage)
24+
reviewsListResponse.reviews.forEach {
25+
it.comments.forEach { comment ->
26+
if (comment.userComment != null) {
27+
if (appVersionCode == null || comment.userComment.appVersionCode == appVersionCode) {
28+
if (comment.userComment.starRating <= maxRating) {
29+
if (!reviews.contains(it)) {
30+
reviews.add(it)
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}
37+
// TODO Pagination is not working as expected
38+
if (reviewsListResponse.pageInfo != null) {
39+
if (reviewsListResponse.pageInfo.startIndex + reviewsListResponse.pageInfo.resultPerPage < reviewsListResponse.pageInfo.totalResults) {
40+
reviews.addAll(internalGetFilteredReviews(app, appVersionCode, maxRating, maxResults, reviewsListResponse.tokenPagination.nextPageToken,
41+
reviewsListResponse.pageInfo.startIndex.toLong() + reviewsListResponse.pageInfo.resultPerPage, translationLanguage))
42+
}
43+
}
44+
45+
return reviews
1446
}
1547
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package com.jdroid.android.googleplay.publisher
22

3-
import com.google.api.services.androidpublisher.model.VoidedPurchase
3+
import com.google.api.services.androidpublisher.model.VoidedPurchasesListResponse
44

55
class VoidedPurchasesService : AbstractGooglePlayPublisher() {
66

7-
fun getVoidedPurchases(app: App, maxResults: Long? = null, paginationToken: String? = null, startIndex: Long? = null, startTime: Long? = null, endTime: Long? = null, type: Int? = null): List<VoidedPurchase> {
7+
fun getVoidedPurchases(app: App, maxResults: Long? = null, paginationToken: String? = null, startIndex: Long? = null, startTime: Long? = null, endTime: Long? = null, type: Int? = null): VoidedPurchasesListResponse {
88
val list = init(app.appContext).purchases().voidedpurchases().list(app.applicationId)
99
list.maxResults = maxResults
1010
list.token = paginationToken
1111
list.startIndex = startIndex
1212
list.startTime = startTime
1313
list.endTime = endTime
1414
list.type = type
15-
return list.execute().voidedPurchases
15+
return list.execute()
1616
}
1717
}

0 commit comments

Comments
 (0)