How to implement infinite scroll with multiple filter on data that get from Firebase in Swift? - ios

I'm using Firebase for my iOS application and I'm having trouble implement infinite scroll and filtering data together.
What I need to do is:
Display items with order/filter on multiple property (location, category, status . . .)
Implement infinite scroll when the user scrolled to bottom of the screen.
I tried to think about some solutions:
The first, I think that I'll query the data with the necessary conditions then limit the number of records by use queryLimitedToFirst(N), and increase N when need to load the next items. But because Firebase can only filter on one property at a time and it's also a waste to reload data. So, I was thinking about the second solution.
As approaches are suggested from Frank van Puffelen (Query based on multiple where clauses in firebase):
filter most on the server, do the rest on the client
Yes, exactly like that. I'll execute queryOrderedByKey, queryStartingAtValue, queryEndingAtValue to implement infinite scroll, pull down the remaining data and filter that on client. But there is one problem that is I would not have enough items to display for the user if execute filter on the client.
For example: each time run the query, I receive 10 items. After data filtering process on the client, I just left 5 (can be 0) items meet the conditions to display to the user.
I don't want this because user may think there is a problem
Can I please get some pointers on this? If I didn't structured the data properly, can I also get some tips there?

Related

Optimize array data size while pagination

I know how to implement pagination with UITableview but my question is we always append data of next page with existing complete data array so every next page array is increasing array size.
For example - We get 50 records in first page and we request for next page and we again get 50 records and then we will append that records in existing complete array so complete array is now having 100 records. I am requesting data with around 100 pages so my array will have 5000 records as we know holding some starting page array data is not good idea as we hardly come back for starting page after visited 100 pages .
Is there any way to optimize array size? please help me on this as i searched a lot but didn't find good answer for this.
I would be very grateful for help and sorry for my bad english.
I think you can achieve that by writing the "old" data to a local storage, and retrieve and insert back into your array.
So, imagine that you've already fetched, lets say 200 items. So when the user scrolls down, and you fetched the next page (the next 20 items), you "cut" from your array the items from 0 to 99 and write to a file. Now your array has 120 items. Then, when the user continues scrolling and again reached 220 (array.count >= 220), repeat the same logic, and so on.
Now the most interesting part. If the user scrolls back and the index of the top visible cell is <100, you read the previously written data from the file (and remove from the file) and insert into your array at 0 position.
And of course it'd be better to clear all that kind of files on the app launch.
Of course the numbers I wrote below are magic numbers and you should play with them to find the right ones that best fit your needs.

Siri Shortcuts how do I sequence the results from JSON in a Siri Shortcut?

I'm using the ptv api call for departures and can successfully return back three results. I'm trying to get Siri to dictate these to me in order but am not having much luck.
When the api is called it returns a bunch of information in an array for however many services you specify (three in my case), but I only want one of the lines to be dictated (scheduled_departure_utc), not the full array.
And I want to pull just this one line out of each of the three blobs of data that are returned so that Siri says...
the next trains to the city are (scheduled_departure_utc),(scheduled_departure_utc),(scheduled_departure_utc). Where (scheduled_departure_utc) is a short form of time (8:28am, 8:38am, 8:58am) as an example.
Any ideas?

How to get the all the recyclerView Items into ArrayList using appium

I have a scenario to verify the Sort&Filter functionality for Mobile App in Android.
Scenario:
Search for Item
Search Result Apper
Sort&Filter with some criteria
Have to Verify that Sort&Filter is applied correctly
Here results are added to RecyclerView.
As per RecyclerView/appium functionality, all the items are not loaded into view. Only visible Items are loaded into the view Hierarchy.
When I scroll Up the Linear Layout Indexes are re-arranged. I could not able to get all the Items.
Could you kindly provide me any sample scenario of this kind?
Or How can we achieve this kind of scenarios in Real Automation while working on the project?
Regards,
Shiva Oleti
Issue with Android as You stated is that it "sees" only what is visible on screen. I have similar issue, so I had to go deeper into element and fetch text. In your case I would do following:
1. Search Result Appear:
- fetch all visible elements, input search, fetch again -n results containing search result. Eg. if input 'beer' there should be eg. 4 elements with text containing "beer". Put elements in list and iterate:
List <MobileElement> listElements = driver.findElements(By.id("someId"));
for(MobileElement el : listElements){
if(el.getText().equalsIgnoreCase(expected)){
// do some validation //
}
}
Search Result Appear:
input exact value that will return unique, one result so You can easily count.
Sort&Filter with some criteria
remember initial values in items (text like 'Budweiser beer'), do some filtering / sorting, and check text in first element if is changed and if correct logic is applied (eg. sort desc.)
Have to Verify that Sort&Filter is applied correctly
think I answered in 3.
Basically:
'pick' text from items store them,
do some action (search, sort, filter),
'pick' newly changed items caused by 2. step, store them,
compare (depending on what You need...),
To get all items you have to swipe and store them in list.

