Skip to content

Commit

Permalink
Fix QR Code scan, static code
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo committed May 9, 2024
1 parent e62d12e commit d6e26e4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class CHIPToolActivity :
startActivity(redirectIntent)
}

override fun SetNetworkType(type: ProvisionNetworkType) {
override fun setNetworkType(type: ProvisionNetworkType?) {
networkType = type
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class SelectActionFragment : Fragment() {
/** Notifies listener of a click to manually input the CHIP device address. */
fun onShowDeviceAddressInput()

fun SetNetworkType(type: ProvisionNetworkType)
fun setNetworkType(type: ProvisionNetworkType?)
}

private fun showFragment(fragment: Fragment, showOnBack: Boolean = true) {
Expand All @@ -172,6 +172,7 @@ class SelectActionFragment : Fragment() {

/** Notifies listener of Scan QR code button click. */
private fun handleScanQrCodeClicked() {
getCallback()?.setNetworkType(null)
showFragment(BarcodeFragment.newInstance())
}

Expand Down Expand Up @@ -226,13 +227,13 @@ class SelectActionFragment : Fragment() {

/** Notifies listener of provision-WiFi-credentials button click. */
private fun handleProvisionWiFiCredentialsClicked() {
getCallback()?.SetNetworkType(ProvisionNetworkType.WIFI)
getCallback()?.setNetworkType(ProvisionNetworkType.WIFI)
showFragment(BarcodeFragment.newInstance())
}

/** Notifies listener of provision-Thread-credentials button click. */
private fun handleProvisionThreadCredentialsClicked() {
getCallback()?.SetNetworkType(ProvisionNetworkType.THREAD)
getCallback()?.setNetworkType(ProvisionNetworkType.THREAD)
showFragment(BarcodeFragment.newInstance())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ class CHIPDeviceDetailsFragment : Fragment() {
QRCodeOnboardingPayloadGenerator(onBoardingPayload)
.payloadBase38RepresentationWithAutoTLVBuffer()

setDiscoveryCapabilitiesEditTextListener()
setQRCodeButtonListener()

return binding.root
}

private fun setDiscoveryCapabilitiesEditTextListener() {
binding.discoveryCapabilitiesEd.setText(onBoardingPayload.getRendezvousInformation().toString())
binding.discoveryCapabilitiesEd.addTextChangedListener(
object : TextWatcher {
Expand All @@ -104,11 +111,18 @@ class CHIPDeviceDetailsFragment : Fragment() {
binding.discoveryCapabilitiesTv.text = "${onBoardingPayload.discoveryCapabilities}"
}

override fun afterTextChanged(p0: Editable?) {}
override fun afterTextChanged(p0: Editable?) {
// no_op
}

override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
// no_op
}
}
)
}

private fun setQRCodeButtonListener() {
binding.showQRCodeBtn.setOnClickListener {
onBoardingPayload.apply {
version = binding.versionEd.text.toString().toInt()
Expand All @@ -121,7 +135,7 @@ class CHIPDeviceDetailsFragment : Fragment() {
try {
removeSerialNumber()
} catch (e: OnboardingPayloadException) {
Log.d(TAG, "Serial Number not set!")
Log.d(TAG, "Serial Number not set!", e)
}
if (serialNumber.isNotEmpty()) {
addSerialNumber(binding.serialNumberEd.text.toString())
Expand All @@ -140,8 +154,6 @@ class CHIPDeviceDetailsFragment : Fragment() {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(qrCodeUri))
startActivity(intent)
}

return binding.root
}

override fun onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.google.chip.chiptool.setuppayloadscanner

import android.os.Parcelable
import android.util.Log
import kotlinx.parcelize.Parcelize
import matter.onboardingpayload.DiscoveryCapability
import matter.onboardingpayload.OnboardingPayload
Expand Down Expand Up @@ -60,11 +61,13 @@ data class CHIPDeviceInfo(
}

companion object {
private const val TAG = "CHIPDeviceInfo"
fun fromSetupPayload(setupPayload: OnboardingPayload): CHIPDeviceInfo {
val serialNumber =
try {
setupPayload.getSerialNumber()
} catch (e: OnboardingPayloadException) {
Log.d(TAG, "serialNumber Exception", e)
""
}
return CHIPDeviceInfo(
Expand Down

0 comments on commit d6e26e4

Please sign in to comment.