Reduced number of FindBugs warnings
This commit is contained in:
parent
ffd1070270
commit
fd5f1fcc0b
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.SearchManager;
|
import android.app.SearchManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -140,34 +141,34 @@ public class SearchActivity extends ActionBarActivity implements AdapterView.OnI
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Log.d(TAG, "Starting background work");
|
Log.d(TAG, "Starting background work");
|
||||||
|
final Activity activity = SearchActivity.this;
|
||||||
final List<SearchResult> result = FeedSearcher
|
final List<SearchResult> result = FeedSearcher
|
||||||
.performSearch(SearchActivity.this, query, feedID);
|
.performSearch(activity, query, feedID);
|
||||||
if (SearchActivity.this != null) {
|
activity.runOnUiThread(new Runnable() {
|
||||||
SearchActivity.this.runOnUiThread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Background work finished");
|
Log.d(TAG, "Background work finished");
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Found " + result.size()
|
Log.d(TAG, "Found " + result.size()
|
||||||
+ " results");
|
+ " results");
|
||||||
|
|
||||||
searchAdapter.clear();
|
searchAdapter.clear();
|
||||||
for (SearchResult s : result) {
|
for (SearchResult s : result) {
|
||||||
searchAdapter.add(s);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
searchAdapter.notifyDataSetChanged();
|
||||||
}
|
txtvStatus
|
||||||
|
.setText(R.string.search_status_no_results);
|
||||||
|
if (!searchAdapter.isEmpty()) {
|
||||||
|
txtvStatus.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
txtvStatus.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
thread.start();
|
thread.start();
|
||||||
|
@ -144,53 +144,6 @@ public class ChapterListAdapter extends ArrayAdapter<Chapter> {
|
|||||||
TextView link;
|
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
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
// ignore invalid chapters
|
// ignore invalid chapters
|
||||||
|
@ -77,7 +77,7 @@ public class ImageLoader {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImageLoader getInstance() {
|
public static synchronized ImageLoader getInstance() {
|
||||||
if (singleton == null) {
|
if (singleton == null) {
|
||||||
singleton = new ImageLoader();
|
singleton = new ImageLoader();
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class EventDistributor extends Observable {
|
|||||||
events = new ConcurrentLinkedQueue<Integer>();
|
events = new ConcurrentLinkedQueue<Integer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EventDistributor getInstance() {
|
public static synchronized EventDistributor getInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new EventDistributor();
|
instance = new EventDistributor();
|
||||||
}
|
}
|
||||||
|
@ -87,11 +87,7 @@ public class Feed extends FeedFile {
|
|||||||
*/
|
*/
|
||||||
public Feed(String url, Date lastUpdate) {
|
public Feed(String url, Date lastUpdate) {
|
||||||
super(null, url, false);
|
super(null, url, false);
|
||||||
if (lastUpdate != null) {
|
this.lastUpdate = (lastUpdate != null) ? (Date) lastUpdate.clone() : null;
|
||||||
this.lastUpdate = lastUpdate;
|
|
||||||
} else {
|
|
||||||
this.lastUpdate = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -323,19 +319,11 @@ public class Feed extends FeedFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Date getLastUpdate() {
|
public Date getLastUpdate() {
|
||||||
if (lastUpdate != null) {
|
return (lastUpdate != null) ? (Date) lastUpdate.clone() : null;
|
||||||
return (Date) lastUpdate.clone();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastUpdate(Date lastUpdate) {
|
public void setLastUpdate(Date lastUpdate) {
|
||||||
if (lastUpdate != null) {
|
this.lastUpdate = (lastUpdate != null) ? (Date) lastUpdate.clone() : null;
|
||||||
this.lastUpdate = (Date) lastUpdate.clone();
|
|
||||||
} else {
|
|
||||||
this.lastUpdate = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFeedIdentifier() {
|
public String getFeedIdentifier() {
|
||||||
|
@ -265,9 +265,9 @@ public class FeedlistFragment extends Fragment implements
|
|||||||
public boolean onItemLongClick(AdapterView<?> parent, View view,
|
public boolean onItemLongClick(AdapterView<?> parent, View view,
|
||||||
int position, long id) {
|
int position, long id) {
|
||||||
Feed selection = fla.getItem(position);
|
Feed selection = fla.getItem(position);
|
||||||
if (AppConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Selected Feed with title " + selection.getTitle());
|
|
||||||
if (selection != null) {
|
if (selection != null) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Selected Feed with title " + selection.getTitle());
|
||||||
if (mActionMode != null) {
|
if (mActionMode != null) {
|
||||||
mActionMode.finish();
|
mActionMode.finish();
|
||||||
}
|
}
|
||||||
|
@ -374,11 +374,10 @@ public class ItemDescriptionFragment extends Fragment {
|
|||||||
Callable<String> shownotesLoadTask = shownotesProvider.loadShownotes();
|
Callable<String> shownotesLoadTask = shownotesProvider.loadShownotes();
|
||||||
final String shownotes = shownotesLoadTask.call();
|
final String shownotes = shownotesLoadTask.call();
|
||||||
|
|
||||||
data = "";
|
|
||||||
data = StringEscapeUtils.unescapeHtml4(shownotes);
|
data = StringEscapeUtils.unescapeHtml4(shownotes);
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
TypedArray res = getActivity()
|
TypedArray res = activity
|
||||||
.getTheme()
|
.getTheme()
|
||||||
.obtainStyledAttributes(
|
.obtainStyledAttributes(
|
||||||
new int[]{android.R.attr.textColorPrimary});
|
new int[]{android.R.attr.textColorPrimary});
|
||||||
|
@ -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 EXTRA_SELECTED_FEEDITEM = "extra.de.danoeh.antennapod.activity.selected_feeditem";
|
||||||
public static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id";
|
public static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id";
|
||||||
protected InternalFeedItemlistAdapter fila;
|
protected InternalFeedItemlistAdapter fila;
|
||||||
protected DownloadRequester requester = DownloadRequester.getInstance();
|
|
||||||
|
|
||||||
private Feed feed;
|
private Feed feed;
|
||||||
protected List<Long> queue;
|
protected List<Long> queue;
|
||||||
@ -156,8 +155,6 @@ public class ItemlistFragment extends ListFragment {
|
|||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Could not load queue");
|
Log.e(TAG, "Could not load queue");
|
||||||
}
|
}
|
||||||
if (result.getItems().isEmpty()) {
|
|
||||||
}
|
|
||||||
setEmptyViewIfListIsEmpty();
|
setEmptyViewIfListIsEmpty();
|
||||||
if (fila != null) {
|
if (fila != null) {
|
||||||
fila.notifyDataSetChanged();
|
fila.notifyDataSetChanged();
|
||||||
|
@ -184,7 +184,7 @@ public class DownloadService extends Service {
|
|||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if (intent.getParcelableExtra(EXTRA_REQUEST) != null) {
|
if (intent.getParcelableExtra(EXTRA_REQUEST) != null) {
|
||||||
onDownloadQueued(intent);
|
onDownloadQueued(intent);
|
||||||
} else if (numberOfDownloads.equals(0)) {
|
} else if (numberOfDownloads.get() == 0) {
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
return Service.START_NOT_STICKY;
|
return Service.START_NOT_STICKY;
|
||||||
|
@ -29,170 +29,179 @@ import de.danoeh.antennapod.util.DownloadError;
|
|||||||
import de.danoeh.antennapod.util.StorageUtils;
|
import de.danoeh.antennapod.util.StorageUtils;
|
||||||
|
|
||||||
public class HttpDownloader extends Downloader {
|
public class HttpDownloader extends Downloader {
|
||||||
private static final String TAG = "HttpDownloader";
|
private static final String TAG = "HttpDownloader";
|
||||||
|
|
||||||
private static final int MAX_REDIRECTS = 5;
|
private static final int MAX_REDIRECTS = 5;
|
||||||
|
|
||||||
private static final int BUFFER_SIZE = 8 * 1024;
|
private static final int BUFFER_SIZE = 8 * 1024;
|
||||||
private static final int CONNECTION_TIMEOUT = 30000;
|
private static final int CONNECTION_TIMEOUT = 30000;
|
||||||
private static final int SOCKET_TIMEOUT = 30000;
|
private static final int SOCKET_TIMEOUT = 30000;
|
||||||
|
|
||||||
public HttpDownloader(DownloadRequest request) {
|
public HttpDownloader(DownloadRequest request) {
|
||||||
super(request);
|
super(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefaultHttpClient createHttpClient() {
|
private DefaultHttpClient createHttpClient() {
|
||||||
DefaultHttpClient httpClient = new DefaultHttpClient();
|
DefaultHttpClient httpClient = new DefaultHttpClient();
|
||||||
HttpParams params = httpClient.getParams();
|
HttpParams params = httpClient.getParams();
|
||||||
params.setIntParameter("http.protocol.max-redirects", MAX_REDIRECTS);
|
params.setIntParameter("http.protocol.max-redirects", MAX_REDIRECTS);
|
||||||
params.setBooleanParameter("http.protocol.reject-relative-redirect",
|
params.setBooleanParameter("http.protocol.reject-relative-redirect",
|
||||||
false);
|
false);
|
||||||
HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);
|
HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);
|
||||||
HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
|
HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
|
||||||
HttpClientParams.setRedirecting(params, true);
|
HttpClientParams.setRedirecting(params, true);
|
||||||
|
|
||||||
// Workaround for broken URLs in redirection
|
// Workaround for broken URLs in redirection
|
||||||
((AbstractHttpClient) httpClient)
|
((AbstractHttpClient) httpClient)
|
||||||
.setRedirectHandler(new APRedirectHandler());
|
.setRedirectHandler(new APRedirectHandler());
|
||||||
return httpClient;
|
return httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void download() {
|
protected void download() {
|
||||||
DefaultHttpClient httpClient = null;
|
DefaultHttpClient httpClient = null;
|
||||||
BufferedOutputStream out = null;
|
BufferedOutputStream out = null;
|
||||||
InputStream connection = null;
|
InputStream connection = null;
|
||||||
try {
|
try {
|
||||||
HttpGet httpGet = new HttpGet(request.getSource());
|
HttpGet httpGet = new HttpGet(request.getSource());
|
||||||
httpClient = createHttpClient();
|
httpClient = createHttpClient();
|
||||||
HttpResponse response = httpClient.execute(httpGet);
|
HttpResponse response = httpClient.execute(httpGet);
|
||||||
HttpEntity httpEntity = response.getEntity();
|
HttpEntity httpEntity = response.getEntity();
|
||||||
int responseCode = response.getStatusLine().getStatusCode();
|
int responseCode = response.getStatusLine().getStatusCode();
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Response code is " + responseCode);
|
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 = 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 (responseCode != HttpURLConnection.HTTP_OK || httpEntity == null) {
|
||||||
if (AppConfig.DEBUG)
|
onFail(DownloadError.ERROR_HTTP_DATA_ERROR,
|
||||||
Log.d(TAG, "Free space is " + freeSpace);
|
String.valueOf(responseCode));
|
||||||
if (request.getSize() == DownloadStatus.SIZE_UNKNOWN
|
return;
|
||||||
|| request.getSize() <= freeSpace) {
|
}
|
||||||
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();
|
|
||||||
}
|
|
||||||
} 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 (!StorageUtils.storageAvailable(PodcastApp.getInstance())) {
|
||||||
if (AppConfig.DEBUG)
|
onFail(DownloadError.ERROR_DEVICE_NOT_FOUND, null);
|
||||||
Log.d(TAG, "Download was successful");
|
return;
|
||||||
result.setSuccessful();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void onFail(DownloadError reason, String reasonDetailed) {
|
File destination = new File(request.getDestination());
|
||||||
if (AppConfig.DEBUG) {
|
if (destination.exists()) {
|
||||||
Log.d(TAG, "Download failed");
|
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);
|
result.setFailed(reason, reasonDetailed);
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onCancelled() {
|
private void onCancelled() {
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Download was cancelled");
|
Log.d(TAG, "Download was cancelled");
|
||||||
result.setCancelled();
|
result.setCancelled();
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Deletes unfinished downloads. */
|
/**
|
||||||
private void cleanup() {
|
* Deletes unfinished downloads.
|
||||||
if (request.getDestination() != null) {
|
*/
|
||||||
File dest = new File(request.getDestination());
|
private void cleanup() {
|
||||||
if (dest.exists()) {
|
if (request.getDestination() != null) {
|
||||||
boolean rc = dest.delete();
|
File dest = new File(request.getDestination());
|
||||||
if (AppConfig.DEBUG)
|
if (dest.exists()) {
|
||||||
Log.d(TAG, "Deleted file " + dest.getName() + "; Result: "
|
boolean rc = dest.delete();
|
||||||
+ rc);
|
if (AppConfig.DEBUG)
|
||||||
} else {
|
Log.d(TAG, "Deleted file " + dest.getName() + "; Result: "
|
||||||
if (AppConfig.DEBUG)
|
+ rc);
|
||||||
Log.d(TAG, "cleanup() didn't delete file: does not exist.");
|
} else {
|
||||||
}
|
if (AppConfig.DEBUG)
|
||||||
}
|
Log.d(TAG, "cleanup() didn't delete file: does not exist.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -229,9 +229,11 @@ public final class DBReader {
|
|||||||
title, item, link);
|
title, item, link);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
chapter.setId(chapterCursor
|
if (chapter != null) {
|
||||||
.getLong(PodDBAdapter.KEY_ID_INDEX));
|
chapter.setId(chapterCursor
|
||||||
item.getChapters().add(chapter);
|
.getLong(PodDBAdapter.KEY_ID_INDEX));
|
||||||
|
item.getChapters().add(chapter);
|
||||||
|
}
|
||||||
} while (chapterCursor.moveToNext());
|
} while (chapterCursor.moveToNext());
|
||||||
}
|
}
|
||||||
chapterCursor.close();
|
chapterCursor.close();
|
||||||
|
@ -38,7 +38,7 @@ public class DownloadRequester {
|
|||||||
downloads = new ConcurrentHashMap<String, DownloadRequest>();
|
downloads = new ConcurrentHashMap<String, DownloadRequest>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DownloadRequester getInstance() {
|
public static synchronized DownloadRequester getInstance() {
|
||||||
if (downloader == null) {
|
if (downloader == null) {
|
||||||
downloader = new DownloadRequester();
|
downloader = new DownloadRequester();
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public class FeedItemStatistics {
|
|||||||
this.numberOfItems = numberOfItems;
|
this.numberOfItems = numberOfItems;
|
||||||
this.numberOfNewItems = numberOfNewItems;
|
this.numberOfNewItems = numberOfNewItems;
|
||||||
this.numberOfInProgressItems = numberOfInProgressItems;
|
this.numberOfInProgressItems = numberOfInProgressItems;
|
||||||
this.lastUpdate = lastUpdate;
|
this.lastUpdate = (lastUpdate != null) ? (Date) lastUpdate.clone() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getFeedID() {
|
public long getFeedID() {
|
||||||
@ -37,6 +37,6 @@ public class FeedItemStatistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Date getLastUpdate() {
|
public Date getLastUpdate() {
|
||||||
return lastUpdate;
|
return (lastUpdate != null) ? (Date) lastUpdate.clone() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,9 @@ public class ChapterUtils {
|
|||||||
* chapters.
|
* chapters.
|
||||||
*/
|
*/
|
||||||
public static void readID3ChaptersFromPlayableStreamUrl(Playable p) {
|
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 (p != null && p.getStreamUrl() != null) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle());
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
try {
|
try {
|
||||||
URL url = new URL(p.getStreamUrl());
|
URL url = new URL(p.getStreamUrl());
|
||||||
@ -86,9 +86,9 @@ public class ChapterUtils {
|
|||||||
* chapters.
|
* chapters.
|
||||||
*/
|
*/
|
||||||
public static void readID3ChaptersFromPlayableFileUrl(Playable p) {
|
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 (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());
|
File source = new File(p.getLocalMediaUrl());
|
||||||
if (source.exists()) {
|
if (source.exists()) {
|
||||||
ChapterReader reader = new ChapterReader();
|
ChapterReader reader = new ChapterReader();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user