Progress bar in listview with sql loader Android - android

I use a loader for sqlite, handler thread (looper with queue) and a listview,
I need to show the user a progress bar while downloading the file inside the listview.
I'm thinking of the below but it doesn't look right as I'll be changing the data source a lot,
1 - User clicks "Download file icon"
2 - Video starts downloading
3 - Update the sql table with the progress
4 - Notify the loader to reload the data
5 - I have the code that keeps the list view at its current position after changing the data source
I can't think of another solution, is there any alternatives?

Related

FMX ListView with LiveBindings

I am developing an FMX (Android) app using a ListView in Delphi 10.2.3. I have the Listview live(bound) to a ClientDataSet with (Synch->*). This works very well, and any changes in Listview are propagated to the ClientDataSet, including the ClientDataSet's event handlers, such as BeforeUpdate, Post and AfterScroll.
Now when I move the record pointer in the ClientDataSet programmatically, the Listview does not synch with the change. It seems the Livebinding only works "one way" (from the UI to the Dataset).
How can I make the Listview follow the ClientDataSet, the way it does in the VCL when using a DataSource?
// here I expect the see the selected item start at the first item
// in the UI in index order and move quickly down through the
// list until it stops at the last one. This doesn't happen. The UI remains
// unaffected.
ClientModule.CDSData.First;
while not ClientModule.CDSData.Eof do
begin
ClientModule.CDSData.Next;
Sleep(100);
end;
The easy answer to this question is to perform a
if ClientModule.CDSData.Locate('PKID', VarArrayOf([PKIDValue]), []) then
It seems that while moving the record pointer using CDSData.Next doesn't sync back to the Live(Bound) Listview, using a locate does.

SQLite and UI update order on android?

Hello this is a simple design question for better practices:
Example and Context:
I'm creating an app that shows a list of items in a players stash. For this i need following requests:
Ask for all items IDS, one request.
Look for each ID and inside each response i'll get the ICON link. As many requests as ITEMS here
Request each ICON. As many request at items here.
All this will be presented on a Recyclerview list with cardviews and saved locally to the device database.
The question is: In which order should i do this???
Option A: get items IDs > Save to DB > Read DB > get ITEM OBJECTS > Save to DB > Read Database > GET ICON IMAGES > FILL UI LIST
Option B: get ONE item ID > get ONE item Object > get ONE item icon > present to UI > save Item Object to Database
ON both cases i will have timeout or try cach for items that fail to get.
ON both cases in the future I will only request ICONs for existant items or full requests for new items in stash.
If you have another suggestion or approach feel free to add it.
If i was you, I would create the loading so that the user sees items without the user having to wait too long.
I would (asynchronously) do the following:
Get Item IDs
Request all items. When a request completes, add a item with a placeholder ICON to the UI
For each requested item, request the ICON. When a ICON request completes, update the UI and save it to database
While the objects are loading, you can show a spinning progress bar on top of the RecyclerView, so the user sees the progess bar spinning, and the items being added one by one in the background. You can even add an animation very easily to the RecyclerView, so your app looks even cooler while loading.

Google Maps Version 2 - Updating information windows

As we know in google maps android version 2, a custom information windows, is a view that converts to an image. Actually google aftre you return you view converts the view to a image an then show it to the info windows.
But I want to show images downloading from internet to my infowindow. Actually, I want that before that download complete show an progress bar to my infowindows and after it compeleted update info windows, by this mechanism how I can do this?
Have a model object that contains int for progress and Bitmap for actual image.
Start some kind of background operation started (e.g. AsyncTask) to download image.
Update model's progress from AsyncTask.onProgressUpdate.
Update model's image from AsyncTask.onPostExecute.
Have an observer for model (see Observer partern).
If you keep AsyncTask (or any other kind of Thread in Activity context, don't forget to cancel it and you may also skip observer pattern.
Save reference to marker showing info window inside InfoWindowAdapter.getInfoWindow. Call it markerShowingInfoWindow.
When you are notified of progress update,
call:
if (markerShowingInfoWindow != null && markerShowingInfoWindow.isShowingInfoWindow()) {
markerShowingInfoWindow.showInfoWindow();
}
To force InfoWindowAdapter.getInfoWindow call and create ViewGroup containing ProgressBar and ImageView from progress and image values inside model.
As always, translate this into C# world.

how to fetch 20 objects at a time from 1000 objects and show in listview

In my application I am fetching the data from a web service in XML format, and parsing it and showing the data in listview. The problem is that if the web service contains 5000 objects then it takes a lot of time to display the data.
Can it be possible to show some data in listview and fetch the data at the same time at the end of the list.
Please provide me some sample code.
If you use convertView in your ListAdapter´s getView method it should not matter how many items you have in the list since the Views are beeing reused.
If your Listadapter takes an array of som sort you could add items to the array continuosly and call
mListAdapter.notifyDataSetChanged();
every time new data is added to the list.
By Using AsyncTask you can do this easily as each object is being fetched can be shown in listview using publishProgress() method while also updating user about what percentage of data hasbeen loaded.
Update:
By the way according to your situation the tool below which is developed by commonsware https://stackoverflow.com/users/115145/commonsware will suits you best...
https://github.com/commonsguy/cwac-endless
cwac-endless: Provides the EndlessAdapter, a wrapper for an existing ListAdapter that adds "endless list" capability. When the user scrolls to the bottom of the list, if there is more data for this list to be retrieved, your code gets invoked in a background thread to fetch the new rows, which then get seamlessly attached to the bottom of the list.

How to update ListView on scrolling while retrieving data from server in Android?

Currently, I'm using AsyncTask to handle Http connection and retrieve data as JSON format.
Loading all data is trivial but it consumes too much time, so I decided to switch to load 10 items at a time using LIMIT OFFSET (mysql).
Next I set up the event onScroll for my list view to create a new AsyncTask each time user scroll. However, from what I read, AsyncTask is stored in a thread pool which is limited 5 threads at a time, so I'm not sure this is a right approach. I'm newbie to client/server app, so could I anyone give me an advice on this issue? Any related article, documentation would be greatly appreciated.
Here are few useful links for it,
Android: Implementing progressbar and "loading..." for Endless List like Android Market
Endless Listview with current Async Task
Android Endless List
http://www.androidguys.com/2009/10/21/tutorial-autogrowing-listview/
http://mylifewithandroid.blogspot.com/2010/03/progressively-loading-listviews.html
In simple steps,
As user scrolls – detect the end of the list 1)Display a progress
notification 2)Ask for update 3)Receive update (asynchronously) and
extend list
A typical approach would be e.g. to load 25 initially and then have a footer in the list that displays e.g. the current count and the total count and upon pressing loads another 25 and so on. That would be a paged sort of loading.
When you do that you have to keep the current position and notify the adapter that the list has changed.
If you are using a ListView, I believe I can safely assume that you must be using some sort of ListAdapter. Instead of starting a new AsyncTask in the onScroll event, you should maintain just one single AsyncTask to retrieve data from the server, add that data to the ListAdapter dataset and then call notifyDatasetChanged on the ListAdapter.
The ListAdapter and ListView will take care of the rest.

Categories

Resources