Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Cluster command detail page #11355

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add responseValueInfo class instead of string split
  • Loading branch information
JasonLiuZhuoCheng committed Nov 3, 2021
commit 539c413de4d78448f268ba615c24c88454e566c4
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import chip.clusterinfo.ClusterCommandCallback
import chip.clusterinfo.ClusterInfo
import chip.clusterinfo.CommandInfo
import chip.clusterinfo.DelegatedClusterCallback
import chip.clusterinfo.ResponseValueInfo
import chip.devicecontroller.ChipClusters
import chip.devicecontroller.ChipDeviceController
import com.google.chip.chiptool.ChipClient
Expand Down Expand Up @@ -136,7 +137,7 @@ class ClusterDetailFragment : Fragment() {
selectedCommandCallback = selectedCommandInfo.commandCallbackSupplier.get()
populateCommandParameter(inflater, parameterList)
selectedCommandCallback!!.setCallbackDelegate(object : ClusterCommandCallback {
override fun onSuccess(responseValues: Map<String, Any>) {
override fun onSuccess(responseValues: Map<ResponseValueInfo, Any>) {
showMessage("Command success")
// Populate UI based on response values. We know the types from CommandInfo.getCommandResponses().
requireActivity().runOnUiThread {
Expand Down Expand Up @@ -168,15 +169,15 @@ class ClusterDetailFragment : Fragment() {
}

private fun populateCallbackResult(
responseValues: Map<String, Any>,
responseValues: Map<ResponseValueInfo, Any>,
inflater: LayoutInflater,
callbackList: LinearLayout
) {
responseValues.forEach { (variableNameType, response) ->
val callback = inflater.inflate(R.layout.callback_item, null, false) as LinearLayout
callback.callbackName.text = variableNameType.split(',')[0]
callback.callbackName.text = variableNameType.name
callback.callbackData.text = response.toString()
callback.callbackType.text = variableNameType.split(',')[1]
callback.callbackType.text = variableNameType.type
callbackList.addView(callback)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ android_library("java") {
"src/chip/clusterinfo/ClusterInfo.java",
"src/chip/clusterinfo/CommandInfo.java",
"src/chip/clusterinfo/CommandParameterInfo.java",
"src/chip/clusterinfo/ResponseValueInfo.java",
"src/chip/clusterinfo/DelegatedClusterCallback.java",
"src/chip/devicecontroller/ChipClusterException.java",
"src/chip/devicecontroller/ChipCommandType.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Interface for making customized callback that implements both onSuccess and onFailure functions.
*/
public interface ClusterCommandCallback {
void onSuccess(Map<String, Object> responseValues);
void onSuccess(Map<ResponseValueInfo, Object> responseValues);

void onFailure(Exception exception);
}
14 changes: 14 additions & 0 deletions src/controller/java/src/chip/clusterinfo/ResponseValueInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package chip.clusterinfo;

/** CommandParameterInfo captures the name and type of a parameter */
public class ResponseValueInfo {
public ResponseValueInfo() {}

public ResponseValueInfo(String name, String type) {
this.name = name;
this.type = type;
}

public String name;
public String type;
}
8 changes: 5 additions & 3 deletions src/controller/java/templates/ClusterInfo-java.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import chip.clusterinfo.CommandInfo;
import chip.clusterinfo.CommandParameterInfo;
import chip.clusterinfo.DelegatedClusterCallback;
import chip.clusterinfo.ClusterCommandCallback;
import chip.clusterinfo.ResponseValueInfo;
import chip.devicecontroller.ChipClusters.DefaultClusterCallback;


Expand All @@ -29,7 +30,7 @@ public class ClusterInfoMapping {
// Parameters and list-adds here should be generated - refer to the template code that creates each callback interface.
@Override
public void onSuccess() {
Map<String, Object> responseValues = new LinkedHashMap<>();
Map<ResponseValueInfo, Object> responseValues = new LinkedHashMap<>();
callback.onSuccess(responseValues);
}

Expand Down Expand Up @@ -62,13 +63,14 @@ public class ClusterInfoMapping {
{{/if}}
{{/chip_cluster_response_arguments}}
) {
Map<String, Object> responseValues = new LinkedHashMap<>();
Map<ResponseValueInfo, Object> responseValues = new LinkedHashMap<>();
{{#chip_cluster_response_arguments}}
{{#if isArray}}
// {{asSymbol label}}: {{asUnderlyingZclType type}}
// Conversion from this type to Java is not properly implemented yet
{{else}}
responseValues.put("{{asSymbol label}},{{asJavaBasicType type}}", {{asSymbol label}});
ResponseValueInfo {{asSymbol label}}ResponseValue = new ResponseValueInfo("{{asSymbol label}}", "{{asJavaBasicType type}}");
responseValues.put({{asSymbol label}}ResponseValue, {{asSymbol label}});
{{/if}}
{{/chip_cluster_response_arguments}}
callback.onSuccess(responseValues);
Expand Down
Loading