Browse Source

Merge pull request #11586 from nextcloud/fixEmptyGalleryView

Show empty message for gallery view
Andy Scherzinger 2 years ago
parent
commit
77d4bd5e83

BIN
app/screenshots/gplay/debug/com.owncloud.android.ui.fragment.GalleryFragmentIT_showEmpty.png


BIN
app/screenshots/gplay/debug/com.owncloud.android.ui.fragment.GalleryFragmentIT_showGallery.png


+ 27 - 14
app/src/androidTest/java/com/owncloud/android/ui/fragment/GalleryFragmentIT.kt

@@ -32,8 +32,10 @@ import com.owncloud.android.AbstractIT
 import com.owncloud.android.datamodel.ImageDimension
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.ThumbnailsCacheManager
+import com.owncloud.android.datamodel.ThumbnailsCacheManager.InitDiskCacheTask
 import com.owncloud.android.datamodel.ThumbnailsCacheManager.PREFIX_RESIZED_IMAGE
 import com.owncloud.android.lib.common.utils.Log_OC
+import com.owncloud.android.utils.ScreenshotTest
 import org.junit.After
 import org.junit.Assert.assertNotNull
 import org.junit.Before
@@ -46,16 +48,14 @@ class GalleryFragmentIT : AbstractIT() {
     val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
 
     lateinit var activity: TestActivity
-    val random = Random()
+    val random = Random(1)
 
     @Before
     fun before() {
         activity = testActivityRule.launchActivity(null)
 
-        createImage(10000001, true, 700, 300)
-        createImage(10000002, true, 500, 300)
-
-        createImage(10000007, true, 300, 400)
+        // initialise thumbnails cache on background thread
+        InitDiskCacheTask().execute()
     }
 
     @After
@@ -65,15 +65,32 @@ class GalleryFragmentIT : AbstractIT() {
         super.after()
     }
 
+    @ScreenshotTest
     @Test
+    fun showEmpty() {
+        val sut = GalleryFragment()
+        activity.addFragment(sut)
+
+        waitForIdleSync()
+
+        screenshot(activity)
+    }
+
+    @Test
+    @ScreenshotTest
     fun showGallery() {
+        createImage(10000001, 700, 300)
+        createImage(10000002, 500, 300)
+        createImage(10000007, 300, 400)
+
         val sut = GalleryFragment()
         activity.addFragment(sut)
 
-        longSleep()
+        waitForIdleSync()
+        screenshot(activity)
     }
 
-    private fun createImage(id: Int, createPreview: Boolean = true, width: Int? = null, height: Int? = null) {
+    private fun createImage(id: Int, width: Int? = null, height: Int? = null) {
         val defaultSize = ThumbnailsCacheManager.getThumbnailDimension().toFloat()
         val file = OCFile("/$id.png").apply {
             fileId = id.toLong()
@@ -85,13 +102,9 @@ class GalleryFragmentIT : AbstractIT() {
             storageManager.saveFile(this)
         }
 
-        if (!createPreview) {
-            return
-        }
-
         // create dummy thumbnail
-        var w: Int
-        var h: Int
+        val w: Int
+        val h: Int
         if (width == null || height == null) {
             if (random.nextBoolean()) {
                 // portrait
@@ -110,7 +123,7 @@ class GalleryFragmentIT : AbstractIT() {
         val bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)
         Canvas(bitmap).apply {
             drawRGB(random.nextInt(256), random.nextInt(256), random.nextInt(256))
-            drawCircle(w / 2f, h / 2f, Math.min(w, h) / 2f, Paint().apply { color = Color.BLACK })
+            drawCircle(w / 2f, h / 2f, w.coerceAtMost(h) / 2f, Paint().apply { color = Color.BLACK })
         }
         ThumbnailsCacheManager.addBitmapToCache(PREFIX_RESIZED_IMAGE + file.remoteId, bitmap)
 

+ 7 - 7
app/src/main/java/com/owncloud/android/ui/adapter/GalleryAdapter.kt

@@ -195,14 +195,14 @@ class GalleryAdapter(
 
         if (finalSortedList.isEmpty()) {
             photoFragment.setEmptyListMessage(SearchType.GALLERY_SEARCH)
-        }
-
-        files = finalSortedList
-            .groupBy { firstOfMonth(it.modificationTimestamp) }
-            .map { GalleryItems(it.key, transformToRows(it.value)) }
-            .sortedBy { it.date }.reversed()
+        } else {
+            files = finalSortedList
+                .groupBy { firstOfMonth(it.modificationTimestamp) }
+                .map { GalleryItems(it.key, transformToRows(it.value)) }
+                .sortedBy { it.date }.reversed()
 
-        Handler(Looper.getMainLooper()).post { notifyDataSetChanged() }
+            Handler(Looper.getMainLooper()).post { notifyDataSetChanged() }
+        }
     }
 
     private fun transformToRows(list: List<OCFile>): List<GalleryRow> {