How to display bunch of data in tableview

In my app I have 800 000 data in server which I have to display to user. User can also search from those data. I really got confused what to do here now. How to achieve this functionality.? I am trying to load first 50 data to table and then at top part there is search bar from that user can search data but user can search by writing approximate word also (i.e if user wrote "bcd" then it will return all data having "bcd" combination). Can anyone suggest me something that will help me to get out of this situation.
You have to do pagination here without it you can't get that much data if you do that then your application will be crash. Fetch some data from the server like 30 or 40 and when you reach at 30 request for next 30 data. Then you can meet the application need.
You need to use pagination in your application .without pagination if you got 8 lakhs data in one shot then your application might be crash.
every time send request to server like"abc"
server get first 10 data from result and return those data.
now for second request server will return 11 to 20 records from resultant data
I am developer with SIMpalm. i would like to suggest you below answer.
why can't you take two array on for displaying in table view other contain all results ,when you search then search result in the Array which contains all results.and add them to the array which shown in the table.
You will have to use pagination, I don't see any other way you can do this without eating up lot of memory or the elegant way and worst case sporadic crash.
You can do the pagination in the browse and the search both. To avoid delay's for user you can preload data. e.g. for pages of 200 records, when user reaches to 150 you start fetching data for next page.
Also if your local/web server is taking more than min to load. you have serious problem on the server, That needs to be fixed. No user will wait for min to reload or get the new data.
I am not expert on the servers/networking but it should not take more than 10-15 secs.
Think about search logic as very similar to the browsing all data.
Search/Browse both needs paging
Browse returns all the data in pages
Search returns specific data in pages
Search/Browse proloads data after user reaches certain point

Data sorting and update of UIcollectionViewCells. Is this a lost cause?

I have core data entries displayed in a collectionView, sorted from 1 2 3 ... n. New batches of entries are added as the user flips through the first n. Data is built from a JSON response obtained from a web server.
Because the first entry of the fetch request is associated to cell 0 - via the datasource delegate -, it's not possible to add a new batch at the bottom of the collection view. If it's added from cell 0, old cell contents are replaced by new ones, or in short the whole page seems to be replaced by new stuff, and the data the user was looking at is offset by the number of new entry. If the batch is large, it's simply buried. Furthermore, if the update is done from cell 0, all entries are made visible, which takes time and memory.
There are several options that I considered:
1) data-redorder, meaning instead of getting the fetch result as 1 2 3 4 ... n, I need the opposite, n ... 3 2 1 (nothing to do with a fetch using reverse order sorting) straight from the fetch request. I'm not sure it's possible? is there a CD gotcha allowing to re-order the fetch result before it is presented to the UICollectionViewDataSource delegate ?
2)Change the Index path/viewCell association in "collectionView cellForItemAtIndexPath:", Use (numberOfItemsInSection - IndexPath.Item). It creates several edges cases, as entries can be removed/updated in the view (hence numberOfItemsInSection changes). So I'd rather avoid it if I can...
3) adding new data from cell 0, ruled out for the reason I explained. There may be a solution: has anyone achieved a satisfactory result by setting a view offset? For example, if 20 new entries are added, then the content of cell 0 is moved to cell 20. So, we just need to tell the view controller to display from cell 20 onwards. Any image flipping or side effects I might expect?
4) download a big chunk of the data, and simply using the built-in core data faulting mechanism. But that's below optimal, because I'm not sure exactly how much I should download - user dependent - and the initial request (JSON+Core Data) might take too long. That's why lazy fetching is here for anyway.
Any advice someone facing the same problem could share ?
Thanks !

Resources