- Add a responseMap (HashMap) to ConnectedActivity so that it only reacts to calls it has made.
- Create AutoSuggestAssetAdapter which is used in the ReceiveTransactionFragment's AutoCompleteTextView to show suggestions backed by the response from queries to the BitShares nodes, according to what the user has already typed in the text field.
This commit is contained in:
parent
8fd7c28256
commit
7f462bec63
4 changed files with 243 additions and 39 deletions
|
@ -31,6 +31,7 @@ import cy.agorise.graphenej.models.FullAccountDetails
|
||||||
import cy.agorise.graphenej.models.JsonRpcResponse
|
import cy.agorise.graphenej.models.JsonRpcResponse
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
|
import java.util.HashMap
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,6 +40,11 @@ import kotlin.collections.ArrayList
|
||||||
abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
|
abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
|
||||||
private val TAG = this.javaClass.simpleName
|
private val TAG = this.javaClass.simpleName
|
||||||
|
|
||||||
|
private val RESPONSE_GET_FULL_ACCOUNTS = 1
|
||||||
|
private val RESPONSE_GET_ACCOUNTS = 2
|
||||||
|
private val RESPONSE_GET_ACCOUNT_BALANCES = 3
|
||||||
|
private val RESPONSE_GET_ASSETS = 4
|
||||||
|
|
||||||
private lateinit var mUserAccountViewModel: UserAccountViewModel
|
private lateinit var mUserAccountViewModel: UserAccountViewModel
|
||||||
private lateinit var mBalanceViewModel: BalanceViewModel
|
private lateinit var mBalanceViewModel: BalanceViewModel
|
||||||
|
|
||||||
|
@ -60,6 +66,9 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
|
||||||
/* Network service connection */
|
/* Network service connection */
|
||||||
protected var mNetworkService: NetworkService? = null
|
protected var mNetworkService: NetworkService? = null
|
||||||
|
|
||||||
|
// Map used to keep track of request and response id pairs
|
||||||
|
private val responseMap = HashMap<Long, Int>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag used to keep track of the NetworkService binding state
|
* Flag used to keep track of the NetworkService binding state
|
||||||
*/
|
*/
|
||||||
|
@ -104,22 +113,31 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
|
||||||
mDisposable = RxBus.getBusInstance()
|
mDisposable = RxBus.getBusInstance()
|
||||||
.asFlowable()
|
.asFlowable()
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe { message ->
|
.subscribe { handleIncomingMessage(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleIncomingMessage(message: Any?) {
|
||||||
if (message is JsonRpcResponse<*>) {
|
if (message is JsonRpcResponse<*>) {
|
||||||
// Generic processing taken care by subclasses
|
// Generic processing taken care by subclasses
|
||||||
handleJsonRpcResponse(message)
|
handleJsonRpcResponse(message)
|
||||||
// Payment detection focused responses
|
|
||||||
if (message.error == null) {
|
if (message.error == null) {
|
||||||
if (message.result is List<*> && (message.result as List<*>).size > 0) {
|
if (responseMap.containsKey(message.id)) {
|
||||||
if ((message.result as List<*>)[0] is FullAccountDetails) {
|
val responseType = responseMap[message.id]
|
||||||
|
when (responseType) {
|
||||||
|
RESPONSE_GET_FULL_ACCOUNTS ->
|
||||||
handleAccountDetails((message.result as List<*>)[0] as FullAccountDetails)
|
handleAccountDetails((message.result as List<*>)[0] as FullAccountDetails)
|
||||||
} else if ((message.result as List<*>)[0] is AccountProperties) {
|
|
||||||
|
RESPONSE_GET_ACCOUNTS ->
|
||||||
handleAccountProperties(message.result as List<AccountProperties>)
|
handleAccountProperties(message.result as List<AccountProperties>)
|
||||||
} else if ((message.result as List<*>)[0] is AssetAmount) {
|
|
||||||
|
RESPONSE_GET_ACCOUNT_BALANCES ->
|
||||||
handleBalanceUpdate(message.result as List<AssetAmount>)
|
handleBalanceUpdate(message.result as List<AssetAmount>)
|
||||||
} else if ((message.result as List<*>)[0] is Asset) {
|
|
||||||
|
RESPONSE_GET_ASSETS ->
|
||||||
handleAssets(message.result as List<Asset>)
|
handleAssets(message.result as List<Asset>)
|
||||||
}
|
}
|
||||||
|
responseMap.remove(message.id)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// In case of error
|
// In case of error
|
||||||
|
@ -132,6 +150,10 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
|
||||||
}
|
}
|
||||||
} else if (message is ConnectionStatusUpdate) {
|
} else if (message is ConnectionStatusUpdate) {
|
||||||
handleConnectionStatusUpdate(message)
|
handleConnectionStatusUpdate(message)
|
||||||
|
if (message.updateCode == ConnectionStatusUpdate.DISCONNECTED) {
|
||||||
|
// If we got a disconnection notification, we should clear our response map, since
|
||||||
|
// all its stored request ids will now be reset
|
||||||
|
responseMap.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,10 +247,10 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
|
||||||
|
|
||||||
private fun updateBalances() {
|
private fun updateBalances() {
|
||||||
if (mNetworkService!!.isConnected) {
|
if (mNetworkService!!.isConnected) {
|
||||||
mNetworkService!!.sendMessage(
|
val id = mNetworkService!!.sendMessage(GetAccountBalances(mCurrentAccount, ArrayList()),
|
||||||
GetAccountBalances(mCurrentAccount, ArrayList()),
|
GetAccountBalances.REQUIRED_API)
|
||||||
GetAccountBalances.REQUIRED_API
|
|
||||||
)
|
responseMap[id] = RESPONSE_GET_ACCOUNT_BALANCES
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +260,9 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
|
||||||
private val mRequestMissingUserAccountsTask = object : Runnable {
|
private val mRequestMissingUserAccountsTask = object : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (mNetworkService!!.isConnected) {
|
if (mNetworkService!!.isConnected) {
|
||||||
mNetworkService!!.sendMessage(GetAccounts(missingUserAccounts), GetAccounts.REQUIRED_API)
|
val id = mNetworkService!!.sendMessage(GetAccounts(missingUserAccounts), GetAccounts.REQUIRED_API)
|
||||||
|
|
||||||
|
responseMap[id] = RESPONSE_GET_ACCOUNTS
|
||||||
} else if (missingUserAccounts.isNotEmpty()){
|
} else if (missingUserAccounts.isNotEmpty()){
|
||||||
mHandler.postDelayed(this, Constants.NETWORK_SERVICE_RETRY_PERIOD)
|
mHandler.postDelayed(this, Constants.NETWORK_SERVICE_RETRY_PERIOD)
|
||||||
}
|
}
|
||||||
|
@ -251,7 +275,9 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
|
||||||
private val mRequestMissingAssetsTask = object : Runnable {
|
private val mRequestMissingAssetsTask = object : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (mNetworkService!!.isConnected) {
|
if (mNetworkService!!.isConnected) {
|
||||||
mNetworkService!!.sendMessage(GetAssets(missingAssets), GetAssets.REQUIRED_API)
|
val id = mNetworkService!!.sendMessage(GetAssets(missingAssets), GetAssets.REQUIRED_API)
|
||||||
|
|
||||||
|
responseMap[id] = RESPONSE_GET_ASSETS
|
||||||
} else if (missingAssets.isNotEmpty()){
|
} else if (missingAssets.isNotEmpty()){
|
||||||
mHandler.postDelayed(this, Constants.NETWORK_SERVICE_RETRY_PERIOD)
|
mHandler.postDelayed(this, Constants.NETWORK_SERVICE_RETRY_PERIOD)
|
||||||
}
|
}
|
||||||
|
@ -267,10 +293,10 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
|
||||||
if (mCurrentAccount != null) {
|
if (mCurrentAccount != null) {
|
||||||
val userAccounts = ArrayList<String>()
|
val userAccounts = ArrayList<String>()
|
||||||
userAccounts.add(mCurrentAccount!!.objectId)
|
userAccounts.add(mCurrentAccount!!.objectId)
|
||||||
mNetworkService!!.sendMessage(
|
val id = mNetworkService!!.sendMessage(GetFullAccounts(userAccounts, false),
|
||||||
GetFullAccounts(userAccounts, false),
|
GetFullAccounts.REQUIRED_API)
|
||||||
GetFullAccounts.REQUIRED_API
|
|
||||||
)
|
responseMap[id] = RESPONSE_GET_FULL_ACCOUNTS
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "NetworkService is null or is not connected. mNetworkService: $mNetworkService")
|
Log.w(TAG, "NetworkService is null or is not connected. mNetworkService: $mNetworkService")
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package cy.agorise.bitsybitshareswallet.adapters
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
|
import android.widget.TextView
|
||||||
|
import cy.agorise.graphenej.Asset
|
||||||
|
|
||||||
|
class AutoSuggestAssetAdapter(context: Context, resource: Int):
|
||||||
|
ArrayAdapter<Asset>(context, resource) {
|
||||||
|
|
||||||
|
private var mAssets = ArrayList<Asset>()
|
||||||
|
|
||||||
|
fun setData(assets: List<Asset>) {
|
||||||
|
mAssets.clear()
|
||||||
|
mAssets.addAll(assets)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCount(): Int {
|
||||||
|
return mAssets.size
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItem(position: Int): Asset? {
|
||||||
|
return mAssets[position]
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
|
var cv = convertView
|
||||||
|
|
||||||
|
if (cv == null) {
|
||||||
|
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
|
cv = inflater.inflate(android.R.layout.simple_spinner_dropdown_item, parent, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
val text: TextView = cv!!.findViewById(android.R.id.text1)
|
||||||
|
|
||||||
|
val asset = getItem(position)
|
||||||
|
text.text = asset!!.symbol
|
||||||
|
|
||||||
|
return cv
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,13 @@
|
||||||
package cy.agorise.bitsybitshareswallet.fragments
|
package cy.agorise.bitsybitshareswallet.fragments
|
||||||
|
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.ServiceConnection
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.IBinder
|
||||||
import android.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
@ -21,10 +26,16 @@ import com.google.zxing.common.BitMatrix
|
||||||
import com.jakewharton.rxbinding2.widget.RxTextView
|
import com.jakewharton.rxbinding2.widget.RxTextView
|
||||||
import cy.agorise.bitsybitshareswallet.R
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
import cy.agorise.bitsybitshareswallet.adapters.AssetsAdapter
|
import cy.agorise.bitsybitshareswallet.adapters.AssetsAdapter
|
||||||
|
import cy.agorise.bitsybitshareswallet.adapters.AutoSuggestAssetAdapter
|
||||||
import cy.agorise.bitsybitshareswallet.utils.Constants
|
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||||
import cy.agorise.bitsybitshareswallet.viewmodels.AssetViewModel
|
import cy.agorise.bitsybitshareswallet.viewmodels.AssetViewModel
|
||||||
import cy.agorise.bitsybitshareswallet.viewmodels.UserAccountViewModel
|
import cy.agorise.bitsybitshareswallet.viewmodels.UserAccountViewModel
|
||||||
import cy.agorise.graphenej.*
|
import cy.agorise.graphenej.*
|
||||||
|
import cy.agorise.graphenej.api.ConnectionStatusUpdate
|
||||||
|
import cy.agorise.graphenej.api.android.NetworkService
|
||||||
|
import cy.agorise.graphenej.api.android.RxBus
|
||||||
|
import cy.agorise.graphenej.api.calls.ListAssets
|
||||||
|
import cy.agorise.graphenej.models.JsonRpcResponse
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import kotlinx.android.synthetic.main.fragment_receive_transaction.*
|
import kotlinx.android.synthetic.main.fragment_receive_transaction.*
|
||||||
|
@ -35,9 +46,14 @@ import java.text.DecimalFormatSymbols
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class ReceiveTransactionFragment : Fragment() {
|
class ReceiveTransactionFragment : Fragment(), ServiceConnection {
|
||||||
private val TAG = this.javaClass.simpleName
|
private val TAG = this.javaClass.simpleName
|
||||||
|
|
||||||
|
private val RESPONSE_LIST_ASSETS = 1
|
||||||
|
|
||||||
|
/** Number of assets to request from the NetworkService to show as suggestions in the AutoCompleteTextView */
|
||||||
|
private val AUTO_SUGGEST_ASSET_LIMIT = 5
|
||||||
|
|
||||||
private val OTHER_ASSET = "other_asset"
|
private val OTHER_ASSET = "other_asset"
|
||||||
|
|
||||||
private lateinit var mUserAccountViewModel: UserAccountViewModel
|
private lateinit var mUserAccountViewModel: UserAccountViewModel
|
||||||
|
@ -52,10 +68,21 @@ class ReceiveTransactionFragment : Fragment() {
|
||||||
|
|
||||||
private var mAssetsAdapter: AssetsAdapter? = null
|
private var mAssetsAdapter: AssetsAdapter? = null
|
||||||
|
|
||||||
|
private lateinit var mAutoSuggestAssetAdapter: AutoSuggestAssetAdapter
|
||||||
|
|
||||||
private var mAssets = ArrayList<cy.agorise.bitsybitshareswallet.database.entities.Asset>()
|
private var mAssets = ArrayList<cy.agorise.bitsybitshareswallet.database.entities.Asset>()
|
||||||
|
|
||||||
private var selectedAssetSymbol = ""
|
private var selectedAssetSymbol = ""
|
||||||
|
|
||||||
|
// Map used to keep track of request and response id pairs
|
||||||
|
private val responseMap = HashMap<Long, Int>()
|
||||||
|
|
||||||
|
/* Network service connection */
|
||||||
|
private var mNetworkService: NetworkService? = null
|
||||||
|
|
||||||
|
/** Flag used to keep track of the NetworkService binding state */
|
||||||
|
private var mShouldUnbindNetwork: Boolean = false
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
return inflater.inflate(R.layout.fragment_receive_transaction, container, false)
|
return inflater.inflate(R.layout.fragment_receive_transaction, container, false)
|
||||||
}
|
}
|
||||||
|
@ -119,6 +146,19 @@ class ReceiveTransactionFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mAssetViewModel.getAll().observe(this,
|
||||||
|
// Observer<List<cy.agorise.bitsybitshareswallet.database.entities.Asset>> { assets ->
|
||||||
|
// val adapter = ArrayAdapter<cy.agorise.bitsybitshareswallet.database.entities.Asset>(context!!,
|
||||||
|
// android.R.layout.simple_dropdown_item_1line, assets)
|
||||||
|
// actvAsset.setAdapter(adapter)
|
||||||
|
// })
|
||||||
|
//
|
||||||
|
// actvAsset.setOnItemClickListener { parent, _, position, _ ->
|
||||||
|
// val asset = parent.adapter.getItem(position) as cy.agorise.bitsybitshareswallet.database.entities.Asset
|
||||||
|
// mAsset = Asset(asset.id, asset.symbol, asset.precision)
|
||||||
|
// updateQR()
|
||||||
|
// }
|
||||||
|
|
||||||
// Use RxJava Debounce to create QR code only after the user stopped typing an amount
|
// Use RxJava Debounce to create QR code only after the user stopped typing an amount
|
||||||
mDisposables.add(
|
mDisposables.add(
|
||||||
RxTextView.textChanges(tietAmount)
|
RxTextView.textChanges(tietAmount)
|
||||||
|
@ -126,11 +166,69 @@ class ReceiveTransactionFragment : Fragment() {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe { updateQR() }
|
.subscribe { updateQR() }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Add adapter to the Assets AutoCompleteTextView
|
||||||
|
mAutoSuggestAssetAdapter = AutoSuggestAssetAdapter(context!!, android.R.layout.simple_dropdown_item_1line)
|
||||||
|
actvAsset.setAdapter(mAutoSuggestAssetAdapter)
|
||||||
|
|
||||||
|
// Use RxJava Debounce to avoid making calls to the NetworkService on every text change event and also avoid
|
||||||
|
// the first call when the View is created
|
||||||
|
mDisposables.add(
|
||||||
|
RxTextView.textChanges(actvAsset)
|
||||||
|
.skipInitialValue()
|
||||||
|
.debounce(500, TimeUnit.MILLISECONDS)
|
||||||
|
.map { it.toString().trim().toUpperCase() }
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe {
|
||||||
|
mAsset = null
|
||||||
|
updateQR()
|
||||||
|
|
||||||
|
// Get a list of assets that match the already typed string by the user
|
||||||
|
if (it.length > 1 && mNetworkService != null) {
|
||||||
|
val id = mNetworkService!!.sendMessage(ListAssets(it, AUTO_SUGGEST_ASSET_LIMIT),
|
||||||
|
ListAssets.REQUIRED_API)
|
||||||
|
responseMap[id] = RESPONSE_LIST_ASSETS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Connect to the RxBus, which receives events from the NetworkService
|
||||||
|
mDisposables.add(
|
||||||
|
RxBus.getBusInstance()
|
||||||
|
.asFlowable()
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe { handleIncomingMessage(it) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleIncomingMessage(message: Any?) {
|
||||||
|
if (message is JsonRpcResponse<*>) {
|
||||||
|
if (responseMap.containsKey(message.id)) {
|
||||||
|
val responseType = responseMap[message.id]
|
||||||
|
when (responseType) {
|
||||||
|
RESPONSE_LIST_ASSETS -> handleListAssets(message.result as List<Asset>)
|
||||||
|
}
|
||||||
|
responseMap.remove(message.id)
|
||||||
|
}
|
||||||
|
} else if (message is ConnectionStatusUpdate) {
|
||||||
|
if (message.updateCode == ConnectionStatusUpdate.DISCONNECTED) {
|
||||||
|
// If we got a disconnection notification, we should clear our response map, since
|
||||||
|
// all its stored request ids will now be reset
|
||||||
|
responseMap.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleListAssets(assetList: List<Asset>) {
|
||||||
|
Log.d(TAG, "handleListAssets")
|
||||||
|
mAutoSuggestAssetAdapter.setData(assetList)
|
||||||
|
mAutoSuggestAssetAdapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateQR() {
|
private fun updateQR() {
|
||||||
if (mAsset == null) {
|
if (mAsset == null) {
|
||||||
ivQR.setImageDrawable(null)
|
ivQR.setImageDrawable(null)
|
||||||
|
// TODO clean the please pay and to text at the bottom too
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,9 +320,38 @@ class ReceiveTransactionFragment : Fragment() {
|
||||||
tvTo.text = txtAccount
|
tvTo.text = txtAccount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
|
||||||
|
val intent = Intent(context, NetworkService::class.java)
|
||||||
|
if (context?.bindService(intent, this, Context.BIND_AUTO_CREATE) == true) {
|
||||||
|
mShouldUnbindNetwork = true
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Binding to the network service failed.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
|
||||||
|
// Unbinding from network service
|
||||||
|
if (mShouldUnbindNetwork) {
|
||||||
|
context?.unbindService(this)
|
||||||
|
mShouldUnbindNetwork = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
|
||||||
if (!mDisposables.isDisposed) mDisposables.dispose()
|
if (!mDisposables.isDisposed) mDisposables.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onServiceDisconnected(name: ComponentName?) { }
|
||||||
|
|
||||||
|
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
||||||
|
// We've bound to LocalService, cast the IBinder and get LocalService instance
|
||||||
|
val binder = service as NetworkService.LocalBinder
|
||||||
|
mNetworkService = binder.service
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -440,7 +440,7 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv
|
||||||
startCameraPreview()
|
startCameraPreview()
|
||||||
|
|
||||||
val intent = Intent(context, NetworkService::class.java)
|
val intent = Intent(context, NetworkService::class.java)
|
||||||
if (context!!.bindService(intent, this, Context.BIND_AUTO_CREATE)) {
|
if (context?.bindService(intent, this, Context.BIND_AUTO_CREATE) == true) {
|
||||||
mShouldUnbindNetwork = true
|
mShouldUnbindNetwork = true
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Binding to the network service failed.")
|
Log.e(TAG, "Binding to the network service failed.")
|
||||||
|
@ -449,6 +449,13 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
|
|
||||||
|
// Unbinding from network service
|
||||||
|
if (mShouldUnbindNetwork) {
|
||||||
|
context?.unbindService(this)
|
||||||
|
mShouldUnbindNetwork = false
|
||||||
|
}
|
||||||
|
|
||||||
if (!isCameraPreviewVisible)
|
if (!isCameraPreviewVisible)
|
||||||
stopCameraPreview()
|
stopCameraPreview()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue