Disable download log cleanup, handle media download before saving DownloadStatus
Might resolve problems with failed downloads being reported as successful
This commit is contained in:
parent
7fcefdbbe7
commit
44e4924db9
|
@ -104,6 +104,7 @@
|
|||
<string name="download_error_malformed_url">Malformed URL</string>
|
||||
<string name="download_error_io_error">IO Error</string>
|
||||
<string name="download_error_request_error">Request error</string>
|
||||
<string name="download_error_db_access">Database access error</string>
|
||||
<string name="downloads_left">\u0020Downloads left</string>
|
||||
<string name="download_notification_title">Downloading podcast data</string>
|
||||
<string name="download_report_content">%1$d downloads succeeded, %2$d failed</string>
|
||||
|
|
|
@ -827,23 +827,24 @@ public class DownloadService extends Service {
|
|||
}
|
||||
}
|
||||
|
||||
saveDownloadStatus(status);
|
||||
sendDownloadHandledIntent();
|
||||
|
||||
try {
|
||||
if (chaptersRead) {
|
||||
DBWriter.setFeedItem(DownloadService.this, media.getItem()).get();
|
||||
}
|
||||
DBWriter.setFeedMedia(DownloadService.this, media).get();
|
||||
if (!DBTasks.isInQueue(DownloadService.this, media.getItem().getId())) {
|
||||
DBWriter.addQueueItem(DownloadService.this, media.getItem().getId()).get();
|
||||
}
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
status = new DownloadStatus(media, media.getEpisodeTitle(), DownloadError.ERROR_DB_ACCESS_ERROR, false, e.getMessage());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
status = new DownloadStatus(media, media.getEpisodeTitle(), DownloadError.ERROR_DB_ACCESS_ERROR, false, e.getMessage());
|
||||
}
|
||||
|
||||
if (!DBTasks.isInQueue(DownloadService.this, media.getItem().getId())) {
|
||||
DBWriter.addQueueItem(DownloadService.this, media.getItem().getId());
|
||||
}
|
||||
saveDownloadStatus(status);
|
||||
sendDownloadHandledIntent();
|
||||
|
||||
numberOfDownloads.decrementAndGet();
|
||||
queryDownloadsAsync();
|
||||
|
|
|
@ -254,9 +254,7 @@ public class DBWriter {
|
|||
|
||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||
adapter.open();
|
||||
|
||||
adapter.setDownloadStatus(status);
|
||||
cleanupDownloadLog(adapter);
|
||||
adapter.close();
|
||||
EventDistributor.getInstance().sendDownloadLogUpdateBroadcast();
|
||||
}
|
||||
|
|
|
@ -558,23 +558,25 @@ public class PodDBAdapter {
|
|||
db.update(TABLE_NAME_DOWNLOAD_LOG, values, KEY_ID + "=?",
|
||||
new String[]{String.valueOf(status.getId())});
|
||||
}
|
||||
|
||||
return status.getId();
|
||||
}
|
||||
|
||||
public long getDownloadLogSize() {
|
||||
Cursor result = db.rawQuery("SELECT COUNT(?) AS ? FROM ?",
|
||||
new String[]{KEY_ID, KEY_ID, TABLE_NAME_DOWNLOAD_LOG});
|
||||
long count = result.getLong(KEY_ID_INDEX);
|
||||
final String query = String.format("SELECT COUNT(%s) FROM %s", KEY_ID, TABLE_NAME_DOWNLOAD_LOG);
|
||||
Cursor result = db.rawQuery(query, null);
|
||||
long count = 0;
|
||||
if (result.moveToFirst()) {
|
||||
count = result.getLong(0);
|
||||
}
|
||||
result.close();
|
||||
return count;
|
||||
}
|
||||
|
||||
public void removeDownloadLogItems(long count) {
|
||||
if (count > 0) {
|
||||
db.rawQuery("DELETE FROM ? ORDER BY ? ASC LIMIT ?",
|
||||
new String[]{TABLE_NAME_DOWNLOAD_LOG,
|
||||
KEY_COMPLETION_DATE, String.valueOf(count)});
|
||||
final String sql = String.format("DELETE FROM %s WHERE %s in (SELECT %s from %s ORDER BY %s ASC LIMIT %d)",
|
||||
TABLE_NAME_DOWNLOAD_LOG, KEY_ID, KEY_ID, TABLE_NAME_DOWNLOAD_LOG, KEY_COMPLETION_DATE, count);
|
||||
db.execSQL(sql, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,8 @@ public enum DownloadError {
|
|||
ERROR_HTTP_DATA_ERROR(9, R.string.download_error_http_data_error),
|
||||
ERROR_NOT_ENOUGH_SPACE(10, R.string.download_error_insufficient_space),
|
||||
ERROR_UNKNOWN_HOST(11, R.string.download_error_unknown_host),
|
||||
ERROR_REQUEST_ERROR(12, R.string.download_error_request_error);
|
||||
ERROR_REQUEST_ERROR(12, R.string.download_error_request_error),
|
||||
ERROR_DB_ACCESS_ERROR(13, R.string.download_error_db_access);
|
||||
|
||||
private final int code;
|
||||
private final int resId;
|
||||
|
|
Loading…
Reference in New Issue