Skip to content

Commit

Permalink
NT-2053:UX – Add pagination to replies (#1311)
Browse files Browse the repository at this point in the history
* Fix pagnation scroll issue

* create RootCommentViewHolderViewModel

* create PaginationViewMoreRepliesViewHolder

* update isReversed in ApolloPaginate

* update PAGE_SIZE in ApolloClient

* Allow to enable and disable scroll with RecyclerViewPaginator

* add start margin in case render replies

* delete unused classes

* update RepliesAdapter

* update ThreadActivity

* Fix RecyclerView position

* Add testing to RootCommentViewHolderViewModel

* Add testing to PaginationViewMoreViewHolderViewModel

* update test

* Fix code style

* fix code conflict

* fix code format

* Handle pagnation error

* show loading with fetching items

* fix format

* fix code comment

* update

Co-authored-by: sunday-okpoluaefe <63934292+sunday-okpoluaefe@users.noreply.github.com>
  • Loading branch information
hadia and sunday-okpoluaefe committed Jul 5, 2021
1 parent ab19752 commit 3227c4a
Show file tree
Hide file tree
Showing 25 changed files with 559 additions and 263 deletions.
Expand Up @@ -18,6 +18,7 @@

public final class RecyclerViewPaginator {
private final @NonNull RecyclerView recyclerView;
private final @NonNull Boolean isScrollEnabled;
private final @NonNull Action0 nextPage;
private final Observable<Boolean> isLoading;
private Subscription subscription;
Expand All @@ -29,6 +30,15 @@ public RecyclerViewPaginator(final @NonNull RecyclerView recyclerView, final @No
this.recyclerView = recyclerView;
this.nextPage = nextPage;
this.isLoading = isLoading;
this.isScrollEnabled =true;
start();
}

public RecyclerViewPaginator(final @NonNull RecyclerView recyclerView, final @NonNull Action0 nextPage, final @NonNull Observable<Boolean> isLoading, final @NonNull Boolean isScrollEnabled) {
this.recyclerView = recyclerView;
this.nextPage = nextPage;
this.isLoading = isLoading;
this.isScrollEnabled =isScrollEnabled;
start();
}

Expand Down Expand Up @@ -59,7 +69,11 @@ public void start() {
.filter(this::visibleItemIsCloseToBottom);

this.subscription = loadNextPage
.subscribe(__ -> this.nextPage.call());
.subscribe(__ ->{
if(this.isScrollEnabled) {
this.nextPage.call();
}
});

this.retrySubscription = this.retryLoadingNextPageSubject
.subscribe(__ ->
Expand Down
Expand Up @@ -54,8 +54,13 @@ class ApolloPaginate<Data, Envelope : ApolloEnvelope, Params>(
private var concater: Func2<List<Data>?, List<Data>?, List<Data>?> =
Func2 { xs: List<Data>?, ys: List<Data>? ->
mutableListOf<Data>().apply {
xs?.toMutableList()?.let { this.addAll(it) }
ys?.toMutableList()?.let { this.addAll(it) }
if (isReversed) {
ys?.toMutableList()?.let { this.addAll(it) }
xs?.toMutableList()?.let { this.addAll(it) }
} else {
xs?.toMutableList()?.let { this.addAll(it) }
ys?.toMutableList()?.let { this.addAll(it) }
}
}.toList()
}
private var distinctUntilChanged = false
Expand Down Expand Up @@ -130,7 +135,7 @@ class ApolloPaginate<Data, Envelope : ApolloEnvelope, Params>(
/**
* [Optional] Determines if the list of loaded data is should be distinct until changed.
*/
fun isReversed(distinctUntilChanged: Boolean): Builder<Data, Envelope, Params> {
fun isReversed(isReversed: Boolean): Builder<Data, Envelope, Params> {
this.isReversed = isReversed
return this
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Expand Up @@ -29,5 +29,13 @@ class CommentEnvelopeFactory {
.pageInfoEnvelope(PageInfoEnvelopeFactory.pageInfoEnvelope())
.build()
}

fun repliesCommentsEnvelopeHasPrevious(createdAt: DateTime): CommentEnvelope {
return CommentEnvelope.builder()
.totalCount(1)
.comments(listOf(CommentFactory.reply(createdAt = createdAt)))
.pageInfoEnvelope(PageInfoEnvelopeFactory.pageInfoEnvelopeHasPrevious())
.build()
}
}
}
Expand Up @@ -9,6 +9,26 @@ class PageInfoEnvelopeFactory {
return PageInfoEnvelope.builder()
.endCursor("WzMyNDk1MzMzXQ==")
.startCursor("WzMyNDk1MzMzXQ==")
.hasPreviousPage(false)
.hasNextPage(false)
.build()
}

fun pageInfoEnvelopeHasPrevious(): PageInfoEnvelope {
return PageInfoEnvelope.builder()
.endCursor("WzMyNDk1MzMzXQ==")
.startCursor("WzMyNDk1MzMzXQ==")
.hasPreviousPage(true)
.hasNextPage(false)
.build()
}

fun pageInfoEnvelopeHasNext(): PageInfoEnvelope {
return PageInfoEnvelope.builder()
.endCursor("WzMyNDk1MzMzXQ==")
.startCursor("WzMyNDk1MzMzXQ==")
.hasPreviousPage(false)
.hasNextPage(true)
.build()
}
}
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/kickstarter/services/ApolloClientType.kt
Expand Up @@ -34,11 +34,11 @@ interface ApolloClientType {

fun clearUnseenActivity(): Observable<Int>

fun getProjectComments(slug: String, cursor: String?, limit: Int = 25): Observable<CommentEnvelope>
fun getProjectComments(slug: String, cursor: String?, limit: Int = PAGE_SIZE): Observable<CommentEnvelope>

fun getProjectUpdateComments(updateId: String, cursor: String?, limit: Int = 25): Observable<CommentEnvelope>
fun getProjectUpdateComments(updateId: String, cursor: String?, limit: Int = PAGE_SIZE): Observable<CommentEnvelope>

fun getRepliesForComment(comment: Comment, cursor: String? = null, pageSize: Int = 25): Observable<CommentEnvelope>
fun getRepliesForComment(comment: Comment, cursor: String? = null, pageSize: Int = REPLIES_PAGE_SIZE): Observable<CommentEnvelope>

fun createComment(comment: PostCommentData): Observable<Comment>

Expand Down Expand Up @@ -72,3 +72,7 @@ interface ApolloClientType {

fun userPrivacy(): Observable<UserPrivacyQuery.Data>
}

private const val PAGE_SIZE = 25

private const val REPLIES_PAGE_SIZE = 7
Expand Up @@ -181,7 +181,6 @@ class CommentsActivity :

override fun retryCallback() {
recyclerViewPaginator.reload()
// viewModel.inputs.nextPage()
}

override fun emptyCommentsLoginClicked(viewHolder: EmptyCommentsViewHolder?) {
Expand Down

0 comments on commit 3227c4a

Please sign in to comment.