├── jars
├── commons-io-1.4.jar
├── guice-2.0-no_aop.jar
├── roboguice-1.1.1.jar
├── MyID3_for_Android.jar
├── jackson-core-asl-1.4.3.jar
└── jackson-mapper-asl-1.4.3.jar
├── res
├── drawable-hdpi
│ ├── cd.png
│ └── icon.png
├── drawable-ldpi
│ ├── cd.png
│ └── icon.png
├── drawable-mdpi
│ ├── cd.png
│ └── icon.png
├── menu
│ ├── podcastmanager.xml
│ └── menu.xml
├── values
│ └── strings.xml
└── layout
│ ├── podcast_list_item.xml
│ ├── archiveview.xml
│ ├── select_device.xml
│ ├── main.xml
│ ├── download_progress.xml
│ ├── subscribe.xml
│ ├── downloadview.xml
│ ├── accountsettings.xml
│ ├── podcast_manager.xml
│ └── playerview.xml
├── .gitignore
├── src
└── com
│ └── unitedcoders
│ ├── android
│ └── gpodroid
│ │ ├── services
│ │ ├── IPlaybackControl.java
│ │ ├── PlayerService.java
│ │ ├── UpdateService.java
│ │ ├── RSSService.java
│ │ └── DownloadService.java
│ │ ├── PlayPodcastReceiver.java
│ │ ├── PlaybackState.java
│ │ ├── activity
│ │ ├── IncomingCallReceiver.java
│ │ ├── DownloadList.java
│ │ ├── DownloadProgress.java
│ │ ├── AccountSettings.java
│ │ ├── Subscribe.java
│ │ ├── SelectDevice.java
│ │ ├── Player.java
│ │ └── PodcastManager.java
│ │ ├── Episode.java
│ │ ├── database
│ │ ├── GpodDBHelper.java
│ │ └── GpodDB.java
│ │ ├── GpodRoid.java
│ │ ├── PodcastElement.java
│ │ ├── PodcastListAdapter.java
│ │ ├── Preferences.java
│ │ ├── RoboActivityDefaultMenu.java
│ │ ├── ShowProvider.java
│ │ └── tools
│ │ └── Tools.java
│ └── gpodder
│ ├── GpodderUpdates.java
│ ├── GpodderSubscriptions.java
│ ├── GpodderPodcast.java
│ └── GpodderAPI.java
├── default.properties
├── .classpath
├── .project
├── GpodRoid.iml
├── AndroidManifest.xml
└── LICENSE.txt
/jars/commons-io-1.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpodder/GpodRoid/HEAD/jars/commons-io-1.4.jar
--------------------------------------------------------------------------------
/jars/guice-2.0-no_aop.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpodder/GpodRoid/HEAD/jars/guice-2.0-no_aop.jar
--------------------------------------------------------------------------------
/jars/roboguice-1.1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpodder/GpodRoid/HEAD/jars/roboguice-1.1.1.jar
--------------------------------------------------------------------------------
/res/drawable-hdpi/cd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpodder/GpodRoid/HEAD/res/drawable-hdpi/cd.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/cd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpodder/GpodRoid/HEAD/res/drawable-ldpi/cd.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/cd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpodder/GpodRoid/HEAD/res/drawable-mdpi/cd.png
--------------------------------------------------------------------------------
/jars/MyID3_for_Android.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpodder/GpodRoid/HEAD/jars/MyID3_for_Android.jar
--------------------------------------------------------------------------------
/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpodder/GpodRoid/HEAD/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpodder/GpodRoid/HEAD/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpodder/GpodRoid/HEAD/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | gen
2 | bin
3 | local.properties
4 | .project
5 | .directory
6 | .classpath
7 | out
8 | .idea
9 |
--------------------------------------------------------------------------------
/jars/jackson-core-asl-1.4.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpodder/GpodRoid/HEAD/jars/jackson-core-asl-1.4.3.jar
--------------------------------------------------------------------------------
/jars/jackson-mapper-asl-1.4.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpodder/GpodRoid/HEAD/jars/jackson-mapper-asl-1.4.3.jar
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/services/IPlaybackControl.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.services;
2 |
3 | public interface IPlaybackControl {
4 |
5 | public void next();
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/PlayPodcastReceiver.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/PlaybackState.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid;
2 |
3 | public class PlaybackState {
4 |
5 | public void saveState(){
6 |
7 | }
8 |
9 | public void getState(){
10 |
11 | }
12 |
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/default.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-10
12 |
--------------------------------------------------------------------------------
/res/menu/podcastmanager.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World, GpodRoid!
4 | GpodRoid
5 |
6 | %2$d:%5$02d
7 |
8 |
9 | %1$d:%3$02d:%5$02d
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/layout/podcast_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/res/layout/archiveview.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/res/layout/select_device.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/res/menu/menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/activity/IncomingCallReceiver.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.activity;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import com.unitedcoders.android.gpodroid.GpodRoid;
7 | import android.util.Log;
8 |
9 | /**
10 | * Author: nheid
11 | * Date: 10.06.2011
12 | */
13 | public class IncomingCallReceiver extends BroadcastReceiver {
14 |
15 | @Override
16 | public void onReceive(Context context, Intent intent) {
17 |
18 | // stop the playback on incoming call
19 | Log.d(GpodRoid.LOGTAG, "incoming phone call, stopping player if necessary");
20 | if (Player.mp != null && Player.mp.isPlaying()) {
21 | Player.mp.pause();
22 | }
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | GpodRoid
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/Episode.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid;
2 |
3 |
4 | import com.unitedcoders.gpodder.GpodderPodcast;
5 |
6 | /**
7 | *
8 | */
9 | public class Episode extends GpodderPodcast {
10 |
11 | int downloaded;
12 | int played;
13 | String file;
14 |
15 |
16 | public Episode(GpodderPodcast podcast) {
17 | this.downloaded = downloaded;
18 | this.played = played;
19 | }
20 |
21 | public int getDownloaded() {
22 | return downloaded;
23 | }
24 |
25 | public void setDownloaded(int downloaded) {
26 | this.downloaded = downloaded;
27 | }
28 |
29 | public int getPlayed() {
30 | return played;
31 | }
32 |
33 | public void setPlayed(int played) {
34 | this.played = played;
35 | }
36 |
37 | public String getFile() {
38 | return file;
39 | }
40 |
41 | public void setFile(String file) {
42 | this.file = file;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/gpodder/GpodderUpdates.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.gpodder;
2 |
3 | import java.util.List;
4 |
5 | public class GpodderUpdates {
6 |
7 | private String timestamp;
8 | private List add;
9 | private List remove;
10 | private List updates;
11 | public String getTimestamp() {
12 | return timestamp;
13 | }
14 | public void setTimestamp(String timestamp) {
15 | this.timestamp = timestamp;
16 | }
17 | public List getAdd() {
18 | return add;
19 | }
20 | public void setAdd(List add) {
21 | this.add = add;
22 | }
23 | public List getRemove() {
24 | return remove;
25 | }
26 | public void setRemove(List remove) {
27 | this.remove = remove;
28 | }
29 | public List getUpdates() {
30 | return updates;
31 | }
32 | public void setUpdates(List updates) {
33 | this.updates = updates;
34 | }
35 |
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
14 |
18 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/res/layout/download_progress.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
11 |
12 |
14 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/database/GpodDBHelper.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.database;
2 |
3 |
4 | import android.content.Context;
5 | import android.database.sqlite.SQLiteDatabase;
6 | import android.database.sqlite.SQLiteOpenHelper;
7 |
8 | public class GpodDBHelper extends SQLiteOpenHelper {
9 |
10 | private static final String DATABASE_NAME = "gpodroid.db";
11 | private static final int DATABASE_VERSION = 2;
12 |
13 | // Database creation sql statement
14 | private static final String DATABASE_CREATE_PODCASTINFO = "CREATE TABLE podcast (_ID INTEGER PRIMARY KEY, file TEXT, title TEXT, show TEXT, downloaded INTEGER, played INTEGER, url TEXT, podcast_url TEXT, released TEXT)";
15 |
16 | public GpodDBHelper(Context context) {
17 | super(context, DATABASE_NAME, null, DATABASE_VERSION);
18 | }
19 |
20 | @Override
21 | public void onCreate(SQLiteDatabase sqLiteDatabase) {
22 | sqLiteDatabase.execSQL(DATABASE_CREATE_PODCASTINFO);
23 | }
24 |
25 | @Override
26 | public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
27 | sqLiteDatabase.execSQL("DROP TABLE IF EXISTS podcast");
28 | onCreate(sqLiteDatabase);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/res/layout/subscribe.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
10 |
11 |
14 |
17 |
18 |
19 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/layout/downloadview.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
9 |
10 |
13 |
15 |
16 |
17 |
18 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/GpodRoid.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid;
2 |
3 |
4 | import android.content.Context;
5 | import com.google.inject.Module;
6 | import roboguice.application.RoboApplication;
7 | import roboguice.config.AbstractAndroidModule;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Host of TabActivity and general info of state.
13 | *
14 | * @author Nico Heid
15 | *
16 | */
17 | public class GpodRoid extends RoboApplication {
18 |
19 | /**
20 | * the tag to be referenced in the log cat
21 | */
22 | public static String LOGTAG = "GPR";
23 |
24 | public static final String BROADCAST_SUBSCRIPTION_CHANGE = "test321";
25 |
26 | /**
27 | * This member is meant to be populated right at the beginning of the application in the "main" function
28 | * and will be referenced for the duration of the application
29 | */
30 | public static Context context;
31 |
32 | public GpodRoid(){
33 | context = this;
34 | }
35 |
36 | protected void addApplicationModules(List modules){
37 | modules.add(new GpodRoidModule());
38 | }
39 |
40 | private class GpodRoidModule extends AbstractAndroidModule {
41 | @Override
42 | protected void configure() {
43 | Preferences.initPreferences();
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/res/layout/accountsettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
10 |
11 |
13 |
16 |
17 |
20 |
23 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/GpodRoid.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/PodcastElement.java:
--------------------------------------------------------------------------------
1 | //package com.unitedcoders.android.gpodroid;
2 | //
3 | //import java.io.File;
4 | //
5 | //
6 | //public class PodcastElement implements Comparable {
7 | //
8 | // private String title = "";
9 | // private String downloadUrl;
10 | // private String album;
11 | // private String file;
12 | // private int seekPosition = 0;
13 | //
14 | //
15 | // public PodcastElement(String title, String downloadUrl) {
16 | // this.title = title;
17 | // this.downloadUrl = downloadUrl;
18 | //
19 | // }
20 | //
21 | // public PodcastElement(File file) {
22 | //
23 | // }
24 | //
25 | // public int getSeekPosition() {
26 | // return seekPosition;
27 | // }
28 | //
29 | // public void setSeekPosition(int seekPosition) {
30 | // this.seekPosition = seekPosition;
31 | // }
32 | //
33 | // public String getFile() {
34 | // return file;
35 | // }
36 | //
37 | // public void setFile(String file) {
38 | // this.file = file;
39 | // }
40 | //
41 | // public String getAlbum() {
42 | // return album;
43 | // }
44 | //
45 | // public void setAlbum(String album) {
46 | // this.album = album;
47 | // }
48 | //
49 | // private boolean checked = false;
50 | //
51 | // public String getDownloadurl() {
52 | // return downloadUrl;
53 | // }
54 | //
55 | // public void setDownloadurl(String downloadurl) {
56 | // this.downloadUrl = downloadurl;
57 | //
58 | // }
59 | //
60 | //
61 | // @Override
62 | // public int compareTo(PodcastElement another) {
63 | // // TODO Auto-generated method stub
64 | // return 0;
65 | // }
66 | //
67 | // public String getTitle() {
68 | // return title;
69 | // }
70 | //
71 | // public void setTitle(String title) {
72 | // this.title = title;
73 | // }
74 | //
75 | // public boolean isChecked() {
76 | // return checked;
77 | // }
78 | //
79 | // public void setChecked(boolean checked) {
80 | // this.checked = checked;
81 | // }
82 | //
83 | //}
84 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/gpodder/GpodderSubscriptions.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.gpodder;
2 |
3 | public class GpodderSubscriptions {
4 |
5 | private String title;
6 | private String url;
7 | private String description;
8 | private String subscribers;
9 | private String subscribers_last_week;
10 | private String logo_url;
11 | private String website;
12 | private String mygpo_link;
13 | private String scaled_logo_url;
14 |
15 | public String getTitle() {
16 | return title;
17 | }
18 | public void setTitle(String title) {
19 | this.title = title;
20 | }
21 | public String getUrl() {
22 | return url;
23 | }
24 | public void setUrl(String url) {
25 | this.url = url;
26 | }
27 | public String getDescription() {
28 | return description;
29 | }
30 | public void setDescription(String description) {
31 | this.description = description;
32 | }
33 | public String getSubscribers() {
34 | return subscribers;
35 | }
36 | public void setSubscribers(String subscribers) {
37 | this.subscribers = subscribers;
38 | }
39 | public String getSubscribers_last_week() {
40 | return subscribers_last_week;
41 | }
42 | public void setSubscribers_last_week(String subscribers_last_week) {
43 | this.subscribers_last_week = subscribers_last_week;
44 | }
45 | public String getLogo_url() {
46 | return logo_url;
47 | }
48 | public void setLogo_url(String logoUrl) {
49 | logo_url = logoUrl;
50 | }
51 | public String getScaled_logo_url(){
52 | return scaled_logo_url;
53 | }
54 | public void setScaled_logo_url(String scaledLogoUrl){
55 | scaled_logo_url = scaledLogoUrl;
56 | }
57 | public String getWebsite() {
58 | return website;
59 | }
60 | public void setWebsite(String website) {
61 | this.website = website;
62 | }
63 | public String getMygpo_link() {
64 | return mygpo_link;
65 | }
66 | public void setMygpo_link(String mygpoLink) {
67 | mygpo_link = mygpoLink;
68 | }
69 | }
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/PodcastListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import android.content.Context;
7 | import android.graphics.Color;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.BaseAdapter;
12 | import android.widget.TextView;
13 | import com.unitedcoders.gpodder.GpodderPodcast;
14 |
15 | public class PodcastListAdapter extends BaseAdapter {
16 |
17 | private List episodes;
18 | private Context context;
19 |
20 | // public PodcastListAdapter(Context context) {
21 | // this.context = context;
22 | // }
23 |
24 | public PodcastListAdapter(Context context, List episodes) {
25 | this.context = context;
26 | this.episodes = episodes;
27 | }
28 |
29 | @Override
30 | public int getCount() {
31 | return episodes.size();
32 | }
33 |
34 | @Override
35 | public Object getItem(int i) {
36 | return episodes.get(i);
37 | }
38 |
39 | @Override
40 | public long getItemId(int arg0) {
41 | return 0;
42 | }
43 |
44 | public void addItem(Episode episode) {
45 | episodes.add(episode);
46 | }
47 |
48 | @Override
49 | public View getView(int position, View convertView, ViewGroup parent) {
50 |
51 | Episode episode = episodes.get(position);
52 | if (convertView == null) {
53 | LayoutInflater inflater = (LayoutInflater) context
54 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
55 | convertView = inflater.inflate(R.layout.podcast_list_item, null);
56 | }
57 |
58 | TextView tvEpisode = (TextView) convertView.findViewById(R.id.tv_podcastitem);
59 | tvEpisode.setText(episode.getTitle());
60 | if (episode.getDownloaded() == 0) {
61 | tvEpisode.setTextColor(Color.RED);
62 | } else {
63 | tvEpisode.setTextColor(Color.GREEN);
64 | }
65 |
66 |
67 | return convertView;
68 |
69 | }
70 |
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/gpodder/GpodderPodcast.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.gpodder;
2 |
3 | public class GpodderPodcast {
4 |
5 | private int id;
6 | private String title;
7 | private String podcast_url;
8 | private String podcast_title;
9 | private String description;
10 | private String website;
11 | private String mygpo_link;
12 | private String released;
13 | private String status;
14 | private String url;
15 | private boolean checked = false;
16 |
17 | public boolean isChecked() {
18 | return checked;
19 | }
20 |
21 | public void setChecked(boolean checked) {
22 | this.checked = checked;
23 | }
24 |
25 | public int getId() {
26 | return id;
27 | }
28 |
29 | public void setId(int id) {
30 | this.id = id;
31 | }
32 |
33 | public String getUrl() {
34 | return url;
35 | }
36 |
37 | public void setUrl(String url) {
38 | this.url = url;
39 | }
40 |
41 | public String getTitle() {
42 | return title;
43 | }
44 |
45 | public void setTitle(String title) {
46 | this.title = title;
47 | }
48 |
49 | public String getPodcast_url() {
50 | return podcast_url;
51 | }
52 |
53 | public void setPodcast_url(String podcastUrl) {
54 | podcast_url = podcastUrl;
55 | }
56 |
57 | public String getPodcast_title() {
58 | return podcast_title;
59 | }
60 |
61 | public void setPodcast_title(String podcastTitle) {
62 | podcast_title = podcastTitle;
63 | }
64 |
65 | public String getDescription() {
66 | return description;
67 | }
68 |
69 | public void setDescription(String description) {
70 | this.description = description;
71 | }
72 |
73 | public String getWebsite() {
74 | return website;
75 | }
76 |
77 | public void setWebsite(String website) {
78 | this.website = website;
79 | }
80 |
81 | public String getMygpo_link() {
82 | return mygpo_link;
83 | }
84 |
85 | public void setMygpo_link(String mygpoLink) {
86 | mygpo_link = mygpoLink;
87 | }
88 |
89 | public String getReleased() {
90 | return released;
91 | }
92 |
93 | public void setReleased(String released) {
94 | this.released = released;
95 | }
96 |
97 | public String getStatus() {
98 | return status;
99 | }
100 |
101 | public void setStatus(String status) {
102 | this.status = status;
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/Preferences.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid;
2 |
3 | import android.content.SharedPreferences;
4 |
5 | /**
6 | * Saves and loads the user preferences
7 | * @author Nico Heid
8 | *
9 | */
10 | public class Preferences {
11 |
12 | private final static String USERNAME_COL = "USERNAME";
13 | private final static String ENCRYPTED_AUTHENTICATION_COL = "ENCRYPTED_AUTHENTICATION";
14 | private final static String DEVICE_COL = "DEVICE";
15 |
16 | private static final String PREFS_NAME = "gpodroidPrefs";
17 | private static String username = "";
18 | private static String encryptedAuthentication = "";
19 | private static String device = "";
20 |
21 | public Preferences() {
22 | super(); //To change body of overridden methods use File | Settings | File Templates.
23 | }
24 |
25 | public static String getUsername() {
26 | return username;
27 | }
28 |
29 | public static void setUsernameAndPassword(String username, String password) {
30 | Preferences.username = username;
31 | String auth = Preferences.getUsername() + ":" + password;
32 | encryptedAuthentication = Base64.encodeBytes(auth.getBytes());
33 | }
34 |
35 | public static void setNewPassword(String password) {
36 | setUsernameAndPassword(username, password);
37 | }
38 |
39 | public static String getDevice() {
40 | return device;
41 | }
42 |
43 | public static void setDevice(String device) {
44 | Preferences.device = device;
45 | }
46 |
47 | public static Boolean hasAuthentication(){
48 | return Preferences.encryptedAuthentication.equals("");
49 | }
50 |
51 | public static String getEncryptedAuthentication(){
52 | return encryptedAuthentication;
53 | }
54 |
55 | public static void save() {
56 | SharedPreferences settings = GpodRoid.context.getSharedPreferences(PREFS_NAME, 0);
57 | SharedPreferences.Editor editor = settings.edit();
58 |
59 | editor.putString(USERNAME_COL, username);
60 | editor.putString(ENCRYPTED_AUTHENTICATION_COL, encryptedAuthentication);
61 | editor.putString(DEVICE_COL, device);
62 |
63 | editor.commit();
64 | }
65 |
66 | public static void initPreferences() {
67 | SharedPreferences settings = GpodRoid.context.getSharedPreferences(PREFS_NAME, 0);
68 |
69 | username = settings.getString(USERNAME_COL, "");
70 | encryptedAuthentication = settings.getString(ENCRYPTED_AUTHENTICATION_COL, "");
71 | device = settings.getString(DEVICE_COL, "");
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/services/PlayerService.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.services;
2 |
3 | import java.io.IOException;
4 |
5 | import android.app.Service;
6 | import android.content.Intent;
7 | import android.media.MediaPlayer;
8 | import android.os.Binder;
9 | import android.os.IBinder;
10 | import android.widget.Toast;
11 |
12 | /**
13 | * Service for Playing the podcasts Is a singleton
14 | *
15 | * @author Nico Heid
16 | *
17 | */
18 | public class PlayerService extends Service {
19 |
20 | private static MediaPlayer player;
21 | private PlayerServiceBinder playerServiceBinder = new PlayerServiceBinder();
22 |
23 | public class PlayerServiceBinder extends Binder {
24 | PlayerService getService() {
25 | return PlayerService.this;
26 | }
27 |
28 | }
29 |
30 | @Override
31 | public IBinder onBind(Intent intent) {
32 | return playerServiceBinder;
33 | }
34 |
35 | @Override
36 | public void onCreate() {
37 | super.onCreate();
38 | if (player == null) {
39 | player = new MediaPlayer();
40 | Toast.makeText(this, "player created", Toast.LENGTH_LONG).show();
41 | }
42 |
43 |
44 | }
45 |
46 | @Override
47 | public void onDestroy() {
48 | player.stop();
49 |
50 | Toast.makeText(this, "player stopped", Toast.LENGTH_LONG).show();
51 | super.onDestroy();
52 | }
53 |
54 | @Override
55 | public void onStart(Intent intent, int startId) {
56 | super.onStart(intent, startId);
57 | Toast.makeText(this, "player started", Toast.LENGTH_LONG).show();
58 |
59 | nextPodcast();
60 |
61 | }
62 |
63 | public void nextPodcast() {
64 | // PodcastElement pce = GpodRoid.getNextPlayback();
65 | // File podcastFile = new File(pce.getFile());
66 |
67 | try {
68 | player.reset();
69 | // player.setDataSource(podcastFile.getAbsolutePath());
70 | player.prepare();
71 | player.start();
72 | } catch (IllegalArgumentException e) {
73 | e.printStackTrace();
74 | } catch (IllegalStateException e) {
75 | e.printStackTrace();
76 | } catch (IOException e) {
77 | e.printStackTrace();
78 | }
79 |
80 | // Intent intent = new Intent(this, com.unitedcoders.android.gpodroid.activity.Player.PlayPodcastReceiver.class);
81 | // intent.putExtra("title", "helloworld");
82 | // sendBroadcast(intent);
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/activity/DownloadList.java:
--------------------------------------------------------------------------------
1 | //package com.unitedcoders.android.gpodroid.activity;
2 | //
3 | //import java.util.List;
4 | //
5 | //import android.app.ListActivity;
6 | //import android.content.Intent;
7 | //import android.os.Bundle;
8 | //import android.view.View;
9 | //import android.view.View.OnClickListener;
10 | //import android.widget.Button;
11 | //import android.widget.Toast;
12 | //
13 | //import com.unitedcoders.android.gpodroid.GpodRoid;
14 | //import com.unitedcoders.android.gpodroid.PodcastListAdapter;
15 | //import com.unitedcoders.android.gpodroid.Preferences;
16 | //import com.unitedcoders.android.gpodroid.R;
17 | //import com.unitedcoders.android.gpodroid.services.DownloadService;
18 | //import com.unitedcoders.gpodder.GpodderAPI;
19 | //import com.unitedcoders.gpodder.GpodderUpdates;
20 | //
21 | ///**
22 | // * Shows a list of available downloads
23 | // *
24 | // * @author Nico Heid
25 | // */
26 | //public class DownloadList extends ListActivity {
27 | //
28 | // @Override
29 | // protected void onCreate(Bundle savedInstanceState) {
30 | // // TODO Auto-generated method stub
31 | // super.onCreate(savedInstanceState);
32 | // setContentView(R.layout.downloadview);
33 | //
34 | // final PodcastListAdapter pcla = new PodcastListAdapter(this);
35 | // pcla.setShowCheckbox(true);
36 | //
37 | // // get preferences
38 | // Preferences pref = GpodRoid.prefs;
39 | // if (pref.getUsername().equals("") || pref.getPassword().equals("") || pref.getDevice().equals("")) {
40 | //
41 | // Toast toast = Toast.makeText(getApplicationContext(), "please enter your settings first",
42 | // Toast.LENGTH_SHORT);
43 | // toast.show();
44 | //
45 | // return;
46 | //
47 | // }
48 | //
49 | // GpodderUpdates podcast = GpodderAPI.getDownloadList();
50 | //
51 | // // add items to download list
52 | // for (int i = 0; i < podcast.getUpdates().size(); i++) {
53 | //// pcla.addItem(new PodcastElement(podcast.getUpdates().get(i).getTitle(), podcast.getUpdates().get(i)
54 | //// .getUrl()));
55 | // }
56 | //
57 | // setListAdapter(pcla);
58 | //
59 | // Button downloadButton = (Button) findViewById(R.id.downloadButton);
60 | // final Intent intent = new Intent(this, DownloadService.class);
61 | // downloadButton.setOnClickListener(new OnClickListener() {
62 | //
63 | // @Override
64 | // public void onClick(View v) {
65 | //
66 | // String download = null;
67 | //
68 | //// List checkedItems = pcla.getCheckedItems();
69 | //// for (PodcastElement pce : checkedItems) {
70 | //// GpodRoid.addDownloadQueue(pce);
71 | //// }
72 | //
73 | // intent.putExtra("podcast", download);
74 | // startService(intent);
75 | //
76 | // }
77 | // });
78 | // }
79 | //
80 | //}
81 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/activity/DownloadProgress.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.activity;
2 |
3 | import com.unitedcoders.android.gpodroid.GpodRoid;
4 | import com.unitedcoders.android.gpodroid.R;
5 |
6 | import android.app.Activity;
7 | import android.app.Notification;
8 | import android.app.NotificationManager;
9 | import android.app.PendingIntent;
10 | import android.content.Context;
11 | import android.content.Intent;
12 | import android.os.Bundle;
13 | import android.widget.ProgressBar;
14 | import android.widget.RemoteViews;
15 |
16 | /**
17 | * Download of podcasts with ProgressBar
18 | * @author Nico Heid
19 | *
20 | */
21 | public class DownloadProgress extends Activity {
22 |
23 | ProgressBar progressBar;
24 | private int progress = 10;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | // TODO Auto-generated method stub
29 | super.onCreate(savedInstanceState);
30 | // setContentView(R.layout.download_progress);
31 |
32 | final Notification notification = new Notification(R.drawable.icon, "downloading podcast", System.currentTimeMillis());
33 | notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
34 | notification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.download_progress);
35 |
36 | Intent intent = new Intent(this, DownloadProgress.class);
37 | final PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
38 |
39 | notification.contentIntent = pendingIntent;
40 |
41 | notification.contentView.setImageViewResource(R.id.status_icon, android.R.drawable.ic_menu_save);
42 | notification.contentView.setTextViewText(R.id.status_text, "downloading podcast");
43 |
44 | notification.contentView.setProgressBar(R.id.status_progress, 100, progress, false);
45 |
46 |
47 | final NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(
48 | Context.NOTIFICATION_SERVICE);
49 |
50 | notificationManager.notify(42, notification);
51 |
52 | Thread download = new Thread() {
53 |
54 | @Override
55 | public void run() {
56 | // TODO Auto-generated method stub
57 |
58 | for (int i = 1; i < 100; i++) {
59 | progress++;
60 | notification.contentView.setProgressBar(R.id.status_progress, 100, progress, false);
61 | notificationManager.notify(42, notification);
62 | try {
63 | Thread.sleep(100);
64 | } catch (InterruptedException e) {
65 | // TODO Auto-generated catch block
66 | e.printStackTrace();
67 | }
68 | }
69 |
70 | notificationManager.cancel(42);
71 |
72 | }
73 | };
74 |
75 | download.run();
76 | //
77 |
78 | }
79 |
80 | }
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/RoboActivityDefaultMenu.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid;
2 |
3 | import android.content.Intent;
4 | import android.content.pm.PackageManager;
5 | import android.os.Build;
6 | import android.util.Log;
7 | import android.view.Menu;
8 | import android.view.MenuInflater;
9 | import android.view.MenuItem;
10 | import com.unitedcoders.android.gpodroid.activity.AccountSettings;
11 | import com.unitedcoders.android.gpodroid.services.UpdateService;
12 | import roboguice.activity.RoboActivity;
13 |
14 | /**
15 | * Activity with default menu
16 | *
17 | * @author nheid
18 | */
19 | public class RoboActivityDefaultMenu extends RoboActivity {
20 |
21 | public boolean onCreateOptionsMenu(Menu menu) {
22 | MenuInflater inflater = getMenuInflater();
23 | inflater.inflate(R.menu.menu, menu);
24 | return true;
25 | }
26 |
27 | @Override
28 | public boolean onOptionsItemSelected(MenuItem item) {
29 | // Handle item selection
30 | switch (item.getItemId()) {
31 | case R.id.account:
32 | Intent account = new Intent(getApplicationContext(), AccountSettings.class);
33 | startActivity(account);
34 | return true;
35 | // case R.id.subscriptions:
36 | // Intent subscriptions = new Intent(getApplicationContext(), Subscribe.class);
37 | // startActivity(subscriptions);
38 | // return true;
39 | case R.id.fetch_updates:
40 | startService(new Intent(getApplicationContext(), UpdateService.class));
41 | return true;
42 | case R.id.send_feedback:
43 | sendFeedback();
44 | return true;
45 | default:
46 | return super.onOptionsItemSelected(item);
47 | }
48 | }
49 |
50 |
51 | /**
52 | * Start intend to send a feedback email via installed mail application
53 | */
54 | private void sendFeedback() {
55 | String version = null;
56 |
57 | try {
58 | version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
59 | } catch (PackageManager.NameNotFoundException e) {
60 | Log.e(GpodRoid.LOGTAG, "could not determin version", e);
61 | }
62 |
63 | String message = String.format("\n\n--DEVELOPER INFO -- \nthis feedback is from version: %s on device: %s with android: %s",
64 | version , Build.MODEL, Build.VERSION.RELEASE);
65 |
66 |
67 | /* Create the Intent */
68 | final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
69 |
70 | /* Fill it with Data */
71 | emailIntent.setType("plain/text");
72 | emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"gpodroid@united-coders.com"});
73 | emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "feedback from GPodRoid");
74 | emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
75 |
76 | /* Send it off to the Activity-Chooser */
77 | GpodRoid.context.startActivity(Intent.createChooser(emailIntent, "Send mail...")
78 | .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/res/layout/podcast_manager.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
10 |
12 |
13 |
14 |
16 |
17 |
19 |
21 |
26 |
27 |
28 |
29 |
30 |
31 |
34 |
36 |
37 |
38 |
39 |
43 |
44 |
47 |
50 |
51 |
52 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/activity/AccountSettings.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.activity;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.view.View.OnClickListener;
9 | import android.view.View.OnKeyListener;
10 | import android.view.KeyEvent;
11 | import android.widget.Button;
12 | import android.widget.EditText;
13 | import android.widget.Toast;
14 | import com.unitedcoders.android.gpodroid.GpodRoid;
15 | import com.unitedcoders.android.gpodroid.Preferences;
16 | import com.unitedcoders.android.gpodroid.R;
17 | import com.unitedcoders.android.gpodroid.R.layout;
18 | import com.unitedcoders.gpodder.GpodderAPI;
19 |
20 | /**
21 | * This class will present the user with an interface to enter their username and password and then login
22 | * or register a new user name and password
23 | *
24 | * @author Brian Bourke-Martin
25 | */
26 | public class AccountSettings extends Activity {
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 |
32 | setContentView(layout.accountsettings);
33 | final EditText etUsername = (EditText) findViewById(R.id.in_username);
34 | final EditText etPassword = (EditText) findViewById(R.id.in_password);
35 | final Button save = (Button) findViewById(R.id.btn_save);
36 | final Button register = (Button) findViewById(R.id.btn_register);
37 |
38 | etUsername.setText(Preferences.getUsername());
39 | etPassword.setText("");
40 |
41 | etUsername.setOnKeyListener(new OnKeyListener() {
42 | public boolean onKey(View v, int keyCode, KeyEvent event) {
43 | switch(keyCode){
44 | case KeyEvent.KEYCODE_ENTER:
45 | case KeyEvent.KEYCODE_TAB:
46 | etPassword.requestFocus();
47 | return true;
48 | default:
49 | return false;
50 | }
51 | }
52 | });
53 |
54 | save.setOnClickListener(new OnClickListener() {
55 | @Override
56 | public void onClick(View v) {
57 | Preferences.setUsernameAndPassword(etUsername.getText().toString(), etPassword.getText().toString());
58 | Preferences.save();
59 |
60 | // check to see if the user name and password function to get a list of devices as an check
61 | SelectDevice.devices = GpodderAPI.getDevices();
62 | if(SelectDevice.devices == null){
63 | // this is a failure to login using this user name and password so lets reset and continue
64 | Toast.makeText(GpodRoid.context, "Could not authenticate this username and password.", Toast.LENGTH_SHORT).show();
65 | }
66 | else{
67 | startActivity(new Intent(GpodRoid.context, SelectDevice.class));
68 | finish();
69 | }
70 | }
71 | });
72 |
73 | register.setOnClickListener(new OnClickListener() {
74 | @Override
75 | public void onClick(View view) {
76 | Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://gpodder.net/register/"));
77 | startActivity(i);
78 | }
79 | });
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/services/UpdateService.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.services;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.Handler;
6 | import android.os.IBinder;
7 | import android.os.Looper;
8 | import android.util.Log;
9 | import android.widget.Toast;
10 | import com.unitedcoders.android.gpodroid.GpodRoid;
11 | import com.unitedcoders.android.gpodroid.Preferences;
12 | import com.unitedcoders.android.gpodroid.activity.AccountSettings;
13 | import com.unitedcoders.android.gpodroid.database.GpodDB;
14 | import com.unitedcoders.gpodder.GpodderAPI;
15 | import com.unitedcoders.gpodder.GpodderPodcast;
16 | import com.unitedcoders.gpodder.GpodderUpdates;
17 |
18 | import java.util.List;
19 |
20 | /**
21 | * Get updates from gpodder
22 | */
23 | public class UpdateService extends Service {
24 |
25 | private Handler handler = new Handler();
26 |
27 | private Thread downloadUpdatesThread = null;
28 |
29 | @Override
30 | public IBinder onBind(Intent intent) {
31 | return null; //To change body of implemented methods use File | Settings | File Templates.
32 | }
33 |
34 | @Override
35 | public void onStart(Intent intent, int startId) {
36 | super.onStart(intent, startId);
37 | downloadProcessing();
38 | }
39 |
40 | public synchronized void downloadProcessing() {
41 | if (Preferences.getUsername().equals("") || Preferences.hasAuthentication() || Preferences.getDevice().equals("")) {
42 |
43 | Toast.makeText(getApplicationContext(), "please enter your settings first", Toast.LENGTH_SHORT).show();
44 |
45 | Intent intent = new Intent(getApplicationContext(), AccountSettings.class);
46 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
47 |
48 | startActivity(intent);
49 |
50 | return;
51 |
52 | }
53 |
54 | if(downloadUpdatesThread == null){
55 | downloadUpdatesThread = new Thread(null, doGetPodcastDownloadInfo, "Background");
56 | downloadUpdatesThread.start();
57 | }
58 | }
59 |
60 | private Runnable doUpdateDownloadList = new Runnable() {
61 | public void run() {
62 |
63 | }
64 | };
65 |
66 | private Runnable doGetPodcastDownloadInfo = new Runnable() {
67 | public void run() {
68 | Looper.prepare();
69 | backgroundPodcastInfoFetcher();
70 | Looper.loop();
71 |
72 | // now that the fetching is done, reset the download thread reference
73 | downloadUpdatesThread = null;
74 | }
75 | };
76 |
77 | private void backgroundPodcastInfoFetcher() {
78 | Log.d(GpodRoid.LOGTAG, "Starting background thread to get info.");
79 | GpodderUpdates podcast = GpodderAPI.getDownloadList();
80 | Log.d(GpodRoid.LOGTAG, "Got podcast updates.");
81 |
82 | if (podcast == null) {
83 | Toast.makeText(GpodRoid.context, "Failed to fetch updates", Toast.LENGTH_LONG);
84 | Log.e(GpodRoid.LOGTAG, "cant display downloads, got empty result");
85 | return;
86 | }
87 |
88 | List pcl = podcast.getUpdates();
89 | if(pcl != null && pcl.size()>0){
90 | GpodDB.addPodcasts(pcl);
91 | }
92 |
93 | handler.post(doUpdateDownloadList);
94 |
95 | // notify views of new content
96 | Log.d(GpodRoid.LOGTAG, "UpdateService broadcasting changes");
97 | Intent subscriptionChanged = new Intent();
98 | subscriptionChanged.setAction(GpodRoid.BROADCAST_SUBSCRIPTION_CHANGE);
99 | sendBroadcast(subscriptionChanged);
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/ShowProvider.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid;
2 |
3 | import android.content.ContentProvider;
4 | import android.content.ContentUris;
5 | import android.content.ContentValues;
6 | import android.content.Context;
7 | import android.database.Cursor;
8 | import android.database.sqlite.SQLiteDatabase;
9 | import android.database.sqlite.SQLiteOpenHelper;
10 | import android.net.Uri;
11 | import android.os.ParcelFileDescriptor;
12 | import com.unitedcoders.android.gpodroid.database.GpodDB;
13 | import com.unitedcoders.android.gpodroid.database.GpodDBHelper;
14 |
15 | import java.io.File;
16 | import java.io.FileNotFoundException;
17 |
18 | /**
19 | * Created by IntelliJ IDEA.
20 | * User: nheid
21 | * Date: 3/5/11
22 | * Time: 10:55 AM
23 | * To change this template use File | Settings | File Templates.
24 | */
25 | public class ShowProvider extends ContentProvider {
26 |
27 | private GpodDBHelper dbHelper;
28 | SQLiteDatabase db3;
29 |
30 | public static final String PROVIDER = "com.unitedcoders.android.gpodroid.Provider";
31 |
32 | @Override
33 | public boolean onCreate() {
34 |
35 | Context c = getContext();
36 | dbHelper = new GpodDBHelper(c);
37 | db3 = dbHelper.getWritableDatabase();
38 |
39 | return true;
40 | }
41 |
42 | @Override
43 | public Cursor query(Uri uri, String[] projection, String selection,
44 | String[] selectionArgs, String sortOrder) {
45 |
46 |
47 | SQLiteDatabase db = dbHelper.getReadableDatabase();
48 | Cursor c = db.query(GpodDB.DATABASE_TABLE, projection, selection, selectionArgs, null, null, sortOrder);
49 | c.setNotificationUri(getContext().getContentResolver(), uri);
50 | return c;
51 | }
52 |
53 | @Override
54 | public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
55 |
56 | SQLiteDatabase db = dbHelper.getReadableDatabase();
57 |
58 | Cursor c = db.query(GpodDB.DATABASE_TABLE, new String[]{"file"},
59 | "_id=?", new String[]{"281"}, null, null, null);
60 |
61 | c.moveToFirst();
62 |
63 |
64 | String filePath = c.getString(0);
65 | File file = new File(filePath);
66 | int imode = 0;
67 | if (mode.contains("r")) imode |= ParcelFileDescriptor.MODE_READ_ONLY;
68 | if (mode.contains("+")) imode |= ParcelFileDescriptor.MODE_APPEND;
69 |
70 | return ParcelFileDescriptor.open(file, imode);
71 |
72 | }
73 |
74 | @Override
75 | public String getType(Uri uri) {
76 | return null; //To change body of implemented methods use File | Settings | File Templates.
77 | }
78 |
79 |
80 | @Override
81 | public Uri insert(Uri uri, ContentValues contentValues) {
82 | SQLiteDatabase db = null;
83 | try {
84 | db = dbHelper.getWritableDatabase();
85 | } catch (Exception e) {
86 | e.printStackTrace();
87 | }
88 |
89 | long rowId = db.insert(GpodDB.DATABASE_TABLE, "show", contentValues);
90 |
91 | if (rowId > 0) {
92 | Uri curi = Uri.parse("content://" + PROVIDER + "/show");
93 | Uri _uri = ContentUris.withAppendedId(curi, rowId);
94 | getContext().getContentResolver().notifyChange(_uri, null);
95 | return _uri;
96 | }
97 |
98 |
99 | return null;
100 | }
101 |
102 | @Override
103 | public int delete(Uri uri, String s, String[] strings) {
104 | return 0; //To change body of implemented methods use File | Settings | File Templates.
105 | }
106 |
107 | @Override
108 | public int update(Uri uri, ContentValues contentValues, String s, String[] strings) {
109 | return 0; //To change body of implemented methods use File | Settings | File Templates.
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/services/RSSService.java:
--------------------------------------------------------------------------------
1 | /*Copyright 2010 NetCatch Team
2 | *Licensed under the Apache License, Version 2.0 (the "License");
3 | *you may not use this file except in compliance with the License.
4 | *You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | *Unless required by applicable law or agreed to in writing, software
9 | *distributed under the License is distributed on an "AS IS" BASIS,
10 | *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | *See the License for the specific language governing permissions and
12 | *limitations under the License.
13 | */
14 | package com.unitedcoders.android.gpodroid.services;
15 |
16 | import com.unitedcoders.android.gpodroid.tools.Tools;
17 |
18 | import android.app.Notification;
19 | import android.app.NotificationManager;
20 | import android.app.PendingIntent;
21 | import android.app.Service;
22 | import android.content.ContentValues;
23 | import android.content.Context;
24 | import android.content.Intent;
25 | import android.content.SharedPreferences;
26 | import android.database.Cursor;
27 | import android.net.Uri;
28 | import android.os.Environment;
29 | import android.os.IBinder;
30 | import android.preference.PreferenceManager;
31 | import android.util.Log;
32 |
33 | import org.apache.http.HttpResponse;
34 | import org.apache.http.client.methods.HttpGet;
35 | import org.apache.http.impl.client.DefaultHttpClient;
36 | import org.w3c.dom.Document;
37 | import org.w3c.dom.Element;
38 | import org.w3c.dom.NodeList;
39 | import org.xml.sax.SAXException;
40 |
41 | import javax.xml.parsers.DocumentBuilder;
42 | import javax.xml.parsers.DocumentBuilderFactory;
43 | import java.io.IOException;
44 |
45 | /**
46 | * A simple service that takes an RSS feed and saves the data from the RSS feed.
47 | *
48 | * Requires either the show object to be pased in, or just a feed,
49 | * which will create a new show object
50 | *
51 | * @author Leif Andersen
52 | */
53 | public class RSSService {
54 |
55 |
56 | private static String getImageUrlFromFeed(Context context, String url) {
57 |
58 | try {
59 | Document doc;
60 | DocumentBuilder builder = DocumentBuilderFactory.newInstance()
61 | .newDocumentBuilder();
62 | DefaultHttpClient client = new DefaultHttpClient();
63 | HttpGet request = new HttpGet(url);
64 | HttpResponse response = client.execute(request);
65 | doc = builder.parse(response.getEntity().getContent());
66 | // return doc;
67 |
68 | // get Image
69 | NodeList item = doc.getElementsByTagName("channel");
70 | Element el = (Element) item.item(0);
71 |
72 | String imageUrl;
73 | NodeList imagNode = el.getElementsByTagName("image");
74 | if (imagNode != null) {
75 | Element ima = (Element) imagNode.item(0);
76 | if (ima != null) {
77 | NodeList urlNode = ima.getElementsByTagName("url");
78 | if (urlNode == null || urlNode.getLength() < 1)
79 | imageUrl = null;
80 | else
81 | imageUrl =
82 | urlNode.item(0).getFirstChild().getNodeValue();
83 | } else
84 | imageUrl = null;
85 | } else
86 | imageUrl = null;
87 |
88 | return imageUrl;
89 |
90 | } catch (IOException e) {
91 | return null; // The network probably died, just return null
92 | } catch (SAXException e) {
93 | // Problem parsing the XML, log and return nothing
94 | Log.e("NCRSS", "Error parsing XML", e);
95 | return null;
96 | } catch (Exception e) {
97 | // Anything else was probably another network problem, fail silently
98 | return null;
99 | }
100 | }
101 | }
102 |
103 |
--------------------------------------------------------------------------------
/res/layout/playerview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
10 |
13 |
14 |
15 |
18 |
19 |
22 |
25 |
26 |
27 |
31 |
32 |
33 |
35 |
37 |
39 |
40 |
41 |
42 |
43 |
45 |
46 |
49 |
50 |
51 |
53 |
57 |
61 |
62 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/activity/Subscribe.java:
--------------------------------------------------------------------------------
1 | //package com.unitedcoders.android.gpodroid.activity;
2 | //
3 | //import android.app.ProgressDialog;
4 | //import android.content.Context;
5 | //import android.content.Intent;
6 | //import android.os.Bundle;
7 | //import android.os.Handler;
8 | //import android.util.Log;
9 | //import android.view.ContextMenu;
10 | //import android.view.ContextMenu.ContextMenuInfo;
11 | //import android.view.MenuItem;
12 | //import android.view.View;
13 | //import android.widget.AdapterView.AdapterContextMenuInfo;
14 | //import android.widget.ArrayAdapter;
15 | //import android.widget.EditText;
16 | //import android.widget.ImageButton;
17 | //import android.widget.ListView;
18 | //import com.unitedcoders.android.gpodroid.GpodRoid;
19 | //import com.unitedcoders.android.gpodroid.R;
20 | //import com.unitedcoders.android.gpodroid.services.UpdateService;
21 | //import com.unitedcoders.gpodder.GpodderAPI;
22 | //import roboguice.activity.RoboActivity;
23 | //import roboguice.inject.InjectView;
24 | //
25 | //import java.util.ArrayList;
26 | //import java.util.HashMap;
27 | //
28 | //public class Subscribe {
29 | //
30 | //
31 | //
32 | // @Override
33 | // protected void onCreate(Bundle savedInstanceState) {
34 | // this.context = getApplicationContext();
35 | // super.onCreate(savedInstanceState);
36 | // setContentView(R.layout.subscribe);
37 | //
38 | // searching = ProgressDialog.show(this, "Searching ...", "digging through podcasts", true, false);
39 | // displayTopPodcasts();
40 | //
41 | // btnPodcastSearch.setOnClickListener(this);
42 | // registerForContextMenu(lvSearchResults);
43 | //
44 | // }
45 | //
46 | // @Override
47 | // public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
48 | // super.onCreateContextMenu(menu, v, menuInfo);
49 | // menu.add("subscribe");
50 | // }
51 | //
52 | // @Override
53 | // public boolean onContextItemSelected(MenuItem item) {
54 | //
55 | // AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
56 | // final String feed = (String) lvSearchResults.getItemAtPosition(info.position);
57 | // Log.d(GpodRoid.LOGTAG, "subscribing to " + top25hm.get(feed));
58 | //
59 | // new Thread(new Runnable() {
60 | // @Override
61 | // public void run() {
62 | // GpodderAPI.addSubcription(top25hm.get(feed));
63 | // startService(new Intent(getApplicationContext(), UpdateService.class));
64 | // }
65 | // }).start();
66 | //
67 | //
68 | // return super.onContextItemSelected(item);
69 | //
70 | // }
71 | //
72 | // @Override
73 | // public void onClick(View view) {
74 | // switch (view.getId()) {
75 | // case R.id.btn_podcast_search:
76 | // searching = ProgressDialog.show(this, "Searching ...", "digging through podcasts", true, false);
77 | // searchPodcasts(etPodcastSearch.getText().toString());
78 | // break;
79 | // }
80 | // }
81 | //
82 | //
83 | // private void searchPodcasts(final String searchTerm) {
84 | // Thread t = new Thread() {
85 | // public void run() {
86 | // top25hm = GpodderAPI.searchFeeds(searchTerm);
87 | // top25 = new ArrayList(top25hm.keySet());
88 | // handler.post(displayResults);
89 | // }
90 | // };
91 | // t.start();
92 | // }
93 | //
94 | // private void displayTopPodcasts() {
95 | // Thread t = new Thread() {
96 | // @Override
97 | // public void run() {
98 | // top25hm = GpodderAPI.getTopSubscriptions();
99 | // top25 = new ArrayList(top25hm.keySet());
100 | // handler.post(displayResults);
101 | // }
102 | // };
103 | // t.start();
104 | //
105 | // }
106 | //
107 | // final Runnable displayResults = new Runnable() {
108 | // @Override
109 | // public void run() {
110 | // displayResultsinUI();
111 | // }
112 | // };
113 | //
114 | // private void displayResultsinUI() {
115 | // lvSearchResults.setAdapter(new ArrayAdapter(context, android.R.layout.simple_list_item_1, top25));
116 | // searching.dismiss();
117 | // }
118 | //}
119 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/tools/Tools.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.tools;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 | import android.util.Log;
6 | import com.unitedcoders.android.gpodroid.R;
7 | import org.apache.http.HttpResponse;
8 | import org.apache.http.client.methods.HttpGet;
9 | import org.apache.http.impl.client.DefaultHttpClient;
10 | import org.w3c.dom.Document;
11 | import org.w3c.dom.Element;
12 | import org.w3c.dom.NodeList;
13 | import org.xml.sax.SAXException;
14 |
15 | import javax.xml.parsers.DocumentBuilder;
16 | import javax.xml.parsers.DocumentBuilderFactory;
17 | import java.io.IOException;
18 | import java.io.InputStream;
19 | import java.net.URL;
20 | import java.util.Formatter;
21 | import java.util.Locale;
22 |
23 | public class Tools {
24 |
25 |
26 | // This method is modified from https://github.com/LeifAndersen/NetCatch
27 | /*Copyright 2010 NetCatch Team
28 | *Licensed under the Apache License, Version 2.0 (the "License");
29 | *you may not use this file except in compliance with the License.
30 | *You may obtain a copy of the License at
31 | *
32 | * http://www.apache.org/licenses/LICENSE-2.0
33 | *
34 | *Unless required by applicable law or agreed to in writing, software
35 | *distributed under the License is distributed on an "AS IS" BASIS,
36 | *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 | *See the License for the specific language governing permissions and
38 | *limitations under the License.
39 | */
40 | public static String getImageUrlFromFeed(Context context, String url) {
41 |
42 | try {
43 | Document doc;
44 | DocumentBuilder builder = DocumentBuilderFactory.newInstance()
45 | .newDocumentBuilder();
46 | DefaultHttpClient client = new DefaultHttpClient();
47 | HttpGet request = new HttpGet(url);
48 | HttpResponse response = client.execute(request);
49 | doc = builder.parse(response.getEntity().getContent());
50 | // return doc;
51 |
52 | // get Image
53 | NodeList item = doc.getElementsByTagName("channel");
54 | Element el = (Element) item.item(0);
55 |
56 | String imageUrl;
57 | NodeList imagNode = el.getElementsByTagName("image");
58 | if (imagNode != null) {
59 | Element ima = (Element) imagNode.item(0);
60 | if (ima != null) {
61 | NodeList urlNode = ima.getElementsByTagName("url");
62 | if (urlNode == null || urlNode.getLength() < 1)
63 | imageUrl = null;
64 | else
65 | imageUrl =
66 | urlNode.item(0).getFirstChild().getNodeValue();
67 | } else
68 | imageUrl = null;
69 | } else
70 | imageUrl = null;
71 |
72 | return imageUrl;
73 |
74 | } catch (IOException e) {
75 | return null; // The network probably died, just return null
76 | } catch (SAXException e) {
77 | // Problem parsing the XML, log and return nothing
78 | Log.e("NCRSS", "Error parsing XML", e);
79 | return null;
80 | } catch (Exception e) {
81 | // Anything else was probably another network problem, fail silently
82 | return null;
83 | }
84 |
85 |
86 | }
87 |
88 | public static Drawable LoadImageFromWebOperations(String url) {
89 | try {
90 | InputStream is = (InputStream) new URL(url).getContent();
91 | Drawable d = Drawable.createFromStream(is, "src name");
92 | return d;
93 | } catch (Exception e) {
94 | System.out.println("Exc=" + e);
95 | return null;
96 | }
97 | }
98 |
99 |
100 | private static StringBuilder sFormatBuilder = new StringBuilder();
101 | private static Formatter sFormatter = new Formatter(sFormatBuilder, Locale.getDefault());
102 | private static final Object[] sTimeArgs = new Object[5];
103 |
104 | public static String makeTimeString(Context context, long secs) {
105 | String durationformat = context.getString(
106 | secs < 3600 ? R.string.durationformatshort : R.string.durationformatlong);
107 |
108 | /* Provide multiple arguments so the format can be changed easily
109 | * by modifying the xml.
110 | */
111 | sFormatBuilder.setLength(0);
112 |
113 | final Object[] timeArgs = sTimeArgs;
114 | timeArgs[0] = secs / 3600;
115 | timeArgs[1] = secs / 60;
116 | timeArgs[2] = (secs / 60) % 60;
117 | timeArgs[3] = secs;
118 | timeArgs[4] = secs % 60;
119 |
120 | return sFormatter.format(durationformat, timeArgs).toString();
121 | }
122 |
123 |
124 | }
125 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/activity/SelectDevice.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.activity;
2 |
3 | import android.app.AlertDialog;
4 | import android.app.ListActivity;
5 | import android.app.ProgressDialog;
6 | import android.content.Context;
7 | import android.content.DialogInterface;
8 | import android.content.Intent;
9 | import android.os.Bundle;
10 | import android.os.Handler;
11 | import android.os.Looper;
12 | import android.util.Log;
13 | import android.view.View;
14 | import android.view.View.OnClickListener;
15 | import android.widget.*;
16 | import com.unitedcoders.android.gpodroid.GpodRoid;
17 | import com.unitedcoders.android.gpodroid.Preferences;
18 | import com.unitedcoders.android.gpodroid.R;
19 | import com.unitedcoders.android.gpodroid.database.GpodDB;
20 | import com.unitedcoders.android.gpodroid.services.UpdateService;
21 | import com.unitedcoders.gpodder.GpodderAPI;
22 |
23 | import java.util.ArrayList;
24 |
25 | /*
26 | * Shows gpodder registered devices.
27 | *
28 | * @author Nico Heid
29 | */
30 | public class SelectDevice extends ListActivity implements OnClickListener {
31 |
32 | private Button btnCustomName;
33 | public static ArrayList devices;
34 | private Handler handler;
35 | private ProgressDialog wheel;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 |
41 | handler = new Handler();
42 | setContentView(R.layout.select_device);
43 |
44 | wheel = ProgressDialog.show(this, "", "fetching devices", true);
45 | getDevices();
46 |
47 |
48 | //devices = GpodderAPI.getDevices();
49 | //if (devices == null) {
50 | //Toast.makeText(GpodRoid.context, "Failed to download devices.", Toast.LENGTH_SHORT).show();
51 | // return;
52 | //}
53 | //Log.i("GPR", "populating device list");
54 |
55 | //setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, devices));
56 |
57 | btnCustomName = (Button) findViewById(R.id.btn_customname);
58 | btnCustomName.setOnClickListener(this);
59 |
60 | }
61 |
62 | @Override
63 | protected void onListItemClick(ListView l, View v, int position, long id) {
64 | // TODO Auto-generated method stub
65 | // super.onListItemClick(l, v, position, id);
66 |
67 | String device = (String) l.getItemAtPosition(position);
68 | Log.d(GpodRoid.LOGTAG, "saving device " + device);
69 | saveDevice(device);
70 | GpodDB.wipeClean();
71 | startService(new Intent(GpodRoid.context, UpdateService.class));
72 | Log.d(GpodRoid.LOGTAG, "Started service");
73 | finish();
74 | }
75 |
76 | @Override
77 | public void onClick(View v) {
78 | if (v == btnCustomName) {
79 | customNameDialoge();
80 | }
81 | }
82 |
83 | private void customNameDialoge() {
84 | AlertDialog.Builder alert = new AlertDialog.Builder(this);
85 | final EditText customName = new EditText(this);
86 | alert.setView(customName);
87 | alert.setPositiveButton("Save", new DialogInterface.OnClickListener() {
88 |
89 | @Override
90 | public void onClick(DialogInterface dialog, int which) {
91 | Context cont = GpodRoid.context;
92 | GpodderAPI.createDevice(cont, customName.getText().toString());
93 | devices = GpodderAPI.getDevices();
94 | if (devices == null) {
95 | Toast.makeText(cont, "Failed to download devices.", Toast.LENGTH_SHORT).show();
96 | return;
97 | }
98 | setListAdapter(new ArrayAdapter(GpodRoid.context, android.R.layout.simple_list_item_1, devices));
99 | }
100 | });
101 | alert.setNegativeButton("Cancel", null);
102 | alert.show();
103 | }
104 |
105 | private void saveDevice(String deviceName) {
106 | Preferences.setDevice(deviceName);
107 | Preferences.save();
108 | }
109 |
110 | private void getDevices() {
111 | Thread t = new Thread() {
112 | @Override
113 | public void run() {
114 | Looper.prepare();
115 |
116 | // this check was added because the list of devices may have been retrieved already during the
117 | // account settings activity, so we can skip it here to reduce redundancy
118 | if(devices == null){
119 | devices = GpodderAPI.getDevices();
120 | }
121 |
122 | handler.post(displayResults);
123 | Looper.loop();
124 | }
125 | };
126 | t.start();
127 | }
128 |
129 | final Runnable displayResults = new Runnable() {
130 | @Override
131 | public void run() {
132 | displayResultsInUI();
133 |
134 | }
135 | };
136 |
137 | private void displayResultsInUI() {
138 | wheel.dismiss();
139 | if (devices == null) {
140 | Toast.makeText(GpodRoid.context, "Failed to download devices.", Toast.LENGTH_SHORT).show();
141 | return;
142 | }
143 | Log.i(GpodRoid.LOGTAG, "populating device list");
144 | setListAdapter(new ArrayAdapter(GpodRoid.context, android.R.layout.simple_list_item_1, devices));
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/database/GpodDB.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.database;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 | import android.database.sqlite.SQLiteDatabase;
6 | import android.util.Log;
7 | import com.unitedcoders.android.gpodroid.Episode;
8 | import com.unitedcoders.android.gpodroid.GpodRoid;
9 | import com.unitedcoders.gpodder.GpodderPodcast;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | public final class GpodDB {
15 |
16 | /**
17 | * holds a reference to the SQLite database
18 | */
19 | private static SQLiteDatabase db;
20 |
21 | /**
22 | * The GpodDBHelper class reference
23 | */
24 | private static GpodDBHelper dbHelper;
25 |
26 | /**
27 | * the name of the data base table
28 | */
29 | public static final String DATABASE_TABLE = "podcast";
30 |
31 | /**
32 | * static Constructor
33 | */
34 | static {
35 | dbHelper = new GpodDBHelper(GpodRoid.context);
36 | db = dbHelper.getWritableDatabase();
37 | }
38 |
39 | /**
40 | * This is just here to prevent the class from being initialized via the private visibility
41 | */
42 | private GpodDB() {
43 | // do nothing on purpose
44 | }
45 |
46 | /**
47 | * The finalizer to cleanup the database helper(non-Javadoc)
48 | *
49 | * @see java.lang.Object#finalize()
50 | *
51 | * protected void finalize() {
52 | * if(db != null){
53 | * db.close();
54 | * }
55 | * if(dbHelper != null){
56 | * dbHelper.close();
57 | * }
58 | * }
59 | */
60 |
61 | public static synchronized void addPodcasts(List pce) {
62 | for (int i = 0; i < pce.size(); i++) {
63 |
64 |
65 | GpodderPodcast gpodderPodcast = pce.get(i);
66 |
67 | // do we know this one?
68 | String podcast = gpodderPodcast.getPodcast_title();
69 | String show = gpodderPodcast.getTitle();
70 |
71 | if (podcast == null || show == null) {
72 | Log.e(GpodRoid.LOGTAG,
73 | String.format("did not insert show because either podcast(%s) or show(%s) missing",
74 | podcast, show));
75 | continue;
76 | }
77 |
78 | Cursor c = db.query(DATABASE_TABLE, new String[]{"title"}, "show=? and title=?", new String[]{show, podcast}, null, null, null, "1");
79 |
80 | if (c.getCount() > 0) {
81 | c.close();
82 | continue;
83 | }
84 |
85 |
86 | ContentValues map = new ContentValues();
87 | map.put("file", "");
88 | map.put("show", gpodderPodcast.getTitle());
89 | map.put("title", gpodderPodcast.getPodcast_title());
90 | map.put("url", gpodderPodcast.getUrl());
91 | map.put("downloaded", 0);
92 | map.put("played", 0);
93 | map.put("podcast_url", gpodderPodcast.getPodcast_url());
94 | map.put("released", gpodderPodcast.getReleased());
95 |
96 | long l = db.insert(DATABASE_TABLE, null, map);
97 | c.close();
98 | }
99 | }
100 |
101 | public static void updateEpisode(Episode episode) {
102 | ContentValues values = new ContentValues();
103 | values.put("downloaded", episode.getDownloaded());
104 | values.put("file", episode.getFile());
105 |
106 | db.update(DATABASE_TABLE, values, "show =? and title=?", new String[]{episode.getTitle(), episode.getPodcast_title()});
107 |
108 | }
109 |
110 | public static List getEpisodes(String title) {
111 | Cursor c = db.query(DATABASE_TABLE, new String[]{"show, title, downloaded, url, file, _id, podcast_url"}, "title=?", new String[]{title}, null, null, null);
112 | ArrayList podcasts = new ArrayList();
113 |
114 | if (c.getCount() != 0) {
115 | while (!c.isLast()) {
116 | c.moveToNext();
117 | Episode pce = new Episode(new GpodderPodcast());
118 | pce.setTitle(c.getString(0));
119 | pce.setPodcast_title(c.getString(1));
120 | pce.setDownloaded(c.getInt(2));
121 | pce.setUrl(c.getString(3));
122 | pce.setFile(c.getString(4));
123 | pce.setId(c.getInt(5));
124 | pce.setPodcast_url(c.getString(6));
125 |
126 | podcasts.add(pce);
127 | }
128 | }
129 |
130 | c.close();
131 | return podcasts;
132 |
133 | }
134 |
135 | public static Episode getEpisode(int id) {
136 | Cursor c = db.query(DATABASE_TABLE, new String[]{"show, title, downloaded, url, file, _id, podcast_url"}, "_id=?", new String[]{Integer.toString(id)}, null, null, null);
137 |
138 | Episode pce = new Episode(new GpodderPodcast());
139 | if (c.getCount() != 0) {
140 |
141 | c.moveToFirst();
142 |
143 | pce.setTitle(c.getString(0));
144 | pce.setPodcast_title(c.getString(1));
145 | pce.setDownloaded(c.getInt(2));
146 | pce.setUrl(c.getString(3));
147 | pce.setFile(c.getString(4));
148 | pce.setId(c.getInt(5));
149 | pce.setPodcast_url(c.getString(6));
150 |
151 | }
152 |
153 | c.close();
154 | return pce;
155 |
156 | }
157 |
158 | public static List getPodcasts() {
159 | Cursor c = db.query(true, DATABASE_TABLE, new String[]{"title"}, null, null, null, null, null, null);
160 |
161 | ArrayList shows = new ArrayList();
162 | if (c.getCount() != 0) {
163 | while (!c.isLast()) {
164 | c.moveToNext();
165 | shows.add(c.getString(0));
166 | }
167 | }
168 |
169 | c.close();
170 | return shows;
171 | }
172 |
173 | public static List getDownloads() {
174 | Cursor c = db.query(DATABASE_TABLE, new String[]{"show, title, downloaded, url, file, _id, podcast_url"}, "downloaded=?", new String[]{"0"}, null, null, "released desc", "20");
175 |
176 | ArrayList podcasts = new ArrayList();
177 |
178 | if (c.getCount() != 0) {
179 | while (!c.isLast()) {
180 | c.moveToNext();
181 | Episode pce = new Episode(new GpodderPodcast());
182 | pce.setTitle(c.getString(0));
183 | pce.setPodcast_title(c.getString(1));
184 | pce.setDownloaded(c.getInt(2));
185 | pce.setUrl(c.getString(3));
186 | pce.setFile(c.getString(4));
187 | pce.setId(c.getInt(5));
188 | pce.setPodcast_url(c.getString(6));
189 |
190 | podcasts.add(pce);
191 | }
192 | }
193 |
194 | c.close();
195 | return podcasts;
196 | }
197 |
198 | public static void wipeClean() {
199 | db.delete(DATABASE_TABLE, "_id > ?", new String[]{"-1"});
200 | }
201 | }
202 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/services/DownloadService.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.services;
2 |
3 | import android.app.Notification;
4 | import android.app.NotificationManager;
5 | import android.app.PendingIntent;
6 | import android.app.Service;
7 | import android.content.Intent;
8 | import android.os.Environment;
9 | import android.os.IBinder;
10 | import android.util.Log;
11 | import android.widget.RemoteViews;
12 | import com.unitedcoders.android.gpodroid.Episode;
13 | import com.unitedcoders.android.gpodroid.GpodRoid;
14 | import com.unitedcoders.android.gpodroid.R;
15 | import com.unitedcoders.android.gpodroid.activity.PodcastManager;
16 | import com.unitedcoders.android.gpodroid.database.GpodDB;
17 | import com.unitedcoders.android.gpodroid.tools.Tools;
18 |
19 | import java.io.File;
20 | import java.io.FileOutputStream;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.net.HttpURLConnection;
24 | import java.net.URL;
25 | import java.util.ArrayList;
26 |
27 | public class DownloadService extends Service {
28 |
29 | private final static int DOWNLOADSERVICE_NOTIFICATIONID = 42;
30 |
31 | private int downloaded, totalDownloadSize;
32 | private Intent intent;
33 |
34 | public static ArrayList downloadQueue = new ArrayList();
35 |
36 | @Override
37 | public IBinder onBind(Intent intent) {
38 | // TODO Auto-generated method stub
39 | return null;
40 | }
41 |
42 | @Override
43 | public void onCreate() {
44 | // TODO Auto-generated method stub
45 | super.onCreate();
46 | }
47 |
48 | @Override
49 | public void onStart(Intent intent, int startId) {
50 | // TODO Auto-generated method stub
51 | super.onStart(intent, startId);
52 | this.intent = intent;
53 |
54 | downloadPodcast.start();
55 |
56 | stopSelf();
57 |
58 | }
59 |
60 | private Thread downloadPodcast = new Thread() {
61 |
62 | public void run() {
63 | Episode episode = null;
64 | while (downloadQueue.size() > 0 && (episode = downloadQueue.get(0)) != null) {
65 | try {
66 | String downloadUrl = episode.getUrl();
67 |
68 | File name = new File(downloadUrl);
69 | String fileName = name.getName().trim();
70 | File SDCardRoot = Environment.getExternalStorageDirectory();
71 | String storageLocation = SDCardRoot.getAbsolutePath() + "/gpodroid/";
72 |
73 | download(downloadUrl, storageLocation, fileName, "downloading " + episode.getTitle());
74 |
75 | episode.setFile(storageLocation + fileName);
76 | episode.setDownloaded(1);
77 | GpodDB.updateEpisode(episode);
78 |
79 | // get imageurl from url
80 | String imageLocation = Tools.getImageUrlFromFeed(getApplicationContext(), episode.getPodcast_url());
81 | download(imageLocation, storageLocation + "covers/", episode.getPodcast_title().trim(), "downloading cover");
82 |
83 |
84 | } catch (IOException e) {
85 | Log.e("Gpodroid", "error when downloading " + episode.getPodcast_url(), e);
86 |
87 | } finally {
88 | if (downloadQueue.size() >= 1) {
89 | downloadQueue.remove(0);
90 | }
91 | }
92 |
93 | // Toast.makeText(this, "download ended", Toast.LENGTH_LONG);
94 |
95 | }
96 | }
97 |
98 | };
99 |
100 | /**
101 | * @param sourceLocation location of the download in the web
102 | * @param storageLocation directory to store the data on sdcard
103 | * @param fileName name of the file after download
104 | * @param displayText what text to show in the notificationbar
105 | * @throws IOException
106 | */
107 | private void download(String sourceLocation, String storageLocation, String fileName, String displayText) throws IOException {
108 | Log.d("Gpodroid", "starting download " + sourceLocation);
109 | URL podcastURL = new URL(sourceLocation);
110 | HttpURLConnection urlConnection = (HttpURLConnection) podcastURL.openConnection();
111 | urlConnection.setRequestMethod("GET");
112 | urlConnection.setDoOutput(true);
113 |
114 | urlConnection.connect();
115 |
116 | new File(storageLocation).mkdir();
117 |
118 | // File name = new File(podcastURL.toString());
119 | // String saveName = name.getName().trim();
120 | File file = new File(storageLocation, fileName);
121 | FileOutputStream fileOutput = new FileOutputStream(file);
122 | InputStream inputStream = urlConnection.getInputStream();
123 | totalDownloadSize = urlConnection.getContentLength();
124 |
125 | byte[] buffer = new byte[1024];
126 | int bufferLength = 0;
127 | downloaded = 0;
128 |
129 | // put download info in notification bar
130 | final Notification notification = new Notification(R.drawable.icon, "downloading podcast", System
131 | .currentTimeMillis());
132 | notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
133 | notification.contentView = new RemoteViews(getApplicationContext().getPackageName(),
134 | R.layout.download_progress);
135 | Intent intent = new Intent(getApplicationContext(), PodcastManager.class);
136 | final PendingIntent pendingIntent = PendingIntent
137 | .getActivity(getApplicationContext(), 0, intent, 0);
138 |
139 | notification.contentIntent = pendingIntent;
140 |
141 | notification.contentView.setImageViewResource(R.id.status_icon, android.R.drawable.ic_menu_save);
142 | notification.contentView.setTextViewText(R.id.status_text, displayText);
143 |
144 | notification.contentView.setProgressBar(R.id.status_progress, totalDownloadSize, downloaded,
145 | false);
146 |
147 | final NotificationManager notificationManager = (NotificationManager) getApplicationContext()
148 | .getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
149 |
150 | notificationManager.notify(DOWNLOADSERVICE_NOTIFICATIONID, notification);
151 |
152 | int nextNotification = 0;
153 | // now, read through the input buffer and write the contents
154 | // to the file
155 | while ((bufferLength = inputStream.read(buffer)) > 0) {
156 | // add the data in the buffer to the file in the file
157 | // output stream (the file on the sd card
158 | fileOutput.write(buffer, 0, bufferLength);
159 | // add up the size so we know how much is downloaded
160 | downloaded += bufferLength;
161 |
162 | // update notification
163 | if (downloaded >= nextNotification) {
164 | notification.contentView.setProgressBar(R.id.status_progress, totalDownloadSize,
165 | downloaded, false);
166 | notificationManager.notify(DOWNLOADSERVICE_NOTIFICATIONID, notification);
167 | nextNotification += totalDownloadSize / 5;
168 | }
169 |
170 | }
171 |
172 | notificationManager.cancel(DOWNLOADSERVICE_NOTIFICATIONID);
173 | fileOutput.close();
174 |
175 | Log.d(GpodRoid.LOGTAG, "finished download " + sourceLocation + " in " + storageLocation + fileName);
176 |
177 |
178 | }
179 |
180 | }
181 |
182 |
183 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/activity/Player.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.activity;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.media.MediaPlayer;
8 | import android.os.Bundle;
9 | import android.os.Environment;
10 | import android.os.Handler;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.view.View.OnClickListener;
14 | import android.widget.*;
15 | import com.unitedcoders.android.gpodroid.Episode;
16 | import com.unitedcoders.android.gpodroid.GpodRoid;
17 | import com.unitedcoders.android.gpodroid.R;
18 | import com.unitedcoders.android.gpodroid.RoboActivityDefaultMenu;
19 | import com.unitedcoders.android.gpodroid.database.GpodDB;
20 | import com.unitedcoders.android.gpodroid.services.UpdateService;
21 | import com.unitedcoders.android.gpodroid.tools.Tools;
22 | import roboguice.inject.InjectView;
23 |
24 | import java.io.File;
25 | import java.io.IOException;
26 |
27 | /**
28 | * Shows the MediaPlayer and controls
29 | *
30 | * @author Nico Heid
31 | */
32 | public class Player extends RoboActivityDefaultMenu implements OnClickListener, SeekBar.OnSeekBarChangeListener {
33 |
34 | final Handler handler = new Handler();
35 | private static int playbackPosition;
36 |
37 | public static MediaPlayer mp;
38 |
39 | // Element playing
40 | public static Episode pce;
41 | public static boolean switchPodcast;
42 |
43 | // podcast information
44 | @InjectView(R.id.tv_podcast_title)
45 | private TextView tvTitle;
46 | @InjectView(R.id.tv_episode_name)
47 | private TextView tvEpisode;
48 | @InjectView(R.id.tv_total_time)
49 | private TextView tvTotalTime;
50 | @InjectView(R.id.tv_position_time)
51 | private TextView tvPositionTime;
52 |
53 | // cover art
54 | @InjectView(R.id.iv_cover)
55 | private ImageView ivCover;
56 |
57 | // buttons
58 | @InjectView(R.id.btn_forward)
59 | private ImageButton btnForward;
60 | @InjectView(R.id.btn_backward)
61 | private ImageButton btnBackward;
62 | @InjectView(R.id.btn_play)
63 | private ImageButton btnPlay;
64 | @InjectView(R.id.bar_playback)
65 | private SeekBar barProgress;
66 |
67 | @Override
68 | protected void onCreate(Bundle savedInstanceState) {
69 | super.onCreate(savedInstanceState);
70 | setContentView(R.layout.playerview);
71 |
72 | startService(new Intent(getApplicationContext(), UpdateService.class));
73 |
74 | if (!switchPodcast) {
75 | loadPlaybackState();
76 | } else {
77 | playbackPosition = 0;
78 | switchPodcast = false;
79 | }
80 |
81 | barProgress.setOnSeekBarChangeListener(this);
82 | btnForward.setOnClickListener(this);
83 | btnBackward.setOnClickListener(this);
84 | btnPlay.setOnClickListener(this);
85 |
86 | if (pce != null) {
87 | play();
88 | }
89 | }
90 |
91 |
92 | @Override
93 | protected void onDestroy() {
94 |
95 | savePlaybackState();
96 | super.onDestroy();
97 |
98 | }
99 |
100 |
101 | private void play() {
102 |
103 | if (pce == null) {
104 | Toast.makeText(GpodRoid.context, "please select a podcast first", Toast.LENGTH_SHORT).show();
105 | return;
106 | }
107 |
108 |
109 | try {
110 | ivCover.setImageResource(R.drawable.cd);
111 | File SDCardRoot = Environment.getExternalStorageDirectory();
112 | String storageLocation = SDCardRoot.getAbsolutePath() + "/gpodroid/covers";
113 | File cover = new File(storageLocation + "/" + pce.getPodcast_title().trim());
114 | Bitmap bm;
115 | if (cover.exists()) {
116 | bm = BitmapFactory.decodeFile(storageLocation + "/" + pce.getPodcast_title().trim());
117 | ivCover.setImageBitmap(bm);
118 | }
119 | } catch (Exception e) {
120 | Log.d(GpodRoid.LOGTAG, "cannot set cover", e);
121 | ivCover.setImageResource(R.drawable.cd);
122 |
123 | }
124 |
125 |
126 | if (pce == null) {
127 | Toast.makeText(GpodRoid.context, "cannot resume podcast, please choose again", Toast.LENGTH_SHORT).show();
128 | return;
129 | }
130 |
131 | try {
132 | if (mp == null) {
133 | mp = new MediaPlayer();
134 | }
135 | mp.reset();
136 | mp.setDataSource(pce.getFile());
137 | mp.prepare();
138 | mp.start();
139 | mp.seekTo(playbackPosition);
140 |
141 | progressReader();
142 |
143 | btnPlay.setImageResource(android.R.drawable.ic_media_pause);
144 | } catch (IllegalArgumentException e) {
145 | Log.e(GpodRoid.LOGTAG, "failure starting player", e);
146 | } catch (IllegalStateException e) {
147 | Log.e(GpodRoid.LOGTAG, "failure starting player", e);
148 | } catch (IOException e) {
149 | Log.e(GpodRoid.LOGTAG, "failure starting player", e);
150 | }
151 |
152 | tvEpisode.setText(pce.getTitle());
153 | tvTitle.setText(pce.getPodcast_title());
154 | tvTotalTime.setText(Tools.makeTimeString(this, mp.getDuration() / 1000));
155 |
156 | }
157 |
158 | public void openPodcastManager(View v) {
159 | Intent intent = new Intent(this, PodcastManager.class);
160 | startActivity(intent);
161 | }
162 |
163 | @Override
164 | public void onClick(View view) {
165 | if (pce == null) {
166 | Intent intent = new Intent(getApplicationContext(), PodcastManager.class);
167 | startActivity(intent);
168 | }
169 |
170 |
171 | switch (view.getId()) {
172 | case R.id.btn_backward:
173 | seek(-mp.getDuration() / 50);
174 | break;
175 | case R.id.btn_forward:
176 | seek(mp.getDuration() / 50);
177 | break;
178 | case R.id.btn_play:
179 | startFailsafePlayback();
180 | break;
181 | }
182 |
183 | }
184 |
185 | private void startFailsafePlayback() {
186 | if (mp == null) {
187 | play();
188 | }
189 |
190 | // we could still have failed to initialize a player
191 | if (mp == null) {
192 | Toast.makeText(GpodRoid.context, "please choose a podcast first", Toast.LENGTH_SHORT).show();
193 | } else {
194 | if (mp.isPlaying()) {
195 | savePlaybackState();
196 | btnPlay.setImageResource(android.R.drawable.ic_media_play);
197 | mp.pause();
198 | } else {
199 | mp.start();
200 | btnPlay.setImageResource(android.R.drawable.ic_media_pause);
201 | progressReader();
202 | }
203 | }
204 | }
205 |
206 |
207 | private void seek(int seek) {
208 | int position = mp.getCurrentPosition();
209 | mp.seekTo(position + seek);
210 | }
211 |
212 | final Runnable changeProgress = new Runnable() {
213 | @Override
214 | public void run() {
215 | updateProgress();
216 | }
217 | };
218 |
219 | private void updateProgress
220 | () {
221 | if (mp != null) {
222 | int position = mp.getCurrentPosition();
223 | barProgress.setProgress(position);
224 | tvPositionTime.setText(Tools.makeTimeString(this, position / 1000));
225 | }
226 | }
227 |
228 |
229 | protected void progressReader
230 | () {
231 | Thread t = new Thread() {
232 | public void run() {
233 | int total = mp.getDuration();
234 | barProgress.setMax(total);
235 | while (mp != null && mp.isPlaying() && playbackPosition < total) {
236 | try {
237 | Thread.sleep(1000);
238 | handler.post(changeProgress);
239 | } catch (InterruptedException e) {
240 | return;
241 | } catch (Exception e) {
242 | return;
243 | }
244 | }
245 | }
246 | };
247 | t.start();
248 | }
249 |
250 |
251 | @Override
252 | public void onProgressChanged
253 | (SeekBar
254 | seekBar, int progress,
255 | boolean fromUser) {
256 | if (fromUser) {
257 | playbackPosition = progress;
258 | if (mp != null && mp.isPlaying()) {
259 | mp.seekTo(progress);
260 | }
261 | }
262 | }
263 |
264 | @Override
265 | public void onStartTrackingTouch
266 | (SeekBar
267 | seekBar) {
268 | //To change body of implemented methods use File | Settings | File Templates.
269 | }
270 |
271 | @Override
272 | public void onStopTrackingTouch
273 | (SeekBar
274 | seekBar) {
275 | //To change body of implemented methods use File | Settings | File Templates.
276 | }
277 |
278 | private void savePlaybackState
279 | () {
280 | if (pce != null) {
281 | // save playback state
282 | SharedPreferences settings = getApplicationContext().getSharedPreferences("PLAYBACKSTATE", 0);
283 | SharedPreferences.Editor editor = settings.edit();
284 |
285 | editor.putInt("PCE", pce.getId());
286 | editor.putInt("SEEKPOSITION", mp.getCurrentPosition());
287 | editor.commit();
288 | }
289 | }
290 |
291 | private void loadPlaybackState
292 | () {
293 | SharedPreferences settings = getApplicationContext().getSharedPreferences("PLAYBACKSTATE", 0);
294 | int id = settings.getInt("PCE", 0);
295 | playbackPosition = settings.getInt("SEEKPOSITION", 0);
296 |
297 | if (id > 0) {
298 | pce = GpodDB.getEpisode(id);
299 | }
300 | }
301 |
302 | //TODO release mediaplayer if its not in use for a while
303 | // workaround for http://code.google.com/p/android/issues/detail?id=4124
304 |
305 |
306 | }
307 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Eclipse Public License - v 1.0
2 |
3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4 |
5 | 1. DEFINITIONS
6 |
7 | "Contribution" means:
8 |
9 | a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
10 | b) in the case of each subsequent Contributor:
11 | i) changes to the Program, and
12 | ii) additions to the Program;
13 | where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
14 | "Contributor" means any person or entity that distributes the Program.
15 |
16 | "Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
17 |
18 | "Program" means the Contributions distributed in accordance with this Agreement.
19 |
20 | "Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
21 |
22 | 2. GRANT OF RIGHTS
23 |
24 | a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
25 | b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
26 | c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
27 | d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
28 | 3. REQUIREMENTS
29 |
30 | A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
31 |
32 | a) it complies with the terms and conditions of this Agreement; and
33 | b) its license agreement:
34 | i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
35 | ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
36 | iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
37 | iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
38 | When the Program is made available in source code form:
39 |
40 | a) it must be made available under this Agreement; and
41 | b) a copy of this Agreement must be included with each copy of the Program.
42 | Contributors may not remove or alter any copyright notices contained within the Program.
43 |
44 | Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
45 |
46 | 4. COMMERCIAL DISTRIBUTION
47 |
48 | Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
49 |
50 | For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
51 |
52 | 5. NO WARRANTY
53 |
54 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
55 |
56 | 6. DISCLAIMER OF LIABILITY
57 |
58 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
59 |
60 | 7. GENERAL
61 |
62 | If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
63 |
64 | If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
65 |
66 | All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
67 |
68 | Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
69 |
70 | This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
--------------------------------------------------------------------------------
/src/com/unitedcoders/gpodder/GpodderAPI.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.gpodder;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageInfo;
5 | import android.content.pm.PackageManager;
6 | import android.util.Log;
7 | import android.webkit.WebView;
8 | import com.unitedcoders.android.gpodroid.*;
9 | import org.apache.commons.io.IOUtils;
10 | import org.codehaus.jackson.JsonParseException;
11 | import org.codehaus.jackson.map.JsonMappingException;
12 | import org.codehaus.jackson.map.ObjectMapper;
13 | import org.json.JSONArray;
14 | import org.json.JSONObject;
15 |
16 | import java.io.BufferedReader;
17 | import java.io.IOException;
18 | import java.io.InputStream;
19 | import java.io.InputStreamReader;
20 | import java.io.OutputStreamWriter;
21 | import java.net.URL;
22 | import java.net.URLConnection;
23 | import java.util.ArrayList;
24 | import java.util.Date;
25 | import java.util.HashMap;
26 |
27 | /**
28 | * The calls against gpodder.net API
29 | *
30 | * @author Nico Heid
31 | */
32 | public class GpodderAPI {
33 |
34 | /**
35 | * the base url for the gpodder.net server
36 | */
37 | private static final String GPODDER_BASE = "http://gpodder.net";
38 |
39 | /**
40 | * the name of the gpodroid preferences
41 | */
42 | public static final String PREFS_NAME = "gpodroidPrefs";
43 |
44 | /**
45 | * The custom User-Agent we send for http requests
46 | * uses GpodroidVersion + default Webview agent information
47 | */
48 | private static String customUserAgent = null;
49 |
50 | /**
51 | * this method is used as a helper to create an url connection
52 | * @param urlStr
53 | * @param useAuthentication
54 | * @param setOutput
55 | * @return
56 | */
57 | private static URLConnection createUrlConnection(String urlStr, Boolean useAuthentication, Boolean setOutput) {
58 | Log.i(GpodRoid.LOGTAG, "Creating Connection: " + urlStr);
59 |
60 | // set custom User-Agent string
61 | if (customUserAgent == null) {
62 | try {
63 | PackageInfo packageInfo = GpodRoid.context.getPackageManager().getPackageInfo(GpodRoid.context.getPackageName(), 0);
64 | String webviewAgent = new WebView(GpodRoid.context).getSettings().getUserAgentString();
65 | customUserAgent = "GpodRoid " + packageInfo.versionName+" "+webviewAgent;
66 | } catch (PackageManager.NameNotFoundException e) {
67 | Log.e(GpodRoid.LOGTAG, "error setting version info in header", e);
68 | customUserAgent = "GpodRoid undefined";
69 | }
70 | }
71 |
72 | URLConnection conn = null;
73 | try {
74 | conn = new URL(urlStr).openConnection();
75 | conn.setDoOutput(setOutput);
76 | conn.setDoInput(true);
77 |
78 | if (useAuthentication) {
79 | String encoded = Preferences.getEncryptedAuthentication();
80 | conn.setRequestProperty("Authorization", "basic " + encoded);
81 | }
82 | conn.addRequestProperty("User-Agent", customUserAgent);
83 | } catch (Exception e) {
84 | Log.e(GpodRoid.LOGTAG, "Error creating Connection: " + stackTrace(e));
85 | return null;
86 | }
87 |
88 | return conn;
89 | }
90 |
91 | public static String stackTrace(Exception e) {
92 | String eol = System.getProperty("line.separator");
93 | String stack = eol + e.getMessage() + eol;
94 |
95 | StackTraceElement[] stackTraces = e.getStackTrace();
96 | for (int cste = 0; cste < stackTraces.length; cste++) {
97 | stack += stackTraces[cste].toString() + eol;
98 | }
99 |
100 | return stack;
101 | }
102 |
103 | /**
104 | * Gets a list of gpodder updates since today's date
105 | * @return
106 | */
107 | public static GpodderUpdates getDownloadList() {
108 | InputStream is = null;
109 | GpodderUpdates updates = null;
110 | // try to get the updates
111 | try {
112 | Long since = (new Date().getTime() / 1000) - 3600 * 24 * 56;
113 | String urlStr = GPODDER_BASE + "/api/2/updates/" + Preferences.getUsername() + "/" + Preferences.getDevice() + ".json?since=" + since;
114 | URLConnection conn = createUrlConnection(urlStr, true, false);
115 | is = conn.getInputStream();
116 | updates = new ObjectMapper().readValue(is, GpodderUpdates.class);
117 | }
118 | catch (JsonParseException e){
119 | Log.e(GpodRoid.LOGTAG, "Failed to parse subscription list: " + stackTrace(e));
120 | }
121 | catch (JsonMappingException e){
122 | Log.e(GpodRoid.LOGTAG, "Failed to map subscription list: " + stackTrace(e));
123 | }
124 | catch(IOException e){
125 | Log.e(GpodRoid.LOGTAG, "Failed to download the subscription list: " + stackTrace(e));
126 | }
127 | catch (Exception e) {
128 | Log.e(GpodRoid.LOGTAG, "General error getting subscription list: " + stackTrace(e));
129 | }
130 | finally{
131 | if(is != null){
132 | try {
133 | is.close();
134 | } catch (IOException e) {
135 | Log.e(GpodRoid.LOGTAG, "Failed to close input stream: " + stackTrace(e));
136 | }
137 | }
138 | }
139 | return updates;
140 | }
141 |
142 | public static void createDevice(Context context, String deviceName) {
143 | String urlStr = String.format(GPODDER_BASE + "/api/2/devices/%s/gpodroid.json", Preferences.getUsername());
144 | JSONObject device = new JSONObject();
145 |
146 | try {
147 | device.put("caption", deviceName);
148 | device.put("id", deviceName);
149 | device.put("type", "mobile");
150 | URLConnection con = createUrlConnection(urlStr, true, true);
151 | OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
152 | out.write(device.toString());
153 | out.close();
154 |
155 | BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
156 |
157 | String decodedString;
158 |
159 | while ((decodedString = in.readLine()) != null) {
160 | System.out.println(decodedString);
161 | }
162 | in.close();
163 |
164 | } catch (Exception e) {
165 | Log.e(GpodRoid.LOGTAG, "error creating device", e);
166 | }
167 |
168 | }
169 |
170 | /**
171 | * gets the devices associated with the user
172 | *
173 | * @return ArrayList A list of strings which are the names of the devices
174 | */
175 | public static ArrayList getDevices() {
176 | ArrayList gpodderDevices = new ArrayList();
177 | String urlStr = GPODDER_BASE + "/api/2/devices/" + Preferences.getUsername() + ".json";
178 | try {
179 | URLConnection conn = createUrlConnection(urlStr, true, false);
180 | InputStream stream = conn.getInputStream();
181 | String response = IOUtils.toString(stream);
182 | JSONArray devices = new JSONArray(response);
183 |
184 | for (int i = 0; i < devices.length(); i++) {
185 | String add = devices.getJSONObject(i).getString("id");
186 | gpodderDevices.add(add);
187 | }
188 | Log.i(GpodRoid.LOGTAG, "Successfully downloaded devices.");
189 |
190 | } catch (Exception e) {
191 | Log.e(GpodRoid.LOGTAG, "Error downloading devices: " + stackTrace(e));
192 | return null;
193 | }
194 | return gpodderDevices;
195 | }
196 |
197 | public static HashMap getTopSubscriptions() {
198 | HashMap subscriptions = new HashMap();
199 |
200 | String urlStr = GPODDER_BASE + "/toplist/25.json";
201 | try {
202 | URLConnection conn = createUrlConnection(urlStr, false, false);
203 | String response = IOUtils.toString(conn.getInputStream());
204 | JSONArray top25 = new JSONArray(response);
205 | for (int i = 0; i < top25.length(); i++) {
206 | String title = top25.getJSONObject(i).getString("title");
207 | String subUrl = top25.getJSONObject(i).getString("url");
208 | subscriptions.put(title, subUrl);
209 |
210 | }
211 | Log.i(GpodRoid.LOGTAG, "Successfully downloaded top subscriptions.");
212 | } catch (Exception e) {
213 | Log.e(GpodRoid.LOGTAG, "Error getting Top Subscriptions:" + stackTrace(e));
214 | }
215 |
216 | return subscriptions;
217 | }
218 |
219 | public static HashMap searchFeeds(String searchTerm) {
220 | HashMap subscriptions = new HashMap();
221 | String urlStr = GPODDER_BASE + "/search.json?q=SEARCHTERM";
222 | urlStr = urlStr.replace("SEARCHTERM", searchTerm);
223 | try {
224 | URLConnection conn = createUrlConnection(urlStr, false, false);
225 | String response = IOUtils.toString(conn.getInputStream());
226 | JSONArray top25 = new JSONArray(response);
227 | for (int i = 0; i < top25.length(); i++) {
228 | String title = top25.getJSONObject(i).getString("title");
229 | String subUrl = top25.getJSONObject(i).getString("url");
230 | subscriptions.put(title, subUrl);
231 |
232 | }
233 | } catch (Exception e) {
234 | Log.e(GpodRoid.LOGTAG, "Error searching feeds:" + stackTrace(e));
235 | }
236 |
237 | return subscriptions;
238 |
239 | }
240 |
241 | public static void addSubcription(String url) {
242 | String urlStr = GPODDER_BASE + "/api/1/subscriptions/USERNAME/DEVICE.json";
243 | JSONObject device = new JSONObject();
244 | JSONArray urls = new JSONArray();
245 |
246 | try {
247 | urls.put(url);
248 | device.put("add", urls);
249 | urlStr = urlStr.replace("USERNAME", Preferences.getUsername());
250 | urlStr = urlStr.replace("DEVICE", Preferences.getDevice());
251 | URLConnection con = createUrlConnection(urlStr, true, false);
252 | con.setDoOutput(true);
253 |
254 | Log.d(GpodRoid.LOGTAG, "sending subscription: " + urlStr + " with body " + device.toString());
255 | OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
256 | out.write(device.toString());
257 | out.close();
258 |
259 | BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
260 |
261 | String decodedString;
262 |
263 | StringBuffer response = new StringBuffer();
264 | while ((decodedString = in.readLine()) != null) {
265 | response.append(decodedString);
266 | // System.out.println(decodedString);
267 |
268 | }
269 | in.close();
270 |
271 | Log.d(GpodRoid.LOGTAG, "Result of subscription request: "+response.toString());
272 |
273 | } catch (Exception e) {
274 | Log.e(GpodRoid.LOGTAG, "Error adding subscription:" + stackTrace(e));
275 | }
276 | }
277 | }
278 |
--------------------------------------------------------------------------------
/src/com/unitedcoders/android/gpodroid/activity/PodcastManager.java:
--------------------------------------------------------------------------------
1 | package com.unitedcoders.android.gpodroid.activity;
2 |
3 | import android.app.AlertDialog;
4 | import android.app.ProgressDialog;
5 | import android.content.*;
6 | import android.os.Bundle;
7 | import android.os.Handler;
8 | import android.util.Log;
9 | import android.view.*;
10 | import android.view.View.OnClickListener;
11 | import android.widget.*;
12 | import android.widget.AdapterView.OnItemClickListener;
13 | import com.unitedcoders.android.gpodroid.*;
14 | import com.unitedcoders.android.gpodroid.database.GpodDB;
15 | import com.unitedcoders.android.gpodroid.services.DownloadService;
16 | import com.unitedcoders.android.gpodroid.services.UpdateService;
17 | import com.unitedcoders.gpodder.GpodderAPI;
18 | import roboguice.activity.RoboTabActivity;
19 | import roboguice.inject.InjectView;
20 |
21 | import java.io.File;
22 | import java.util.ArrayList;
23 | import java.util.HashMap;
24 | import java.util.List;
25 |
26 | public class PodcastManager extends RoboTabActivity implements OnClickListener {
27 |
28 | private TabHost mTabHost;
29 |
30 | // podcasts in archive
31 | @InjectView(R.id.lv_shows)
32 | private ListView lvShows;
33 | @InjectView(R.id.lv_podcasts)
34 | private ListView lvPodcasts;
35 | @InjectView(R.id.lv_downloads)
36 | private ListView lvDownloads;
37 | // private ListView lvDownloads;
38 |
39 | @InjectView(R.id.tabmgr_sdcard)
40 | private ViewFlipper sdcardFlipper;
41 | private PodcastListAdapter podcastAdapter;
42 | private PodcastListAdapter downloadAdapter;
43 | private ArrayAdapter showAdapter;
44 |
45 |
46 | private PodcastListAdapter pcla;
47 | private static String show = "";
48 |
49 | private boolean podcastSubmenu = false;
50 |
51 | public static boolean archiveDirty = false;
52 | private static IntentFilter filter = new IntentFilter();
53 |
54 | @InjectView(R.id.lv_search_results) ListView lvSearchResults;
55 | ProgressDialog searching;
56 |
57 |
58 | @InjectView(R.id.btn_podcast_search) ImageButton btnPodcastSearch;
59 | @InjectView(R.id.et_podcast_search) EditText etPodcastSearch;
60 |
61 |
62 | private final Handler handler = new Handler();
63 | ArrayList top25;
64 | HashMap top25hm;
65 |
66 |
67 | static {
68 | filter.addAction(GpodRoid.BROADCAST_SUBSCRIPTION_CHANGE);
69 | }
70 |
71 | @Override
72 | protected void onCreate(Bundle savedInstanceState) {
73 | super.onCreate(savedInstanceState);
74 | setContentView(R.layout.podcast_manager);
75 |
76 | sdcardFlipper.setOnClickListener(this);
77 |
78 | mTabHost = getTabHost();
79 |
80 | mTabHost.addTab(mTabHost.newTabSpec("tab_podcasts").setIndicator("Podcasts").setContent(R.id.tabmgr_sdcard));
81 | mTabHost.addTab(mTabHost.newTabSpec("tab_new").setIndicator("New").setContent(R.id.tabmgr_subscriptions));
82 | mTabHost.addTab(mTabHost.newTabSpec("tab_search").setIndicator("Search").setContent(R.id.tabmgr_podcast_search));
83 |
84 | mTabHost.setCurrentTab(0);
85 |
86 | registerForContextMenu(lvSearchResults);
87 |
88 | etPodcastSearch.setOnClickListener(new OnClickListener() {
89 | @Override
90 | public void onClick(View view) {
91 | if (etPodcastSearch.getText().toString().equals("search for subscriptions")) {
92 | etPodcastSearch.setText("");
93 | }
94 | }
95 | });
96 |
97 | }
98 |
99 | @Override
100 | public void onResume() {
101 | GpodRoid.context.registerReceiver(subscriptionChangeReceiver, filter);
102 | showShows(false);
103 | showDownloads();
104 |
105 | super.onResume();
106 | }
107 |
108 | @Override
109 | public void onPause() {
110 | GpodRoid.context.unregisterReceiver(subscriptionChangeReceiver);
111 | super.onPause();
112 | }
113 |
114 | @Override
115 | public boolean onKeyDown(int keyCode, KeyEvent event) {
116 |
117 | // if we're in the podcast view bring us back to archive view
118 | // so it feels like regular behavior
119 | if ((keyCode == KeyEvent.KEYCODE_BACK)) {
120 | if (podcastSubmenu) {
121 | sdcardFlipper.showNext();
122 | podcastSubmenu = !podcastSubmenu;
123 | return true;
124 | }
125 | }
126 | return super.onKeyDown(keyCode, event);
127 | }
128 |
129 |
130 | private void showEpisodes(String show, boolean flipView) {
131 |
132 | List shows = GpodDB.getEpisodes(show);
133 |
134 | podcastAdapter = new PodcastListAdapter(GpodRoid.context, shows);
135 | lvPodcasts.setAdapter(podcastAdapter);
136 |
137 | if (flipView) {
138 | podcastSubmenu = true;
139 | sdcardFlipper.showNext();
140 | }
141 |
142 | // download or play depending on if we have the show
143 | lvPodcasts.setOnItemClickListener(new OnItemClickListener() {
144 |
145 | @Override
146 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
147 |
148 | // ask for download if not present, or start playing
149 | final Episode episode = (Episode) parent.getItemAtPosition(position);
150 | //final Intent downloadService = new Intent(GpodRoid.context, DownloadService.class);
151 | if (episode.getDownloaded() == 0) {
152 | addToDownloadQueue(parent, position);
153 | } else {
154 | Toast.makeText(GpodRoid.context, "starting podcast", Toast.LENGTH_SHORT).show();
155 | Intent intent = new Intent(GpodRoid.context, Player.class);
156 | Player.pce = episode;
157 | Player.switchPodcast = true;
158 | startActivity(intent);
159 | }
160 |
161 | }
162 | });
163 |
164 | lvPodcasts.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
165 | @Override
166 | public boolean onItemLongClick(final AdapterView> av, View v, final int pos, long id) {
167 |
168 | final AlertDialog alert = new AlertDialog.Builder(lvPodcasts.getContext()).create();
169 | alert.setTitle("Delete");
170 | alert.setMessage("Delete Podcast?");
171 | alert.setButton("OK", new DialogInterface.OnClickListener() {
172 | @Override
173 | public void onClick(DialogInterface dialogInterface, int i) {
174 | Episode episode = (Episode) av.getItemAtPosition(pos);
175 | if (episode.getDownloaded() != 1) {
176 | return;
177 | }
178 | File f = new File(episode.getFile());
179 | f.delete();
180 | episode.setDownloaded(0);
181 | GpodDB.updateEpisode(episode);
182 |
183 | }
184 | });
185 | alert.setButton2("CANCEL", new DialogInterface.OnClickListener() {
186 | @Override
187 | public void onClick(DialogInterface dialogInterface, int i) {
188 | alert.cancel();
189 | }
190 | });
191 | alert.show();
192 | return false;
193 |
194 | }
195 |
196 | });
197 |
198 |
199 | }
200 |
201 | private void showShows(boolean flipView) {
202 |
203 | if (flipView) {
204 | podcastSubmenu = false;
205 | }
206 |
207 | List shows = GpodDB.getPodcasts();
208 |
209 | showAdapter = new ArrayAdapter(GpodRoid.context, android.R.layout.simple_list_item_1, shows);
210 | lvShows.setAdapter(showAdapter);
211 | // lvAlbums.setOnClickListener(this);
212 |
213 |
214 | lvShows.setOnItemClickListener(new OnItemClickListener() {
215 |
216 | @Override
217 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
218 | show = (String) parent.getItemAtPosition(position);
219 |
220 | showEpisodes(show, true);
221 | }
222 | });
223 |
224 |
225 | }
226 |
227 | private void showDownloads() {
228 | List shows = GpodDB.getDownloads();
229 | downloadAdapter = new PodcastListAdapter(GpodRoid.context, shows);
230 | lvDownloads.setAdapter(downloadAdapter);
231 |
232 | lvDownloads.setOnItemClickListener(new OnItemClickListener() {
233 | @Override
234 | public void onItemClick(AdapterView> parent, View view, int position, long l) {
235 | addToDownloadQueue(parent, position);
236 | }
237 | });
238 |
239 |
240 | }
241 |
242 | /**
243 | * adds the show to the download queue
244 | *
245 | * @param parent
246 | * @param position
247 | */
248 | private void addToDownloadQueue(AdapterView> parent, int position) {
249 | final Episode episode = (Episode) parent.getItemAtPosition(position);
250 | final Intent downloadService = new Intent(GpodRoid.context, DownloadService.class);
251 |
252 | // get confirmation for download
253 | final AlertDialog alert = new AlertDialog.Builder(lvPodcasts.getContext()).create();
254 | alert.setTitle("Download");
255 | alert.setMessage("Download Podcast now?");
256 | alert.setButton("OK", new DialogInterface.OnClickListener() {
257 | @Override
258 | public void onClick(DialogInterface dialogInterface, int i) {
259 | DownloadService.downloadQueue.add(episode);
260 | startService(downloadService);
261 | }
262 | });
263 | alert.setButton2("CANCEL", new DialogInterface.OnClickListener() {
264 | @Override
265 | public void onClick(DialogInterface dialogInterface, int i) {
266 | alert.cancel();
267 | }
268 | });
269 | alert.show();
270 | }
271 |
272 | @Override
273 | public void onClick(View view) {
274 | //To change body of implemented methods use File | Settings | File Templates.
275 | }
276 |
277 | private BroadcastReceiver subscriptionChangeReceiver = new BroadcastReceiver() {
278 | @Override
279 | public void onReceive(Context context, Intent intent) {
280 | Log.d(GpodRoid.LOGTAG, "received Broadcast, refreshing views");
281 | showDownloads();
282 | showShows(false);
283 | showEpisodes(show, false);
284 | podcastAdapter.notifyDataSetChanged();
285 | // downloadAdapter.notifyDataSetChanged();
286 | showAdapter.notifyDataSetChanged();
287 |
288 | }
289 | };
290 |
291 |
292 | @Override
293 | public boolean onCreateOptionsMenu(Menu menu) {
294 | // super.onCreateOptionsMenu(menu);
295 | if (getParent() != null) {
296 | return getParent().onCreateOptionsMenu(menu);
297 | }
298 |
299 | MenuInflater inflater = getMenuInflater();
300 | inflater.inflate(R.menu.menu, menu);
301 | return true;
302 | }
303 |
304 | /**
305 | * fetch new subscriptions
306 | *
307 | * @param item
308 | * @return
309 | */
310 | @Override
311 | public boolean onOptionsItemSelected(MenuItem item) {
312 | // Handle item selection
313 | switch (item.getItemId()) {
314 | case R.id.account:
315 | Log.d(GpodRoid.LOGTAG, "Getting account settings");
316 | Intent account = new Intent(GpodRoid.context, AccountSettings.class);
317 | startActivity(account);
318 | return true;
319 | // case R.id.subscriptions:
320 | // Intent subscriptions = new Intent(GpodRoid.context, Subscribe.class);
321 | // startActivity(subscriptions);
322 | // return true;
323 | case R.id.fetch_updates:
324 | Log.d(GpodRoid.LOGTAG, "Fetching updates");
325 | startService(new Intent(GpodRoid.context, UpdateService.class));
326 | return true;
327 | default:
328 | return super.onOptionsItemSelected(item);
329 | }
330 | }
331 |
332 |
333 | // @Override
334 | // public void onTabChanged(String s) {
335 | //
336 | // }
337 |
338 | /**
339 | * search for podcasts
340 | *
341 | * @param view
342 | */
343 | public void searchClicked(View view) {
344 | searching = ProgressDialog.show(this, "Searching ...", "digging through podcasts", true, false);
345 | searchPodcasts(etPodcastSearch.getText().toString());
346 | // displayTopPodcasts();
347 | }
348 |
349 | private void searchPodcasts(final String searchTerm) {
350 | Thread t = new Thread() {
351 | public void run() {
352 | top25hm = GpodderAPI.searchFeeds(searchTerm);
353 | top25 = new ArrayList(top25hm.keySet());
354 | handler.post(displayResults);
355 | }
356 | };
357 | t.start();
358 | }
359 |
360 | // private void displayTopPodcasts() {
361 | // Thread t = new Thread() {
362 | // @Override
363 | // public void run() {
364 | // top25hm = GpodderAPI.getTopSubscriptions();
365 | // top25 = new ArrayList(top25hm.keySet());
366 | // handler.post(displayResults);
367 | // }
368 | // };
369 | // t.start();
370 | // }
371 |
372 | final Runnable displayResults = new Runnable() {
373 | @Override
374 | public void run() {
375 | displayResultsinUI();
376 | }
377 | };
378 |
379 | private void displayResultsinUI() {
380 | lvSearchResults.setAdapter(new ArrayAdapter(GpodRoid.context, android.R.layout.simple_list_item_1, top25));
381 | searching.dismiss();
382 | }
383 |
384 | @Override
385 | public boolean onContextItemSelected(MenuItem item) {
386 |
387 | AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
388 | final String feed = (String) lvSearchResults.getItemAtPosition(info.position);
389 | Log.d(GpodRoid.LOGTAG, "subscribing to " + top25hm.get(feed));
390 |
391 | new Thread(new Runnable() {
392 | @Override
393 | public void run() {
394 | GpodderAPI.addSubcription(top25hm.get(feed));
395 | startService(new Intent(GpodRoid.context, UpdateService.class));
396 | }
397 | }).start();
398 |
399 |
400 | return super.onContextItemSelected(item);
401 |
402 | }
403 |
404 | @Override
405 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
406 | super.onCreateContextMenu(menu, v, menuInfo);
407 | menu.add("subscribe");
408 | }
409 |
410 |
411 | }
412 |
--------------------------------------------------------------------------------