From 33707622484273b1422aff528454fd798aade543 Mon Sep 17 00:00:00 2001 From: Kate Glazko Date: Fri, 21 Aug 2020 08:22:32 -0700 Subject: [PATCH] For #13983: Show Only Completed Downloads in List --- .../fenix/library/downloads/DownloadFragment.kt | 8 ++++++-- .../library/downloads/DownloadFragmentStore.kt | 6 ++++-- app/src/test/java/org/mozilla/fenix/ext/ListTest.kt | 13 +++++++------ .../library/downloads/DownloadControllerTest.kt | 3 ++- .../library/downloads/DownloadInteractorTest.kt | 3 ++- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/library/downloads/DownloadFragment.kt b/app/src/main/java/org/mozilla/fenix/library/downloads/DownloadFragment.kt index 52af61d85..95effa563 100644 --- a/app/src/main/java/org/mozilla/fenix/library/downloads/DownloadFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/downloads/DownloadFragment.kt @@ -10,6 +10,7 @@ import android.view.View import android.view.ViewGroup import kotlinx.android.synthetic.main.fragment_downloads.view.* import kotlinx.coroutines.ExperimentalCoroutinesApi +import mozilla.components.browser.state.state.content.DownloadState import mozilla.components.feature.downloads.AbstractFetchDownloadService import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.support.base.feature.UserInteractionHandler @@ -38,12 +39,15 @@ class DownloadFragment : LibraryPageFragment(), UserInteractionHan val items = requireComponents.core.store.state.downloads.map { DownloadItem( - it.value.id, + it.value.id.toString(), it.value.fileName, it.value.filePath, it.value.contentLength.toString(), - it.value.contentType + it.value.contentType, + it.value.status ) + }.filter { + it.status == DownloadState.Status.COMPLETED }.filterNotExistsOnDisk() downloadStore = StoreProvider.get(this) { diff --git a/app/src/main/java/org/mozilla/fenix/library/downloads/DownloadFragmentStore.kt b/app/src/main/java/org/mozilla/fenix/library/downloads/DownloadFragmentStore.kt index c79d45027..8f4915e33 100644 --- a/app/src/main/java/org/mozilla/fenix/library/downloads/DownloadFragmentStore.kt +++ b/app/src/main/java/org/mozilla/fenix/library/downloads/DownloadFragmentStore.kt @@ -4,6 +4,7 @@ package org.mozilla.fenix.library.downloads +import mozilla.components.browser.state.state.content.DownloadState import mozilla.components.lib.state.Action import mozilla.components.lib.state.State import mozilla.components.lib.state.Store @@ -17,11 +18,12 @@ import mozilla.components.lib.state.Store * @property contentType The type of file the download is */ data class DownloadItem( - val id: Long, + val id: String, val fileName: String?, val filePath: String, val size: String, - val contentType: String? + val contentType: String?, + val status: DownloadState.Status ) /** diff --git a/app/src/test/java/org/mozilla/fenix/ext/ListTest.kt b/app/src/test/java/org/mozilla/fenix/ext/ListTest.kt index f565b66fd..e6ff4a337 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/ListTest.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/ListTest.kt @@ -4,6 +4,7 @@ package org.mozilla.fenix.ext +import mozilla.components.browser.state.state.content.DownloadState import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith @@ -26,9 +27,9 @@ class ListTest { file1.createNewFile() file3.createNewFile() - val item1 = DownloadItem(71, "filepath.txt", filePath1, "71 Mb", "Image/png") - val item2 = DownloadItem(71, "filepath2.txt", "filepath2.txt", "71 Mb", "Image/png") - val item3 = DownloadItem(71, "filepath3.txt", filePath3, "71 Mb", "Image/png") + val item1 = DownloadItem("71", "filepath.txt", filePath1, "71 Mb", "Image/png", DownloadState.Status.COMPLETED) + val item2 = DownloadItem("71", "filepath2.txt", "filepath2.txt", "71 Mb", "Image/png", DownloadState.Status.COMPLETED) + val item3 = DownloadItem("71", "filepath3.txt", filePath3, "71 Mb", "Image/png", DownloadState.Status.COMPLETED) val testList = mutableListOf(item1, item2, item3) val comparisonList: MutableList = mutableListOf(item1, item3) @@ -57,9 +58,9 @@ class ListTest { file2.createNewFile() file3.createNewFile() - val item1 = DownloadItem(71, "filepath.txt", filePath1, "71 Mb", "text/plain") - val item2 = DownloadItem(71, "filepath2.txt", filePath2, "71 Mb", "text/plain") - val item3 = DownloadItem(71, "filepath3.txt", filePath3, "71 Mb", "text/plain") + val item1 = DownloadItem("71", "filepath.txt", filePath1, "71 Mb", "text/plain", DownloadState.Status.COMPLETED) + val item2 = DownloadItem("72", "filepath2.txt", filePath2, "71 Mb", "text/plain", DownloadState.Status.COMPLETED) + val item3 = DownloadItem("73", "filepath3.txt", filePath3, "71 Mb", "text/plain", DownloadState.Status.COMPLETED) val testList = mutableListOf(item1, item2, item3) val comparisonList: MutableList = mutableListOf(item1, item2, item3) diff --git a/app/src/test/java/org/mozilla/fenix/library/downloads/DownloadControllerTest.kt b/app/src/test/java/org/mozilla/fenix/library/downloads/DownloadControllerTest.kt index 68ae555dd..75d3d7418 100644 --- a/app/src/test/java/org/mozilla/fenix/library/downloads/DownloadControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/downloads/DownloadControllerTest.kt @@ -10,6 +10,7 @@ import io.mockk.verify import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestCoroutineScope +import mozilla.components.browser.state.state.content.DownloadState import org.junit.Assert.assertFalse import org.junit.Before import org.junit.Test @@ -20,7 +21,7 @@ import org.mozilla.fenix.helpers.FenixRobolectricTestRunner @ExperimentalCoroutinesApi @RunWith(FenixRobolectricTestRunner::class) class DownloadControllerTest { - private val downloadItem = DownloadItem(0, "title", "url", "77", "jpg") + private val downloadItem = DownloadItem("0", "title", "url", "77", "jpg", DownloadState.Status.COMPLETED) private val scope: CoroutineScope = TestCoroutineScope() private val store: DownloadFragmentStore = mockk(relaxed = true) private val state: DownloadFragmentState = mockk(relaxed = true) diff --git a/app/src/test/java/org/mozilla/fenix/library/downloads/DownloadInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/library/downloads/DownloadInteractorTest.kt index 3e552d6ab..74a80f888 100644 --- a/app/src/test/java/org/mozilla/fenix/library/downloads/DownloadInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/downloads/DownloadInteractorTest.kt @@ -7,11 +7,12 @@ package org.mozilla.fenix.library.downloads import io.mockk.every import io.mockk.mockk import io.mockk.verifyAll +import mozilla.components.browser.state.state.content.DownloadState import org.junit.Assert.assertTrue import org.junit.Test class DownloadInteractorTest { - private val downloadItem = DownloadItem(0, "title", "url", "5.6 mb", "png") + private val downloadItem = DownloadItem("0", "title", "url", "5.6 mb", "png", DownloadState.Status.COMPLETED) val controller: DownloadController = mockk(relaxed = true) val interactor = DownloadInteractor(controller)