The functionality of my app can be modeled after something like wanelo.
The user will enter a search term for what they want to buy in one Activity. They will get presented with a list of items that match that search term. So, the ListView will contain Items. An Item has many attributes, the main ones being:
id– corresponds to theItem‘s id in a databasedate_modified– timestamp to know whether theItemwas updatedremote_directory– a URL to the base directory of theItem‘s assets like icon and other images. The URL is formatted like this:http://my.domain.com/items/a1bc234d/wherea1bc234dis randomly generated, seeded bydate_modified.remote_dir_name– a substring ofremote_directory. From the example above, this value would bea1bc234d.
From the list of search results, the user can mark an item to be viewed later. This will trigger a couple of things:
- First, I want to ad the
Itemto a differentListViewthat represents theItems the user has “downloaded”. - Then, I want to actually download of all of the
Item‘s data: description, all assets inremote_directory. These things get stored my app’s internal storage in foldersremote_dir_name:/data/data/my.app.package.name/files/a1bc234d/.
These “downloaded” items are meant to be viewable in offline mode.
This “downloaded” ListView corresponds to a different Activity and will have list items that show a progress bar of the download status for an Item. Also, this ListView should be editable: use should be able to delete and re-order the Items in the list.
Finally, the “downloaded” ListView needs to be persistent. It should preserve order. The ListView of search results need not persist.
I’m having a lot of trouble figuring out how to store the list of Items getting downloaded. The “download” ListView needs to know when to update a list item’s progress bar if it’s getting downloaded. I think it’s a little overkill to store the Items in a database because I’ll be constantly updating a row’s column until the download finishes. How should I pass this download status information between these two ListViews?
I am not entirely sure I am grasping the whole picture here, but it seems to me that you need two ArrayList fields.
then what you need to do is create your own custom ListAdapter for the DownloadListView and create your own custom download_item.xml that you will inflate inside of the ListAdapter. In your case it sounds like this download_item.xml will consist of a textview, and a progressbar, and will need the containing (or top layer) layout set to wrap content.
Now in the on click listener for the SearchListView set it so that it will call a function that will take the item that was tapped and add it to the downloadedItems ArrayList and start the download, as well as refresh the listadapter dataset so it knows to update the items in the list.
The download should be in a AsyncTask, and you will want to use the
@Override publishProgress()portion of this, so that you can update the status of the download bar.forgive me for any mis sights or mistakes, I just woke up.