diff --git a/Simplenote/src/main/java/com/automattic/simplenote/CollaboratorsActivity.kt b/Simplenote/src/main/java/com/automattic/simplenote/CollaboratorsActivity.kt index 004a979d1..dfb4723fd 100644 --- a/Simplenote/src/main/java/com/automattic/simplenote/CollaboratorsActivity.kt +++ b/Simplenote/src/main/java/com/automattic/simplenote/CollaboratorsActivity.kt @@ -3,6 +3,7 @@ package com.automattic.simplenote import android.content.Intent import android.os.Bundle import android.text.SpannableString +import android.view.HapticFeedbackConstants import android.view.MenuItem import android.view.View import android.widget.Toast @@ -93,6 +94,10 @@ class CollaboratorsActivity : ThemedAppCompatActivity() { buttonAddCollaborator.setOnApplyWindowInsetsListener { view, insets -> DisplayUtils.applyWindowInsetsForFloatingActionButton(insets, resources, view) } + buttonAddCollaborator.setOnLongClickListener { + viewModel.longClickAddCollaborator() + true + } empty.image.setImageResource(R.drawable.ic_collaborate_24dp) empty.title.text = getString(R.string.no_collaborators) @@ -128,12 +133,20 @@ class CollaboratorsActivity : ThemedAppCompatActivity() { viewModel.event.observe(this@CollaboratorsActivity, { event -> when (event) { is Event.AddCollaboratorEvent -> showAddCollaboratorFragment(event) + is Event.LongAddCollaboratorEvent -> showLongAddToast() is Event.RemoveCollaboratorEvent -> showRemoveCollaboratorDialog(event) Event.CloseCollaboratorsEvent -> finish() } }) } + private fun ActivityCollaboratorsBinding.showLongAddToast() { + if (buttonAddCollaborator.isHapticFeedbackEnabled) { + buttonAddCollaborator.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) + } + toast(R.string.add_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/viewmodels/CollaboratorsViewModel.kt b/Simplenote/src/main/java/com/automattic/simplenote/viewmodels/CollaboratorsViewModel.kt index 2b254af76..eb0b7c5b4 100644 --- a/Simplenote/src/main/java/com/automattic/simplenote/viewmodels/CollaboratorsViewModel.kt +++ b/Simplenote/src/main/java/com/automattic/simplenote/viewmodels/CollaboratorsViewModel.kt @@ -62,6 +62,10 @@ class CollaboratorsViewModel @Inject constructor( _event.value = Event.AddCollaboratorEvent(noteId) } + fun longClickAddCollaborator() { + _event.postValue(Event.LongAddCollaboratorEvent) + } + fun clickRemoveCollaborator(collaborator: String) { _event.value = Event.RemoveCollaboratorEvent(collaborator) } @@ -102,6 +106,7 @@ class CollaboratorsViewModel @Inject constructor( sealed class Event { data class AddCollaboratorEvent(val noteId: String) : Event() object CloseCollaboratorsEvent : Event() + object LongAddCollaboratorEvent : Event() data class RemoveCollaboratorEvent(val collaborator: String) : Event() } } diff --git a/Simplenote/src/test/java/com/automattic/simplenote/viewmodels/CollaboratorsViewModelTest.kt b/Simplenote/src/test/java/com/automattic/simplenote/viewmodels/CollaboratorsViewModelTest.kt index 00b5e0e49..c6110926a 100644 --- a/Simplenote/src/test/java/com/automattic/simplenote/viewmodels/CollaboratorsViewModelTest.kt +++ b/Simplenote/src/test/java/com/automattic/simplenote/viewmodels/CollaboratorsViewModelTest.kt @@ -127,6 +127,13 @@ class CollaboratorsViewModelTest { assertEquals(Event.AddCollaboratorEvent(noteId), viewModel.event.value) } + @Test + fun longClickAddCollaboratorShouldTriggerLongAddCollaboratorEVent() { + viewModel.longClickAddCollaborator() + + assertEquals(viewModel.event.value, Event.LongAddCollaboratorEvent) + } + @Test fun clickRemoveCollaboratorShouldTriggerEventAddCollaborator() { val collaborator = "test@emil.com"