use of com.quran.labs.androidquran.service.util.QuranDownloadNotifier.NotificationDetails in project quran_android by quran.
the class QuranDownloadService method onHandleIntent.
private void onHandleIntent(Intent intent) {
if (ACTION_DOWNLOAD_URL.equals(intent.getAction())) {
String url = intent.getStringExtra(EXTRA_URL);
String key = intent.getStringExtra(EXTRA_DOWNLOAD_KEY);
int type = intent.getIntExtra(EXTRA_DOWNLOAD_TYPE, 0);
String notificationTitle = intent.getStringExtra(EXTRA_NOTIFICATION_NAME);
NotificationDetails details = new NotificationDetails(notificationTitle, key, type);
// check if already downloaded, and if so, send broadcast
boolean isZipFile = url.endsWith(".zip");
if (isZipFile && mSuccessfulZippedDownloads.containsKey(url)) {
mLastSentIntent = mNotifier.broadcastDownloadSuccessful(details);
return;
} else if (mRecentlyFailedDownloads.containsKey(url)) {
// if recently failed and we want to repeat the last error...
if (intent.getBooleanExtra(EXTRA_REPEAT_LAST_ERROR, false)) {
Intent failedIntent = mRecentlyFailedDownloads.get(url);
if (failedIntent != null) {
// re-broadcast and leave - just in case of race condition
mBroadcastManager.sendBroadcast(failedIntent);
return;
}
} else // otherwise, remove the fact it was an error and retry
{
mRecentlyFailedDownloads.remove(url);
}
}
mNotifier.resetNotifications();
// get the start/end ayah info if it's a ranged download
SuraAyah startAyah = intent.getParcelableExtra(EXTRA_START_VERSE);
SuraAyah endAyah = intent.getParcelableExtra(EXTRA_END_VERSE);
boolean isGapless = intent.getBooleanExtra(EXTRA_IS_GAPLESS, false);
String outputFile = intent.getStringExtra(EXTRA_OUTPUT_FILE_NAME);
if (outputFile == null) {
outputFile = getFilenameFromUrl(url);
}
String destination = intent.getStringExtra(EXTRA_DESTINATION);
mLastSentIntent = null;
if (destination == null) {
return;
}
boolean result;
if (startAyah != null && endAyah != null) {
result = downloadRange(url, destination, startAyah, endAyah, isGapless, details);
} else {
result = download(url, destination, outputFile, details);
}
if (result && isZipFile) {
mSuccessfulZippedDownloads.put(url, true);
} else if (!result) {
mRecentlyFailedDownloads.put(url, mLastSentIntent);
}
mLastSentIntent = null;
}
}
Aggregations