@@ -9,10 +9,12 @@ import androidx.compose.foundation.layout.Column
9
9
import androidx.compose.foundation.layout.fillMaxWidth
10
10
import androidx.compose.ui.Modifier
11
11
import androidx.compose.ui.res.stringResource
12
+ import androidx.core.os.BundleCompat
12
13
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
13
14
import com.squareup.phrase.Phrase
14
15
import dagger.hilt.android.AndroidEntryPoint
15
16
import network.loki.messenger.R
17
+ import org.session.libsession.utilities.Address
16
18
import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
17
19
import org.thoughtcrime.securesms.showSessionDialog
18
20
import org.thoughtcrime.securesms.ui.components.ActionSheetItem
@@ -21,19 +23,19 @@ import org.thoughtcrime.securesms.ui.createThemedComposeView
21
23
@AndroidEntryPoint
22
24
class SearchContactActionBottomSheet : BottomSheetDialogFragment () {
23
25
24
- private var accountId : String ? = null
26
+ private var address : Address ? = null
25
27
private var contactName: String? = null
26
28
27
29
interface Callbacks {
28
- fun onBlockContact (accountId : String )
29
- fun onDeleteContact (accountId : String )
30
+ fun onBlockContact (address : Address )
31
+ fun onDeleteContact (address : Address )
30
32
}
31
33
32
34
private var callbacks: Callbacks ? = null
33
35
34
36
override fun onCreate (savedInstanceState : Bundle ? ) {
35
37
super .onCreate(savedInstanceState)
36
- accountId = arguments?.getString( ARG_ACCOUNT_ID )
38
+ address = arguments?.let { BundleCompat .getParcelable(it, ARG_ADDRESS , Address :: class .java) }
37
39
contactName = arguments?.getString(ARG_CONTACT_NAME )
38
40
}
39
41
@@ -52,15 +54,18 @@ class SearchContactActionBottomSheet : BottomSheetDialogFragment() {
52
54
Column (
53
55
modifier = Modifier .fillMaxWidth()
54
56
) {
55
- ActionSheetItem (
56
- text = stringResource(R .string.block),
57
- leadingIcon = R .drawable.ic_user_round_x,
58
- qaTag = stringResource(R .string.AccessibilityId_block ),
59
- onClick = {
60
- showBlockConfirmation()
61
- dismiss()
62
- }
63
- )
57
+ // Only standard address can be blocked
58
+ if (address is Address .Standard ) {
59
+ ActionSheetItem (
60
+ text = stringResource(R .string.block),
61
+ leadingIcon = R .drawable.ic_user_round_x,
62
+ qaTag = stringResource(R .string.AccessibilityId_block ),
63
+ onClick = {
64
+ showBlockConfirmation()
65
+ dismiss()
66
+ }
67
+ )
68
+ }
64
69
65
70
ActionSheetItem (
66
71
text = stringResource(R .string.contactDelete),
@@ -75,7 +80,7 @@ class SearchContactActionBottomSheet : BottomSheetDialogFragment() {
75
80
}
76
81
77
82
private fun showBlockConfirmation () {
78
- val accountId = accountId ? : return
83
+ val address = this @SearchContactActionBottomSheet.address ? : return
79
84
val contactName = contactName ? : return
80
85
81
86
showSessionDialog {
@@ -85,15 +90,15 @@ class SearchContactActionBottomSheet : BottomSheetDialogFragment() {
85
90
.put(NAME_KEY , contactName)
86
91
.format())
87
92
dangerButton(R .string.block, R .string.AccessibilityId_blockConfirm ) {
88
- callbacks?.onBlockContact(accountId )
93
+ callbacks?.onBlockContact(address )
89
94
callbacks = null
90
95
}
91
96
cancelButton()
92
97
}
93
98
}
94
99
95
100
private fun showDeleteConfirmation () {
96
- val accountId = accountId ? : return
101
+ val address = this @SearchContactActionBottomSheet.address ? : return
97
102
val contactName = contactName ? : return
98
103
99
104
showSessionDialog {
@@ -104,21 +109,21 @@ class SearchContactActionBottomSheet : BottomSheetDialogFragment() {
104
109
.put(NAME_KEY , contactName)
105
110
.format())
106
111
dangerButton(R .string.delete, R .string.AccessibilityId_delete ) {
107
- callbacks?.onDeleteContact(accountId )
112
+ callbacks?.onDeleteContact(address )
108
113
callbacks = null
109
114
}
110
115
cancelButton()
111
116
}
112
117
}
113
118
114
119
companion object {
115
- private const val ARG_ACCOUNT_ID = " arg_account_id "
120
+ private const val ARG_ADDRESS = " arg_address "
116
121
private const val ARG_CONTACT_NAME = " arg_contact_name"
117
122
118
- fun newInstance (accountId : String , contactName : String ): SearchContactActionBottomSheet {
123
+ fun newInstance (address : Address , contactName : String ): SearchContactActionBottomSheet {
119
124
return SearchContactActionBottomSheet ().apply {
120
- arguments = Bundle ().apply {
121
- putString( ARG_ACCOUNT_ID , accountId )
125
+ arguments = Bundle (2 ).apply {
126
+ putParcelable( ARG_ADDRESS , address )
122
127
putString(ARG_CONTACT_NAME , contactName)
123
128
}
124
129
}
0 commit comments