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.

master
Severiano Jaramillo 2019-04-11 20:43:58 -05:00
parent b5371954e0
commit e88ef6cb91
6 changed files with 57 additions and 11 deletions

View File

@ -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

View File

@ -33,7 +33,7 @@
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
@ -41,7 +41,10 @@
android:name=".activities.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.Bitsy"
android:windowSoftInputMode="adjustPan"/>
android:windowSoftInputMode="adjustPan">
<nav-graph android:value="@navigation/mobile_navigation" />
</activity>
<!-- Used to share Images like the QR code and the eReceipt -->
<provider
android:name="androidx.core.content.FileProvider"

View File

@ -256,6 +256,7 @@ class ReceiveTransactionFragment : ConnectedFragment() {
}
}
// TODO use coroutines to move this process to a background thread
private fun updateQR() {
if (mAsset == null) {
ivQR.setImageDrawable(null)

View File

@ -200,8 +200,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
.debounce(500, TimeUnit.MILLISECONDS)
.map { it.toString().trim() }
.subscribe {
val id = mNetworkService?.sendMessage(GetAccountByName(it!!), GetAccountByName.REQUIRED_API)
if (id != null) responseMap[id] = RESPONSE_GET_ACCOUNT_BY_NAME
validateAccount(it)
}
)
@ -213,6 +212,15 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
.observeOn(AndroidSchedulers.mainThread())
.subscribe { validateAmount() }
)
// Populates the To field if a Deep Link was used
if (args.to != " " && args.asset != " " && args.amount > 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()

View File

@ -97,6 +97,25 @@
android:name="openCamera"
app:argType="boolean"
android:defaultValue="false" />
<argument
android:name="to"
android:defaultValue=" " />
<argument
android:name="amount"
app:argType="float"
android:defaultValue="0.0" />
<argument
android:name="asset"
android:defaultValue=" " />
<argument
android:name="memo"
android:defaultValue=" " />
<deepLink app:uri="www.bitshares.com/{to}/{amount}/{asset}/{memo}" />
</fragment>
<fragment

View File

@ -2,7 +2,7 @@
buildscript {
ext.kotlin_version = '1.3.21'
ext.nav_version = '1.0.0'
ext.nav_version = '2.0.0'
repositories {
google()
jcenter()
@ -14,7 +14,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath 'com.google.gms:google-services:4.2.0'
classpath 'io.fabric.tools:gradle:1.27.1'