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.
This commit is contained in:
parent
b5371954e0
commit
e88ef6cb91
6 changed files with 57 additions and 11 deletions
|
@ -83,8 +83,8 @@ dependencies {
|
||||||
kapt "androidx.room:room-compiler:$room_version"
|
kapt "androidx.room:room-compiler:$room_version"
|
||||||
implementation "androidx.room:room-rxjava2:$room_version" // RxJava support for Room
|
implementation "androidx.room:room-rxjava2:$room_version" // RxJava support for Room
|
||||||
// AAC Navigation
|
// AAC Navigation
|
||||||
implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
|
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
|
||||||
implementation "android.arch.navigation:navigation-ui-ktx:$nav_version"
|
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
|
||||||
// RxBindings
|
// RxBindings
|
||||||
implementation "com.jakewharton.rxbinding3:rxbinding:$rx_bindings_version"
|
implementation "com.jakewharton.rxbinding3:rxbinding:$rx_bindings_version"
|
||||||
implementation "com.jakewharton.rxbinding3:rxbinding-material:$rx_bindings_version" // Material Components widgets
|
implementation "com.jakewharton.rxbinding3:rxbinding-material:$rx_bindings_version" // Material Components widgets
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
android:theme="@style/SplashTheme">
|
android:theme="@style/SplashTheme">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
@ -41,7 +41,10 @@
|
||||||
android:name=".activities.MainActivity"
|
android:name=".activities.MainActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:theme="@style/Theme.Bitsy"
|
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 -->
|
<!-- Used to share Images like the QR code and the eReceipt -->
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.core.content.FileProvider"
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
|
|
@ -256,6 +256,7 @@ class ReceiveTransactionFragment : ConnectedFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO use coroutines to move this process to a background thread
|
||||||
private fun updateQR() {
|
private fun updateQR() {
|
||||||
if (mAsset == null) {
|
if (mAsset == null) {
|
||||||
ivQR.setImageDrawable(null)
|
ivQR.setImageDrawable(null)
|
||||||
|
|
|
@ -200,8 +200,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
|
||||||
.debounce(500, TimeUnit.MILLISECONDS)
|
.debounce(500, TimeUnit.MILLISECONDS)
|
||||||
.map { it.toString().trim() }
|
.map { it.toString().trim() }
|
||||||
.subscribe {
|
.subscribe {
|
||||||
val id = mNetworkService?.sendMessage(GetAccountByName(it!!), GetAccountByName.REQUIRED_API)
|
validateAccount(it)
|
||||||
if (id != null) responseMap[id] = RESPONSE_GET_ACCOUNT_BY_NAME
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -213,6 +212,15 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe { validateAmount() }
|
.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
|
/** 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()
|
cameraPreview.stopCamera()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handles the result of the QR code read from the camera and tries to populate the Account, Amount and Memo fields
|
/** Handles the result of the QR code read from the camera **/
|
||||||
* and the Asset spinner with the obtained information */
|
|
||||||
override fun handleResult(result: Result?) {
|
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 {
|
try {
|
||||||
val invoice = Invoice.fromQrCode(result!!.text)
|
val invoice = Invoice.fromQrCode(qrString)
|
||||||
|
|
||||||
Log.d(TAG, "QR Code read: " + invoice.toJsonString())
|
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() {
|
private fun validateAmount() {
|
||||||
val txtAmount = tietAmount.text.toString()
|
val txtAmount = tietAmount.text.toString()
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,25 @@
|
||||||
android:name="openCamera"
|
android:name="openCamera"
|
||||||
app:argType="boolean"
|
app:argType="boolean"
|
||||||
android:defaultValue="false" />
|
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>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.3.21'
|
ext.kotlin_version = '1.3.21'
|
||||||
ext.nav_version = '1.0.0'
|
ext.nav_version = '2.0.0'
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
|
@ -14,7 +14,7 @@ buildscript {
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.3.2'
|
classpath 'com.android.tools.build:gradle:3.3.2'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
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 'com.google.gms:google-services:4.2.0'
|
||||||
classpath 'io.fabric.tools:gradle:1.27.1'
|
classpath 'io.fabric.tools:gradle:1.27.1'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue