Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f15489f
Add offline Memorize mode and prayer corrector
amrfahmyt1983-wq Oct 22, 2026
27f430a
Test with many reciters and readers, follow the testing strategy, add…
amrfahmyt1983-wq Oct 22, 2026
48582ff
Merge remote-tracking branch 'origin/main' into feature/offline-memorize
amrfahmyt1983-wq Oct 22, 2026
c6261b7
Memorize: continuous sessions, floating mic, recordings, downloads
amrfahmyt1983-wq Oct 22, 2026
d8dbe1e
Memorize: start where the user is, and a floating mic to start
amrfahmyt1983-wq Oct 22, 2026
259de20
Memorize: hide the words as soon as the session starts
amrfahmyt1983-wq Oct 22, 2026
e1ca2b1
Allow choosing which page the volume up key turns to
amrfahmyt1983-wq Oct 22, 2026
3d8561d
Memorize: find the start reliably, and keep salah hints cautious
amrfahmyt1983-wq Oct 22, 2026
be41cbf
Memorize: a recording starts where the user started
amrfahmyt1983-wq Oct 22, 2026
ba0ea96
Memorize: recording tests report a session from its first word
amrfahmyt1983-wq Oct 22, 2026
80e2e9e
Memorize: find the passage when salah listening starts after Al-Fatiha
amrfahmyt1983-wq Oct 22, 2026
b5f425c
Memorize: an optional double-check before correcting, recommended by …
amrfahmyt1983-wq Oct 23, 2026
527e79c
Memorize: run the double-check's model in a process of its own
amrfahmyt1983-wq Oct 23, 2026
ee1f274
Memorize: credit the double-check's model and text apart; show a fail…
amrfahmyt1983-wq Oct 23, 2026
5dfce92
Memorize: trace event names that survive R8, and session times from t…
amrfahmyt1983-wq Oct 23, 2026
b9d3b9f
Memorize: a device test for the double-check
amrfahmyt1983-wq Oct 23, 2026
5689918
Memorize: let reading screens go when they close
amrfahmyt1983-wq Oct 23, 2026
8d8032a
Memorize: a model download that fails for any reason ends as failed; …
amrfahmyt1983-wq Oct 23, 2026
046a33c
Memorize: send the double-check's audio through a file, and keep its …
amrfahmyt1983-wq Oct 23, 2026
c8c573d
Add the Madani mushaf with tajweed colors as a page type
amrfahmyt1983-wq Oct 23, 2026
8a0f554
Merge upstream main into feature/offline-memorize
amrfahmyt1983-wq Nov 12, 2026
a76d14e
Memorize: fix two crashes on the reading screen
amrfahmyt1983-wq Nov 12, 2026
75b2000
Reading bookmarks: the moved/cleared toast no longer gets stuck, and …
amrfahmyt1983-wq Nov 12, 2026
94200e9
Page editions: the store app's page types, and Memorize on them
amrfahmyt1983-wq Nov 14, 2026
49f7b1e
Memorize: Recitation mode, Record and contribute, Recording sessions
amrfahmyt1983-wq Nov 14, 2026
10c7dfd
Memorize: no ayah is left out, and similar ayat no longer pull the se…
amrfahmyt1983-wq Nov 14, 2026
5282896
Progress: reading cycles, charts and a daily reminder; eight reading …
amrfahmyt1983-wq Nov 14, 2026
3c49d9c
Sync and Download manager: back arrows and chevrons point the right w…
amrfahmyt1983-wq Nov 14, 2026
964ccb4
Progress: a bookmark not placed yet shows sample days too
amrfahmyt1983-wq Nov 14, 2026
2232a1b
Memorize: a start dropped after a misheard word is taken up again whe…
amrfahmyt1983-wq Nov 14, 2026
bb04109
Recording sessions: on a phone on its side, the player sits beside th…
amrfahmyt1983-wq Nov 15, 2026
f34787b
Reading bookmarks: the backup's slot names survive minification
amrfahmyt1983-wq Nov 15, 2026
e119c55
Memorize: a model download cut off by the network is tried again
amrfahmyt1983-wq Nov 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v6

