Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Pagination #1681

Closed

Conversation

aggarwalpulkit596
Copy link
Contributor

@aggarwalpulkit596 aggarwalpulkit596 commented Apr 28, 2019

Fixes #84

Changes: Add Pagination for Searching Location Events

Screenshots for the change:
Infinite Scrolling
videotogif_2019 05 02_19 17 29

@fossasia fossasia deleted a comment May 1, 2019
@fossasia fossasia deleted a comment May 1, 2019
@fossasia fossasia deleted a comment May 1, 2019
@aggarwalpulkit596 aggarwalpulkit596 changed the title [WIP]feat: Add Pagination[skip ci] feat: Add Pagination May 2, 2019
@auto-label auto-label bot added the feature label May 2, 2019
@aggarwalpulkit596
Copy link
Contributor Author

@iamareebjamal @nikit19 please do an initial review after that I'll be moving forward to integrate for similar and search event API calls


compositeDisposable += mutableEventsPaged
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doFinally Block is not working

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot get it, why it is not working!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal can you tell why doFinally Block is not working here because of that shimmer layout do not stop everything else just works fine. is it because pagination requires continuous API calls to different pages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal please a little bit of help here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will try locally today

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please do. I'm not getting any time these days

Copy link
Contributor Author

@aggarwalpulkit596 aggarwalpulkit596 May 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal i tried with calling doFinally in the data source class and it was working there,i might be right that it RxPagedList don't call doFinally as it subscribes again and again to fetch all the pages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was searching for some solution the only way i found is to send a mutableprogress object to data source and update that on doFinally

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed it but I don't think so it is the best possible method to implement it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, doFinally will never be called in case of Observable or Flowable because the stream is never completed

