diff --git a/QuranMajeed/Quiz/Main/View/VerseListView.swift b/QuranMajeed/Quiz/Main/View/VerseListView.swift index 12de131..9aad5a9 100644 --- a/QuranMajeed/Quiz/Main/View/VerseListView.swift +++ b/QuranMajeed/Quiz/Main/View/VerseListView.swift @@ -29,8 +29,8 @@ struct VerseListView_Previews: PreviewProvider { .shared .theQuranDependencyContainer .makeQuranRepository() - if let verses = try? await repo.getTextFor(verses: repo.getFirstSura().verses) { - self.verses = verses.enumerated().map { Verse(id: $0 + 1, text: $1) } + if let verses = try? await repo.getTranslatedVerses(verses: repo.getFirstSura().verses).verses { + self.verses = verses.enumerated().map { Verse(id: $0 + 1, text: $1.arabicText) } } } } diff --git a/QuranMajeed/Quiz/Main/ViewModel/QuizViewModel.swift b/QuranMajeed/Quiz/Main/ViewModel/QuizViewModel.swift index 996431e..31f30f6 100644 --- a/QuranMajeed/Quiz/Main/ViewModel/QuizViewModel.swift +++ b/QuranMajeed/Quiz/Main/ViewModel/QuizViewModel.swift @@ -44,14 +44,12 @@ extension QuizView { @MainActor private func loadVersesOfFirstSurah() async { do { - versesOfSelectedSura = try await theQuranRepository - .getTextFor(verses: selectedSurah.verses) + let translatedVerses = try await theQuranRepository.getTranslatedVerses(verses: selectedSurah.verses) + versesOfSelectedSura = translatedVerses + .verses .enumerated() - .map { (id, text) in - var verseText = text - if selectedSurah.startsWithBesmAllah, selectedSurah.suraNumber > 1, id == 0 { - verseText = verseText.replacingOccurrences(of: theQuranRepository.arabicBismillah, with: "") - } + .map { (id, verse) in + var verseText = verse.arabicText return Verse(id: id + 1, text: verseText) } if let verse = versesOfSelectedSura.first { diff --git a/QuranMajeed/QuranMajeed/Quran/Provider/MainQuranProvider.swift b/QuranMajeed/QuranMajeed/Quran/Provider/MainQuranProvider.swift index 356232f..b339349 100644 --- a/QuranMajeed/QuranMajeed/Quran/Provider/MainQuranProvider.swift +++ b/QuranMajeed/QuranMajeed/Quran/Provider/MainQuranProvider.swift @@ -13,8 +13,8 @@ struct MainQuranProvider: QuranProvider { Quran.hafsMadani1440 } - func getShareableTextRetriever() -> ShareableVerseTextRetriever { - ShareableVerseTextRetriever( + func getQuranTextDataService() -> QuranTextDataService { + QuranTextDataService( databasesURL: AppDependencyContainer.shared.databasesURL, quranFileURL: AppDependencyContainer.shared.quranUthmaniV2Database ) diff --git a/QuranMajeed/QuranMajeed/Quran/Provider/QuranProvider.swift b/QuranMajeed/QuranMajeed/Quran/Provider/QuranProvider.swift index 5e4a904..cdcacfb 100644 --- a/QuranMajeed/QuranMajeed/Quran/Provider/QuranProvider.swift +++ b/QuranMajeed/QuranMajeed/Quran/Provider/QuranProvider.swift @@ -10,5 +10,5 @@ import QuranTextKit protocol QuranProvider { func getQuranKit() -> Quran - func getShareableTextRetriever() -> ShareableVerseTextRetriever + func getQuranTextDataService() -> QuranTextDataService } diff --git a/QuranMajeed/QuranMajeed/Quran/Repository/MainQuranRepository.swift b/QuranMajeed/QuranMajeed/Quran/Repository/MainQuranRepository.swift index 7883366..96f00fc 100644 --- a/QuranMajeed/QuranMajeed/Quran/Repository/MainQuranRepository.swift +++ b/QuranMajeed/QuranMajeed/Quran/Repository/MainQuranRepository.swift @@ -7,6 +7,7 @@ import Foundation import QuranKit +import QuranText struct MainQuranRepository: QuranRepository { @@ -28,8 +29,8 @@ struct MainQuranRepository: QuranRepository { theQuranService.getFirstSura() } - func getTextFor(verses: [AyahNumber]) async throws -> [String] { - try await theQuranService.getTextFor(verses: verses) + func getTranslatedVerses(verses: [AyahNumber]) async throws -> TranslatedVerses { + try await theQuranService.getTranslatedVerses(verses: verses) } var arabicBismillah: String { "بِسۡمِ ٱللَّهِ ٱلرَّحۡمَـٰنِ ٱلرَّحِیمِ" } diff --git a/QuranMajeed/QuranMajeed/Quran/Repository/QuranRepository.swift b/QuranMajeed/QuranMajeed/Quran/Repository/QuranRepository.swift index 4f9fd5f..7d3cb8f 100644 --- a/QuranMajeed/QuranMajeed/Quran/Repository/QuranRepository.swift +++ b/QuranMajeed/QuranMajeed/Quran/Repository/QuranRepository.swift @@ -6,12 +6,13 @@ // import QuranKit +import QuranText protocol QuranRepository { func getQuran() -> Quran func getSuras() -> [Sura] func getFirstSura() -> Sura - func getTextFor(verses: [AyahNumber]) async throws -> [String] + func getTranslatedVerses(verses: [AyahNumber]) async throws -> TranslatedVerses var arabicBismillah: String { get } } diff --git a/QuranMajeed/QuranMajeed/Quran/Service/MainQuranService.swift b/QuranMajeed/QuranMajeed/Quran/Service/MainQuranService.swift index 6207f3a..0d55310 100644 --- a/QuranMajeed/QuranMajeed/Quran/Service/MainQuranService.swift +++ b/QuranMajeed/QuranMajeed/Quran/Service/MainQuranService.swift @@ -16,7 +16,7 @@ struct MainQuranService: QuranService { ) { self.providerForQuran = providerForQuran self.theQuranKit = providerForQuran.getQuranKit() - self.shareableTextRetriever = providerForQuran.getShareableTextRetriever() + self.theQuranTextDataService = providerForQuran.getQuranTextDataService() } func getQuran() -> Quran { @@ -31,15 +31,15 @@ struct MainQuranService: QuranService { theQuranKit.suras[0] } - func getTextFor( + func getTranslatedVerses( verses: [AyahNumber] - ) async throws -> [String] { - try await shareableTextRetriever.versesAsArray(verses) + ) async throws -> TranslatedVerses { + try await theQuranTextDataService.textForVerses(verses) } private let providerForQuran: QuranProvider private let theQuranKit: Quran - private let shareableTextRetriever: ShareableVerseTextRetriever + private let theQuranTextDataService: QuranTextDataService } diff --git a/QuranMajeed/QuranMajeed/Quran/Service/QuranService.swift b/QuranMajeed/QuranMajeed/Quran/Service/QuranService.swift index ec4ba79..f4a92de 100644 --- a/QuranMajeed/QuranMajeed/Quran/Service/QuranService.swift +++ b/QuranMajeed/QuranMajeed/Quran/Service/QuranService.swift @@ -6,11 +6,12 @@ // import QuranKit +import QuranText protocol QuranService { func getQuran() -> Quran func getSuras() -> [Sura] func getFirstSura() -> Sura - func getTextFor(verses: [AyahNumber]) async throws -> [String] + func getTranslatedVerses(verses: [AyahNumber]) async throws -> TranslatedVerses }