For #17393: Dead code removed around Delete downloads

upstream-sync
sunil9211 3 years ago committed by mergify[bot]
parent 671dfa59c2
commit 05d0bca6a3

@ -36,7 +36,7 @@ class DownloadAdapter(
override fun onBindViewHolder(holder: DownloadsListItemViewHolder, position: Int) {
val current = downloads[position]
val isPendingDeletion = pendingDeletionIds.contains(current.id)
holder.bind(downloads[position], mode, isPendingDeletion)
holder.bind(downloads[position], isPendingDeletion)
}
fun updateDownloads(downloads: List<DownloadItem>) {

@ -13,13 +13,11 @@ interface DownloadController {
fun handleBackPressed(): Boolean
fun handleModeSwitched()
fun handleDeleteSome(items: Set<DownloadItem>)
fun handleDeleteAll()
}
class DefaultDownloadController(
private val store: DownloadFragmentStore,
private val openToFileManager: (item: DownloadItem, mode: BrowsingMode?) -> Unit,
private val displayDeleteAll: () -> Unit,
private val invalidateOptionsMenu: () -> Unit,
private val deleteDownloadItems: (Set<DownloadItem>) -> Unit
) : DownloadController {
@ -48,10 +46,6 @@ class DefaultDownloadController(
invalidateOptionsMenu.invoke()
}
override fun handleDeleteAll() {
displayDeleteAll.invoke()
}
override fun handleDeleteSome(items: Set<DownloadItem>) {
deleteDownloadItems.invoke(items)
}

@ -4,7 +4,6 @@
package org.mozilla.fenix.library.downloads
import android.content.DialogInterface
import android.os.Bundle
import android.text.SpannableString
import android.view.LayoutInflater
@ -14,10 +13,8 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.browser.state.state.BrowserState
@ -29,7 +26,6 @@ import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.base.feature.UserInteractionHandler
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.addons.showSnackBar
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.databinding.FragmentDownloadsBinding
@ -76,7 +72,6 @@ class DownloadFragment : LibraryPageFragment<DownloadItem>(), UserInteractionHan
val downloadController: DownloadController = DefaultDownloadController(
downloadStore,
::openItem,
::displayDeleteAll,
::invalidateOptionsMenu,
::deleteDownloadItems
)
@ -127,32 +122,6 @@ class DownloadFragment : LibraryPageFragment<DownloadItem>(), UserInteractionHan
setHasOptionsMenu(true)
}
private fun displayDeleteAll() {
activity?.let { activity ->
AlertDialog.Builder(activity).apply {
setMessage(R.string.download_delete_all_dialog)
setNegativeButton(R.string.delete_browsing_data_prompt_cancel) { dialog: DialogInterface, _ ->
dialog.cancel()
}
setPositiveButton(R.string.delete_browsing_data_prompt_allow) { dialog: DialogInterface, _ ->
// Use fragment's lifecycle; the view may be gone by the time dialog is interacted with.
lifecycleScope.launch(IO) {
downloadsUseCases.removeAllDownloads()
updatePendingDownloadToDelete(downloadStore.state.items.toSet())
launch(Dispatchers.Main) {
showSnackBar(
requireView(),
getString(R.string.download_delete_multiple_items_snackbar_1)
)
}
}
dialog.dismiss()
}
create()
}.show()
}
}
/**
* Schedules [items] for deletion.
* Note: When tapping on a download item's "trash" button

@ -34,8 +34,4 @@ class DownloadInteractor(
override fun onDeleteSome(items: Set<DownloadItem>) {
downloadController.handleDeleteSome(items)
}
override fun onDeleteAll() {
downloadController.handleDeleteAll()
}
}

@ -36,11 +36,6 @@ interface DownloadViewInteractor : SelectionInteractor<DownloadItem> {
* @param items the downloads items to delete
*/
fun onDeleteSome(items: Set<DownloadItem>)
/**
* Called when all downloads items are deleted
*/
fun onDeleteAll()
}
/**

@ -5,7 +5,6 @@
package org.mozilla.fenix.library.downloads.viewholders
import android.view.View
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import mozilla.components.feature.downloads.toMegabyteOrKilobyteString
import org.mozilla.fenix.R
@ -16,7 +15,6 @@ import org.mozilla.fenix.library.downloads.DownloadInteractor
import org.mozilla.fenix.library.downloads.DownloadItem
import org.mozilla.fenix.ext.getIcon
import org.mozilla.fenix.ext.showAndEnable
import org.mozilla.fenix.library.downloads.DownloadFragmentState
import org.mozilla.fenix.library.downloads.DownloadItemMenu
class DownloadsListItemViewHolder(
@ -31,20 +29,10 @@ class DownloadsListItemViewHolder(
init {
setupMenu()
binding.deleteDownloadsButton.setOnClickListener {
val selected = selectionHolder.selectedItems
if (selected.isEmpty()) {
downloadInteractor.onDeleteAll()
} else {
downloadInteractor.onDeleteSome(selected)
}
}
}
fun bind(
item: DownloadItem,
mode: DownloadFragmentState.Mode,
isPendingDeletion: Boolean = false
) {
binding.downloadLayout.visibility = if (isPendingDeletion) {
@ -55,8 +43,6 @@ class DownloadsListItemViewHolder(
binding.downloadLayout.titleView.text = item.fileName
binding.downloadLayout.urlView.text = item.size.toLong().toMegabyteOrKilobyteString()
toggleTopContent(false, mode == DownloadFragmentState.Mode.Normal)
binding.downloadLayout.setSelectionInteractor(item, selectionHolder, downloadInteractor)
binding.downloadLayout.changeSelected(item in selectionHolder.selectedItems)
@ -73,25 +59,6 @@ class DownloadsListItemViewHolder(
this.item = item
}
private fun toggleTopContent(
showTopContent: Boolean,
isNormalMode: Boolean
) {
binding.deleteDownloadsButton.isVisible = showTopContent
if (showTopContent) {
binding.deleteDownloadsButton.run {
if (isNormalMode) {
isEnabled = true
alpha = 1f
} else {
isEnabled = false
alpha = DELETE_BUTTON_DISABLED_ALPHA
}
}
}
}
private fun setupMenu() {
val downloadMenu = DownloadItemMenu(itemView.context) {
val item = this.item ?: return@DownloadItemMenu
@ -104,7 +71,6 @@ class DownloadsListItemViewHolder(
}
companion object {
const val DELETE_BUTTON_DISABLED_ALPHA = 0.4f
const val LAYOUT_ID = R.layout.download_list_item
}
}

@ -1,24 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
<?xml version="1.0" encoding="utf-8"?><!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<org.mozilla.fenix.library.LibrarySiteItemView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/download_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
android:minHeight="@dimen/library_item_height" />
<com.google.android.material.button.MaterialButton
android:id="@+id/delete_downloads_button"
style="@style/DestructiveButton"
android:layout_marginHorizontal="16dp"
android:text="@string/download_delete_all"
android:visibility="gone" />
<org.mozilla.fenix.library.LibrarySiteItemView
android:id="@+id/download_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/library_item_height" />
</LinearLayout>

@ -883,10 +883,6 @@
<string name="history_empty_message">No history here</string>
<!-- Downloads -->
<!-- Text for the button to clear all downloads -->
<string name="download_delete_all">Delete downloads</string>
<!-- Text for the dialog to confirm clearing all downloads -->
<string name="download_delete_all_dialog">Are you sure you want to clear your downloads?</string>
<!-- Text for the snackbar to confirm that multiple downloads items have been removed -->
<string name="download_delete_multiple_items_snackbar_1">Downloads Removed</string>
<!-- Text for the snackbar to confirm that a single download item has been removed. The first parameter is the name of the download item. -->

@ -40,9 +40,6 @@ class DownloadControllerTest {
private var openToFileManagerCapturedItem: DownloadItem? = null
private var openToFileManagerCapturedMode: BrowsingMode? = null
private val displayDeleteAll: () -> Unit = { wasDisplayDeleteAllCalled = true }
private var wasDisplayDeleteAllCalled = false
private val invalidateOptionsMenu: () -> Unit = { wasInvalidateOptionsMenuCalled = true }
private var wasInvalidateOptionsMenuCalled = false
@ -52,7 +49,6 @@ class DownloadControllerTest {
private val controller = DefaultDownloadController(
store,
openToFileManager,
displayDeleteAll,
invalidateOptionsMenu,
deleteDownloadItems
)
@ -119,13 +115,6 @@ class DownloadControllerTest {
assertTrue(wasInvalidateOptionsMenuCalled)
}
@Test
fun onDeleteAll() {
controller.handleDeleteAll()
assertTrue(wasDisplayDeleteAllCalled)
}
@Test
fun onDeleteSome() {
val itemsToDelete = setOf(downloadItem)

@ -74,15 +74,6 @@ class DownloadInteractorTest {
}
}
@Test
fun onDeleteAll() {
interactor.onDeleteAll()
verifyAll {
controller.handleDeleteAll()
}
}
@Test
fun onDeleteSome() {
val items = setOf(downloadItem)

Loading…
Cancel
Save