From e88ef6cb916157720a28c98516089ff5d8efd4d0 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Thu, 11 Apr 2019 20:43:58 -0500 Subject: [PATCH] Added a Deep Link to the app so that it can tell the Android system that it can consume a link of the form 'www.bitshares.com/{to}/{amount}/{asset}/{memo}' so when a user clicks on a link like that the Android system lets the user choose Bitsy to manage it. This deep link takes to user directly to the SendTransactionFragment, fills all the required fields and validates the information so that if it is valid then the user all that needs to do is click the send button and authorize the operation. --- app/build.gradle | 4 +-- app/src/main/AndroidManifest.xml | 7 ++-- .../fragments/ReceiveTransactionFragment.kt | 1 + .../fragments/SendTransactionFragment.kt | 33 ++++++++++++++++--- .../main/res/navigation/mobile_navigation.xml | 19 +++++++++++ build.gradle | 4 +-- 6 files changed, 57 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ab79919..ca23267 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -83,8 +83,8 @@ dependencies { kapt "androidx.room:room-compiler:$room_version" implementation "androidx.room:room-rxjava2:$room_version" // RxJava support for Room // AAC Navigation - implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version" - implementation "android.arch.navigation:navigation-ui-ktx:$nav_version" + implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" + implementation "androidx.navigation:navigation-ui-ktx:$nav_version" // RxBindings implementation "com.jakewharton.rxbinding3:rxbinding:$rx_bindings_version" implementation "com.jakewharton.rxbinding3:rxbinding-material:$rx_bindings_version" // Material Components widgets diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 618526c..6137f1c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,7 +33,7 @@ android:theme="@style/SplashTheme"> - + @@ -41,7 +41,10 @@ android:name=".activities.MainActivity" android:screenOrientation="portrait" android:theme="@style/Theme.Bitsy" - android:windowSoftInputMode="adjustPan"/> + android:windowSoftInputMode="adjustPan"> + + + 0 && args.memo != " ") { + val items = arrayOf(LineItem("transfer", 1, args.amount.toDouble())) + val invoice = Invoice(args.to, "", args.memo, args.asset, items, "", "") + Handler().postDelayed({ + populatePropertiesFromQRCodeString(Invoice.toQrCode(invoice)) + }, 2000) // Wait to let the other elements of the fragment initialize + } } /** Handles the selection of items in the Asset spinner, to keep track of the selectedAssetSymbol and show the @@ -369,11 +377,16 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand cameraPreview.stopCamera() } - /** Handles the result of the QR code read from the camera and tries to populate the Account, Amount and Memo fields - * and the Asset spinner with the obtained information */ + /** Handles the result of the QR code read from the camera **/ override fun handleResult(result: Result?) { + populatePropertiesFromQRCodeString(result!!.text) + } + + /** Tries to populate the Account, Amount and Memo fields + * and the Asset spinner with the obtained information */ + private fun populatePropertiesFromQRCodeString(qrString: String) { try { - val invoice = Invoice.fromQrCode(result!!.text) + val invoice = Invoice.fromQrCode(qrString) Log.d(TAG, "QR Code read: " + invoice.toJsonString()) @@ -422,6 +435,16 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand } } + /** + * Sends a request to the node through the NetworkService to validate that accountName is a valid + * BitShares account. + */ + private fun validateAccount(accountName: String) { + isToAccountCorrect = false + val id = mNetworkService?.sendMessage(GetAccountByName(accountName), GetAccountByName.REQUIRED_API) + if (id != null) responseMap[id] = RESPONSE_GET_ACCOUNT_BY_NAME + } + private fun validateAmount() { val txtAmount = tietAmount.text.toString() diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index 0195c99..65ffa16 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -97,6 +97,25 @@ android:name="openCamera" app:argType="boolean" android:defaultValue="false" /> + + + + + + + + + +