Skip to content

Commit

Permalink
Allow different qirat to handle patch upgrades (quran#1616)
Browse files Browse the repository at this point in the history
In the cases of patch upgrades (i.e. from data version 1 to 2), allow
the flavor to handle it (so as to copy the database from assets, for
example, etc).
  • Loading branch information
ahmedre authored Jun 25, 2021
1 parent cf82cd0 commit e471e5e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class QuranDataPresenter @Inject internal constructor(
.andThen(actuallyCheckPages(pages))
.flatMap { Single.fromCallable { localDataUpgrade.processData(it) } }
.map { checkPatchStatus(it) }
.flatMap { Single.fromCallable { localDataUpgrade.processPatch(it) } }
.doOnSuccess {
if (!it.havePages()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@ class QuranFileUtils @Inject constructor(
copyFromAssets(assetsPath, filename, actualDestination)
}

@WorkerThread
override fun removeOldArabicDatabase(): Boolean {
val databaseQuranArabicDatabase = File(
getQuranDatabaseDirectory(appContext),
QuranDataProvider.QURAN_ARABIC_DATABASE
)

return if (databaseQuranArabicDatabase.exists()) {
databaseQuranArabicDatabase.delete()
} else true
}

@WorkerThread
private fun copyFromAssets(assetsPath: String, filename: String, destination: String) {
val assets = appContext.assets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ interface QuranFileManager {
@WorkerThread
fun copyFromAssetsRelative(assetsPath: String, filename: String, destination: String)

@WorkerThread
fun removeOldArabicDatabase(): Boolean

@WorkerThread
fun hasArabicSearchDatabase(): Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import com.quran.data.model.QuranDataStatus
* Interface for handling data upgrades (pages, databases, etc) between
* upgrades of versions of Quran for Android.
*/
fun interface LocalDataUpgrade {
interface LocalDataUpgrade {
@WorkerThread
fun processData(quranDataStatus: QuranDataStatus): QuranDataStatus
fun processData(quranDataStatus: QuranDataStatus): QuranDataStatus { return quranDataStatus }

@WorkerThread
fun processPatch(quranDataStatus: QuranDataStatus): QuranDataStatus { return quranDataStatus }
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object QuranPageModule {

@JvmStatic
@Provides
fun provideLocalDataUpgrade(): LocalDataUpgrade = LocalDataUpgrade { it }
fun provideLocalDataUpgrade(): LocalDataUpgrade = object : LocalDataUpgrade { }

@JvmStatic
@Provides
Expand Down

0 comments on commit e471e5e

Please sign in to comment.