Skip to content

Commit

Permalink
Code clean up.
Browse files Browse the repository at this point in the history
Found better class
  • Loading branch information
takasurazeem committed Sep 20, 2023
1 parent 37dca10 commit 2402554
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions QuranMajeed/Quiz/Main/View/VerseListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions QuranMajeed/Quiz/Main/ViewModel/QuizViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion QuranMajeed/QuranMajeed/Quran/Provider/QuranProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import QuranTextKit

protocol QuranProvider {
func getQuranKit() -> Quran
func getShareableTextRetriever() -> ShareableVerseTextRetriever
func getQuranTextDataService() -> QuranTextDataService
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import QuranKit
import QuranText

struct MainQuranRepository: QuranRepository {

Expand All @@ -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 { "بِسۡمِ ٱللَّهِ ٱلرَّحۡمَـٰنِ ٱلرَّحِیمِ" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
10 changes: 5 additions & 5 deletions QuranMajeed/QuranMajeed/Quran/Service/MainQuranService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}


Expand Down
3 changes: 2 additions & 1 deletion QuranMajeed/QuranMajeed/Quran/Service/QuranService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 2402554

Please sign in to comment.