0

Let's jump directly to the topic! Here's the thing: I've got an android app using mvp pattern. There's an activity containing two fragments which are tabs and both of them are lists. Both fragments share the same Database Interactor and a ViewHolder. Both lists display the same content with the only difference that first one contains all items and the second is filtered. Filtering is done in Database Interactor so fragments presenter query Database Interactor for filtered or not filtered list of items.

In the Activity, on ActionBar there's a menu that I want to use for sorting both lists. Acitivity does nothing, it is just a container for fragments and action bar.

I'm really confused. How can i tell both fragments to sort their items? And how should it look like? I guess that putting all the code in fragments' presenters is not a good idea.

Another thing is that lists contains objects with multiple attribute, like: MyObject(Date, Distance, Name) and depending on choosen option i want to sort by Date OR Distance OR ... etc.

Thanks in advance!

v1t0
  • 23
  • 7
  • some code of how you pull the data would be useful – pantos27 May 31 '17 at 19:06
  • it's the simplest possible code for pulling data from FireBase. I assume that you are asking about it because you would like to suggest sorting data while acquiring it from database but i don't think it would be very elegant solution. Otherwise, enlighten me, what your idea is so I could post right ammount of code. – v1t0 May 31 '17 at 19:26
  • There are ways of sorting when creating the query to firebase. Depends on how you implemented your adapter, if you choose to sort it after you fetch it, it could be messed up if you activity needs to be recreated. – pantos27 May 31 '17 at 20:21
  • So, for sorting by multiple parameters I used this: [link](https://stackoverflow.com/questions/1421322/how-do-i-sort-a-list-by-different-parameters-at-different-timed) And to tell both fragments to sort their items I called supportFragmentManager to call fragments' methods. – v1t0 Jun 04 '17 at 09:30
  • You can sort the data when you make the DB reference in your adapter. See this page https://firebase.google.com/docs/database/android/lists-of-data – pantos27 Jun 04 '17 at 10:06
  • Problem with this solution is the fact that some of the sorting optins are based on values calculated after getting data from FB, like for example distance between coordinates stored in DB and current user location. In this case, base solution is the one that I posted in my previous comment. – v1t0 Jun 04 '17 at 13:58

0 Answers0