From 08c941b543aa73c1161ab932e292bf400cb601ed Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Mon, 10 Feb 2020 00:12:04 +0400 Subject: [PATCH] Fix bugs with the partial page checker and tablet (#1276) Al7amdulillah, got really lucky here! The parital page checker had a number of bugs - namely it used the width where it should have used the tablet width. Consequently, it marks a massive number of pages as "to be deleted." Due to another bug though (looping over only the pages to delete instead of all pages to delete), al7amdulillah the pages didn't actually get deleted in this case. This fixes these bugs. --- .../com/quran/labs/androidquran/util/QuranScreenInfo.java | 2 +- .../labs/androidquran/worker/PartialPageCheckingWorker.kt | 6 +++--- .../data/pageinfo/common/size/DefaultPageSizeCalculator.kt | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/quran/labs/androidquran/util/QuranScreenInfo.java b/app/src/main/java/com/quran/labs/androidquran/util/QuranScreenInfo.java index 770fb78dfd..de0dd95b46 100644 --- a/app/src/main/java/com/quran/labs/androidquran/util/QuranScreenInfo.java +++ b/app/src/main/java/com/quran/labs/androidquran/util/QuranScreenInfo.java @@ -28,7 +28,7 @@ public QuranScreenInfo(@NonNull Context appContext, height = point.y; altDimension = point.x; - maxWidth = (point.x > point.y) ? point.x : point.y; + maxWidth = Math.max(point.x, point.y); orientation = appContext.getResources().getConfiguration().orientation; this.context = appContext; diff --git a/app/src/main/java/com/quran/labs/androidquran/worker/PartialPageCheckingWorker.kt b/app/src/main/java/com/quran/labs/androidquran/worker/PartialPageCheckingWorker.kt index b13d3dbb06..30ea93c130 100644 --- a/app/src/main/java/com/quran/labs/androidquran/worker/PartialPageCheckingWorker.kt +++ b/app/src/main/java/com/quran/labs/androidquran/worker/PartialPageCheckingWorker.kt @@ -43,7 +43,7 @@ class PartialPageCheckingWorker(private val context: Context, val width = quranScreenInfo.widthParam val pagesDirectory = quranFileUtils.getQuranImagesDirectory(context, width) val tabletWidth = quranScreenInfo.tabletWidthParam - val tabletPagesDirectory = quranFileUtils.getQuranImagesDirectory(context, width) + val tabletPagesDirectory = quranFileUtils.getQuranImagesDirectory(context, tabletWidth) // compute the partial page sets val partialPages = @@ -57,7 +57,7 @@ class PartialPageCheckingWorker(private val context: Context, quranPartialPageChecker.checkPages(tabletPagesDirectory, numberOfPages, tabletWidth) .map { PartialPage(tabletWidth, it) } } - Timber.d("Found %d partial images for tablet width %s", tabletPartialPages.size, width) + Timber.d("Found %d partial images for tablet width %s", tabletPartialPages.size, tabletWidth) val allPartialPages = partialPages + tabletPartialPages if (allPartialPages.size > PARTIAL_PAGE_LIMIT) { @@ -77,7 +77,7 @@ class PartialPageCheckingWorker(private val context: Context, val deletionSucceeded = try { // iterate through each one and delete the partial pages - partialPages.firstOrNull { + allPartialPages.firstOrNull { val path = if (it.width == width) pagesDirectory else tabletPagesDirectory !deletePage(path, it.page) } == null diff --git a/common/data/src/main/java/com/quran/data/pageinfo/common/size/DefaultPageSizeCalculator.kt b/common/data/src/main/java/com/quran/data/pageinfo/common/size/DefaultPageSizeCalculator.kt index 791a50e750..7a98616c4d 100644 --- a/common/data/src/main/java/com/quran/data/pageinfo/common/size/DefaultPageSizeCalculator.kt +++ b/common/data/src/main/java/com/quran/data/pageinfo/common/size/DefaultPageSizeCalculator.kt @@ -29,10 +29,10 @@ open class DefaultPageSizeCalculator(displaySize: DisplaySize) : PageSizeCalcula } override fun setOverrideParameter(parameter: String) { - if (parameter.isNotBlank()) { - overrideParam = parameter + overrideParam = if (parameter.isNotBlank()) { + parameter } else { - overrideParam = null + null } } }