diff options
Diffstat (limited to 'src/de/danoeh')
40 files changed, 410 insertions, 368 deletions
diff --git a/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java b/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java index 984491174..62273c960 100644 --- a/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java +++ b/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java @@ -347,7 +347,9 @@ public class DirectoryChooserActivity extends ActionBarActivity { * CREATE_DIRECTORY_NAME. */ private int createFolder() { - if (selectedDir != null && selectedDir.canWrite()) { + if (selectedDir == null) { + return R.string.create_folder_error; + } else if (selectedDir.canWrite()) { File newDir = new File(selectedDir, CREATE_DIRECTORY_NAME); if (!newDir.exists()) { boolean result = newDir.mkdir(); @@ -359,10 +361,8 @@ public class DirectoryChooserActivity extends ActionBarActivity { } else { return R.string.create_folder_error_already_exists; } - } else if (selectedDir.canWrite() == false) { - return R.string.create_folder_error_no_write_access; } else { - return R.string.create_folder_error; + return R.string.create_folder_error_no_write_access; } } diff --git a/src/de/danoeh/antennapod/activity/DownloadActivity.java b/src/de/danoeh/antennapod/activity/DownloadActivity.java index 40c75d336..57c86f760 100644 --- a/src/de/danoeh/antennapod/activity/DownloadActivity.java +++ b/src/de/danoeh/antennapod/activity/DownloadActivity.java @@ -121,7 +121,7 @@ public class DownloadActivity extends ActionBarActivity implements contentRefresher.cancel(true); } contentRefresher = new AsyncTask<Void, Void, Void>() { - private final int WAITING_INTERVALL = 1000; + private static final int WAITING_INTERVAL = 1000; @Override protected void onProgressUpdate(Void... values) { @@ -137,7 +137,7 @@ public class DownloadActivity extends ActionBarActivity implements protected Void doInBackground(Void... params) { while (!isCancelled()) { try { - Thread.sleep(WAITING_INTERVALL); + Thread.sleep(WAITING_INTERVAL); publishProgress(); } catch (InterruptedException e) { return null; diff --git a/src/de/danoeh/antennapod/activity/MiroGuideCategoryActivity.java b/src/de/danoeh/antennapod/activity/MiroGuideCategoryActivity.java index c039e96f8..e3d77a68a 100644 --- a/src/de/danoeh/antennapod/activity/MiroGuideCategoryActivity.java +++ b/src/de/danoeh/antennapod/activity/MiroGuideCategoryActivity.java @@ -22,7 +22,7 @@ import de.danoeh.antennapod.preferences.UserPreferences; public class MiroGuideCategoryActivity extends ActionBarActivity { private static final String TAG = "MiroGuideCategoryActivity"; - public static String EXTRA_CATEGORY = "category"; + public static final String EXTRA_CATEGORY = "category"; private ViewPager viewpager; private CategoryPagerAdapter pagerAdapter; diff --git a/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index cb1c66cab..fbac7057d 100644 --- a/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -157,7 +157,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity { @Override public void run() { - String reasonDetailed = new String(); + String reasonDetailed = ""; boolean successful = false; FeedHandler handler = new FeedHandler(); try { diff --git a/src/de/danoeh/antennapod/activity/OpmlImportFromIntentActivity.java b/src/de/danoeh/antennapod/activity/OpmlImportFromIntentActivity.java index dc698a851..58e3a96dd 100644 --- a/src/de/danoeh/antennapod/activity/OpmlImportFromIntentActivity.java +++ b/src/de/danoeh/antennapod/activity/OpmlImportFromIntentActivity.java @@ -7,6 +7,7 @@ import java.net.URL; import android.app.AlertDialog; import android.os.Bundle; import de.danoeh.antennapod.preferences.UserPreferences; +import de.danoeh.antennapod.util.LangUtils; /** Lets the user start the OPML-import process. */ public class OpmlImportFromIntentActivity extends OpmlImportBaseActivity { @@ -20,7 +21,8 @@ public class OpmlImportFromIntentActivity extends OpmlImportBaseActivity { try { URL mOpmlURL = new URL(getIntent().getData().toString()); - BufferedReader in = new BufferedReader(new InputStreamReader(mOpmlURL.openStream())); + BufferedReader in = new BufferedReader(new InputStreamReader(mOpmlURL.openStream(), + LangUtils.UTF_8)); startImport(in); } catch (Exception e) { new AlertDialog.Builder(this).setMessage("Cannot open XML - Reason: " + e.getMessage()).show(); diff --git a/src/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java b/src/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java index 259689abf..2aafb46db 100644 --- a/src/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java +++ b/src/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java @@ -1,8 +1,10 @@ package de.danoeh.antennapod.activity; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileReader; +import java.io.InputStreamReader; +import java.io.IOException; import java.io.Reader; import android.app.AlertDialog; @@ -20,6 +22,7 @@ import android.widget.Toast; import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.preferences.UserPreferences; +import de.danoeh.antennapod.util.LangUtils; import de.danoeh.antennapod.util.StorageUtils; /** @@ -125,13 +128,24 @@ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity { } private void startImport(File file) { + Reader mReader = null; try { - Reader mReader = new FileReader(file); + mReader = new InputStreamReader(new FileInputStream(file), + LangUtils.UTF_8); if (AppConfig.DEBUG) Log.d(TAG, "Parsing " + file.toString()); startImport(mReader); } catch (FileNotFoundException e) { Log.d(TAG, "File not found which really should be there"); // this should never happen as it is a file we have just chosen + } finally { + if (mReader != null) { + try { + mReader.close(); + } catch (IOException ioe) { + Log.w(TAG, "IOException while importing OPML: " + + ioe.getMessage()); + } + } } } diff --git a/src/de/danoeh/antennapod/activity/SearchActivity.java b/src/de/danoeh/antennapod/activity/SearchActivity.java index 29d55c102..86f7301cf 100644 --- a/src/de/danoeh/antennapod/activity/SearchActivity.java +++ b/src/de/danoeh/antennapod/activity/SearchActivity.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import android.annotation.SuppressLint; +import android.app.Activity; import android.app.SearchManager; import android.content.Intent; import android.os.Bundle; @@ -140,34 +141,34 @@ public class SearchActivity extends ActionBarActivity implements AdapterView.OnI @Override public void run() { Log.d(TAG, "Starting background work"); + final Activity activity = SearchActivity.this; final List<SearchResult> result = FeedSearcher - .performSearch(SearchActivity.this, query, feedID); - if (SearchActivity.this != null) { - SearchActivity.this.runOnUiThread(new Runnable() { - - @Override - public void run() { - if (AppConfig.DEBUG) - Log.d(TAG, "Background work finished"); - if (AppConfig.DEBUG) - Log.d(TAG, "Found " + result.size() - + " results"); - - searchAdapter.clear(); - for (SearchResult s : result) { - searchAdapter.add(s); - } - searchAdapter.notifyDataSetChanged(); - txtvStatus - .setText(R.string.search_status_no_results); - if (!searchAdapter.isEmpty()) { - txtvStatus.setVisibility(View.GONE); - } else { - txtvStatus.setVisibility(View.VISIBLE); - } + .performSearch(activity, query, feedID); + activity.runOnUiThread(new Runnable() { + + @Override + public void run() { + if (AppConfig.DEBUG) + Log.d(TAG, "Background work finished"); + if (AppConfig.DEBUG) + Log.d(TAG, "Found " + result.size() + + " results"); + + searchAdapter.clear(); + for (SearchResult s : result) { + searchAdapter.add(s); } - }); - } + searchAdapter.notifyDataSetChanged(); + txtvStatus + .setText(R.string.search_status_no_results); + if (!searchAdapter.isEmpty()) { + txtvStatus.setVisibility(View.GONE); + } else { + txtvStatus.setVisibility(View.VISIBLE); + } + } + }); + } }; thread.start(); diff --git a/src/de/danoeh/antennapod/adapter/ChapterListAdapter.java b/src/de/danoeh/antennapod/adapter/ChapterListAdapter.java index 3e9b586ce..5a8dfb2bf 100644 --- a/src/de/danoeh/antennapod/adapter/ChapterListAdapter.java +++ b/src/de/danoeh/antennapod/adapter/ChapterListAdapter.java @@ -144,53 +144,6 @@ public class ChapterListAdapter extends ArrayAdapter<Chapter> { TextView link; } - private LinkMovementMethod linkMovementMethod = new LinkMovementMethod() { - - @Override - public boolean onTouchEvent(TextView widget, Spannable buffer, - MotionEvent event) { - Object text = widget.getText(); - if (text instanceof Spanned) { - int action = event.getAction(); - - if (action == MotionEvent.ACTION_UP - || action == MotionEvent.ACTION_DOWN) { - int x = (int) event.getX(); - int y = (int) event.getY(); - - x -= widget.getTotalPaddingLeft(); - y -= widget.getTotalPaddingTop(); - - x += widget.getScrollX(); - y += widget.getScrollY(); - - Layout layout = widget.getLayout(); - int line = layout.getLineForVertical(y); - int off = layout.getOffsetForHorizontal(line, x); - - ClickableSpan[] link = buffer.getSpans(off, off, - ClickableSpan.class); - - if (link.length != 0) { - if (action == MotionEvent.ACTION_UP) { - link[0].onClick(widget); - } else if (action == MotionEvent.ACTION_DOWN) { - Selection.setSelection(buffer, - buffer.getSpanStart(link[0]), - buffer.getSpanEnd(link[0])); - } - return true; - } - } - - } - - return false; - - } - - }; - @Override public int getCount() { // ignore invalid chapters diff --git a/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java b/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java index 4380bc6ea..7ba68ae22 100644 --- a/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java +++ b/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java @@ -47,7 +47,7 @@ public class BitmapDecodeWorkerTask extends Thread { */ protected boolean tagsMatching(ImageView target) { return target.getTag() == null - || target.getTag() == imageResource.getImageLoaderCacheKey(); + || target.getTag().equals(imageResource.getImageLoaderCacheKey()); } protected void onPostExecute() { diff --git a/src/de/danoeh/antennapod/asynctask/ImageLoader.java b/src/de/danoeh/antennapod/asynctask/ImageLoader.java index fb807f469..45a99e704 100644 --- a/src/de/danoeh/antennapod/asynctask/ImageLoader.java +++ b/src/de/danoeh/antennapod/asynctask/ImageLoader.java @@ -77,7 +77,7 @@ public class ImageLoader { }); } - public static ImageLoader getInstance() { + public static synchronized ImageLoader getInstance() { if (singleton == null) { singleton = new ImageLoader(); } diff --git a/src/de/danoeh/antennapod/asynctask/OpmlExportWorker.java b/src/de/danoeh/antennapod/asynctask/OpmlExportWorker.java index e14e22917..745bc7079 100644 --- a/src/de/danoeh/antennapod/asynctask/OpmlExportWorker.java +++ b/src/de/danoeh/antennapod/asynctask/OpmlExportWorker.java @@ -1,8 +1,9 @@ package de.danoeh.antennapod.asynctask; import java.io.File; -import java.io.FileWriter; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStreamWriter; import java.util.Arrays; import android.annotation.SuppressLint; @@ -16,6 +17,7 @@ import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.R; import de.danoeh.antennapod.opml.OpmlWriter; import de.danoeh.antennapod.preferences.UserPreferences; +import de.danoeh.antennapod.util.LangUtils; import de.danoeh.antennapod.storage.DBReader; /** Writes an OPML file into the export directory in the background. */ @@ -49,13 +51,21 @@ public class OpmlExportWorker extends AsyncTask<Void, Void, Void> { output.delete(); } } + OutputStreamWriter writer = null; try { - FileWriter writer = new FileWriter(output); + writer = new OutputStreamWriter(new FileOutputStream(output), LangUtils.UTF_8); opmlWriter.writeDocument(DBReader.getFeedList(context), writer); - writer.close(); } catch (IOException e) { e.printStackTrace(); exception = e; + } finally { + if (writer != null) { + try { + writer.close(); + } catch (IOException ioe) { + exception = ioe; + } + } } return null; } diff --git a/src/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java b/src/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java index 4d9c9867e..64e678086 100644 --- a/src/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java +++ b/src/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java @@ -1,5 +1,6 @@ package de.danoeh.antennapod.asynctask; +import java.util.Arrays; import java.util.Date; import android.annotation.SuppressLint; @@ -22,7 +23,7 @@ public class OpmlFeedQueuer extends AsyncTask<Void, Void, Void> { public OpmlFeedQueuer(Context context, int[] selection) { super(); this.context = context; - this.selection = selection; + this.selection = Arrays.copyOf(selection, selection.length); } @Override diff --git a/src/de/danoeh/antennapod/feed/EventDistributor.java b/src/de/danoeh/antennapod/feed/EventDistributor.java index c538808e2..56333da52 100644 --- a/src/de/danoeh/antennapod/feed/EventDistributor.java +++ b/src/de/danoeh/antennapod/feed/EventDistributor.java @@ -39,7 +39,7 @@ public class EventDistributor extends Observable { events = new ConcurrentLinkedQueue<Integer>(); } - public static EventDistributor getInstance() { + public static synchronized EventDistributor getInstance() { if (instance == null) { instance = new EventDistributor(); } diff --git a/src/de/danoeh/antennapod/feed/Feed.java b/src/de/danoeh/antennapod/feed/Feed.java index 34505dda9..032930f83 100644 --- a/src/de/danoeh/antennapod/feed/Feed.java +++ b/src/de/danoeh/antennapod/feed/Feed.java @@ -55,7 +55,11 @@ public class Feed extends FeedFile { super(fileUrl, downloadUrl, downloaded); this.id = id; this.title = title; - this.lastUpdate = lastUpdate; + if (lastUpdate != null) { + this.lastUpdate = (Date) lastUpdate.clone(); + } else { + this.lastUpdate = null; + } this.link = link; this.description = description; this.paymentLink = paymentLink; @@ -83,7 +87,7 @@ public class Feed extends FeedFile { */ public Feed(String url, Date lastUpdate) { super(null, url, false); - this.lastUpdate = lastUpdate; + this.lastUpdate = (lastUpdate != null) ? (Date) lastUpdate.clone() : null; } /** @@ -315,11 +319,11 @@ public class Feed extends FeedFile { } public Date getLastUpdate() { - return lastUpdate; + return (lastUpdate != null) ? (Date) lastUpdate.clone() : null; } public void setLastUpdate(Date lastUpdate) { - this.lastUpdate = lastUpdate; + this.lastUpdate = (lastUpdate != null) ? (Date) lastUpdate.clone() : null; } public String getFeedIdentifier() { diff --git a/src/de/danoeh/antennapod/feed/FeedItem.java b/src/de/danoeh/antennapod/feed/FeedItem.java index 54682397e..a80460ece 100644 --- a/src/de/danoeh/antennapod/feed/FeedItem.java +++ b/src/de/danoeh/antennapod/feed/FeedItem.java @@ -48,6 +48,19 @@ public class FeedItem extends FeedComponent implements this.read = true; } + /** + * This constructor should be used for creating test objects. + * */ + public FeedItem(long id, String title, String itemIdentifier, String link, Date pubDate, boolean read, Feed feed) { + this.id = id; + this.title = title; + this.itemIdentifier = itemIdentifier; + this.link = link; + this.pubDate = (pubDate != null) ? (Date) pubDate.clone() : null; + this.read = read; + this.feed = feed; + } + public void updateFromOther(FeedItem other) { super.updateFromOther(other); if (other.title != null) { @@ -123,19 +136,35 @@ public class FeedItem extends FeedComponent implements } public Date getPubDate() { - return pubDate; + if (pubDate != null) { + return (Date) pubDate.clone(); + } else { + return null; + } } public void setPubDate(Date pubDate) { - this.pubDate = pubDate; + if (pubDate != null) { + this.pubDate = (Date) pubDate.clone(); + } else { + this.pubDate = null; + } } public FeedMedia getMedia() { return media; } + /** + * Sets the media object of this FeedItem. If the given + * FeedMedia object is not null, it's 'item'-attribute value + * will also be set to this item. + * */ public void setMedia(FeedMedia media) { this.media = media; + if (media != null && media.getItem() != this) { + media.setItem(this); + } } public Feed getFeed() { diff --git a/src/de/danoeh/antennapod/feed/FeedMedia.java b/src/de/danoeh/antennapod/feed/FeedMedia.java index f140a37e6..492867983 100644 --- a/src/de/danoeh/antennapod/feed/FeedMedia.java +++ b/src/de/danoeh/antennapod/feed/FeedMedia.java @@ -53,7 +53,8 @@ public class FeedMedia extends FeedFile implements Playable { this.position = position; this.size = size; this.mime_type = mime_type; - this.playbackCompletionDate = playbackCompletionDate; + this.playbackCompletionDate = playbackCompletionDate == null + ? null : (Date) playbackCompletionDate.clone(); } public FeedMedia(long id, FeedItem item) { @@ -164,16 +165,25 @@ public class FeedMedia extends FeedFile implements Playable { return item; } + /** + * Sets the item object of this FeedMedia. If the given + * FeedItem object is not null, it's 'media'-attribute value + * will also be set to this media object. + * */ public void setItem(FeedItem item) { this.item = item; + if (item != null && item.getMedia() != this) { + item.setMedia(this); + } } public Date getPlaybackCompletionDate() { - return playbackCompletionDate; - } + return playbackCompletionDate == null + ? null : (Date) playbackCompletionDate.clone(); } public void setPlaybackCompletionDate(Date playbackCompletionDate) { - this.playbackCompletionDate = playbackCompletionDate; + this.playbackCompletionDate = playbackCompletionDate == null + ? null : (Date) playbackCompletionDate.clone(); } public boolean isInProgress() { diff --git a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java index 0e06e546e..0dc29c415 100644 --- a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java @@ -265,9 +265,9 @@ public class FeedlistFragment extends Fragment implements public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Feed selection = fla.getItem(position); - if (AppConfig.DEBUG) - Log.d(TAG, "Selected Feed with title " + selection.getTitle()); if (selection != null) { + if (AppConfig.DEBUG) + Log.d(TAG, "Selected Feed with title " + selection.getTitle()); if (mActionMode != null) { mActionMode.finish(); } diff --git a/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java b/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java index 9183180c1..c996f497e 100644 --- a/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java +++ b/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java @@ -1,5 +1,6 @@ package de.danoeh.antennapod.fragment; +import android.content.*; import android.support.v4.app.Fragment; import android.support.v7.app.ActionBarActivity; import de.danoeh.antennapod.feed.FeedItem; @@ -9,10 +10,6 @@ import org.apache.commons.lang3.StringEscapeUtils; import android.annotation.SuppressLint; import android.app.Activity; -import android.content.ClipData; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; import android.content.res.TypedArray; import android.net.Uri; import android.os.AsyncTask; @@ -117,7 +114,12 @@ public class ItemDescriptionFragment extends Fragment { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - startActivity(intent); + try { + startActivity(intent); + } catch (ActivityNotFoundException e) { + e.printStackTrace(); + return false; + } return true; } @@ -138,6 +140,7 @@ public class ItemDescriptionFragment extends Fragment { } }); + registerForContextMenu(webvDescription); return webvDescription; } @@ -371,11 +374,10 @@ public class ItemDescriptionFragment extends Fragment { Callable<String> shownotesLoadTask = shownotesProvider.loadShownotes(); final String shownotes = shownotesLoadTask.call(); - data = ""; data = StringEscapeUtils.unescapeHtml4(shownotes); Activity activity = getActivity(); if (activity != null) { - TypedArray res = getActivity() + TypedArray res = activity .getTheme() .obtainStyledAttributes( new int[]{android.R.attr.textColorPrimary}); diff --git a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java index 40637544d..fb086019c 100644 --- a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -50,7 +50,6 @@ public class ItemlistFragment extends ListFragment { public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.danoeh.antennapod.activity.selected_feeditem"; public static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id"; protected InternalFeedItemlistAdapter fila; - protected DownloadRequester requester = DownloadRequester.getInstance(); private Feed feed; protected List<Long> queue; @@ -156,8 +155,6 @@ public class ItemlistFragment extends ListFragment { } else { Log.e(TAG, "Could not load queue"); } - if (result.getItems().isEmpty()) { - } setEmptyViewIfListIsEmpty(); if (fila != null) { fila.notifyDataSetChanged(); diff --git a/src/de/danoeh/antennapod/miroguide/conn/MiroGuideConnector.java b/src/de/danoeh/antennapod/miroguide/conn/MiroGuideConnector.java index 99bef4bd8..ee1a3ea21 100644 --- a/src/de/danoeh/antennapod/miroguide/conn/MiroGuideConnector.java +++ b/src/de/danoeh/antennapod/miroguide/conn/MiroGuideConnector.java @@ -16,6 +16,8 @@ import org.json.JSONObject; import android.net.Uri; +import de.danoeh.antennapod.util.LangUtils; + /** Executes HTTP requests and returns the results. */ public class MiroGuideConnector { private HttpClient httpClient; @@ -73,12 +75,14 @@ public class MiroGuideConnector { if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); if (entity != null) { - InputStream in = entity.getContent(); - BufferedReader reader = new BufferedReader( - new InputStreamReader(in)); - result = reader.readLine(); - in.close(); + new InputStreamReader(entity.getContent(), + LangUtils.UTF_8)); + try { + result = reader.readLine(); + } finally { + reader.close(); + } } } else { throw new MiroGuideException(response.getStatusLine() diff --git a/src/de/danoeh/antennapod/miroguide/model/MiroGuideItem.java b/src/de/danoeh/antennapod/miroguide/model/MiroGuideItem.java index 89a2250df..cb5b15c56 100644 --- a/src/de/danoeh/antennapod/miroguide/model/MiroGuideItem.java +++ b/src/de/danoeh/antennapod/miroguide/model/MiroGuideItem.java @@ -12,7 +12,7 @@ public class MiroGuideItem { super(); this.name = name; this.description = description; - this.date = date; + this.date = (Date) date.clone(); this.url = url; } @@ -30,7 +30,7 @@ public class MiroGuideItem { } public Date getDate() { - return date; + return (Date) date.clone(); } public String getUrl() { diff --git a/src/de/danoeh/antennapod/service/PlaybackService.java b/src/de/danoeh/antennapod/service/PlaybackService.java index c29624cf3..556a58ee8 100644 --- a/src/de/danoeh/antennapod/service/PlaybackService.java +++ b/src/de/danoeh/antennapod/service/PlaybackService.java @@ -876,7 +876,6 @@ public class PlaybackService extends Service { DBWriter.removeQueueItem(PlaybackService.this, item.getId(), true); } DBWriter.addItemToPlaybackHistory(PlaybackService.this, (FeedMedia) media); - DBWriter.setFeedMedia(PlaybackService.this, (FeedMedia) media); long autoDeleteMediaId = ((FeedComponent) media).getId(); if (shouldStream) { autoDeleteMediaId = -1; @@ -1376,18 +1375,20 @@ public class PlaybackService extends Service { isPlaying = true; } - Intent i = new Intent(AVRCP_ACTION_PLAYER_STATUS_CHANGED); - i.putExtra("id", 1); - i.putExtra("artist", ""); - i.putExtra("album", media.getFeedTitle()); - i.putExtra("track", media.getEpisodeTitle()); - i.putExtra("playing", isPlaying); - if (queue != null) { - i.putExtra("ListSize", queue.size()); + if (media != null) { + Intent i = new Intent(AVRCP_ACTION_PLAYER_STATUS_CHANGED); + i.putExtra("id", 1); + i.putExtra("artist", ""); + i.putExtra("album", media.getFeedTitle()); + i.putExtra("track", media.getEpisodeTitle()); + i.putExtra("playing", isPlaying); + if (queue != null) { + i.putExtra("ListSize", queue.size()); + } + i.putExtra("duration", media.getDuration()); + i.putExtra("position", media.getPosition()); + sendBroadcast(i); } - i.putExtra("duration", media.getDuration()); - i.putExtra("position", media.getPosition()); - sendBroadcast(i); } /** diff --git a/src/de/danoeh/antennapod/service/download/DownloadService.java b/src/de/danoeh/antennapod/service/download/DownloadService.java index 8b090981c..4040c85a8 100644 --- a/src/de/danoeh/antennapod/service/download/DownloadService.java +++ b/src/de/danoeh/antennapod/service/download/DownloadService.java @@ -184,7 +184,7 @@ public class DownloadService extends Service { public int onStartCommand(Intent intent, int flags, int startId) { if (intent.getParcelableExtra(EXTRA_REQUEST) != null) { onDownloadQueued(intent); - } else if (numberOfDownloads.equals(0)) { + } else if (numberOfDownloads.get() == 0) { stopSelf(); } return Service.START_NOT_STICKY; @@ -421,52 +421,24 @@ public class DownloadService extends Service { return null; } - @SuppressLint("NewApi") - public void onDownloadCompleted(final Downloader downloader) { - final AsyncTask<Void, Void, Void> handlerTask = new AsyncTask<Void, Void, Void>() { - boolean successful; - - @Override - protected void onPostExecute(Void result) { - super.onPostExecute(result); - if (!successful) { - queryDownloads(); - } - } - - @Override - protected void onPreExecute() { - super.onPreExecute(); - removeDownload(downloader); - } - - @Override - protected Void doInBackground(Void... params) { - - - return null; - } - }; - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - handlerTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - handlerTask.execute(); - } - } - /** * Remove download from the DownloadRequester list and from the * DownloadService list. */ private void removeDownload(final Downloader d) { - if (AppConfig.DEBUG) - Log.d(TAG, "Removing downloader: " - + d.getDownloadRequest().getSource()); - boolean rc = downloads.remove(d); - if (AppConfig.DEBUG) - Log.d(TAG, "Result of downloads.remove: " + rc); - DownloadRequester.getInstance().removeDownload(d.getDownloadRequest()); - sendBroadcast(new Intent(ACTION_DOWNLOADS_CONTENT_CHANGED)); + handler.post(new Runnable() { + @Override + public void run() { + if (AppConfig.DEBUG) + Log.d(TAG, "Removing downloader: " + + d.getDownloadRequest().getSource()); + boolean rc = downloads.remove(d); + if (AppConfig.DEBUG) + Log.d(TAG, "Result of downloads.remove: " + rc); + DownloadRequester.getInstance().removeDownload(d.getDownloadRequest()); + sendBroadcast(new Intent(ACTION_DOWNLOADS_CONTENT_CHANGED)); + } + }); } /** diff --git a/src/de/danoeh/antennapod/service/download/DownloadStatus.java b/src/de/danoeh/antennapod/service/download/DownloadStatus.java index 62e54cbb4..487c3b3de 100644 --- a/src/de/danoeh/antennapod/service/download/DownloadStatus.java +++ b/src/de/danoeh/antennapod/service/download/DownloadStatus.java @@ -52,7 +52,7 @@ public class DownloadStatus { this.feedfileId = feedfileId; this.reason = reason; this.successful = successful; - this.completionDate = completionDate; + this.completionDate = (Date) completionDate.clone(); this.reasonDetailed = reasonDetailed; this.feedfileType = feedfileType; } @@ -133,7 +133,7 @@ public class DownloadStatus { } public Date getCompletionDate() { - return completionDate; + return (Date) completionDate.clone(); } public long getFeedfileId() { @@ -162,6 +162,7 @@ public class DownloadStatus { this.successful = false; this.reason = reason; this.reasonDetailed = reasonDetailed; + this.done = true; } public void setCancelled() { @@ -172,7 +173,7 @@ public class DownloadStatus { } public void setCompletionDate(Date completionDate) { - this.completionDate = completionDate; + this.completionDate = (Date) completionDate.clone(); } public void setId(long id) { diff --git a/src/de/danoeh/antennapod/service/download/HttpDownloader.java b/src/de/danoeh/antennapod/service/download/HttpDownloader.java index c9671ceb3..adf93e0f2 100644 --- a/src/de/danoeh/antennapod/service/download/HttpDownloader.java +++ b/src/de/danoeh/antennapod/service/download/HttpDownloader.java @@ -6,7 +6,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.SocketTimeoutException; import java.net.UnknownHostException; @@ -30,161 +29,179 @@ import de.danoeh.antennapod.util.DownloadError; import de.danoeh.antennapod.util.StorageUtils; public class HttpDownloader extends Downloader { - private static final String TAG = "HttpDownloader"; - - private static final int MAX_REDIRECTS = 5; - - private static final int BUFFER_SIZE = 8 * 1024; - private static final int CONNECTION_TIMEOUT = 30000; - private static final int SOCKET_TIMEOUT = 30000; - - public HttpDownloader(DownloadRequest request) { - super(request); - } - - private DefaultHttpClient createHttpClient() { - DefaultHttpClient httpClient = new DefaultHttpClient(); - HttpParams params = httpClient.getParams(); - params.setIntParameter("http.protocol.max-redirects", MAX_REDIRECTS); - params.setBooleanParameter("http.protocol.reject-relative-redirect", - false); - HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT); - HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); - HttpClientParams.setRedirecting(params, true); - - // Workaround for broken URLs in redirection - ((AbstractHttpClient) httpClient) - .setRedirectHandler(new APRedirectHandler()); - return httpClient; - } - - @Override - protected void download() { - DefaultHttpClient httpClient = null; - OutputStream out = null; - InputStream connection = null; - try { - HttpGet httpGet = new HttpGet(request.getSource()); - httpClient = createHttpClient(); - HttpResponse response = httpClient.execute(httpGet); - HttpEntity httpEntity = response.getEntity(); - int responseCode = response.getStatusLine().getStatusCode(); - if (AppConfig.DEBUG) - Log.d(TAG, "Response code is " + responseCode); - if (responseCode == HttpURLConnection.HTTP_OK && httpEntity != null) { - if (StorageUtils.storageAvailable(PodcastApp.getInstance())) { - File destination = new File(request.getDestination()); - if (!destination.exists()) { - connection = AndroidHttpClient - .getUngzippedContent(httpEntity); - InputStream in = new BufferedInputStream(connection); - out = new BufferedOutputStream(new FileOutputStream( - destination)); - byte[] buffer = new byte[BUFFER_SIZE]; - int count = 0; - request.setStatusMsg(R.string.download_running); - if (AppConfig.DEBUG) - Log.d(TAG, "Getting size of download"); - request.setSize(httpEntity.getContentLength()); - if (AppConfig.DEBUG) - Log.d(TAG, "Size is " + request.getSize()); - if (request.getSize() < 0) { - request.setSize(DownloadStatus.SIZE_UNKNOWN); - } - - long freeSpace = StorageUtils.getFreeSpaceAvailable(); - if (AppConfig.DEBUG) - Log.d(TAG, "Free space is " + freeSpace); - if (request.getSize() == DownloadStatus.SIZE_UNKNOWN - || request.getSize() <= freeSpace) { - if (AppConfig.DEBUG) - Log.d(TAG, "Starting download"); - while (!cancelled - && (count = in.read(buffer)) != -1) { - out.write(buffer, 0, count); - request.setSoFar(request.getSoFar() + count); - request.setProgressPercent((int) (((double) request - .getSoFar() / (double) request - .getSize()) * 100)); - } - if (cancelled) { - onCancelled(); - } else { - onSuccess(); - } - } else { - onFail(DownloadError.ERROR_NOT_ENOUGH_SPACE, null); - } - } else { - Log.w(TAG, "File already exists"); - onFail(DownloadError.ERROR_FILE_EXISTS, null); - } - } else { - onFail(DownloadError.ERROR_DEVICE_NOT_FOUND, null); - } - } else { - onFail(DownloadError.ERROR_HTTP_DATA_ERROR, - String.valueOf(responseCode)); - } - } catch (IllegalArgumentException e) { - e.printStackTrace(); - onFail(DownloadError.ERROR_MALFORMED_URL, e.getMessage()); - } catch (SocketTimeoutException e) { - e.printStackTrace(); - onFail(DownloadError.ERROR_CONNECTION_ERROR, e.getMessage()); - } catch (UnknownHostException e) { - e.printStackTrace(); - onFail(DownloadError.ERROR_UNKNOWN_HOST, e.getMessage()); - } catch (IOException e) { - e.printStackTrace(); - onFail(DownloadError.ERROR_IO_ERROR, e.getMessage()); - } catch (NullPointerException e) { - // might be thrown by connection.getInputStream() - e.printStackTrace(); - onFail(DownloadError.ERROR_CONNECTION_ERROR, request.getSource()); - } finally { - IOUtils.closeQuietly(out); - if (httpClient != null) { - httpClient.getConnectionManager().shutdown(); - } - } - } - - private void onSuccess() { - if (AppConfig.DEBUG) - Log.d(TAG, "Download was successful"); - result.setSuccessful(); - } - - private void onFail(DownloadError reason, String reasonDetailed) { - if (AppConfig.DEBUG) { - Log.d(TAG, "Download failed"); - } + private static final String TAG = "HttpDownloader"; + + private static final int MAX_REDIRECTS = 5; + + private static final int BUFFER_SIZE = 8 * 1024; + private static final int CONNECTION_TIMEOUT = 30000; + private static final int SOCKET_TIMEOUT = 30000; + + public HttpDownloader(DownloadRequest request) { + super(request); + } + + private DefaultHttpClient createHttpClient() { + DefaultHttpClient httpClient = new DefaultHttpClient(); + HttpParams params = httpClient.getParams(); + params.setIntParameter("http.protocol.max-redirects", MAX_REDIRECTS); + params.setBooleanParameter("http.protocol.reject-relative-redirect", + false); + HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT); + HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); + HttpClientParams.setRedirecting(params, true); + + // Workaround for broken URLs in redirection + ((AbstractHttpClient) httpClient) + .setRedirectHandler(new APRedirectHandler()); + return httpClient; + } + + @Override + protected void download() { + DefaultHttpClient httpClient = null; + BufferedOutputStream out = null; + InputStream connection = null; + try { + HttpGet httpGet = new HttpGet(request.getSource()); + httpClient = createHttpClient(); + HttpResponse response = httpClient.execute(httpGet); + HttpEntity httpEntity = response.getEntity(); + int responseCode = response.getStatusLine().getStatusCode(); + if (AppConfig.DEBUG) + Log.d(TAG, "Response code is " + responseCode); + + if (responseCode != HttpURLConnection.HTTP_OK || httpEntity == null) { + onFail(DownloadError.ERROR_HTTP_DATA_ERROR, + String.valueOf(responseCode)); + return; + } + + if (!StorageUtils.storageAvailable(PodcastApp.getInstance())) { + onFail(DownloadError.ERROR_DEVICE_NOT_FOUND, null); + return; + } + + File destination = new File(request.getDestination()); + if (destination.exists()) { + Log.w(TAG, "File already exists"); + onFail(DownloadError.ERROR_FILE_EXISTS, null); + return; + } + + connection = new BufferedInputStream(AndroidHttpClient + .getUngzippedContent(httpEntity)); + out = new BufferedOutputStream(new FileOutputStream( + destination)); + byte[] buffer = new byte[BUFFER_SIZE]; + int count = 0; + request.setStatusMsg(R.string.download_running); + if (AppConfig.DEBUG) + Log.d(TAG, "Getting size of download"); + request.setSize(httpEntity.getContentLength()); + if (AppConfig.DEBUG) + Log.d(TAG, "Size is " + request.getSize()); + if (request.getSize() < 0) { + request.setSize(DownloadStatus.SIZE_UNKNOWN); + } + + long freeSpace = StorageUtils.getFreeSpaceAvailable(); + if (AppConfig.DEBUG) + Log.d(TAG, "Free space is " + freeSpace); + + if (request.getSize() != DownloadStatus.SIZE_UNKNOWN + && request.getSize() > freeSpace) { + onFail(DownloadError.ERROR_NOT_ENOUGH_SPACE, null); + return; + } + + if (AppConfig.DEBUG) + Log.d(TAG, "Starting download"); + while (!cancelled + && (count = connection.read(buffer)) != -1) { + out.write(buffer, 0, count); + request.setSoFar(request.getSoFar() + count); + request.setProgressPercent((int) (((double) request + .getSoFar() / (double) request + .getSize()) * 100)); + } + if (cancelled) { + onCancelled(); + } else { + out.flush(); + if (request.getSize() != DownloadStatus.SIZE_UNKNOWN && + request.getSoFar() != request.getSize()) { + onFail(DownloadError.ERROR_IO_ERROR, + "Download completed but size: " + + request.getSoFar() + + " does not equal expected size " + + request.getSize()); + return; + } + onSuccess(); + } + + } catch (IllegalArgumentException e) { + e.printStackTrace(); + onFail(DownloadError.ERROR_MALFORMED_URL, e.getMessage()); + } catch (SocketTimeoutException e) { + e.printStackTrace(); + onFail(DownloadError.ERROR_CONNECTION_ERROR, e.getMessage()); + } catch (UnknownHostException e) { + e.printStackTrace(); + onFail(DownloadError.ERROR_UNKNOWN_HOST, e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + onFail(DownloadError.ERROR_IO_ERROR, e.getMessage()); + } catch (NullPointerException e) { + // might be thrown by connection.getInputStream() + e.printStackTrace(); + onFail(DownloadError.ERROR_CONNECTION_ERROR, request.getSource()); + } finally { + IOUtils.closeQuietly(out); + if (httpClient != null) { + httpClient.getConnectionManager().shutdown(); + } + } + } + + private void onSuccess() { + if (AppConfig.DEBUG) + Log.d(TAG, "Download was successful"); + result.setSuccessful(); + } + + private void onFail(DownloadError reason, String reasonDetailed) { + if (AppConfig.DEBUG) { + Log.d(TAG, "Download failed"); + } result.setFailed(reason, reasonDetailed); - cleanup(); - } + cleanup(); + } - private void onCancelled() { - if (AppConfig.DEBUG) - Log.d(TAG, "Download was cancelled"); + private void onCancelled() { + if (AppConfig.DEBUG) + Log.d(TAG, "Download was cancelled"); result.setCancelled(); - cleanup(); - } - - /** Deletes unfinished downloads. */ - private void cleanup() { - if (request.getDestination() != null) { - File dest = new File(request.getDestination()); - if (dest.exists()) { - boolean rc = dest.delete(); - if (AppConfig.DEBUG) - Log.d(TAG, "Deleted file " + dest.getName() + "; Result: " - + rc); - } else { - if (AppConfig.DEBUG) - Log.d(TAG, "cleanup() didn't delete file: does not exist."); - } - } - } + cleanup(); + } + + /** + * Deletes unfinished downloads. + */ + private void cleanup() { + if (request.getDestination() != null) { + File dest = new File(request.getDestination()); + if (dest.exists()) { + boolean rc = dest.delete(); + if (AppConfig.DEBUG) + Log.d(TAG, "Deleted file " + dest.getName() + "; Result: " + + rc); + } else { + if (AppConfig.DEBUG) + Log.d(TAG, "cleanup() didn't delete file: does not exist."); + } + } + } } diff --git a/src/de/danoeh/antennapod/storage/DBReader.java b/src/de/danoeh/antennapod/storage/DBReader.java index c96051874..28ab3d939 100644 --- a/src/de/danoeh/antennapod/storage/DBReader.java +++ b/src/de/danoeh/antennapod/storage/DBReader.java @@ -229,9 +229,11 @@ public final class DBReader { title, item, link); break; } - chapter.setId(chapterCursor - .getLong(PodDBAdapter.KEY_ID_INDEX)); - item.getChapters().add(chapter); + if (chapter != null) { + chapter.setId(chapterCursor + .getLong(PodDBAdapter.KEY_ID_INDEX)); + item.getChapters().add(chapter); + } } while (chapterCursor.moveToNext()); } chapterCursor.close(); diff --git a/src/de/danoeh/antennapod/storage/DBTasks.java b/src/de/danoeh/antennapod/storage/DBTasks.java index f25625949..4ce1a0c96 100644 --- a/src/de/danoeh/antennapod/storage/DBTasks.java +++ b/src/de/danoeh/antennapod/storage/DBTasks.java @@ -408,11 +408,11 @@ public final class DBTasks { final int episodeNumber) { List<FeedItem> candidates = new ArrayList<FeedItem>(); List<FeedItem> downloadedItems = DBReader.getDownloadedItems(context); - List<FeedItem> queue = DBReader.getQueue(context); + QueueAccess queue = QueueAccess.IDListAccess(DBReader.getQueueIDList(context)); List<FeedItem> delete; for (FeedItem item : downloadedItems) { if (item.hasMedia() && item.getMedia().isDownloaded() - && !queue.contains(item) && item.isRead()) { + && !queue.contains(item.getId()) && item.isRead()) { candidates.add(item); } diff --git a/src/de/danoeh/antennapod/storage/DBWriter.java b/src/de/danoeh/antennapod/storage/DBWriter.java index aed8b93c9..d96299dbe 100644 --- a/src/de/danoeh/antennapod/storage/DBWriter.java +++ b/src/de/danoeh/antennapod/storage/DBWriter.java @@ -215,7 +215,7 @@ public class DBWriter { media.setPlaybackCompletionDate(new Date()); PodDBAdapter adapter = new PodDBAdapter(context); adapter.open(); - adapter.setMedia(media); + adapter.setFeedMediaPlaybackCompletionDate(media); adapter.close(); EventDistributor.getInstance().sendPlaybackHistoryUpdateBroadcast(); diff --git a/src/de/danoeh/antennapod/storage/DownloadRequester.java b/src/de/danoeh/antennapod/storage/DownloadRequester.java index 246b8bdfd..013162f0c 100644 --- a/src/de/danoeh/antennapod/storage/DownloadRequester.java +++ b/src/de/danoeh/antennapod/storage/DownloadRequester.java @@ -26,9 +26,9 @@ import de.danoeh.antennapod.util.URLChecker; public class DownloadRequester { private static final String TAG = "DownloadRequester"; - public static String IMAGE_DOWNLOADPATH = "images/"; - public static String FEED_DOWNLOADPATH = "cache/"; - public static String MEDIA_DOWNLOADPATH = "media/"; + public static final String IMAGE_DOWNLOADPATH = "images/"; + public static final String FEED_DOWNLOADPATH = "cache/"; + public static final String MEDIA_DOWNLOADPATH = "media/"; private static DownloadRequester downloader; @@ -38,7 +38,7 @@ public class DownloadRequester { downloads = new ConcurrentHashMap<String, DownloadRequest>(); } - public static DownloadRequester getInstance() { + public static synchronized DownloadRequester getInstance() { if (downloader == null) { downloader = new DownloadRequester(); } diff --git a/src/de/danoeh/antennapod/storage/FeedItemStatistics.java b/src/de/danoeh/antennapod/storage/FeedItemStatistics.java index 17e838761..6b79dd144 100644 --- a/src/de/danoeh/antennapod/storage/FeedItemStatistics.java +++ b/src/de/danoeh/antennapod/storage/FeedItemStatistics.java @@ -17,7 +17,7 @@ public class FeedItemStatistics { this.numberOfItems = numberOfItems; this.numberOfNewItems = numberOfNewItems; this.numberOfInProgressItems = numberOfInProgressItems; - this.lastUpdate = lastUpdate; + this.lastUpdate = (lastUpdate != null) ? (Date) lastUpdate.clone() : null; } public long getFeedID() { @@ -37,6 +37,6 @@ public class FeedItemStatistics { } public Date getLastUpdate() { - return lastUpdate; + return (lastUpdate != null) ? (Date) lastUpdate.clone() : null; } } diff --git a/src/de/danoeh/antennapod/storage/PodDBAdapter.java b/src/de/danoeh/antennapod/storage/PodDBAdapter.java index 78b4c6daa..bb743e2b1 100644 --- a/src/de/danoeh/antennapod/storage/PodDBAdapter.java +++ b/src/de/danoeh/antennapod/storage/PodDBAdapter.java @@ -10,7 +10,6 @@ import android.database.DatabaseUtils; import android.database.MergeCursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteStatement; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; @@ -235,7 +234,7 @@ public class PodDBAdapter { /** * Select id, description and content-encoded column from feeditems. */ - public static final String[] SEL_FI_EXTRA = {KEY_ID, KEY_DESCRIPTION, + private static final String[] SEL_FI_EXTRA = {KEY_ID, KEY_DESCRIPTION, KEY_CONTENT_ENCODED, KEY_FEED}; // column indices for SEL_FI_EXTRA @@ -279,6 +278,13 @@ public class PodDBAdapter { //db.close(); } + public static boolean deleteDatabase(Context context) { + Log.w(TAG, "Deleting database"); + dbHelperSingleton.close(); + dbHelperSingleton = null; + return context.deleteDatabase(DATABASE_NAME); + } + /** * Inserts or updates a feed entry * @@ -392,6 +398,17 @@ public class PodDBAdapter { } } + public void setFeedMediaPlaybackCompletionDate(FeedMedia media) { + if (media.getId() != 0) { + ContentValues values = new ContentValues(); + values.put(KEY_PLAYBACK_COMPLETION_DATE, media.getPlaybackCompletionDate().getTime()); + db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID + "=?", + new String[]{String.valueOf(media.getId())}); + } else { + Log.e(TAG, "setFeedMediaPlaybackCompletionDate: ID of media was 0"); + } + } + /** * Insert all FeedItems of a feed and the feed object itself in a single * transaction @@ -764,7 +781,7 @@ public class PodDBAdapter { final String query = "SELECT " + SEL_FI_SMALL_STR + " FROM " + TABLE_NAME_FEED_ITEMS + " INNER JOIN " + TABLE_NAME_FEED_MEDIA + " ON " + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + "=" - + TABLE_NAME_FEED_MEDIA + "." + KEY_ID + " WHERE " + + TABLE_NAME_FEED_MEDIA + "." + KEY_FEEDITEM + " WHERE " + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOADED + ">0"; Cursor c = db.rawQuery(query, null); return c; diff --git a/src/de/danoeh/antennapod/syndication/namespace/atom/NSAtom.java b/src/de/danoeh/antennapod/syndication/namespace/atom/NSAtom.java index 1efaac359..bcb0422ce 100644 --- a/src/de/danoeh/antennapod/syndication/namespace/atom/NSAtom.java +++ b/src/de/danoeh/antennapod/syndication/namespace/atom/NSAtom.java @@ -121,7 +121,7 @@ public class NSAtom extends Namespace { if (state.getContentBuf() != null) { content = state.getContentBuf().toString(); } else { - content = new String(); + content = ""; } SyndElement topElement = state.getTagstack().peek(); String top = topElement.getName(); diff --git a/src/de/danoeh/antennapod/syndication/util/SyndDateUtils.java b/src/de/danoeh/antennapod/syndication/util/SyndDateUtils.java index 30835434f..a1ed01354 100644 --- a/src/de/danoeh/antennapod/syndication/util/SyndDateUtils.java +++ b/src/de/danoeh/antennapod/syndication/util/SyndDateUtils.java @@ -11,7 +11,7 @@ import android.util.Log; public class SyndDateUtils { private static final String TAG = "DateUtils"; - public static final String[] RFC822DATES = { "dd MMM yy HH:mm:ss Z", }; + private static final String[] RFC822DATES = { "dd MMM yy HH:mm:ss Z", }; /** RFC 3339 date format for UTC dates. */ public static final String RFC3339UTC = "yyyy-MM-dd'T'HH:mm:ss'Z'"; @@ -123,12 +123,12 @@ public class SyndDateUtils { int idx = 0; if (parts.length == 3) { // string has hours - result += Integer.valueOf(parts[idx]) * 3600000; + result += Integer.valueOf(parts[idx]) * 3600000L; idx++; } - result += Integer.valueOf(parts[idx]) * 60000; + result += Integer.valueOf(parts[idx]) * 60000L; idx++; - result += (Float.valueOf(parts[idx])) * 1000; + result += (Float.valueOf(parts[idx])) * 1000L; return result; } } diff --git a/src/de/danoeh/antennapod/util/ChapterUtils.java b/src/de/danoeh/antennapod/util/ChapterUtils.java index ac8149119..521bfebea 100644 --- a/src/de/danoeh/antennapod/util/ChapterUtils.java +++ b/src/de/danoeh/antennapod/util/ChapterUtils.java @@ -35,9 +35,9 @@ public class ChapterUtils { * chapters. */ public static void readID3ChaptersFromPlayableStreamUrl(Playable p) { - if (AppConfig.DEBUG) - Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle()); if (p != null && p.getStreamUrl() != null) { + if (AppConfig.DEBUG) + Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle()); InputStream in = null; try { URL url = new URL(p.getStreamUrl()); @@ -86,9 +86,9 @@ public class ChapterUtils { * chapters. */ public static void readID3ChaptersFromPlayableFileUrl(Playable p) { - if (AppConfig.DEBUG) - Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle()); if (p != null && p.localFileAvailable() && p.getLocalMediaUrl() != null) { + if (AppConfig.DEBUG) + Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle()); File source = new File(p.getLocalMediaUrl()); if (source.exists()) { ChapterReader reader = new ChapterReader(); diff --git a/src/de/danoeh/antennapod/util/LangUtils.java b/src/de/danoeh/antennapod/util/LangUtils.java index 53f8de773..e6e1d8399 100644 --- a/src/de/danoeh/antennapod/util/LangUtils.java +++ b/src/de/danoeh/antennapod/util/LangUtils.java @@ -1,8 +1,11 @@ package de.danoeh.antennapod.util; +import java.nio.charset.Charset; import java.util.HashMap; public class LangUtils { + public static final Charset UTF_8 = Charset.forName("UTF-8"); + private static HashMap<String, String> languages; static { languages = new HashMap<String, String>(); diff --git a/src/de/danoeh/antennapod/util/URLChecker.java b/src/de/danoeh/antennapod/util/URLChecker.java index 6d9b8ff03..13668d4a9 100644 --- a/src/de/danoeh/antennapod/util/URLChecker.java +++ b/src/de/danoeh/antennapod/util/URLChecker.java @@ -19,13 +19,12 @@ public final class URLChecker { * */ public static String prepareURL(String url) { StringBuilder builder = new StringBuilder(); - url = url.trim(); - if (!url.startsWith("http")) { + if (url.startsWith("feed://")) { + if (AppConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://"); + url = url.replace("feed://", "http://"); + } else if (!(url.startsWith("http://") || url.startsWith("https://"))) { + if (AppConfig.DEBUG) Log.d(TAG, "Adding http:// at the beginning of the URL"); builder.append("http://"); - if (AppConfig.DEBUG) Log.d(TAG, "Missing http; appending"); - } else if (url.startsWith("https")) { - if (AppConfig.DEBUG) Log.d(TAG, "Replacing https with http"); - url = url.replaceFirst("https", "http"); } builder.append(url); diff --git a/src/de/danoeh/antennapod/util/comparator/DownloadStatusComparator.java b/src/de/danoeh/antennapod/util/comparator/DownloadStatusComparator.java index 2cfe52364..d0561252f 100644 --- a/src/de/danoeh/antennapod/util/comparator/DownloadStatusComparator.java +++ b/src/de/danoeh/antennapod/util/comparator/DownloadStatusComparator.java @@ -9,8 +9,7 @@ public class DownloadStatusComparator implements Comparator<DownloadStatus> { @Override public int compare(DownloadStatus lhs, DownloadStatus rhs) { - return -lhs.getCompletionDate().compareTo(rhs.getCompletionDate()); - + return rhs.getCompletionDate().compareTo(lhs.getCompletionDate()); } } diff --git a/src/de/danoeh/antennapod/util/comparator/FeedItemPubdateComparator.java b/src/de/danoeh/antennapod/util/comparator/FeedItemPubdateComparator.java index b9ee6c07e..c95c0833c 100644 --- a/src/de/danoeh/antennapod/util/comparator/FeedItemPubdateComparator.java +++ b/src/de/danoeh/antennapod/util/comparator/FeedItemPubdateComparator.java @@ -13,7 +13,7 @@ public class FeedItemPubdateComparator implements Comparator<FeedItem> { }*/ @Override public int compare(FeedItem lhs, FeedItem rhs) { - return -lhs.getPubDate().compareTo(rhs.getPubDate()); + return rhs.getPubDate().compareTo(lhs.getPubDate()); } } diff --git a/src/de/danoeh/antennapod/util/comparator/PlaybackCompletionDateComparator.java b/src/de/danoeh/antennapod/util/comparator/PlaybackCompletionDateComparator.java index 2d0ce75ca..434a5a956 100644 --- a/src/de/danoeh/antennapod/util/comparator/PlaybackCompletionDateComparator.java +++ b/src/de/danoeh/antennapod/util/comparator/PlaybackCompletionDateComparator.java @@ -11,8 +11,8 @@ public class PlaybackCompletionDateComparator implements Comparator<FeedItem> { && lhs.getMedia().getPlaybackCompletionDate() != null && rhs.getMedia() != null && rhs.getMedia().getPlaybackCompletionDate() != null) { - return -lhs.getMedia().getPlaybackCompletionDate() - .compareTo(rhs.getMedia().getPlaybackCompletionDate()); + return rhs.getMedia().getPlaybackCompletionDate() + .compareTo(lhs.getMedia().getPlaybackCompletionDate()); } return 0; } diff --git a/src/de/danoeh/antennapod/util/playback/ExternalMedia.java b/src/de/danoeh/antennapod/util/playback/ExternalMedia.java index 1ada0ec03..e937ee437 100644 --- a/src/de/danoeh/antennapod/util/playback/ExternalMedia.java +++ b/src/de/danoeh/antennapod/util/playback/ExternalMedia.java @@ -25,7 +25,6 @@ public class ExternalMedia implements Playable { private String episodeTitle; private String feedTitle; - private String shownotes; private MediaType mediaType = MediaType.AUDIO; private List<Chapter> chapters; private int duration; @@ -80,8 +79,13 @@ public class ExternalMedia implements Playable { .extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); feedTitle = mmr .extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM); - duration = Integer.parseInt(mmr + try { + duration = Integer.parseInt(mmr .extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)); + } catch (NumberFormatException e) { + e.printStackTrace(); + throw new PlayableException("NumberFormatException when reading duration of media file"); + } ChapterUtils.loadChaptersFromFileUrl(this); } |