How to sync large data - android

Hi to all Android heroes out there, I have been facing this interesting problem which I am trying to explain here
I have a simple requirement of showing a large amount of data in recycler view in a grid view which I am achieving using the Paging library provided by Android Jetpack.
I am using Single Source Of Truth pattern in which data fetched from the server is stored in Room DB first and then the database is observed for any changes.
The data I am fetching is sorted. It starts with A then B and so on as I scroll down
Now the requirement is there is a scroller besides the recycler view which contains all the alphabet listed down in vertical fashion giving the user the functionality
to jump to any alphabet directly instead of scrolling down to reach it.
The total rows of data starting from A to Z are around 100,000.
Now suppose the user is scrolling in normal fashion and is on the data starting with A letter, suddenly he taps on P alphabet from the scroller then the app
should show the data starting with P and then it should resume it's the behavior of scrolling i.e if user scrolls up then he should see data starting from O and
if he scrolls down then he should start seeing data with Q and so on.
The next requirement is since I am using local DB via Room then I should update data only when it gets updated saving the hits to the server.
What should be the ideal way to sync data with server considering the fact that minimum hits go to the server and we do not have old data in local DB
How can I achieve above-mentioned functionalities in an optimized way

Related

LIKE autocompletion too stressful on the database?

I'm writing an android application that has a search feature that needs to autocomplete from a list of stores. This list will only have up to a few thousand stores in it.
My current methodology is to send a LIKE query to the database every few hundred ms after the user has stopped typing and to populate the autocomplete list with these results.
Would using this method be stressful to the database?
It has been suggested to me that this wouldn't work because making continuous calls would be poor for users with a slow connection and that I should load all the stores into memory and filter from there.
At my work I ran into a similar problem a few months back. The contents of a text box filled by the user were supposed to filter their available options to choose from in a list of strings. The list needed to be updated every time the user typed a key so database calls to fetch records that matched their text were being made several times a second.
This ended up being wayy to slow to update as someone was typing, and this was only with several thousand records and with a server that was being accessed on site.
If you want to update as quickly as someone can type, making that many database calls simply won't do. Users will get pretty antsy having to let their phone buffer to type in some text.
In Short: Make one databse call and load it up onto the phone, and run your filter algorithm from there.
Regularly syncing the list of stores from your back end to the user's device and implementing autocomplete locally is the best way to go.
The JobScheduler API provides a flexible way to set constraints on your background syncing processes.

Update List from server when scroll like google mail app

I build an android app in which i have a large customer list.It receive data from server in JSON from and I show this JSON in Custom List view. But it take lot of time when Internet show cause of large list of customer.
I want to use Auto Update List when i scroll list it receive next JSON list from server and show it in list view like android mail app.
i am totally new in this so i want help in section from beginning.
You will need to implement pagination on server side. In your original request the server will send you a list of customers (say 20), and total no. of pages (considering each page has 20 customers) or total no. of customers. Based on this data, you can request for the next list of customers once your scroll hits the end, send another request with the page_no or whatever logic you implement to request the next list. Add the next list of customers into your adapter's data.
You can find many code snippets on how to figure out if your scroll has reached the end of list. Here is a guide on how to implement EndLess scroll in your listview.

Caching Data for iOS/Android mobile Apps to work with Pagination

Give the following scenario. I have a mobile App on iOS/Android which is connected to a server backend via REST. Within the app you can display news items. These items can be created, edited and deleted of you are the creator of the item. On one page in the app there is a news feed where you can see an overview of news items created by other app users. The iOS/Android app stores the data of these news items in a local sqlite database. When the user scrolls down the list of items further items should be loaded if there are any.
The task I want to solve is how the items will be cached in the SQLite database to work with pagination. The cache must be updated sometimes when items are deleted or reordered on the server. This must be taken into account when working with pagination.
Here is the algorithm I've used so far:
if the feed page opens check if there are any items to display in the
sqlite database
if true retrieve p items with offset offset=0 from the database and contact the server to check if the first p items should be updated or deleted
if items should be updated or deleted perform these operations on the items in display
else contact the server for p items with offset offset=0 and display them
if the user scrolls down start 1. again with offset = offset + p
How does caching data for mobile apps work with pagination?
The question is how long you want to store data. You can store every data you get in part:
"else contact the server for p items with offset offset=0 and display them"
And set some time stamp to data. When time stamp expires you delete data ( in background ). In this way you save a lot of requests and also you don't waste with memory.
Hope this helps you with your problem.

Android ListView Sourced from REST JSON response

I can't seem to find exactly what I'm looking for after a few day's worth of hunting, so if anyone has seen exactly what I'm trying to do elsewhere, I'd love a link or two.
Anyway, I'm trying to build an app to connect into an ERP system that returns user access information in JSON format via REST request using an e-mail address and password. Most users of the system only have a singular access role, so no big deal for them, but others have multiple roles. The trouble I'm having is taking these multiple access roles and adding them into a ListView where they can select the role with which they wish to use to gain access.
Trouble is, I need a display that uses two lines per selection (to properly display all user-pertinent data) and some way to record the user selection. The data useful in the background for the selection would not be displayed, as it would not mean anything to the user. I've been able to take the JSON response and map it to a custom class I designed for it without any problems (not actually all that useful, mostly only helps for discerning the results count prior to displaying multiple results to the ListView). But I can't figure out how to properly build the ListView layout and map the data to the layout. I'm having trouble understanding how to build the view and insert data into new list items.
The best I figure, if I can get the results to display in a ListView and then record the selection in the shared preferences, I'll be golden.
If the listview items being populated from some JSONArray then you could use listview.setOnItemClickListener to get the position of the selected item and match it from the array.Your question seems a little vague. Can you post some code of what you've tried so that it becomes a little clearer?

Using Android content provider with GridView to browse large number of images

I need to implement an Android application which allows users to browse a large number of images (10000) stored on a server.
I can use REST style HTTP calls to get the information about images e.g. GET http://uri...?itemsstart=n&itemscount=m which returns me the names and locations of images.
I have a content provider with a cursor adapter which I can use to get this information. I’d like to hook this up to a GridView to allow for scrolling of images.
There are several examples here and elsewhere on the web about using similar scenario for a small fixed number of images : you just use setAdapter on the GridView or ListView and it will do its magic when user initiates a database query via menu etc.
In my case, user should be able to scroll through images continuously while the app is loading them in “chunks” in the background.
My question is how and when to initiate a new query to get a new “chunk” of images in such a way that my CursorAdapter/GridView combination will be updated for continuous scrolling?
I would appreciate some advice about this scenario.

Categories

Resources