Skip to content

Commit

Permalink
[Android] Add Endpoint Number in Fragment (#25892)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeonghwan7 authored and pull[bot] committed May 6, 2024
1 parent f3da4dd commit 6086984
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ class AddressUpdateFragment: Fragment() {

val deviceId: Long
get() = binding.deviceIdEd.text.toString().toULong().toLong()

var endpointId : Int
get() = binding.epIdEd.text.toString().toInt()
set(value) {
binding.epIdEd.setText(value.toString())
}
private var _binding: AddressUpdateFragmentBinding? = null
private val binding get() = _binding!!

Expand All @@ -39,6 +43,7 @@ class AddressUpdateFragment: Fragment() {
val compressedFabricId = deviceController.compressedFabricId
binding.fabricIdEd.setText(compressedFabricId.toULong().toString(16).padStart(16, '0'))
binding.deviceIdEd.setText(DeviceIdUtil.getLastDeviceId(requireContext()).toString())
binding.epIdEd.setText(endpointId.toString())
}

override fun onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class BasicClientFragment : Fragment() {

addressUpdateFragment =
childFragmentManager.findFragmentById(R.id.addressUpdateFragment) as AddressUpdateFragment

binding.writeNodeLabelBtn.setOnClickListener { scope.launch {
sendWriteNodeLabelAttribute()
binding.nodeLabelEd.onEditorAction(EditorInfo.IME_ACTION_DONE)
Expand Down Expand Up @@ -480,10 +479,15 @@ class BasicClientFragment : Fragment() {

private suspend fun getBasicClusterForDevice(): BasicInformationCluster {
return BasicInformationCluster(
ChipClient.getConnectedDevicePointer(requireContext(), addressUpdateFragment.deviceId), ENDPOINT
ChipClient.getConnectedDevicePointer(requireContext(), addressUpdateFragment.deviceId), addressUpdateFragment.endpointId
)
}

override fun onResume() {
super.onResume()
addressUpdateFragment.endpointId = ENDPOINT
}

companion object {
private const val TAG = "BasicClientFragment"
private const val ENDPOINT = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class OnOffClientFragment : Fragment() {
private suspend fun sendLevelCommandClick() {
val cluster = ChipClusters.LevelControlCluster(
ChipClient.getConnectedDevicePointer(requireContext(), addressUpdateFragment.deviceId),
LEVEL_CONTROL_CLUSTER_ENDPOINT
addressUpdateFragment.endpointId
)
cluster.moveToLevel(object : ChipClusters.DefaultClusterCallback {
override fun onSuccess() {
Expand Down Expand Up @@ -223,8 +223,9 @@ class OnOffClientFragment : Fragment() {

private suspend fun getOnOffClusterForDevice(): OnOffCluster {
return OnOffCluster(

ChipClient.getConnectedDevicePointer(requireContext(), addressUpdateFragment.deviceId),
ON_OFF_CLUSTER_ENDPOINT
addressUpdateFragment.endpointId
)
}

Expand All @@ -240,6 +241,12 @@ class OnOffClientFragment : Fragment() {
}
}

override fun onResume() {
super.onResume()
addressUpdateFragment.endpointId = ON_OFF_CLUSTER_ENDPOINT

}

companion object {
private const val TAG = "OnOffClientFragment"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<EditText
android:id="@+id/fabricIdEd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:inputType="text"
android:textSize="20sp"
android:hint="@string/enter_fabric_id_hint_text"/>
android:layout_height="match_parent">

<EditText
android:id="@+id/fabricIdEd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:hint="@string/enter_fabric_id_hint_text"
android:inputType="number"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toLeftOf="@+id/deviceIdEd"/>

<EditText
android:id="@+id/deviceIdEd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:textSize="20sp"
android:hint="@string/enter_device_id_hint_text"
app:layout_constraintStart_toEndOf="@+id/fabricIdEd"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/deviceIdEd"
android:id="@+id/epIdEd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_toEndOf="@id/fabricIdEd"
android:inputType="text"
android:hint="@string/enter_endpoint_id_hint_text"
android:inputType="number"
android:textSize="20sp"
android:hint="@string/enter_device_id_hint_text"/>
android:text ="1"
app:layout_constraintStart_toEndOf="@+id/deviceIdEd"
app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="fabricIdEd,deviceIdEd" />
app:constraint_referenced_ids="fabricIdEd,deviceIdEd,epIdEd" />
</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 6086984

Please sign in to comment.