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

Hide older gapped qaris from download manager #2193

Merged
merged 1 commit into from
Feb 15, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ class QariDownloadInfoManager @Inject constructor(
return storageCache.flow()
}

fun downloadQariInfoFilteringNonDownloadedGappedQaris(): Flow<List<QariDownloadInfo>> {
return downloadedQariInfo().map { list ->
list.filter { qariDownloadInfo ->
val qari = qariDownloadInfo.qari
val gappedItem = qariDownloadInfo as? QariDownloadInfo.GappedQariDownloadInfo
qari.isGapless ||
// gapped qaris are only shown if they don't have a gapless alternative or if
// some file for the qari is already downloaded.
(!qari.hasGaplessAlternative ||
qariDownloadInfo.fullyDownloadedSuras.isNotEmpty() ||
(gappedItem?.partiallyDownloadedSuras?.isNotEmpty() ?: false))
}
}
}

private fun populateCache() {
val audioDirectory = quranFileManager.audioFileDirectory() ?: return
val qariDownloadInfo = audioInfoCommand.generateAllQariDownloadInfo(audioDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AudioManagerPresenter @Inject constructor(
fun downloadedShuyookh(
lambda: ((Qari) -> QariItem)
): Flow<List<DownloadedSheikhUiModel>> {
return qariDownloadInfoManager.downloadedQariInfo()
return qariDownloadInfoManager.downloadQariInfoFilteringNonDownloadedGappedQaris()
.map { qariDownloadInfoList ->
qariDownloadInfoList
.map { qariDownloadInfo ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,7 @@ import kotlinx.coroutines.flow.map
class QariListPresenter @Inject constructor(private val qariDownloadInfoManager: QariDownloadInfoManager) {

fun qariList(start: SuraAyah, end: SuraAyah, qariTranslationLambda: ((Qari) -> QariItem)): Flow<List<QariUiModel>> {
return qariDownloadInfoManager.downloadedQariInfo().map { list ->
list.filter { qariDownloadInfo ->
val qari = qariDownloadInfo.qari
val gappedItem = qariDownloadInfo as? QariDownloadInfo.GappedQariDownloadInfo
qari.isGapless ||
// gapped qaris are only shown if they don't have a gapless alternative or if
// some file for the qari is already downloaded.
(!qari.hasGaplessAlternative ||
qariDownloadInfo.fullyDownloadedSuras.isNotEmpty() ||
(gappedItem?.partiallyDownloadedSuras?.isNotEmpty() ?: false))
}
}
return qariDownloadInfoManager.downloadQariInfoFilteringNonDownloadedGappedQaris()
.map { unsortedQariList ->
val readyToPlay = unsortedQariList.filter { it.isRangeDownloaded(start, end) }
.toSortedQariItemList(qariTranslationLambda)
Expand Down