For #13983: Show Only Completed Downloads in List
This commit is contained in:
parent
7f9e2255f7
commit
3370762248
|
@ -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<DownloadItem>(), 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) {
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<DownloadItem> = 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<DownloadItem> = mutableListOf(item1, item2, item3)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user