Skip to content

Commit

Permalink
Implement Android ICD queue Btn (#33743)
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo authored and pull[bot] committed Nov 18, 2024
1 parent 1dc7419 commit 11992a1
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
setVisibilityEachView(radioBtnId)
}

binding.sendBtn.setOnClickListener { showDialog() }
binding.sendBtn.setOnClickListener { showDialog(isICDQueueBtn = false) }

binding.shutdownSubscriptionBtn.setOnClickListener { showShutdownSubscriptionDialog() }

Expand All @@ -183,6 +183,16 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
binding.addListBtn.setOnClickListener { addRequest() }
binding.resetBtn.setOnClickListener { resetPath() }
binding.writeInvokeresetBtn.setOnClickListener { resetPath() }
binding.icdQueueBtn.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
val isSetting = showDialog(isICDQueueBtn = true)
if (!isSetting) {
binding.icdQueueBtn.isChecked = false
}
} else {
resetICDConfig()
}
}

addressUpdateFragment =
childFragmentManager.findFragmentById(R.id.addressUpdateFragment) as AddressUpdateFragment
Expand All @@ -202,11 +212,11 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall

override fun notifyCheckInMessage() {
Log.d(TAG, "notifyCheckInMessage")
if (attributePath.isNotEmpty() || eventPath.isNotEmpty()) {
if (binding.readRadioBtn.isChecked && readICDConfig != null) {
scope.launch { read(readICDConfig!!.isFabricFiltered, readICDConfig!!.eventMin) }
} else if (binding.subscribeRadioBtn.isChecked && subscribeICDConfig != null) {
scope.launch {
scope.launch {
if (attributePath.isNotEmpty() || eventPath.isNotEmpty()) {
if (binding.readRadioBtn.isChecked && readICDConfig != null) {
read(readICDConfig!!.isFabricFiltered, readICDConfig!!.eventMin)
} else if (binding.subscribeRadioBtn.isChecked && subscribeICDConfig != null) {
subscribe(
subscribeICDConfig!!.minInterval,
subscribeICDConfig!!.maxInterval,
Expand All @@ -215,20 +225,27 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
subscribeICDConfig!!.eventMin
)
}
}
} else if (
binding.writeRadioBtn.isChecked && writePath.isNotEmpty() && writeICDConfig != null
) {
scope.launch { write(writeICDConfig!!.timedRequestTimeoutMs, writeICDConfig!!.imTimeoutMs) }
} else if (
binding.invokeRadioBtn.isChecked && invokePath.isNotEmpty() && invokeICDConfig != null
) {
scope.launch {
} else if (
binding.writeRadioBtn.isChecked && writePath.isNotEmpty() && writeICDConfig != null
) {
write(writeICDConfig!!.timedRequestTimeoutMs, writeICDConfig!!.imTimeoutMs)
} else if (
binding.invokeRadioBtn.isChecked && invokePath.isNotEmpty() && invokeICDConfig != null
) {
invoke(invokeICDConfig!!.timedRequestTimeoutMs, invokeICDConfig!!.imTimeoutMs)
}
requireActivity().runOnUiThread { binding.icdQueueBtn.isChecked = false }
resetICDConfig()
}
}

private fun resetICDConfig() {
readICDConfig = null
subscribeICDConfig = null
writeICDConfig = null
invokeICDConfig = null
}

private fun setVisibilityEachView(radioBtnId: Int) {
val readBtnOn = (radioBtnId == R.id.readRadioBtn)
val subscribeBtnOn = (radioBtnId == R.id.subscribeRadioBtn)
Expand Down Expand Up @@ -261,16 +278,20 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
resetPath()
}

private fun showDialog() {
private fun showDialog(isICDQueueBtn: Boolean): Boolean {
var ret = false
if (binding.readRadioBtn.isChecked) {
showReadDialog()
ret = showReadDialog(isICDQueueBtn)
} else if (binding.subscribeRadioBtn.isChecked) {
showSubscribeDialog()
ret = showSubscribeDialog(isICDQueueBtn)
} else if (binding.writeRadioBtn.isChecked) {
showWriteDialog()
showWriteDialog(isICDQueueBtn)
ret = true
} else if (binding.invokeRadioBtn.isChecked) {
showInvokeDialog()
showInvokeDialog(isICDQueueBtn)
ret = true
}
return ret
}

private fun addRequest() {
Expand Down Expand Up @@ -547,7 +568,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
)
}

private fun showReadDialog() {
private fun showReadDialog(isICDQueueBtn: Boolean): Boolean {
if (attributePath.isEmpty() && eventPath.isEmpty()) {
requireActivity().runOnUiThread {
Toast.makeText(
Expand All @@ -557,7 +578,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
)
.show()
}
return
return false
}
val dialogView = requireActivity().layoutInflater.inflate(R.layout.read_dialog, null)
val eventMinEd = dialogView.findViewById<EditText>(R.id.eventMinEd)
Expand All @@ -576,7 +597,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
if (eventPath.isNotEmpty() && eventMinEd.text.isNotBlank()) {
eventMin = eventMinEd.text.toString().toULong().toLong()
}
if (addressUpdateFragment.isICDDevice()) {
if (isICDQueueBtn) {
readICDConfig =
ReadICDConfig(isFabricFilteredEd.selectedItem.toString().toBoolean(), eventMin)
} else {
Expand All @@ -586,9 +607,10 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
}
}
dialog.show()
return true
}

private fun showWriteDialog() {
private fun showWriteDialog(isICDQueueBtn: Boolean) {
binding.outputTv.text = ""
val dialogView = requireActivity().layoutInflater.inflate(R.layout.write_dialog, null)
val dialog = AlertDialog.Builder(requireContext()).apply { setView(dialogView) }.create()
Expand All @@ -610,7 +632,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
} else {
imTimeout.toInt()
}
if (addressUpdateFragment.isICDDevice()) {
if (isICDQueueBtn) {
writeICDConfig = WriteInvokeICDConfig(timedRequestTimeoutInt, imTimeoutInt)
} else {
write(timedRequestTimeoutInt, imTimeoutInt)
Expand All @@ -621,7 +643,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
dialog.show()
}

private fun showSubscribeDialog() {
private fun showSubscribeDialog(isICDQueueBtn: Boolean): Boolean {
if (attributePath.isEmpty() && eventPath.isEmpty()) {
requireActivity().runOnUiThread {
Toast.makeText(
Expand All @@ -631,7 +653,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
)
.show()
}
return
return false
}
val dialogView = requireActivity().layoutInflater.inflate(R.layout.subscribe_dialog, null)
val eventMinEd = dialogView.findViewById<EditText>(R.id.eventMinEd)
Expand All @@ -654,7 +676,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
if (eventPath.isNotEmpty() && eventMinEd.text.isNotBlank()) {
eventMin = eventMinEd.text.toString().toULong().toLong()
}
if (addressUpdateFragment.isICDDevice()) {
if (isICDQueueBtn) {
subscribeICDConfig =
SubscribeICDConfig(
minIntervalEd.text.toString().toInt(),
Expand All @@ -679,9 +701,10 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
}
}
dialog.show()
return true
}

private fun showInvokeDialog() {
private fun showInvokeDialog(isICDQueueBtn: Boolean) {
binding.outputTv.text = ""
val dialogView = requireActivity().layoutInflater.inflate(R.layout.invoke_dialog, null)
val dialog = AlertDialog.Builder(requireContext()).apply { setView(dialogView) }.create()
Expand All @@ -703,7 +726,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
} else {
imTimeout.toInt()
}
if (addressUpdateFragment.isICDDevice()) {
if (isICDQueueBtn) {
invokeICDConfig = WriteInvokeICDConfig(timedRequestTimeoutInt, imTimeoutInt)
} else {
invoke(timedRequestTimeoutInt, imTimeoutInt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,23 @@
android:textSize="16sp"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/sendBtn"
app:layout_constraintEnd_toStartOf="@id/writeInvokeresetBtn"
app:layout_constraintTop_toBottomOf="@id/addLayout"/>

<Button
android:id="@+id/writeInvokeresetBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:text="@string/wildcard_reset_btn_text"
app:layout_constraintStart_toEndOf="@id/addListBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/addLayout"
android:visibility="gone"
android:textSize="16sp" />

<Button
android:id="@+id/sendBtn"
android:layout_width="wrap_content"
Expand All @@ -313,45 +327,48 @@
android:text="@string/wildcard_send_btn_text"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/shutdownSubscriptionBtn"
app:layout_constraintTop_toBottomOf="@id/addLayout"/>
app:layout_constraintEnd_toStartOf="@id/icdQueueBtn"
app:layout_constraintTop_toBottomOf="@id/addListBtn"/>

<Button
android:id="@+id/shutdownSubscriptionBtn"
<ToggleButton
android:id="@+id/icdQueueBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:layout_gravity="center"
android:text="@string/wildcard_shutdown_subscription_btn_text"
android:textOn="@string/wildcard_wait_check_in_message_btn_text"
android:textOff="@string/wildcard_send_when_check_in_message_btn_text"
android:textSize="16sp"
android:visibility="gone"
app:layout_constraintStart_toEndOf="@id/sendBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/addLayout"/>
app:layout_constraintTop_toBottomOf="@id/addListBtn"/>



<Button
android:id="@+id/writeInvokeresetBtn"
android:id="@+id/shutdownSubscriptionBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:text="@string/wildcard_reset_btn_text"
app:layout_constraintStart_toEndOf="@id/sendBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/addLayout"
android:layout_gravity="center"
android:text="@string/wildcard_shutdown_subscription_btn_text"
android:textSize="16sp"
android:visibility="gone"
android:textSize="16sp" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/sendBtn"/>

<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:fadeScrollbars="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sendBtn">
app:layout_constraintTop_toBottomOf="@id/shutdownSubscriptionBtn">
<TextView
android:id="@+id/outputTv"
android:layout_width="match_parent"
Expand Down
2 changes: 2 additions & 0 deletions examples/android/CHIPTool/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@
<string name="wildcard_add_btn_text">Add</string>
<string name="wildcard_reset_btn_text">Reset</string>
<string name="wildcard_send_btn_text">Send</string>
<string name="wildcard_wait_check_in_message_btn_text">Wait Check In\nexperimental ICD Queue</string>
<string name="wildcard_send_when_check_in_message_btn_text">Set Send\nexperimental ICD Queue</string>
<string name="wildcard_shutdown_subscription_btn_text">Shutdown Subscription</string>
<string name="wildcard_subscribe_event_btn_text">Subscribe Event</string>
<string name="wildcard_read_event_btn_text">Read Event</string>
Expand Down

0 comments on commit 11992a1

Please sign in to comment.