From 8d55bdadfd50f103982571a986dfc3f6580cac84 Mon Sep 17 00:00:00 2001 From: James Swan <122404367+swan-amazon@users.noreply.github.com> Date: Thu, 18 Jul 2024 00:22:37 +0000 Subject: [PATCH] wip: finished moving strings --- .../CHIPLedgerDetailsFragment.kt | 31 +++++++++++++++---- .../app/src/main/res/values/strings.xml | 3 -- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPLedgerDetailsFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPLedgerDetailsFragment.kt index c65cb2504b8d65..35db09ddc8f181 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPLedgerDetailsFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPLedgerDetailsFragment.kt @@ -33,6 +33,8 @@ import com.google.chip.chiptool.R import com.google.chip.chiptool.databinding.ChipLedgerInfoFragmentBinding import com.google.chip.chiptool.util.FragmentUtil import com.google.gson.Gson +import java.io.BufferedReader +import java.io.InputStreamReader /** Show the [CHIPDeviceInfo] from Ledger */ class CHIPLedgerDetailsFragment : Fragment() { @@ -73,7 +75,7 @@ class CHIPLedgerDetailsFragment : Fragment() { Log.d(TAG, "Response from dcl $response") // parse redirect Url - val responseJson = response.getJSONObject(context!!.getString(R.string.dcl_response_key)) + val responseJson = response.getJSONObject("model") val redirectUrl = responseJson.getString(DCL_CUSTOM_FLOW_URL_KEY) Log.d(TAG, "Redirect Url from Ledger: $redirectUrl") binding.commissioningFlowUrlTv.text = redirectUrl @@ -86,10 +88,7 @@ class CHIPLedgerDetailsFragment : Fragment() { Uri.parse(redirectUrl) .buildUpon() .appendQueryParameter("payload", payloadBase64) - .appendQueryParameter( - "returnUrl", - context!!.getString(R.string.custom_flow_return_url) - ) + .appendQueryParameter("returnUrl", CUSTOM_FLOW_RETURN_URL) .build() .toString() @@ -118,6 +117,25 @@ class CHIPLedgerDetailsFragment : Fragment() { _binding = null } + private fun readRawResourceFile(resourceId: Int): String? { + return try { + val inputStream = resources.openRawResource(resourceId) + val bufferedReader = BufferedReader(InputStreamReader(inputStream)) + val stringBuilder = StringBuilder() + var line: String? = bufferedReader.readLine() + while (line != null) { + stringBuilder.append(line) + line = bufferedReader.readLine() + } + bufferedReader.close() + inputStream.close() + stringBuilder.toString() + } catch (e: Exception) { + Log.e("MainActivity", "Error reading raw resource file", e) + null + } + } + /** Interface for notifying the host. */ interface Callback { /** Notifies listener of Custom flow redirect button click. */ @@ -127,8 +145,9 @@ class CHIPLedgerDetailsFragment : Fragment() { companion object { private const val TAG = "CUSTOM_FLOW" private const val ARG_DEVICE_INFO = "device_info" - private const val DCL_CUSTOM_FLOW_URL_KEY = "custom"; + private const val DCL_CUSTOM_FLOW_URL_KEY = "commissioningCustomFlowUrl"; private const val DCL_API_ROOT_URL = "https://on.dcl.csa-iot.org/dcl/model/models"; + private const val CUSTOM_FLOW_RETURN_URL = "mt://modelinfo"; @JvmStatic fun newInstance(deviceInfo: CHIPDeviceInfo): CHIPLedgerDetailsFragment { diff --git a/examples/android/CHIPTool/app/src/main/res/values/strings.xml b/examples/android/CHIPTool/app/src/main/res/values/strings.xml index 05c9f162e1568c..ecdf793326d5d2 100644 --- a/examples/android/CHIPTool/app/src/main/res/values/strings.xml +++ b/examples/android/CHIPTool/app/src/main/res/values/strings.xml @@ -219,9 +219,6 @@ Not available Commissioning flow Completed. - result - - mt://modelinfo Retrieve Endpoint List Invoke Select a command