diff --git a/Simplenote/src/main/java/com/automattic/simplenote/CollaboratorsActivity.kt b/Simplenote/src/main/java/com/automattic/simplenote/CollaboratorsActivity.kt index dfb4723fd..794501e61 100644 --- a/Simplenote/src/main/java/com/automattic/simplenote/CollaboratorsActivity.kt +++ b/Simplenote/src/main/java/com/automattic/simplenote/CollaboratorsActivity.kt @@ -85,7 +85,7 @@ class CollaboratorsActivity : ThemedAppCompatActivity() { private fun ActivityCollaboratorsBinding.setupViews() { setupToolbar() - collaboratorsList.adapter = CollaboratorsAdapter(viewModel::clickRemoveCollaborator) + collaboratorsList.adapter = CollaboratorsAdapter(viewModel::clickRemoveCollaborator, viewModel::longClickRemoveCollaborator) collaboratorsList.isNestedScrollingEnabled = false collaboratorsList.layoutManager = LinearLayoutManager(this@CollaboratorsActivity) collaboratorsList.setEmptyView(empty.root) @@ -134,6 +134,7 @@ class CollaboratorsActivity : ThemedAppCompatActivity() { when (event) { is Event.AddCollaboratorEvent -> showAddCollaboratorFragment(event) is Event.LongAddCollaboratorEvent -> showLongAddToast() + is Event.LongRemoveCollaboratorEvent -> showLongRemoveToast() is Event.RemoveCollaboratorEvent -> showRemoveCollaboratorDialog(event) Event.CloseCollaboratorsEvent -> finish() } @@ -147,6 +148,14 @@ class CollaboratorsActivity : ThemedAppCompatActivity() { toast(R.string.add_collaborator) } + private fun ActivityCollaboratorsBinding.showLongRemoveToast() { + if (buttonAddCollaborator.isHapticFeedbackEnabled) { + buttonAddCollaborator.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) + } + + toast(R.string.remove_collaborator) + } + private fun ActivityCollaboratorsBinding.handleCollaboratorsList(collaborators: List) { hideEmptyView() val items = listOf(HeaderItem) + collaborators.map { CollaboratorItem(it) } diff --git a/Simplenote/src/main/java/com/automattic/simplenote/utils/CollaboratorsAdapter.kt b/Simplenote/src/main/java/com/automattic/simplenote/utils/CollaboratorsAdapter.kt index 5bfcb7efd..3acba7930 100644 --- a/Simplenote/src/main/java/com/automattic/simplenote/utils/CollaboratorsAdapter.kt +++ b/Simplenote/src/main/java/com/automattic/simplenote/utils/CollaboratorsAdapter.kt @@ -10,6 +10,7 @@ import com.automattic.simplenote.databinding.CollaboratorsHeaderBinding class CollaboratorsAdapter( private val onDeleteClick: (collaborator: String) -> Unit, + private val onDeleteLongClick: () -> Unit, ) : ListAdapter(DIFF_CALLBACK) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { @@ -20,7 +21,7 @@ class CollaboratorsAdapter( } ITEM_VIEW_TYPE_ITEM -> { val binding = CollaboratorRowBinding.inflate(LayoutInflater.from(parent.context), parent, false) - CollaboratorViewHolder(binding, onDeleteClick) + CollaboratorViewHolder(binding, onDeleteClick, onDeleteLongClick) } else -> throw ClassCastException("Unknown viewType $viewType") } @@ -55,12 +56,17 @@ class CollaboratorsAdapter( class CollaboratorViewHolder( private val binding: CollaboratorRowBinding, - private val onDeleteClick: (collaborator: String) -> Unit + private val onDeleteClick: (collaborator: String) -> Unit, + private val onDeleteLongClick: () -> Unit ): RecyclerView.ViewHolder(binding.root) { fun bind(collaborator: CollaboratorDataItem.CollaboratorItem) { binding.collaboratorText.text = collaborator.email binding.collaboratorRemoveButton.setOnClickListener { onDeleteClick(collaborator.email) } + binding.collaboratorRemoveButton.setOnLongClickListener { + onDeleteLongClick() + true + } } } diff --git a/Simplenote/src/main/java/com/automattic/simplenote/viewmodels/CollaboratorsViewModel.kt b/Simplenote/src/main/java/com/automattic/simplenote/viewmodels/CollaboratorsViewModel.kt index eb0b7c5b4..389dd8ddb 100644 --- a/Simplenote/src/main/java/com/automattic/simplenote/viewmodels/CollaboratorsViewModel.kt +++ b/Simplenote/src/main/java/com/automattic/simplenote/viewmodels/CollaboratorsViewModel.kt @@ -9,7 +9,6 @@ import com.automattic.simplenote.repositories.CollaboratorsActionResult import com.automattic.simplenote.repositories.CollaboratorsRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import javax.inject.Inject @@ -70,6 +69,10 @@ class CollaboratorsViewModel @Inject constructor( _event.value = Event.RemoveCollaboratorEvent(collaborator) } + fun longClickRemoveCollaborator() { + _event.postValue(Event.LongRemoveCollaboratorEvent) + } + fun close() { _event.value = Event.CloseCollaboratorsEvent } @@ -107,6 +110,7 @@ class CollaboratorsViewModel @Inject constructor( data class AddCollaboratorEvent(val noteId: String) : Event() object CloseCollaboratorsEvent : Event() object LongAddCollaboratorEvent : Event() + object LongRemoveCollaboratorEvent : Event() data class RemoveCollaboratorEvent(val collaborator: String) : Event() } } diff --git a/Simplenote/src/main/res/layout/collaborator_row.xml b/Simplenote/src/main/res/layout/collaborator_row.xml index 81007731e..06fc73856 100644 --- a/Simplenote/src/main/res/layout/collaborator_row.xml +++ b/Simplenote/src/main/res/layout/collaborator_row.xml @@ -25,7 +25,7 @@