Search in sources :

Example 16 with SuraAyah

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);
}
Also used : SuraAyah(com.quran.labs.androidquran.data.SuraAyah)

Example 17 with SuraAyah

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);
    }
}
Also used : SuraAyah(com.quran.labs.androidquran.data.SuraAyah)

Example 18 with SuraAyah

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);
}
Also used : SuraAyah(com.quran.labs.androidquran.data.SuraAyah) Intent(android.content.Intent)

Example 19 with SuraAyah

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;
    }
}
Also used : NotificationDetails(com.quran.labs.androidquran.service.util.QuranDownloadNotifier.NotificationDetails) SuraAyah(com.quran.labs.androidquran.data.SuraAyah) Intent(android.content.Intent) ProgressIntent(com.quran.labs.androidquran.service.util.QuranDownloadNotifier.ProgressIntent)

Example 20 with SuraAyah

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;
}
Also used : SuraAyah(com.quran.labs.androidquran.data.SuraAyah) File(java.io.File)

Aggregations

SuraAyah (com.quran.labs.androidquran.data.SuraAyah)20 Intent (android.content.Intent)3 Context (android.content.Context)2 AudioRequest (com.quran.labs.androidquran.service.util.AudioRequest)2 DownloadAudioRequest (com.quran.labs.androidquran.service.util.DownloadAudioRequest)2 PagerActivity (com.quran.labs.androidquran.ui.PagerActivity)2 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 MadaniDataSource (com.quran.data.pageinfo.common.MadaniDataSource)1 PageProvider (com.quran.data.source.PageProvider)1 QuranText (com.quran.labs.androidquran.common.QuranText)1 QuranInfo (com.quran.labs.androidquran.data.QuranInfo)1 SuraAyahIterator (com.quran.labs.androidquran.data.SuraAyahIterator)1 NotificationDetails (com.quran.labs.androidquran.service.util.QuranDownloadNotifier.NotificationDetails)1 ProgressIntent (com.quran.labs.androidquran.service.util.QuranDownloadNotifier.ProgressIntent)1 StreamingAudioRequest (com.quran.labs.androidquran.service.util.StreamingAudioRequest)1 QuranPage (com.quran.labs.androidquran.ui.helpers.QuranPage)1 DisposableSingleObserver (io.reactivex.observers.DisposableSingleObserver)1 File (java.io.File)1 Test (org.junit.Test)1