Skip to content

Commit

Permalink
wip: finished moving strings
Browse files Browse the repository at this point in the history
  • Loading branch information
swan-amazon committed Jul 18, 2024
1 parent 0a2b981 commit 8d55bda
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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. */
Expand All @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions examples/android/CHIPTool/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,6 @@
<string name="chip_ledger_info_commissioning_flow_url_not_available">Not available</string>
<string name="provision_custom_flow_alert_title">Commissioning flow Completed.</string>

<string name="dcl_response_key">result</string>

<string name="custom_flow_return_url">mt://modelinfo</string>
<string name="retrieve_endpoint_list">Retrieve Endpoint List</string>
<string name="invoke">Invoke</string>
<string name="select_a_command">Select a command</string>
Expand Down

0 comments on commit 8d55bda

Please sign in to comment.