Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share Audio Feature #2072

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ dependencies {
implementation project(path: ':common:toolbar')
implementation project(path: ':common:upgrade')
implementation project(path: ':common:ui:core')
implementation project(path: ':common:util')

implementation project(path: ':feature:audio')
implementation project(path: ':feature:audioshare')
implementation project(path: ':feature:downloadmanager')
implementation project(path: ':feature:qarilist')

Expand Down Expand Up @@ -170,7 +172,7 @@ dependencies {
kapt("com.squareup.moshi:moshi-kotlin-codegen:${moshiVersion}")

implementation "dev.chrisbanes:insetter-ktx:0.3.1"
implementation 'com.jakewharton.timber:timber:5.0.1'
implementation "com.jakewharton.timber:timber:${timberVersion}"
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
implementation 'com.google.firebase:firebase-crashlytics:18.2.13'

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
android:resource="@xml/file_paths" />
</provider>

<receiver android:name="androidx.media.session.MediaButtonReceiver">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.quran.labs.androidquran.dao.audio
import android.os.Parcelable
import com.quran.labs.androidquran.common.audio.model.QariItem
import com.quran.data.model.SuraAyah
import com.quran.labs.androidquran.common.audio.model.AudioPathInfo
import kotlinx.parcelize.Parcelize

@Parcelize
Expand All @@ -13,7 +14,8 @@ data class AudioRequest(val start: SuraAyah,
val rangeRepeatInfo: Int = 0,
val enforceBounds: Boolean,
val shouldStream: Boolean,
val audioPathInfo: AudioPathInfo) : Parcelable {
val audioPathInfo: AudioPathInfo
) : Parcelable {
fun isGapless() = qari.isGapless
fun needsIsti3athaAudio() =
!isGapless() || audioPathInfo.gaplessDatabase?.contains("minshawi_murattal") ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import android.graphics.RectF;
import androidx.annotation.NonNull;

import com.quran.labs.androidquran.database.DatabaseUtils;
import com.quran.common.util.database.DatabaseUtils;
import com.quran.labs.androidquran.util.QuranFileUtils;
import com.quran.page.common.data.AyahBounds;
import com.quran.page.common.data.AyahCoordinates;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import android.net.Uri;
import android.provider.BaseColumns;

import com.quran.common.util.database.DatabaseUtils;
import com.quran.data.core.QuranInfo;
import com.quran.labs.androidquran.BuildConfig;
import com.quran.labs.androidquran.QuranApplication;
import com.quran.labs.androidquran.R;
import com.quran.labs.androidquran.common.LocalTranslation;
import com.quran.labs.androidquran.database.DatabaseHandler;
import com.quran.labs.androidquran.database.DatabaseUtils;
import com.quran.labs.androidquran.database.TranslationsDBAdapter;
import com.quran.labs.androidquran.util.QuranFileUtils;
import com.quran.labs.androidquran.util.QuranUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.quran.labs.androidquran.database

import com.quran.labs.androidquran.common.audio.timing.SuraTimingDatabaseHandler
import com.quran.labs.androidquran.feature.audio.VersionableDatabaseChecker
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.core.content.ContextCompat
import com.quran.common.search.ArabicSearcher
import com.quran.common.search.DefaultSearcher
import com.quran.common.search.Searcher
import com.quran.common.util.database.DatabaseUtils
import com.quran.data.model.QuranText
import com.quran.data.model.VerseRange
import com.quran.labs.androidquran.R
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import android.content.Context;
import android.database.Cursor;

import com.quran.common.util.database.DatabaseUtils;
import com.quran.data.core.QuranInfo;
import com.quran.data.model.QuranText;
import com.quran.data.model.bookmark.Bookmark;
import com.quran.labs.androidquran.data.QuranDataProvider;
import com.quran.labs.androidquran.data.QuranFileConstants;
import com.quran.data.model.SuraAyah;
import com.quran.labs.androidquran.database.DatabaseHandler;
import com.quran.labs.androidquran.database.DatabaseUtils;
import com.quran.labs.androidquran.util.QuranFileUtils;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import android.content.Context
import android.content.Intent
import com.quran.data.model.SuraAyah
import com.quran.labs.androidquran.R
import com.quran.labs.androidquran.common.audio.model.AudioDownloadMetadata
import com.quran.labs.androidquran.common.audio.model.AudioPathInfo
import com.quran.labs.androidquran.common.audio.model.QariItem
import com.quran.labs.androidquran.dao.audio.AudioPathInfo
import com.quran.labs.androidquran.common.audio.util.AudioFileUtil
import com.quran.labs.androidquran.dao.audio.AudioRequest
import com.quran.labs.androidquran.data.QuranDisplayData
import com.quran.labs.androidquran.presenter.Presenter
import com.quran.labs.androidquran.service.QuranDownloadService
import com.quran.labs.androidquran.common.audio.model.AudioDownloadMetadata
import com.quran.labs.androidquran.service.util.ServiceIntentHelper
import com.quran.labs.androidquran.ui.PagerActivity
import com.quran.labs.androidquran.util.AudioUtils
Expand All @@ -22,6 +23,7 @@ import javax.inject.Inject
class AudioPresenter @Inject
constructor(private val quranDisplayData: QuranDisplayData,
private val audioUtil: AudioUtils,
private val audioFileUtil: AudioFileUtil,
private val quranFileUtils: QuranFileUtils) : Presenter<PagerActivity> {
private var pagerActivity: PagerActivity? = null
private var lastAudioRequest: AudioRequest? = null
Expand All @@ -33,7 +35,7 @@ constructor(private val quranDisplayData: QuranDisplayData,
rangeRepeat: Int,
enforceRange: Boolean,
shouldStream: Boolean) {
val audioPathInfo = getLocalAudioPathInfo(qari)
val audioPathInfo = audioFileUtil.getLocalAudioPathInfo(qari)
if (audioPathInfo != null) {
// override streaming if all the files are already downloaded
val stream = if (shouldStream) {
Expand Down Expand Up @@ -88,7 +90,7 @@ constructor(private val quranDisplayData: QuranDisplayData,
lastAudioRequest?.let { play(it) }
}

private fun getDownloadIntent(context: Context, request: AudioRequest): Intent? {
fun getDownloadIntent(context: Context, request: AudioRequest): Intent? {
val qari = request.qari
val audioPathInfo = request.audioPathInfo
val path = audioPathInfo.localDirectory
Expand Down Expand Up @@ -136,23 +138,6 @@ constructor(private val quranDisplayData: QuranDisplayData,
return ServiceIntentHelper.getAudioDownloadIntent(context, url, destination, title)
}

private fun getLocalAudioPathInfo(qari: QariItem): AudioPathInfo? {
pagerActivity?.let {
val localPath = audioUtil.getLocalQariUrl(qari)
if (localPath != null) {
val databasePath = audioUtil.getQariDatabasePathIfGapless(qari)
val urlFormat = if (databasePath.isNullOrEmpty()) {
localPath + File.separator + "%d" + File.separator +
"%d" + AudioUtils.AUDIO_EXTENSION
} else {
localPath + File.separator + "%03d" + AudioUtils.AUDIO_EXTENSION
}
return AudioPathInfo(urlFormat, localPath, databasePath)
}
}
return null
}

private fun haveAllFiles(audioPathInfo: AudioPathInfo, start: SuraAyah, end: SuraAyah): Boolean {
return audioUtil.haveAllFiles(audioPathInfo.urlFormat,
audioPathInfo.localDirectory, start, end, audioPathInfo.gaplessDatabase != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.media.session.MediaButtonReceiver
import com.quran.common.util.database.DatabaseUtils
import com.quran.data.core.QuranInfo
import com.quran.data.model.SuraAyah
import com.quran.labs.androidquran.QuranApplication
import com.quran.labs.androidquran.R
import com.quran.labs.androidquran.common.audio.timing.SuraTimingDatabaseHandler.Companion.getDatabaseHandler
import com.quran.labs.androidquran.dao.audio.AudioPlaybackInfo
import com.quran.labs.androidquran.dao.audio.AudioRequest
import com.quran.labs.androidquran.data.Constants
import com.quran.labs.androidquran.data.QuranDisplayData
import com.quran.labs.androidquran.data.QuranFileConstants
import com.quran.labs.androidquran.database.DatabaseUtils.closeCursor
import com.quran.labs.androidquran.database.SuraTimingDatabaseHandler.Companion.getDatabaseHandler
import com.quran.labs.androidquran.extension.requiresBasmallah
import com.quran.labs.androidquran.presenter.audio.service.AudioQueue
import com.quran.labs.androidquran.service.util.AudioFocusHelper
Expand Down Expand Up @@ -410,27 +410,7 @@ class AudioService : Service(), OnCompletionListener, OnPreparedListener,
timingDisposable?.dispose()
timingDisposable = Single.fromCallable {
val db = getDatabaseHandler(databasePath)

val map = SparseIntArray()
var cursor: Cursor? = null
try {
cursor = db.getAyahTimings(sura)
Timber.d("got cursor of data")
if (cursor != null && cursor.moveToFirst()) {
do {
val ayah = cursor.getInt(1)
val time = cursor.getInt(2)
map.put(ayah, time)
} while (cursor.moveToNext())
}
} catch (se: SQLException) {
// don't crash the app if the database is corrupt
Timber.e(se)
} finally {
closeCursor(cursor)
}

map
db.getAyahTimings(sura)
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Expand Down
Loading