Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
Expand All @@ -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<String>) {
hideEmptyView()
val items = listOf(HeaderItem) + collaborators.map { CollaboratorItem(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.automattic.simplenote.databinding.CollaboratorsHeaderBinding

class CollaboratorsAdapter(
private val onDeleteClick: (collaborator: String) -> Unit,
private val onDeleteLongClick: () -> Unit,
) : ListAdapter<CollaboratorsAdapter.CollaboratorDataItem, RecyclerView.ViewHolder>(DIFF_CALLBACK) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
Expand All @@ -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")
}
Expand Down Expand Up @@ -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
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
}
}
2 changes: 1 addition & 1 deletion Simplenote/src/main/res/layout/collaborator_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<ImageButton
android:id="@+id/collaborator_remove_button"
android:background="?attr/selectableItemBackgroundBorderless"
android:background="?attr/actionBarItemBackground"
android:contentDescription="@string/remove_collaborator"
android:focusable="false"
android:focusableInTouchMode="false"
Expand Down
2 changes: 1 addition & 1 deletion Simplenote/src/main/res/layout/search_suggestion.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<ImageButton
android:id="@+id/suggestion_delete"
android:background="?attr/selectableItemBackgroundBorderless"
android:background="?attr/actionBarItemBackground"
android:contentDescription="@string/description_delete_item"
android:focusable="false"
android:focusableInTouchMode="false"
Expand Down
2 changes: 1 addition & 1 deletion Simplenote/src/main/res/layout/tags_list_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<ImageButton
android:id="@+id/tag_trash"
android:background="?attr/selectableItemBackgroundBorderless"
android:background="?attr/actionBarItemBackground"
android:contentDescription="@string/delete_tag"
android:focusable="false"
android:focusableInTouchMode="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ class CollaboratorsViewModelTest {
assertEquals(Event.RemoveCollaboratorEvent(collaborator), viewModel.event.value)
}

@Test
fun longClickRemoveCollaboratorShouldTriggerLongRemoveCollaboratorEvent() {
viewModel.longClickRemoveCollaborator()

assertEquals(viewModel.event.value, Event.LongRemoveCollaboratorEvent)
}

@Test
fun closeShouldTriggerCloseCollaborators() {
viewModel.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class TagsViewModelTest {
}

@Test
fun lonClickAddTagShouldTriggerLongAddTagEvent() {
fun longClickAddTagShouldTriggerLongAddTagEvent() {
viewModel.longClickAddTag()

assertEquals(viewModel.event.value, TagsEvent.LongAddTagEvent)
Expand Down