Skip to content

Commit

Permalink
Fix a number of crashes (#1477)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedre authored Oct 30, 2020
1 parent 9e00b38 commit 84471a0
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
defaultConfig {
minSdkVersion deps.android.build.minSdkVersion
targetSdkVersion deps.android.build.targetSdkVersion
versionCode 3020
versionCode 3021
versionName "3.0.2"
testInstrumentationRunner "com.quran.labs.androidquran.core.QuranTestRunner"
multiDexEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
TranslationsTable.FILENAME + ", " +
TranslationsTable.URL + ", " +
(oldVersion < 3 ? "" : (TranslationsTable.LANGUAGE_CODE + ",")) +
TranslationsTable.VERSION + ") " +
TranslationsTable.VERSION + ", " +
TranslationsTable.DISPLAY_ORDER + ") " +
"SELECT " + TranslationsTable.ID + ", " +
TranslationsTable.NAME + ", " +
TranslationsTable.TRANSLATOR + ", " +
(oldVersion < 2 ? "" : "translator_foreign, ") +
TranslationsTable.FILENAME + ", " +
TranslationsTable.URL + ", " +
(oldVersion < 3 ? "" : (TranslationsTable.LANGUAGE_CODE + ",")) +
TranslationsTable.VERSION +
TranslationsTable.VERSION + ", " +
TranslationsTable.ID +
" FROM " + BACKUP_TABLE);
db.execSQL("DROP TABLE " + BACKUP_TABLE);
db.execSQL("UPDATE " + TranslationsTable.TABLE_NAME + " SET " +
Expand All @@ -70,9 +72,9 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
} finally {
db.endTransaction();
}
}

if (oldVersion < 5) {
} else if (oldVersion < 5) {
// the v3 and below update also updates to v5.
// this code is called for updating from v4.
upgradeToV5(db);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.quran.labs.androidquran.service.util.ServiceIntentHelper
import com.quran.labs.androidquran.ui.PagerActivity
import com.quran.labs.androidquran.util.AudioUtils
import com.quran.labs.androidquran.util.QuranFileUtils
import timber.log.Timber
import java.io.File
import javax.inject.Inject

Expand Down Expand Up @@ -48,8 +49,19 @@ constructor(private val quranDisplayData: QuranDisplayData,
audioPathInfo
}

val (actualStart, actualEnd) = if (start > end) {
start to end
} else {
Timber.e(
IllegalStateException(
"End isn't larger than the start: $start to $end"
)
)
end to start
}

val audioRequest = AudioRequest(
start, end, qari, verseRepeat, rangeRepeat, enforceRange, stream, audioPath)
actualStart, actualEnd, qari, verseRepeat, rangeRepeat, enforceRange, stream, audioPath)
play(audioRequest)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.annotation.SuppressLint;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.google.android.material.snackbar.Snackbar;

Expand Down Expand Up @@ -196,7 +197,7 @@ public void deleteAfterSomeTime(List<QuranRow> remove) {
.subscribeWith(new DisposableSingleObserver<BookmarkResult>() {

@Override
public void onSuccess(BookmarkResult result) {
public void onSuccess(@NonNull BookmarkResult result) {
pendingRemoval = null;
cachedData = result;
if (fragment != null) {
Expand All @@ -205,14 +206,14 @@ public void onSuccess(BookmarkResult result) {
}

@Override
public void onError(Throwable e) {
public void onError(@NonNull Throwable e) {
}
});
}

private BookmarkResult predictQuranListAfterDeletion(List<QuranRow> remove) {
if (cachedData != null) {
List<QuranRow> placeholder = new ArrayList<>(cachedData.getRows().size() - remove.size());
List<QuranRow> placeholder = new ArrayList<>(Math.max(0, cachedData.getRows().size() - remove.size()));
List<QuranRow> rows = cachedData.getRows();
List<Long> removedTags = new ArrayList<>();
for (int i = 0, rowsSize = rows.size(); i < rowsSize; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ class QuranIndexEventLoggerImpl @Inject constructor(

override fun logAnalytics() {
val appLocation = quranSettings.appCustomLocation
val pathType = if ("com.quran" in appLocation) { "external" } else { "sdcard" }
val pathType =
when {
appLocation == null -> "unknown"
"com.quran" in appLocation -> "external"
else -> "sdcard"
}

val params: Map<String, Any> = mapOf(
"pathType" to pathType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1974,12 +1974,14 @@ public boolean onMenuItemClick(MenuItem item) {

@Override
public void requestMenuPositionUpdate(AyahTracker tracker) {
ayahToolBarPos = tracker.getToolBarPosition(start.sura, start.ayah,
ayahToolBar.getToolBarWidth(), ayahToolBarTotalHeight);
if (ayahToolBarPos != null) {
ayahToolBar.updatePosition(ayahToolBarPos);
if (ayahToolBar.getVisibility() != View.VISIBLE) {
ayahToolBar.setVisibility(View.VISIBLE);
if (start != null) {
ayahToolBarPos = tracker.getToolBarPosition(start.sura, start.ayah,
ayahToolBar.getToolBarWidth(), ayahToolBarTotalHeight);
if (ayahToolBarPos != null) {
ayahToolBar.updatePosition(ayahToolBarPos);
if (ayahToolBar.getVisibility() != View.VISIBLE) {
ayahToolBar.setVisibility(View.VISIBLE);
}
}
}
}
Expand Down
16 changes: 13 additions & 3 deletions app/src/main/java/com/quran/labs/androidquran/util/AudioUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ constructor(private val quranInfo: QuranInfo, private val quranFileUtils: QuranF
if (juz == 30) {
return SuraAyah(114, 6)
} else if (juz in 1..29) {
var endJuz = quranInfo.getQuarterByIndex(juz * 8)
val endJuz = quranInfo.getQuarterByIndex(juz * 8)
if (pageLastSura > endJuz[0]) {
// ex between jathiya and a7qaf
endJuz = quranInfo.getQuarterByIndex((juz + 1) * 8)
return getQuarterForNextJuz(juz)
} else if (pageLastSura == endJuz[0] && pageLastAyah > endJuz[1]) {
// ex surat al anfal
endJuz = quranInfo.getQuarterByIndex((juz + 1) * 8)
return getQuarterForNextJuz(juz)
}

return SuraAyah(endJuz[0], endJuz[1])
Expand All @@ -167,6 +167,16 @@ constructor(private val quranInfo: QuranInfo, private val quranFileUtils: QuranF
return SuraAyah(pageLastSura, pageLastAyah)
}

private fun getQuarterForNextJuz(currentJuz: Int): SuraAyah {
return if (currentJuz < 29) {
val juz = quranInfo.getQuarterByIndex((currentJuz + 1) * 8)
SuraAyah(juz[0], juz[1])
} else {
// if we're currently at the 29th juz', just return the end of the 30th.
SuraAyah(114, 6)
}
}

fun shouldDownloadBasmallah(
baseDirectory: String,
start: SuraAyah,
Expand Down

0 comments on commit 84471a0

Please sign in to comment.