Added Downloads Activity
This commit is contained in:
parent
7944ea0ba4
commit
278fbc224c
|
@ -2,33 +2,35 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="de.podfetcher"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
android:versionName="1.0" >
|
||||
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_ALL_DOWNLOADS" /> -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_ALL_DOWNLOADS" /> -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-sdk android:minSdkVersion="10" />
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.Sherlock.Light"
|
||||
android:name=".PodcastApp">
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.Sherlock.Light"
|
||||
android:name=".PodcastApp">
|
||||
<activity
|
||||
android:label="@string/app_name"
|
||||
android:name="de.podfetcher.activity.PodfetcherActivity" >
|
||||
android:name="de.podfetcher.activity.PodfetcherActivity" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="de.podfetcher.activity.AddFeedActivity"
|
||||
android:label="@string/add_new_feed_label"/>
|
||||
<activity android:name="de.podfetcher.activity.FeedItemlistActivity"/>
|
||||
<activity android:name="de.podfetcher.activity.ItemviewActivity"/>
|
||||
<activity android:name="de.podfetcher.activity.AddFeedActivity"
|
||||
android:label="@string/add_new_feed_label"/>
|
||||
<activity android:name="de.podfetcher.activity.FeedItemlistActivity"/>
|
||||
<activity android:name="de.podfetcher.activity.ItemviewActivity"/>
|
||||
<activity android:name="de.podfetcher.activity.DownloadActivity"
|
||||
android:label="@string/downloads_label"/>
|
||||
|
||||
<service android:enabled="true" android:name="de.podfetcher.service.DownloadService" />
|
||||
<service android:enabled="true" android:name="de.podfetcher.service.PlaybackService" />
|
||||
<service android:enabled="true" android:name="de.podfetcher.service.DownloadService" />
|
||||
<service android:enabled="true" android:name="de.podfetcher.service.PlaybackService" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/txtvTitle"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:textStyle="bold"/>
|
||||
<RelativeLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent">
|
||||
<TextView
|
||||
android:id="@+id/txtvDownloaded"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_alignParentLeft="true"/>
|
||||
<TextView
|
||||
android:id="@+id/txtvPercent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_alignParentRight="true"/>
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
|
@ -5,11 +5,17 @@
|
|||
android:title="Add Feed"
|
||||
android:icon="@drawable/content_new"
|
||||
android:showAsAction="ifRoom">
|
||||
</item>
|
||||
<item
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/all_feed_refresh"
|
||||
android:title="Refresh"
|
||||
android:icon="@drawable/navigation_refresh"
|
||||
android:showAsAction="ifRoom">
|
||||
</item>
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/show_downloads"
|
||||
android:title="Downloads"
|
||||
android:icon="@drawable/av_download"
|
||||
android:showAsAction="ifRoom">
|
||||
</item>
|
||||
</menu>
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<string name="feeds_label">Feeds</string>
|
||||
<string name="settings_label">Settings</string>
|
||||
<string name="add_new_feed_label">Add a new Feed</string>
|
||||
<string name="downloads_label">Downloads</string>
|
||||
|
||||
<!-- -->
|
||||
<string name="confirm_label">Confirm</string>
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package de.podfetcher.activity;
|
||||
|
||||
|
||||
import de.podfetcher.storage.DownloadRequester;
|
||||
import de.podfetcher.adapter.DownloadlistAdapter;
|
||||
import de.podfetcher.service.DownloadObserver;
|
||||
import de.podfetcher.feed.FeedMedia;
|
||||
import de.podfetcher.feed.FeedFile;
|
||||
import com.actionbarsherlock.app.SherlockListActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
public class DownloadActivity extends SherlockListActivity {
|
||||
private static final String TAG = "DownloadActivity";
|
||||
|
||||
private DownloadlistAdapter dla;
|
||||
private DownloadRequester requester;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
requester = DownloadRequester.getInstance();
|
||||
observer.execute(requester.getMediaDownloads().toArray(
|
||||
new FeedFile[requester.getMediaDownloads().size()]));
|
||||
|
||||
}
|
||||
|
||||
private final DownloadObserver observer = new DownloadObserver(this) {
|
||||
@Override
|
||||
protected void onProgressUpdate(DownloadObserver.DownloadStatus... values) {
|
||||
if (dla != null) {
|
||||
dla.notifyDataSetChanged();
|
||||
} else {
|
||||
dla = new DownloadlistAdapter(getContext(), 0, getStatusList());
|
||||
setListAdapter(dla);
|
||||
dla.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package de.podfetcher.adapter;
|
||||
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.LayoutInflater;
|
||||
import android.content.Context;
|
||||
|
||||
import de.podfetcher.R;
|
||||
import de.podfetcher.util.Converter;
|
||||
import de.podfetcher.feed.FeedMedia;
|
||||
import de.podfetcher.service.DownloadObserver;
|
||||
|
||||
public class DownloadlistAdapter extends ArrayAdapter<DownloadObserver.DownloadStatus> {
|
||||
public DownloadlistAdapter(Context context,
|
||||
int textViewResourceId, DownloadObserver.DownloadStatus[] objects) {
|
||||
super(context, textViewResourceId, objects);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Holder holder;
|
||||
DownloadObserver.DownloadStatus status = getItem(position);
|
||||
|
||||
// Inflate layout
|
||||
if (convertView == null) {
|
||||
holder = new Holder();
|
||||
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
|
||||
Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.downloadlist_item, null);
|
||||
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
|
||||
holder.downloaded = (TextView) convertView.findViewById(R.id.txtvDownloaded);
|
||||
holder.percent = (TextView) convertView.findViewById(R.id.txtvPercent);
|
||||
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (Holder) convertView.getTag();
|
||||
}
|
||||
|
||||
holder.title.setText( ((FeedMedia) status.getFeedFile()).getItem().getTitle());
|
||||
holder.downloaded.setText(Converter.byteToString(status.getSoFar()) + " / "
|
||||
+ Converter.byteToString(status.getSize()));
|
||||
holder.percent.setText(status.getProgressPercent() + "%");
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
static class Holder {
|
||||
TextView title;
|
||||
TextView downloaded;
|
||||
TextView percent;
|
||||
}
|
||||
}
|
|
@ -76,6 +76,9 @@ public class FeedlistFragment extends SherlockListFragment {
|
|||
case R.id.all_feed_refresh:
|
||||
manager.refreshAllFeeds(pActivity);
|
||||
return true;
|
||||
case R.id.show_downloads:
|
||||
startActivity(new Intent(pActivity, DownloadActivity.class));
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ public class DownloadObserver extends AsyncTask<FeedFile, DownloadObserver.Downl
|
|||
if (status.done == false) {
|
||||
Cursor cursor = getDownloadCursor(status.feedfile);
|
||||
int statusId = getDownloadStatus(cursor, DownloadManager.COLUMN_STATUS);
|
||||
status.progressPercent = getDownloadProgress(cursor);
|
||||
getDownloadProgress(cursor, status);
|
||||
switch(statusId) {
|
||||
case DownloadManager.STATUS_SUCCESSFUL:
|
||||
status.statusMsg = R.string.download_successful;
|
||||
|
@ -91,6 +91,7 @@ public class DownloadObserver extends AsyncTask<FeedFile, DownloadObserver.Downl
|
|||
Log.w(TAG, "Thread was interrupted while waiting.");
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "Background Task finished.");
|
||||
return Boolean.valueOf(true);
|
||||
}
|
||||
|
||||
|
@ -110,17 +111,16 @@ public class DownloadObserver extends AsyncTask<FeedFile, DownloadObserver.Downl
|
|||
}
|
||||
}
|
||||
|
||||
private int getDownloadProgress(Cursor c) {
|
||||
if (c.moveToFirst()) {
|
||||
long size = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
|
||||
long soFar = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
|
||||
int progress = (int) (((double) soFar / (double) size) * 100);
|
||||
Log.d(TAG, "Setting progress to " + progress);
|
||||
return progress;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
private void getDownloadProgress(Cursor c, DownloadStatus status) {
|
||||
if (c.moveToFirst()) {
|
||||
status.size = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
|
||||
status.soFar = c.getLong(c.getColumnIndex(
|
||||
DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
|
||||
status.progressPercent = (int) ((
|
||||
(double) status.soFar / (double) status.size) * 100);
|
||||
Log.d(TAG, "Setting progress to " + status.progressPercent);
|
||||
}
|
||||
}
|
||||
|
||||
private DownloadManager.Query buildQuery(long id) {
|
||||
DownloadManager.Query query = new DownloadManager.Query();
|
||||
|
|
|
@ -158,6 +158,9 @@ public class DownloadRequester {
|
|||
images.remove(fi);
|
||||
}
|
||||
|
||||
public ArrayList<FeedFile> getMediaDownloads() {
|
||||
return media;
|
||||
}
|
||||
|
||||
/** Get the number of uncompleted Downloads */
|
||||
public int getNumberOfDownloads() {
|
||||
|
|
Loading…
Reference in New Issue