use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class ImageAyahUtils method getAyahFromKey.
private static SuraAyah getAyahFromKey(String key) {
String[] parts = key.split(":", -1);
SuraAyah result = null;
if (parts.length == 2) {
try {
int sura = Integer.parseInt(parts[0]);
int ayah = Integer.parseInt(parts[1]);
result = new SuraAyah(sura, ayah);
} catch (Exception e) {
// no op
}
}
return result;
}
use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class AudioUtilsTest method testGetLastAyahWithNewSurahOnNextPageForMadani.
@Test
public void testGetLastAyahWithNewSurahOnNextPageForMadani() throws Exception {
PageProvider pageProviderMock = Mockito.mock(PageProvider.class);
when(pageProviderMock.getDataSource()).thenReturn(new MadaniDataSource());
QuranInfo quranInfoMock = new QuranInfo(pageProviderMock);
AudioUtils audioUtils = new AudioUtils(quranInfoMock, null);
SuraAyah lastAyah = audioUtils.getLastAyahToPlay(new SuraAyah(109, 1), 603, 1, false);
assertTrue(lastAyah.ayah == 5);
assertTrue(lastAyah.sura == 111);
}
use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class PagerActivity method playFromAyah.
private void playFromAyah(int page, int startSura, int startAyah, boolean force) {
final SuraAyah start = new SuraAyah(startSura, startAyah);
playFromAyah(start, null, page, 0, 0, false, force);
}
use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class PagerActivity method getAudioDownloadRequest.
@Nullable
private DownloadAudioRequest getAudioDownloadRequest(SuraAyah ayah, SuraAyah ending, int page, @NonNull QariItem item, int verseRepeat, int rangeRepeat, boolean enforceBounds) {
final SuraAyah endAyah;
if (ending != null) {
endAyah = ending;
} else {
endAyah = audioUtils.getLastAyahToPlay(ayah, page, quranSettings.getPreferredDownloadAmount(), isDualPages);
}
String baseUri = audioUtils.getLocalQariUrl(this, item);
if (endAyah == null || baseUri == null) {
return null;
}
String dbFile = audioUtils.getQariDatabasePathIfGapless(this, item);
String fileUrl;
if (TextUtils.isEmpty(dbFile)) {
fileUrl = baseUri + File.separator + "%d" + File.separator + "%d" + audioUtils.AUDIO_EXTENSION;
} else {
fileUrl = baseUri + File.separator + "%03d" + audioUtils.AUDIO_EXTENSION;
}
DownloadAudioRequest request = new DownloadAudioRequest(fileUrl, ayah, item, baseUri, quranInfo.getNumAyahs(ayah.sura));
request.setGaplessDatabaseFilePath(dbFile);
request.setPlayBounds(ayah, endAyah);
request.setEnforceBounds(enforceBounds);
request.setRangeRepeatCount(rangeRepeat);
request.setVerseRepeatCount(verseRepeat);
return request;
}
use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.
the class AyahPlaybackFragment method apply.
private void apply() {
final Context context = getActivity();
if (context instanceof PagerActivity) {
final SuraAyah start = new SuraAyah(startSuraSpinner.getSelectedItemPosition() + 1, startAyahSpinner.getSelectedItemPosition() + 1);
final SuraAyah ending = new SuraAyah(endingSuraSpinner.getSelectedItemPosition() + 1, endingAyahSpinner.getSelectedItemPosition() + 1);
// force the correct order
final SuraAyah currentStart;
final SuraAyah currentEnding;
if (ending.after(start)) {
currentStart = start;
currentEnding = ending;
} else {
currentStart = ending;
currentEnding = start;
}
final int page = quranInfo.getPageFromSuraAyah(currentStart.sura, currentStart.ayah);
final int verseRepeat = positionToRepeat(repeatVerseSpinner.getSelectedItemPosition());
final int rangeRepeat = positionToRepeat(repeatRangeSpinner.getSelectedItemPosition());
final boolean enforceRange = restrictToRange.isChecked();
boolean updatedRange = false;
final PagerActivity pagerActivity = (PagerActivity) context;
if (!currentStart.equals(decidedStart) || !currentEnding.equals(decidedEnd)) {
// different range or not playing, so make a new request
updatedRange = true;
if (this.start != null) {
final SuraAyah starting = decidedStart == null ? this.start : decidedStart;
final int origPage = quranInfo.getPageFromSuraAyah(starting.sura, starting.ayah);
if (page != origPage) {
pagerActivity.highlightAyah(currentStart.sura, currentStart.ayah, HighlightType.AUDIO);
}
}
pagerActivity.playFromAyah(currentStart, currentEnding, page, verseRepeat, rangeRepeat, enforceRange, true);
} else if (shouldEnforce != enforceRange || rangeRepeatCount != rangeRepeat || verseRepeatCount != verseRepeat) {
// can just update repeat settings
if (!pagerActivity.updatePlayOptions(rangeRepeat, verseRepeat, enforceRange)) {
// audio stopped in the process, let's start it
pagerActivity.playFromAyah(currentStart, currentEnding, page, verseRepeat, rangeRepeat, enforceRange, true);
}
}
pagerActivity.endAyahMode();
if (updatedRange) {
pagerActivity.toggleActionBarVisibility(true);
}
}
}
Aggregations