Show empty message for gallery view

added tests

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2023-05-04 10:17:46 +02:00
parent ffac056474
commit 3b5d2a0391
No known key found for this signature in database
GPG Key ID: 0E00D4D47D0C5AF7
4 changed files with 35 additions and 22 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

View File

@ -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 showGallery() {
fun showEmpty() {
val sut = GalleryFragment()
activity.addFragment(sut)
longSleep()
waitForIdleSync()
screenshot(activity)
}
private fun createImage(id: Int, createPreview: Boolean = true, width: Int? = null, height: Int? = null) {
@Test
@ScreenshotTest
fun showGallery() {
createImage(10000001, 700, 300)
createImage(10000002, 500, 300)
createImage(10000007, 300, 400)
val sut = GalleryFragment()
activity.addFragment(sut)
waitForIdleSync()
screenshot(activity)
}
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)

View File

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