@@ -57,7 +59,7 @@ class EventsListAdapter(
* The function to call when the adapter has to be cleared of items
*/
fun clear() {
this.submitList(emptyList())
// this.submitList()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to pass empty paged list I couldn't get it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this emptyList() method returning earlier?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty list returns a list whereas the adapter required a pagedlist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking to use
this.currentList?.clear()
would that work @liveHarshit

app/build.gradle Outdated
@@ -36,11 +36,11 @@ android {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "DEFAULT_BASE_URL", '"https://api.eventyay.com/v1/"'
buildConfigField "String", "DEFAULT_BASE_URL", '"https://open-event-api-dev.herokuapp.com/v1/"'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be reverting this

@aggarwalpulkit596
Copy link
Contributor Author

@nikit19 any update on this

@aggarwalpulkit596
Copy link
Contributor Author

@iamareebjamal any update regarding this ?

@iamareebjamal
Copy link
Member

Take peer reviews

@aggarwalpulkit596
Copy link
Contributor Author

@nikit19 @liveHarshit please review

@@ -57,7 +59,7 @@ class EventsListAdapter(
* The function to call when the adapter has to be cleared of items
*/
fun clear() {
this.submitList(emptyList())
// this.submitList()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this emptyList() method returning earlier?


compositeDisposable += mutableEventsPaged
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot get it, why it is not working!

if (similarEventsListAdapter.currentList.size != similarEvents.size) similarEvents.shuffle()
similarEventsListAdapter.submitList(similarEvents)
// if (similarEventsListAdapter.currentList.size != similarEvents.size) similarEvents.shuffle()
// similarEventsListAdapter.submitList(similarEvents)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will implement pagination here as well it uses same adapters event view holder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal should i implement pagination here as well because this method won't no longer work as the adapter expects as pagedlist and we are passing a normal list here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And there would be a heavy network usage if I implement pagination here as well I suggest we should create a seperate adapter for this and use this as a normal list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal updated

eventService.getEventsByLocationPaged(query, requestedPage)
.withDefaultSchedulers()
.doFinally {
mutableProgress.value = false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this approach be okay? i couldn't find any other method to get this working @iamareebjamal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is getEventsByLocationPaged returning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is returning a Observable Paged List

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot use doFinally here, move this call inside subscribe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay but inside the individual call of page finally is working

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should i add a check using using pageNo if equal pageNo == 1 then update the value because we want to hide the shimmer only once

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's reasonable

@@ -60,6 +74,12 @@ class EventsViewModel(
} else {
mutableProgress.value = false
}

mutableProgress.observeForever {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal I can't observer in the ViewModel i guess. can i ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, use MediatorLiveData

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal updated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal should I implement pagination for search events as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build is failing. Yeah, implement that in other PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some unrelated changes will undo them and fix spotless. Rest all good?

@aggarwalpulkit596 aggarwalpulkit596 force-pushed the paging branch 5 times, most recently from d3d64b3 to 9c2fc88 Compare May 14, 2019 21:24
@iamareebjamal
Copy link
Member

@anhanh11001 @liveHarshit Please test

@liveHarshit
Copy link
Member

@iamareebjamal @aggarwalpulkit596 App is crashing while navigating to another fragment and press back button while loading -

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.eventyay.attendee, PID: 6821
    java.lang.IllegalArgumentException: This source was already added with the different observer
        at androidx.lifecycle.MediatorLiveData.addSource(MediatorLiveData.java:89)
        at org.fossasia.openevent.general.event.EventsViewModel.loadLocationEvents(EventsViewModel.kt:78)

@liveHarshit
Copy link
Member

Also during loading events-
image

@aggarwalpulkit596
Copy link
Contributor Author

@liveHarshit will check

@aggarwalpulkit596
Copy link
Contributor Author

aggarwalpulkit596 commented May 15, 2019

@iamareebjamal @aggarwalpulkit596 App is crashing while navigating to another fragment and press back button while loading -

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.eventyay.attendee, PID: 6821
    java.lang.IllegalArgumentException: This source was already added with the different observer
        at androidx.lifecycle.MediatorLiveData.addSource(MediatorLiveData.java:89)
        at org.fossasia.openevent.general.event.EventsViewModel.loadLocationEvents(EventsViewModel.kt:78)

not able to reproduce it @liveHarshit

@liveHarshit
Copy link
Member

not able to reproduce it @liveHarshit

While loading goes to notification fragment and press back button. It's crashing in my device. Let me check again.

@aggarwalpulkit596
Copy link
Contributor Author

not able to reproduce it @liveHarshit

While loading goes to notification fragment and press back button. It's crashing in my device. Let me check again.
Yup i got it

@aggarwalpulkit596
Copy link
Contributor Author

@liveHarshit @iamareebjamal please review there is only issue now

Also during loading events-
image

this always shows up because previously observer was only called upon a valid api request not with paged list it is called as soon api call is made so we need to check additional param whether showShimmer is false or not, just an observable on event list can't work

@liveHarshit
Copy link
Member

liveHarshit commented May 19, 2019

Please fix Travis also.

@aggarwalpulkit596
Copy link
Contributor Author

aggarwalpulkit596 commented May 19, 2019

Probably a spotless error will fix it but please first check for any crashes 😅

@liveHarshit
Copy link
Member

@aggarwalpulkit596 It is not showing upcoming events.

@liveHarshit
Copy link
Member

check how swipe refresh is working. It is showing no events instead of shimmer during refreshing.

also

@aggarwalpulkit596
Copy link
Contributor Author

@aggarwalpulkit596 It is not showing upcoming events.

Oh the logic must have been changed i forgot will change the end point

@aggarwalpulkit596
Copy link
Contributor Author

check how swipe refresh is working. It is showing no events instead of shimmer during refreshing.

also

Forgot that will fix it rest all good ?

@liveHarshit
Copy link
Member

I don't see Infinite Scrolling in my device.

@aggarwalpulkit596
Copy link
Contributor Author

Did you try with changing the base url ther aren't many events in the staging server try with prod server

@liveHarshit
Copy link
Member

Did you try with changing the base url ther aren't many events in the staging server try with prod server

Yes I have tried with Singapore and Delhi location with the release API. For what location you are testing?

@aggarwalpulkit596
Copy link
Contributor Author

Wait let me share a gif with you

@aggarwalpulkit596
Copy link
Contributor Author

videotogif_2019 05 19_19 35 24
@liveHarshit

@@ -65,28 +88,14 @@ class EventsViewModel(
fun isConnected(): Boolean = mutableConnectionLiveData.value ?: false

fun clearEvents() {
mutableEvents.value = null

// mutableEventsPaged
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal couldn't find anything to clear this out please help out here

@@ -99,6 +99,18 @@ class EventService(
}
}

fun getEventsByLocationPaged(locationName: String?, page: Int): Single<List<Event>> {
val query = "[{\"name\":\"location-name\",\"op\":\"ilike\",\"val\":\"%$locationName%\"}," +
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liveHarshit updated query for upcoming events

@aggarwalpulkit596
Copy link
Contributor Author

@liveHarshit rest all good ?

@liveHarshit
Copy link
Member

@liveHarshit rest all good ?

What is the minimum number of events required for infinite scrolling?

@liveHarshit
Copy link
Member

Because after filtering events, I can list max 5 number of events and infinite scrolling is not working.
Also showing no events card before loading events in rv.

@aggarwalpulkit596
Copy link
Contributor Author

@liveHarshit rest all good ?

What is the minimum number of events required for infinite scrolling?

It is 6 but can be changed in config object and it is showing because of

@liveHarshit @iamareebjamal please review there is only issue now

Also during loading events-
image

this always shows up because previously observer was only called upon a valid api request not with paged list it is called as soon api call is made so we need to check additional param whether showShimmer is false or not, just an observable on event list can't work

PagedList
.Config
.Builder()
.setPageSize(10)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liveHarshit it is 10

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Then there are three bugs to solve that I've already told you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already @iamareebjamal for a little bit of assistance as i am unable to find anything for @liveHarshit you can also suggest something if you find anything 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firstly you need to modify the logic for showing no events card and shimmer effect. Both are in conflicts right now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also how the swipe refresh is connected with both.

Copy link
Member

@liveHarshit liveHarshit May 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

triggered with a zero size list

Oh, got it. So here we cannot compare the size of the list, but

hat whether the intial request is completer or not

In that case, can we check if there are no events?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can only be checked after the first request is completed that is progress live data is set to false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then show shimmer until the request will complete.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for swipe to refresh we need to clear the mutableEventsPaged but that is observable before it was a live data so its value can be set to null and I can't find anything to set it source factory to null or zero-sized list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then show shimmer until the request will complete.

but that's the point I need to check 2 separate live data values and then work accordingly will find some workaround for that definitely but couldn't find anything for observable disposable.clear() would work I guess then?

@aggarwalpulkit596
Copy link
Contributor Author

@liveHarshit updated,everything is working fine now
Couldn't check though because test events have been deleted i guess

@liveHarshit
Copy link
Member

@liveHarshit updated,everything is working fine now
Couldn't check though because test events have been deleted i guess

Please test it by removing the filter and change the debug API to release.

@aggarwalpulkit596
Copy link
Contributor Author

upcoming event filter? Cool

@anhanh11001
Copy link
Contributor

Any updates on this? If not then I'm taking this up as it is an issue listed in GSoC Milestones. @aggarwalpulkit596

@aggarwalpulkit596
Copy link
Contributor Author

Would wind up by end of the week

@anhanh11001
Copy link
Contributor

@aggarwalpulkit596 Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement pagination in the app
4 participants