@@ -95,6 +95,8 @@ class ClusterDetailFragment : Fragment() {
95
95
return when (type) {
96
96
Int ::class .java -> data.toInt()
97
97
Boolean ::class .java -> data.toBoolean()
98
+ ByteArray ::class .java -> data.encodeToByteArray()
99
+ Long ::class .java -> data.toLong()
98
100
else -> data
99
101
}
100
102
}
@@ -169,7 +171,14 @@ class ClusterDetailFragment : Fragment() {
169
171
selectedInteractionInfo.commandParameters.forEach { (paramName, paramInfo) ->
170
172
val param = inflater.inflate(R .layout.cluster_parameter_item, null , false ) as ConstraintLayout
171
173
param.clusterParameterNameTv.text = " ${paramName} "
172
- param.clusterParameterTypeTv.text = " ${paramInfo.type} "
174
+ // byte[].class will be output as class [B, which is not readable, so dynamically change it
175
+ // to Byte[]. If more custom logic is required, should add a className field in
176
+ // commandParameterInfo
177
+ if (paramInfo.type == ByteArray ::class .java) {
178
+ param.clusterParameterTypeTv.text = " Byte[]"
179
+ } else {
180
+ param.clusterParameterTypeTv.text = " ${paramInfo.type} "
181
+ }
173
182
parameterList.addView(param)
174
183
}
175
184
}
@@ -181,14 +190,14 @@ class ClusterDetailFragment : Fragment() {
181
190
) {
182
191
responseValues.forEach { (variableNameType, response) ->
183
192
if (response is List <* >) {
184
- createListReadAttributeView (response, inflater, callbackList, variableNameType)
193
+ createListResponseView (response, inflater, callbackList, variableNameType)
185
194
} else {
186
- createBasicReadAttributeView (response, inflater, callbackList, variableNameType)
195
+ createBasicResponseView (response, inflater, callbackList, variableNameType)
187
196
}
188
197
}
189
198
}
190
199
191
- private fun createBasicReadAttributeView (
200
+ private fun createBasicResponseView (
192
201
response : Any ,
193
202
inflater : LayoutInflater ,
194
203
callbackList : LinearLayout ,
@@ -197,12 +206,16 @@ class ClusterDetailFragment : Fragment() {
197
206
val callbackItem =
198
207
inflater.inflate(R .layout.cluster_callback_item, null , false ) as ConstraintLayout
199
208
callbackItem.clusterCallbackNameTv.text = variableNameType.name
200
- callbackItem.clusterCallbackDataTv.text = response.toString()
209
+ callbackItem.clusterCallbackDataTv.text = if (response.javaClass == ByteArray ::class .java) {
210
+ (response as ByteArray ).decodeToString()
211
+ } else {
212
+ response.toString()
213
+ }
201
214
callbackItem.clusterCallbackTypeTv.text = variableNameType.type
202
215
callbackList.addView(callbackItem)
203
216
}
204
217
205
- private fun createListReadAttributeView (
218
+ private fun createListResponseView (
206
219
response : List <* >,
207
220
inflater : LayoutInflater ,
208
221
callbackList : LinearLayout ,
@@ -215,21 +228,29 @@ class ClusterDetailFragment : Fragment() {
215
228
callbackList.addView(emptyCallback)
216
229
} else {
217
230
response.forEachIndexed { index, it ->
218
- val readAttributeCallbackItem =
231
+ val attributeCallbackItem =
219
232
inflater.inflate(R .layout.cluster_callback_item, null , false ) as ConstraintLayout
220
- readAttributeCallbackItem.clusterCallbackNameTv.text = variableNameType.name + " [$index ]"
221
- val objectString = it.toString()
222
- val callbackClassName = it!! .javaClass.toString().split(' $' ).last()
223
- readAttributeCallbackItem.clusterCallbackDataTv.text = callbackClassName
224
- readAttributeCallbackItem.clusterCallbackDataTv.setOnClickListener {
233
+ attributeCallbackItem.clusterCallbackNameTv.text = variableNameType.name + " [$index ]"
234
+ val objectString = if (it!! .javaClass == ByteArray ::class .java) {
235
+ (it as ByteArray ).contentToString()
236
+ } else {
237
+ it.toString()
238
+ }
239
+ var callbackClassName = if (it!! .javaClass == ByteArray ::class .java) {
240
+ " Byte[]"
241
+ } else {
242
+ it!! .javaClass.toString().split(' $' ).last()
243
+ }
244
+ attributeCallbackItem.clusterCallbackDataTv.text = callbackClassName
245
+ attributeCallbackItem.clusterCallbackDataTv.setOnClickListener {
225
246
AlertDialog .Builder (requireContext())
226
247
.setTitle(callbackClassName)
227
248
.setMessage(objectString)
228
249
.create()
229
250
.show()
230
251
}
231
- readAttributeCallbackItem .clusterCallbackTypeTv.text = " List<$callbackClassName >"
232
- callbackList.addView(readAttributeCallbackItem )
252
+ attributeCallbackItem .clusterCallbackTypeTv.text = " List<$callbackClassName >"
253
+ callbackList.addView(attributeCallbackItem )
233
254
}
234
255
}
235
256
}
0 commit comments