use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class PagerActivity method onAudioSettingsPressed.
@Override
public void onAudioSettingsPressed() {
if (lastPlayingSura != null) {
start = new SuraAyah(lastPlayingSura, lastPlayingAyah);
end = start;
}
if (start == null) {
final int[] bounds = quranInfo.getPageBounds(getCurrentPage());
start = new SuraAyah(bounds[0], bounds[1]);
end = start;
}
showSlider(AUDIO_PAGE);
}
use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class PagerActivity method previousAyah.
public void previousAyah() {
if (end != null) {
final SuraAyah s;
if (end.ayah > 1) {
s = new SuraAyah(end.sura, end.ayah - 1);
} else if (end.sura > 1) {
s = new SuraAyah(end.sura - 1, quranInfo.getNumAyahs(end.sura - 1));
} else {
return;
}
selectAyah(s);
}
}
use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class AudioManagerActivity method download.
private void download(QariItem qariItem) {
String baseUri = basePath + qariItem.getPath();
boolean isGapless = qariItem.isGapless();
String sheikhName = qariItem.getName();
Intent intent = ServiceIntentHelper.getDownloadIntent(this, audioUtils.getQariUrl(qariItem), baseUri, sheikhName, AUDIO_DOWNLOAD_KEY, QuranDownloadService.DOWNLOAD_TYPE_AUDIO);
intent.putExtra(QuranDownloadService.EXTRA_START_VERSE, new SuraAyah(1, 1));
intent.putExtra(QuranDownloadService.EXTRA_END_VERSE, new SuraAyah(114, 6));
intent.putExtra(QuranDownloadService.EXTRA_IS_GAPLESS, isGapless);
startService(intent);
AudioManagerUtils.clearCacheKeyForSheikh(qariItem);
}
use of com.quran.labs.androidquran.data.SuraAyah 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;
}
}
use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class AudioUtils method haveAllFiles.
public boolean haveAllFiles(DownloadAudioRequest request) {
String baseDirectory = request.getLocalPath();
if (TextUtils.isEmpty(baseDirectory)) {
return false;
}
boolean isGapless = request.isGapless();
File f = new File(baseDirectory);
if (!f.exists()) {
f.mkdirs();
return false;
}
SuraAyah minAyah = request.getMinAyah();
int startSura = minAyah.sura;
int startAyah = minAyah.ayah;
SuraAyah maxAyah = request.getMaxAyah();
int endSura = maxAyah.sura;
int endAyah = maxAyah.ayah;
if (endSura < startAyah || (endSura == startSura && endAyah < startAyah))
throw new IllegalStateException("End isn't larger than the start");
for (int i = startSura; i <= endSura; i++) {
int lastAyah = quranInfo.getNumAyahs(i);
if (i == endSura) {
lastAyah = endAyah;
}
int firstAyah = 1;
if (i == startSura) {
firstAyah = startAyah;
}
if (isGapless) {
if (i == endSura && endAyah == 0) {
continue;
}
String p = request.getBaseUrl();
String fileName = String.format(Locale.US, p, i);
Timber.d("gapless, checking if we have %s", fileName);
f = new File(fileName);
if (!f.exists()) {
return false;
}
continue;
}
Timber.d("not gapless, checking each ayah...");
for (int j = firstAyah; j <= lastAyah; j++) {
String filename = i + File.separator + j + AUDIO_EXTENSION;
f = new File(baseDirectory + File.separator + filename);
if (!f.exists()) {
return false;
}
}
}
return true;
}
Aggregations