For #1539: Only allow delete when folders multi-selected (#4062)

nightly-build-test
Colin Lee 5 years ago committed by Sawyer Blatz
parent da59e36c1b
commit 33e881ca8a

@ -203,7 +203,6 @@ class BookmarkAdapter(val emptyView: View, val interactor: BookmarkViewInteracto
if (!item.inRoots()) { if (!item.inRoots()) {
setupMenu(item) setupMenu(item)
view.setOnLongClickListener(null)
} else { } else {
view.overflowView.visibility = View.GONE view.overflowView.visibility = View.GONE
} }

@ -28,6 +28,7 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import mozilla.appservices.places.BookmarkRoot import mozilla.appservices.places.BookmarkRoot
import mozilla.components.concept.storage.BookmarkNode import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.storage.BookmarkNodeType
import mozilla.components.concept.sync.AccountObserver import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.OAuthAccount import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile import mozilla.components.concept.sync.Profile
@ -158,7 +159,11 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), BackHandler, Accou
inflater.inflate(R.menu.bookmarks_menu, menu) inflater.inflate(R.menu.bookmarks_menu, menu)
} }
is BookmarkState.Mode.Selecting -> { is BookmarkState.Mode.Selecting -> {
inflater.inflate(R.menu.bookmarks_select_multi, menu) if (mode.selectedItems.any { it.type != BookmarkNodeType.ITEM }) {
inflater.inflate(R.menu.bookmarks_select_multi_not_item, menu)
} else {
inflater.inflate(R.menu.bookmarks_select_multi, menu)
}
menu.findItem(R.id.edit_bookmark_multi_select)?.run { menu.findItem(R.id.edit_bookmark_multi_select)?.run {
isVisible = mode.selectedItems.size == 1 isVisible = mode.selectedItems.size == 1
icon.colorFilter = PorterDuffColorFilter( icon.colorFilter = PorterDuffColorFilter(

@ -84,6 +84,10 @@ class BookmarkFragmentInteractor(
} }
override fun select(node: BookmarkNode) { override fun select(node: BookmarkNode) {
if (node.inRoots()) {
snackbarPresenter.present(context.getString(R.string.bookmark_cannot_edit_root))
return
}
bookmarkStore.dispatch(BookmarkAction.Select(node)) bookmarkStore.dispatch(BookmarkAction.Select(node))
} }

@ -0,0 +1,14 @@
<?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/. -->
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/delete_bookmarks_multi_select"
android:icon="@drawable/mozac_ic_delete"
android:iconTint="?primaryText"
android:title="@string/bookmark_menu_delete_button"
app:showAsAction="ifRoom"
tools:targetApi="o" />
</menu>

@ -709,4 +709,6 @@
<string name="sign_out_disconnect">Disconnect</string> <string name="sign_out_disconnect">Disconnect</string>
<!-- Option to cancel signing out shown in confirmation dialog to sign out of account --> <!-- Option to cancel signing out shown in confirmation dialog to sign out of account -->
<string name="sign_out_cancel">Cancel</string> <string name="sign_out_cancel">Cancel</string>
<!-- Error message snackbar shown after the user tried to select a default folder which cannot be altered -->
<string name="bookmark_cannot_edit_root">Cant edit default folders</string>
</resources> </resources>

@ -10,12 +10,14 @@ import android.content.Context
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import androidx.navigation.NavController import androidx.navigation.NavController
import androidx.navigation.NavDestination import androidx.navigation.NavDestination
import io.mockk.called
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import io.mockk.mockkStatic import io.mockk.mockkStatic
import io.mockk.spyk import io.mockk.spyk
import io.mockk.verify import io.mockk.verify
import io.mockk.verifyOrder import io.mockk.verifyOrder
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.concept.storage.BookmarkNode import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.storage.BookmarkNodeType import mozilla.components.concept.storage.BookmarkNodeType
import org.junit.Before import org.junit.Before
@ -61,6 +63,9 @@ class BookmarkFragmentInteractorTest {
private val tree = BookmarkNode( private val tree = BookmarkNode(
BookmarkNodeType.FOLDER, "123", null, 0, "Mobile", null, listOf(item, separator, childItem, subfolder) BookmarkNodeType.FOLDER, "123", null, 0, "Mobile", null, listOf(item, separator, childItem, subfolder)
) )
private val root = BookmarkNode(
BookmarkNodeType.FOLDER, BookmarkRoot.Root.id, null, 0, BookmarkRoot.Root.name, null, null
)
@Before @Before
fun setup() { fun setup() {
@ -164,6 +169,13 @@ class BookmarkFragmentInteractorTest {
} }
} }
@Test
fun `cannot select bookmark roots`() {
interactor.select(root)
verify { bookmarkStore wasNot called }
}
@Test @Test
fun `copy a bookmark item`() { fun `copy a bookmark item`() {
val clipboardManager: ClipboardManager = mockk(relaxed = true) val clipboardManager: ClipboardManager = mockk(relaxed = true)

Loading…
Cancel
Save