- name: Fetch native dependencies
run: tools/memorize/fetch_sherpa_onnx.sh

- name: Build debug APK
run: ./gradlew assembleMadaniDebug

Expand All @@ -45,7 +48,7 @@ jobs:
run: ./gradlew verifySqlDelightMigration

- name: Run tests
run: ./gradlew testMadaniDebug testReleaseUnitTest -PdisableFirebase
run: ./gradlew testMadaniDebug testReleaseUnitTest :feature:memorize:tracker:test -PdisableFirebase

- name: Upload test report
uses: actions/upload-artifact@v7
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v6

- name: Fetch native dependencies
run: tools/memorize/fetch_sherpa_onnx.sh

- name: Build debug APK
run: ./gradlew assembleMadaniDebug

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/post_merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v6

- name: Fetch native dependencies
run: tools/memorize/fetch_sherpa_onnx.sh

- name: Build debug Apk
run: ./gradlew assembleDebug

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ crashlytics-build.properties
com_crashlytics_export_strings.xml
extras
app/google-services.json

# memorize feature: vendored native dependencies (tools/memorize/fetch_sherpa_onnx.sh)
/third_party/
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ dependencies {
implementation(project(":common:networking"))
implementation(project(":common:pages"))
implementation(project(":common:preference"))
implementation(project(":common:progress"))
implementation(project(":common:reading"))
implementation(project(":common:recitation"))
implementation(project(":common:search"))
Expand All @@ -236,6 +237,7 @@ dependencies {
implementation(project(":feature:audiobar"))
implementation(project(":feature:ayahbookmark"))
implementation(project(":feature:pagetheme"))
implementation(project(":feature:progress"))
implementation(project(":feature:downloadmanager"))
implementation(project(":feature:qarilist"))
implementation(project(":feature:sync"))
Expand Down
5 changes: 4 additions & 1 deletion app/pluggable.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
dependencies {
implementation project(path: ':pages:madani')
implementation project(path: ':pages:common:madani')
implementation project(path: ':feature:recitation')
implementation project(path: ':feature:memorize')
// page types drawn line by line
implementation project(path: ':feature:linebyline')
implementation project(path: ':pages:linebyline')
}
25 changes: 25 additions & 0 deletions app/src/main/java/com/quran/labs/androidquran/QuranApplication.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.quran.labs.androidquran

import android.app.Application
import android.os.Build
import androidx.core.os.UserManagerCompat
import androidx.work.Configuration
import androidx.work.WorkManager
Expand All @@ -13,10 +14,12 @@ import com.quran.labs.androidquran.widget.BookmarksWidgetSubscriber
import com.quran.mobile.di.QuranApplicationComponent
import com.quran.mobile.di.QuranApplicationComponentProvider
import com.quran.mobile.feature.sync.QuranSyncManager
import com.quran.mobile.feature.progress.ProgressStartup
import dev.zacsweers.metro.HasMemberInjections
import dev.zacsweers.metro.Inject
import dev.zacsweers.metro.createGraphFactory
import timber.log.Timber
import java.io.File

@HasMemberInjections
open class QuranApplication : Application(), QuranApplicationComponentProvider, Configuration.Provider {
Expand All @@ -26,25 +29,39 @@ open class QuranApplication : Application(), QuranApplicationComponentProvider,
@Inject lateinit var bookmarksWidgetSubscriber: BookmarksWidgetSubscriber
@Inject lateinit var quranSettings: QuranSettings
@Inject lateinit var quranSyncManager: QuranSyncManager
@Inject lateinit var progressStartup: ProgressStartup

override fun provideQuranApplicationComponent(): QuranApplicationComponent {
return applicationComponent
}

override fun onCreate() {
super.onCreate()
// A secondary process (e.g. memorize's double-check, which keeps its model apart from the
// speech engine's) runs a service of its own and needs none of the app's setup.
if (isSecondaryProcess()) return
setupTimber()
applicationComponent = initializeInjector()
applicationComponent.inject(this)
quranSyncManager.startForegroundSync()
initializeWorkManager()
startProgress()
bookmarksWidgetSubscriber.subscribeBookmarksWidgetIfNecessary()

// theme setup
val theme = quranSettings.currentTheme()
ThemeUtil.setTheme(theme)
}

private fun isSecondaryProcess(): Boolean {
val name = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getProcessName()
} else {
runCatching { File("/proc/self/cmdline").readText().trim(Char(0), ' ') }.getOrNull()
}
return name != null && name.contains(':')
}

open fun setupTimber() {
Timber.plant(RecordingLogTree())
}
Expand All @@ -59,6 +76,14 @@ open class QuranApplication : Application(), QuranApplicationComponentProvider,
.setWorkerFactory(quranWorkerFactory)
.build()

/**
* Progress keeps each reading bookmark's moves and checks the daily reminder (its data is only
* readable once the user unlocked, as WorkManager is only initialized then).
*/
open fun startProgress() {
if (UserManagerCompat.isUserUnlocked(this)) progressStartup.start()
}

open fun initializeWorkManager() {
if (UserManagerCompat.isUserUnlocked(this)) {
WorkManager.initialize(this, workManagerConfiguration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.graphics.RectF;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.quran.labs.androidquran.database.DatabaseUtils;
import com.quran.labs.androidquran.util.QuranFileUtils;
Expand All @@ -14,6 +15,8 @@
import com.quran.page.common.data.AyahMarkerLocation;
import com.quran.page.common.data.PageCoordinates;
import com.quran.page.common.data.SuraHeaderLocation;
import com.quran.page.common.data.coordinates.GlyphSize;
import com.quran.page.common.data.coordinates.GlyphTypeResolver;
import com.quran.page.common.data.coordinates.PageGlyphsCoords;

import java.io.File;
Expand Down Expand Up @@ -42,9 +45,17 @@ public class AyahInfoDatabaseHandler {

private final SQLiteDatabase database;
private final boolean hasGlyphData;
@Nullable private final GlyphTypeResolver glyphTypeResolver;

static AyahInfoDatabaseHandler getAyahInfoDatabaseHandler(
String databaseName, QuranFileUtils quranFileUtils) {
return getAyahInfoDatabaseHandler(databaseName, quranFileUtils, null);
}

static AyahInfoDatabaseHandler getAyahInfoDatabaseHandler(
String databaseName,
QuranFileUtils quranFileUtils,
@Nullable GlyphTypeResolver glyphTypeResolver) {
final File currentAyahDatabaseDirectory = quranFileUtils.getQuranAyahDatabaseDirectory();
if (!currentAyahDatabaseDirectory.equals(quranDatabaseDirectory)) {
quranDatabaseDirectory = currentAyahDatabaseDirectory;
Expand All @@ -54,7 +65,8 @@ static AyahInfoDatabaseHandler getAyahInfoDatabaseHandler(
AyahInfoDatabaseHandler handler = ayahInfoCache.get(databaseName);
if (handler == null) {
try {
AyahInfoDatabaseHandler db = new AyahInfoDatabaseHandler(databaseName, quranFileUtils);
AyahInfoDatabaseHandler db =
new AyahInfoDatabaseHandler(databaseName, quranFileUtils, glyphTypeResolver);
if (db.validDatabase()) {
ayahInfoCache.put(databaseName, db);
handler = db;
Expand Down Expand Up @@ -82,11 +94,13 @@ private static void clearAyahInfoCache() {
}

private AyahInfoDatabaseHandler(String databaseName,
QuranFileUtils quranFileUtils) throws SQLException {
QuranFileUtils quranFileUtils,
@Nullable GlyphTypeResolver glyphTypeResolver) throws SQLException {
File base = quranFileUtils.getQuranAyahDatabaseDirectory();
File path = new File(base, databaseName);
database = SQLiteDatabase.openDatabase(path.getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
hasGlyphData = quranFileUtils.getAyahInfoDbHasGlyphData();
this.glyphTypeResolver = glyphTypeResolver;
}

private boolean validDatabase() {
Expand Down Expand Up @@ -128,6 +142,10 @@ private RectF getPageBounds(int page) {
public AyahCoordinates getVersesBoundsForPage(int page) {
boolean includeGlyphData = hasGlyphData && haveGlyphData();
GlyphsBuilder glyphsBuilder = new GlyphsBuilder();
Map<String, String> derivedTypes =
(!includeGlyphData && glyphTypeResolver != null) ? derivedGlyphTypesForPage(page) : null;
GlyphsBuilder wordGlyphsBuilder = derivedTypes != null ? new GlyphsBuilder() : null;
Map<String, int[]> wordNumbers = new HashMap<>();
Map<String, List<AyahBounds>> ayahBounds = new HashMap<>();
Cursor cursor = null;
try {
Expand All @@ -142,13 +160,26 @@ public AyahCoordinates getVersesBoundsForPage(int page) {
int maxX = cursor.getInt(7);
int maxY = cursor.getInt(8);

String key = sura + ":" + ayah;
if (includeGlyphData) {
String glyphType = cursor.getString(9);
RectF r = new RectF(minX, minY, maxX, maxY);
glyphsBuilder.append(sura, ayah, position, line, glyphType, r);
} else if (wordGlyphsBuilder != null) {
String types = derivedTypes.get(key);
if (types != null) {
int[] words = wordNumbers.get(key);
if (words == null) {
words = wordNumbers(types);
wordNumbers.put(key, words);
}
char type = types.charAt(position - 1);
Integer wordPosition = type == GlyphTypeResolver.WORD ? words[position - 1] : null;
RectF r = new RectF(minX, minY, maxX, maxY);
wordGlyphsBuilder.append(sura, ayah, position, line, glyphTypeName(type), r, wordPosition);
}
}

String key = sura + ":" + ayah;
List<AyahBounds> bounds = ayahBounds.get(key);
if (bounds == null) {
bounds = new ArrayList<>();
Expand All @@ -173,8 +204,89 @@ public AyahCoordinates getVersesBoundsForPage(int page) {

PageGlyphsCoords glyphCoords = includeGlyphData ?
new PageGlyphsCoords(page, glyphsBuilder.build()) : null;
PageGlyphsCoords wordGlyphCoords = wordGlyphsBuilder != null ?
new PageGlyphsCoords(page, wordGlyphsBuilder.build()) : null;

return new AyahCoordinates(page, ayahBounds, glyphCoords, new HashMap<>(), 0f, wordGlyphCoords);
}

return new AyahCoordinates(page, ayahBounds, glyphCoords);
/**
* Glyph types for the ayat on this page from the {@link GlyphTypeResolver}, keyed by "sura:ayah",
* worked out from the sizes of each ayah's glyphs in this database (every page type has its own
* font). An ayah is left out (so it keeps ayah level behavior) if its glyphs can't be told apart
* or its positions aren't numbered 1..n.
*/
@Nullable
private Map<String, String> derivedGlyphTypesForPage(int page) {
Map<String, String> result = new HashMap<>();
Cursor cursor = null;
try {
// all glyphs of every ayah that is (even partly) on this page; a join rather than a row value
// comparison (SQLite 3.15+, API 26+) so that both lookups use an index
cursor = database.rawQuery(
"SELECT g." + COL_SURA + ", g." + COL_AYAH + ", g." + COL_POSITION + ", g." + MAX_X +
" - g." + MIN_X + ", g." + MAX_Y + " - g." + MIN_Y +
" FROM (SELECT DISTINCT " + COL_SURA + ", " + COL_AYAH + " FROM " + GLYPHS_TABLE +
" WHERE " + COL_PAGE + " = ?) AS p JOIN " + GLYPHS_TABLE + " AS g ON g." + COL_SURA +
" = p." + COL_SURA + " AND g." + COL_AYAH + " = p." + COL_AYAH +
" ORDER BY g." + COL_SURA + ", g." + COL_AYAH + ", g." + COL_POSITION,
new String[] { String.valueOf(page) });
int sura = -1;
int ayah = -1;
List<GlyphSize> glyphs = new ArrayList<>();
boolean numbered = true;
while (cursor.moveToNext()) {
int rowSura = cursor.getInt(0);
int rowAyah = cursor.getInt(1);
if (rowSura != sura || rowAyah != ayah) {
addDerivedTypes(result, sura, ayah, glyphs, numbered);
sura = rowSura;
ayah = rowAyah;
glyphs = new ArrayList<>();
numbered = true;
}
numbered &= cursor.getInt(2) == glyphs.size() + 1;
glyphs.add(new GlyphSize(cursor.getInt(3), cursor.getInt(4)));
}
addDerivedTypes(result, sura, ayah, glyphs, numbered);
} catch (SQLException e) {
return null;
} finally {
DatabaseUtils.closeCursor(cursor);
}
return result;
}

private void addDerivedTypes(
Map<String, String> result, int sura, int ayah, List<GlyphSize> glyphs, boolean numbered) {
if (glyphs.isEmpty() || !numbered || glyphTypeResolver == null) return;
String types = glyphTypeResolver.glyphTypes(sura, ayah, glyphs);
if (types != null && types.length() == glyphs.size()) {
result.put(sura + ":" + ayah, types);
}
}

/** The word number of each glyph of an ayah, counting only the glyphs that are words. */
private static int[] wordNumbers(String types) {
int[] result = new int[types.length()];
int words = 0;
for (int i = 0; i < types.length(); i++) {
if (types.charAt(i) == GlyphTypeResolver.WORD) {
words++;
}
result[i] = words;
}
return result;
}

private static String glyphTypeName(char type) {
switch (type) {
case GlyphTypeResolver.WORD: return GlyphsBuilder.WORD;
case GlyphTypeResolver.PAUSE: return GlyphsBuilder.PAUSE;
case GlyphTypeResolver.SAJDAH: return GlyphsBuilder.SAJDAH;
case GlyphTypeResolver.HIZB: return GlyphsBuilder.HIZB;
default: return GlyphsBuilder.END;
}
}

private boolean haveVerseMarkerData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import android.content.Context
import com.quran.data.di.ActivityScope
import com.quran.labs.androidquran.util.QuranFileUtils
import com.quran.mobile.di.qualifier.ApplicationContext
import com.quran.page.common.data.coordinates.GlyphTypeResolver
import dev.zacsweers.metro.Inject

@ActivityScope
class AyahInfoDatabaseProvider @Inject constructor(
@ApplicationContext private val context: Context,
private val widthParameter: String,
private val quranFileUtils: QuranFileUtils
private val quranFileUtils: QuranFileUtils,
private val glyphTypeResolvers: Set<GlyphTypeResolver>
) {
private var databaseHandler: AyahInfoDatabaseHandler? = null

Expand All @@ -19,7 +21,8 @@ class AyahInfoDatabaseProvider @Inject constructor(
val filename = quranFileUtils.getAyaPositionFileName(widthParameter)
databaseHandler = AyahInfoDatabaseHandler.getAyahInfoDatabaseHandler(
filename,
quranFileUtils
quranFileUtils,
glyphTypeResolvers.firstOrNull()
)
}
return databaseHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ object Constants {
const val PREF_HAVE_UPDATED_TRANSLATIONS = "haveUpdatedTranslations"
const val PREF_USE_NEW_BACKGROUND = "useNewBackground"
const val PREF_USE_VOLUME_KEY_NAV = "volumeKeyNavigation"
const val PREF_SWAP_VOLUME_KEYS = "swapVolumeKeys"
const val PREF_SORT_BOOKMARKS = "sortBookmarks"
const val PREF_GROUP_BOOKMARKS_BY_TAG = "groupBookmarksByTag"
const val PREF_SHOW_RECENTS = "showRecents"
Expand Down
Loading