Skip to content

Commit

Permalink
Fixes and logs for some crashes
Browse files Browse the repository at this point in the history
- fixes multiple bookmarks with the same id present
- fixes export to csv
- logs whether the file exists when a line image cannot be loaded
  • Loading branch information
ahmedre committed Dec 4, 2024
1 parent 3502fe3 commit 2841931
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class BookmarkJsonModel @Inject constructor() {

@Throws(IOException::class)
fun toCSV(sink: BufferedSink, bookmarks: BookmarkData) {
toCSV(sink, bookmarks)
com.quran.labs.androidquran.model.bookmark.toCSV(sink, bookmarks)
}

@Throws(IOException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.quran.mobile.bookmark.mapper.convergeCommonlyTagged
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
import javax.inject.Inject

Expand Down Expand Up @@ -75,7 +74,12 @@ class BookmarksDaoImpl @Inject constructor(

override suspend fun togglePageBookmark(page: Int): Boolean {
return withContext(Dispatchers.IO) {
val bookmarkId = bookmarkQueries.getBookmarkIdForPage(page).executeAsOneOrNull()
val bookmarkIds = bookmarkQueries.getBookmarkIdForPage(page).executeAsList()
if (bookmarkIds.size > 1) {
bookmarkIds.drop(1).forEach { deleteBookmarkById(it) }
}

val bookmarkId = bookmarkIds.firstOrNull()
if (bookmarkId != null) {
deleteBookmarkById(bookmarkId)
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,17 @@ class QuranLineByLinePresenter @Inject constructor(
val lines = mutableListOf<LineModel>()
val whence = quranFileManager.quranImagesDirectory()
for (lineNumber in 1..15) {
val file = File(File(whence, page.toString()), "$lineNumber.png")
try {
val fileName = File(File(whence, page.toString()), "$lineNumber.png").toString()
val fileName = file.toString()
val sourceBitmap = BitmapFactory.decodeFile(fileName, options)
val bitmap = sourceBitmap.extractAlpha()
sourceBitmap.recycle()
lines.add(LineModel(lineNumber - 1, bitmap.asImageBitmap()))
} catch (exception: Exception) {
val status = if (file.exists()) { "exists" } else { "missing" }
// make sure to add the line number and page to the crash metadata
crashReporter.log("Failed to load line $lineNumber for page $page")
crashReporter.log("Failed to load line $lineNumber for page $page - file $status")
throw exception
}
}
Expand Down

0 comments on commit 2841931

Please sign in to comment.