Skip to content

Commit a8686e0

Browse files
committed
feat: show confirmation dialog when removing a share
Signed-off-by: Jorge Aguado Recio <jaguado@izertis.com>
1 parent 6005b9d commit a8686e0

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/GraphShareFragment.kt‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package com.owncloud.android.presentation.sharing
2222

23+
import android.app.AlertDialog
2324
import android.content.Context
2425
import android.os.Bundle
2526
import android.view.LayoutInflater
@@ -32,6 +33,8 @@ import com.owncloud.android.R
3233
import com.owncloud.android.databinding.MembersFragmentBinding
3334
import com.owncloud.android.domain.files.model.OCFile
3435
import com.owncloud.android.domain.roles.model.OCRole
36+
import com.owncloud.android.domain.sharing.shares.model.MemberPermission
37+
import com.owncloud.android.extensions.avoidScreenshotsIfNeeded
3538
import com.owncloud.android.extensions.collectLatestLifecycleFlow
3639
import com.owncloud.android.extensions.showErrorInSnackbar
3740
import com.owncloud.android.extensions.showMessageInSnackbar
@@ -40,7 +43,7 @@ import org.koin.androidx.viewmodel.ext.android.activityViewModel
4043
import org.koin.core.parameter.parametersOf
4144
import timber.log.Timber
4245

43-
class GraphShareFragment : Fragment() {
46+
class GraphShareFragment : Fragment(), GraphSharesAdapter.GraphSharesAdapterListener {
4447
private var _binding: MembersFragmentBinding? = null
4548
private val binding get() = _binding!!
4649

@@ -66,7 +69,7 @@ class GraphShareFragment : Fragment() {
6669
super.onViewCreated(view, savedInstanceState)
6770
binding.membersTitle.text = getString(R.string.share_with_people_title)
6871

69-
graphSharesAdapter = GraphSharesAdapter()
72+
graphSharesAdapter = GraphSharesAdapter(this)
7073
binding.membersRecyclerView.apply {
7174
layoutManager = LinearLayoutManager(requireContext())
7275
adapter = graphSharesAdapter
@@ -105,6 +108,15 @@ class GraphShareFragment : Fragment() {
105108
_binding = null
106109
}
107110

111+
override fun onRemoveShare(share: MemberPermission) {
112+
AlertDialog.Builder(requireContext())
113+
.setMessage(getString(R.string.confirmation_remove_share_message, share.displayName))
114+
.setPositiveButton(getString(R.string.common_yes)) { _, _ -> }
115+
.setNegativeButton(getString(R.string.common_no)) { dialog, _ -> dialog.dismiss() }
116+
.show()
117+
.avoidScreenshotsIfNeeded()
118+
}
119+
108120
private fun subscribeToViewModels() {
109121
observeRoles()
110122
observeShares()

‎owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/GraphSharesAdapter.kt‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ import com.owncloud.android.domain.sharing.shares.model.MemberPermission
3333
import com.owncloud.android.utils.DisplayUtils
3434
import com.owncloud.android.utils.PreferenceUtils
3535

36-
class GraphSharesAdapter : RecyclerView.Adapter<GraphSharesAdapter.GraphShareViewHolder>() {
36+
class GraphSharesAdapter(
37+
private val listener: GraphSharesAdapterListener,
38+
) : RecyclerView.Adapter<GraphSharesAdapter.GraphShareViewHolder>() {
3739

3840
private var shares: List<MemberPermission> = emptyList()
3941
private var rolesMap: Map<String, String> = emptyMap()
@@ -62,6 +64,9 @@ class GraphSharesAdapter : RecyclerView.Adapter<GraphSharesAdapter.GraphShareVie
6264
removeMemberButton.apply {
6365
contentDescription = holder.itemView.context.getString(R.string.content_description_remove_share_button, share.displayName)
6466
isVisible = canRemoveShares
67+
setOnClickListener {
68+
listener.onRemoveShare(share)
69+
}
6570
}
6671

6772
val hasExpirationDate = share.expirationDateTime != null
@@ -93,4 +98,8 @@ class GraphSharesAdapter : RecyclerView.Adapter<GraphSharesAdapter.GraphShareVie
9398
class GraphShareViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
9499
val binding = MemberItemBinding.bind(itemView)
95100
}
101+
102+
interface GraphSharesAdapterListener {
103+
fun onRemoveShare(share: MemberPermission)
104+
}
96105
}

0 commit comments

Comments
 (0)