use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class PagerActivity method showAyahModeRangeHighlights.
private void showAyahModeRangeHighlights() {
// Determine the start and end of the selection
final int startPage = quranInfo.getPageFromSuraAyah(start.sura, start.ayah);
final int endingPage = quranInfo.getPageFromSuraAyah(end.sura, end.ayah);
int minPage = Math.min(startPage, endingPage);
int maxPage = Math.max(startPage, endingPage);
SuraAyah start = SuraAyah.min(this.start, end);
SuraAyah end = SuraAyah.max(this.start, this.end);
// Iterate from beginning to end
for (int i = minPage; i <= maxPage; i++) {
QuranPage fragment = pagerAdapter.getFragmentIfExistsForPage(i);
if (fragment != null) {
Set<String> ayahKeys = quranInfo.getAyahKeysOnPage(i, start, end);
fragment.getAyahTracker().highlightAyat(i, ayahKeys, HighlightType.SELECTION);
}
}
}
use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class PagerActivity method playAudioRequest.
private void playAudioRequest(@Nullable DownloadAudioRequest request) {
if (request == null) {
audioStatusBar.switchMode(AudioStatusBar.STOPPED_MODE);
return;
}
boolean needsPermission = needsPermissionToDownloadOver3g;
if (needsPermission) {
if (QuranUtils.isOnWifiNetwork(this)) {
Timber.d("on wifi, don't need permission for download...");
needsPermission = false;
}
}
Timber.d("seeing if we can play audio request...");
if (!quranFileUtils.haveAyaPositionFile(this)) {
if (needsPermission) {
audioStatusBar.switchMode(AudioStatusBar.PROMPT_DOWNLOAD_MODE);
return;
}
if (isActionBarHidden) {
toggleActionBar();
}
audioStatusBar.switchMode(AudioStatusBar.DOWNLOADING_MODE);
String url = quranFileUtils.getAyaPositionFileUrl();
String destination = quranFileUtils.getQuranDatabaseDirectory(this);
// start the download
String notificationTitle = getString(R.string.highlighting_database);
Intent intent = ServiceIntentHelper.getDownloadIntent(this, url, destination, notificationTitle, AUDIO_DOWNLOAD_KEY, QuranDownloadService.DOWNLOAD_TYPE_AUDIO);
startService(intent);
} else if (audioUtils.shouldDownloadGaplessDatabase(request)) {
Timber.d("need to download gapless database...");
if (needsPermission) {
audioStatusBar.switchMode(AudioStatusBar.PROMPT_DOWNLOAD_MODE);
return;
}
if (isActionBarHidden) {
toggleActionBar();
}
audioStatusBar.switchMode(AudioStatusBar.DOWNLOADING_MODE);
String url = audioUtils.getGaplessDatabaseUrl(request);
String destination = request.getLocalPath();
// start the download
String notificationTitle = getString(R.string.timing_database);
Intent intent = ServiceIntentHelper.getDownloadIntent(this, url, destination, notificationTitle, AUDIO_DOWNLOAD_KEY, QuranDownloadService.DOWNLOAD_TYPE_AUDIO);
startService(intent);
} else if (audioUtils.haveAllFiles(request)) {
if (!audioUtils.shouldDownloadBasmallah(request)) {
Timber.d("have all files, playing!");
play(request);
lastAudioDownloadRequest = null;
} else {
Timber.d("should download basmalla...");
if (needsPermission) {
audioStatusBar.switchMode(AudioStatusBar.PROMPT_DOWNLOAD_MODE);
return;
}
SuraAyah firstAyah = new SuraAyah(1, 1);
String qariUrl = audioUtils.getQariUrl(request.getQariItem());
audioStatusBar.switchMode(AudioStatusBar.DOWNLOADING_MODE);
if (isActionBarHidden) {
toggleActionBar();
}
String notificationTitle = quranInfo.getNotificationTitle(this, firstAyah, firstAyah, request.isGapless());
Intent intent = ServiceIntentHelper.getDownloadIntent(this, qariUrl, request.getLocalPath(), notificationTitle, AUDIO_DOWNLOAD_KEY, QuranDownloadService.DOWNLOAD_TYPE_AUDIO);
intent.putExtra(QuranDownloadService.EXTRA_START_VERSE, firstAyah);
intent.putExtra(QuranDownloadService.EXTRA_END_VERSE, firstAyah);
startService(intent);
}
} else {
if (needsPermission) {
audioStatusBar.switchMode(AudioStatusBar.PROMPT_DOWNLOAD_MODE);
return;
}
if (isActionBarHidden) {
toggleActionBar();
}
audioStatusBar.switchMode(AudioStatusBar.DOWNLOADING_MODE);
String notificationTitle = quranInfo.getNotificationTitle(this, request.getMinAyah(), request.getMaxAyah(), request.isGapless());
String qariUrl = audioUtils.getQariUrl(request.getQariItem());
Timber.d("need to start download: %s", qariUrl);
// start service
Intent intent = ServiceIntentHelper.getDownloadIntent(this, qariUrl, request.getLocalPath(), notificationTitle, AUDIO_DOWNLOAD_KEY, QuranDownloadService.DOWNLOAD_TYPE_AUDIO);
intent.putExtra(QuranDownloadService.EXTRA_START_VERSE, request.getMinAyah());
intent.putExtra(QuranDownloadService.EXTRA_END_VERSE, request.getMaxAyah());
intent.putExtra(QuranDownloadService.EXTRA_IS_GAPLESS, request.isGapless());
startService(intent);
}
}
use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class PagerActivity method toggleBookmark.
private void toggleBookmark(final Integer sura, final Integer ayah, final int page) {
compositeDisposable.add(bookmarkModel.toggleBookmarkObservable(sura, ayah, page).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSingleObserver<Boolean>() {
@Override
public void onSuccess(Boolean isBookmarked) {
if (sura == null || ayah == null) {
// page bookmark
bookmarksCache.put(page, isBookmarked);
supportInvalidateOptionsMenu();
} else {
// ayah bookmark
SuraAyah suraAyah = new SuraAyah(sura, ayah);
updateAyahBookmark(suraAyah, isBookmarked, true);
}
}
@Override
public void onError(Throwable e) {
}
}));
}
use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class PagerActivity method nextAyah.
public void nextAyah() {
if (end != null) {
final int ayat = quranInfo.getNumAyahs(end.sura);
final SuraAyah s;
if (end.ayah + 1 <= ayat) {
s = new SuraAyah(end.sura, end.ayah + 1);
} else if (end.sura < 114) {
s = new SuraAyah(end.sura + 1, 1);
} else {
return;
}
selectAyah(s);
}
}
use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class PagerActivity method playStreaming.
private void playStreaming(SuraAyah ayah, SuraAyah end, int page, QariItem item, int verseRepeat, int rangeRepeat, boolean enforceRange) {
String qariUrl = audioUtils.getQariUrl(item);
String dbFile = audioUtils.getQariDatabasePathIfGapless(this, item);
if (!TextUtils.isEmpty(dbFile)) {
// gapless audio is "download only"
lastAudioDownloadRequest = getAudioDownloadRequest(ayah, end, page, item, verseRepeat, rangeRepeat, enforceRange);
playAudioRequest(lastAudioDownloadRequest);
return;
}
final SuraAyah ending;
if (end != null) {
ending = end;
} else {
// this won't be enforced unless the user sets a range
// repeat, but we set it to a sane default anyway.
ending = audioUtils.getLastAyahToPlay(ayah, page, quranSettings.getPreferredDownloadAmount(), isDualPages);
}
AudioRequest request = new StreamingAudioRequest(qariUrl, ayah, quranInfo.getNumAyahs(ayah.sura));
request.setPlayBounds(ayah, ending);
request.setEnforceBounds(enforceRange);
request.setRangeRepeatCount(rangeRepeat);
request.setVerseRepeatCount(verseRepeat);
play(request);
audioStatusBar.switchMode(AudioStatusBar.PLAYING_MODE);
audioStatusBar.setRepeatCount(verseRepeat);
}
Aggregations