Updated on 2026-08-14
This commit is contained in:
parent
78ef89d2cf
commit
bbed187fab
9 changed files with 168 additions and 73 deletions
|
|
@ -68,16 +68,15 @@ dependencies {
|
|||
// implementation 'com.github.TangemCash:server-android:0.1.4'
|
||||
implementation 'android.arch.navigation:navigation-fragment:1.0.0'
|
||||
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
|
||||
implementation "androidx.preference:preference:1.1.0-alpha04"
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
|
||||
implementation 'androidx.biometric:biometric:1.0.0-alpha04'
|
||||
implementation 'co.nstant.in:cbor:0.8'
|
||||
implementation 'com.google.android.material:material:1.1.0-alpha05'
|
||||
implementation 'com.google.dagger:dagger:2.21'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation "androidx.preference:preference:1.1.0-alpha04"
|
||||
implementation 'androidx.biometric:biometric:1.0.0-alpha04'
|
||||
implementation 'com.google.android.material:material:1.1.0-alpha05'
|
||||
implementation 'com.google.dagger:dagger:2.21'
|
||||
kapt 'com.google.dagger:dagger-compiler:2.21'
|
||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.21'
|
||||
implementation 'com.google.zxing:core:3.3.3'
|
||||
|
|
@ -92,6 +91,7 @@ dependencies {
|
|||
implementation 'com.skyfishjy.ripplebackground:library:1.0.1'
|
||||
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
|
||||
implementation "com.orhanobut:hawk:2.0.1"
|
||||
implementation 'co.nstant.in:cbor:0.8'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0'
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0"
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ object Constant {
|
|||
|
||||
const val INTENT_TYPE_TEXT_PLAIN = "text/plain"
|
||||
|
||||
// LoadedWallet, VerifyCard
|
||||
// LoadedWalletFragment, VerifyCard
|
||||
const val REQUEST_CODE_SEND_TRANSACTION = 1
|
||||
const val REQUEST_CODE_PURGE = 2
|
||||
const val REQUEST_CODE_REQUEST_PIN2_FOR_PURGE = 3
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import com.tangem.Constant
|
|||
import com.tangem.di.Navigator
|
||||
import com.tangem.di.ToastHelper
|
||||
import com.tangem.wallet.TangemContext
|
||||
import com.tangem.ui.fragment.LoadedWallet
|
||||
import com.tangem.ui.fragment.LoadedWalletFragment
|
||||
import com.tangem.wallet.R
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ class LoadedWalletActivity : AppCompatActivity() {
|
|||
if (intent.extras!!.containsKey(NfcAdapter.EXTRA_TAG)) {
|
||||
val tag = intent.getParcelableExtra<Tag>(NfcAdapter.EXTRA_TAG)
|
||||
if (tag != null) {
|
||||
val fragment = supportFragmentManager.findFragmentById(R.id.loaded_wallet_fragment) as LoadedWallet
|
||||
val fragment = supportFragmentManager.findFragmentById(R.id.loaded_wallet_fragment) as LoadedWalletFragment
|
||||
fragment.onTagDiscovered(tag)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import android.nfc.tech.IsoDep
|
|||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.util.Log
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
|
@ -20,6 +21,8 @@ import android.view.ViewGroup
|
|||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.data.Blockchain
|
||||
|
|
@ -63,11 +66,12 @@ import java.io.InputStream
|
|||
import java.util.*
|
||||
import kotlin.concurrent.timerTask
|
||||
|
||||
class LoadedWallet : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
companion object {
|
||||
val TAG: String = LoadedWallet::class.java.simpleName
|
||||
val TAG: String = LoadedWalletFragment::class.java.simpleName
|
||||
}
|
||||
|
||||
private lateinit var viewModel: LoadedWalletViewModel
|
||||
private lateinit var ctx: TangemContext
|
||||
private lateinit var nfcManager: NfcManager
|
||||
private lateinit var mpSecondScanSound: MediaPlayer
|
||||
|
|
@ -275,18 +279,40 @@ class LoadedWallet : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback
|
|||
serverApiTangem.setArtworkListener(artworkListener)
|
||||
|
||||
// request rate info listener
|
||||
serverApiCommon.setRateInfoListener {
|
||||
if (activity == null || !UtilHelper.isOnline(activity!!)) return@setRateInfoListener
|
||||
val rate = it.priceUsd.toFloat()
|
||||
ctx.coinData!!.rate = rate
|
||||
ctx.coinData!!.rateAlter = rate
|
||||
}
|
||||
// serverApiCommon.setRateInfoListener {
|
||||
// if (activity == null || !UtilHelper.isOnline(activity!!)) return@setRateInfoListener
|
||||
// val rate = it.priceUsd.toFloat()
|
||||
// ctx.coinData!!.rate = rate
|
||||
// ctx.coinData!!.rateAlter = rate
|
||||
//
|
||||
// Log.i(TAG, "scscscsc222 " + rate)
|
||||
// }
|
||||
|
||||
refresh()
|
||||
|
||||
startVerify(lastTag)
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
viewModel = ViewModelProviders.of(this).get(LoadedWalletViewModel::class.java)
|
||||
|
||||
// set rate info to CoinData
|
||||
// viewModel.getRateInfo(ctx).observe(this, Observer<Float> { rate ->
|
||||
// Log.i(TAG, "scscscsc111 " + rate)
|
||||
//
|
||||
// ctx.coinData.rate = rate
|
||||
// ctx.coinData.rateAlter = rate
|
||||
// })
|
||||
|
||||
viewModel.getRateInfo(ctx).observeForever { rate ->
|
||||
Log.i(TAG, "scscscsc111 $rate")
|
||||
|
||||
ctx.coinData.rate = rate
|
||||
ctx.coinData.rateAlter = rate
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
if (timerHideErrorAndMessage != null) {
|
||||
|
|
@ -647,7 +673,11 @@ class LoadedWallet : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback
|
|||
|
||||
requestBalanceAndUnspentTransactions()
|
||||
|
||||
requestRateInfo()
|
||||
// requestRateInfo()
|
||||
if (::viewModel.isInitialized) {
|
||||
viewModel.getRateInfo(ctx)
|
||||
Log.i(TAG, "isInitialized")
|
||||
}
|
||||
|
||||
if (requestCounter == 0) {
|
||||
// if no connection and no requests posted
|
||||
|
|
@ -709,34 +739,33 @@ class LoadedWallet : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback
|
|||
}
|
||||
}
|
||||
|
||||
private fun requestRateInfo() {
|
||||
if (UtilHelper.isOnline(context as Activity)) {
|
||||
LOG.i(TAG, "requestRateInfo")
|
||||
|
||||
// TODO - move requestRateInfo to CoinEngine
|
||||
val cryptoId: String = when (ctx.blockchain) {
|
||||
Blockchain.Bitcoin -> "bitcoin"
|
||||
Blockchain.BitcoinTestNet -> "bitcoin"
|
||||
Blockchain.Ethereum -> "ethereum"
|
||||
Blockchain.EthereumTestNet -> "ethereum"
|
||||
Blockchain.Token -> "ethereum"
|
||||
Blockchain.NftToken -> "ethereum"
|
||||
Blockchain.BitcoinCash -> "bitcoin-cash"
|
||||
Blockchain.Litecoin -> "litecoin"
|
||||
Blockchain.Rootstock -> "bitcoin"
|
||||
Blockchain.RootstockToken -> "bitcoin"
|
||||
Blockchain.Cardano -> "cardano"
|
||||
Blockchain.Ripple -> "ripple"
|
||||
else -> {
|
||||
throw Exception("Can''t get rate for blockchain " + ctx.blockchainName)
|
||||
}
|
||||
}
|
||||
serverApiCommon.requestRateInfo(cryptoId)
|
||||
} else {
|
||||
ctx.error = getString(R.string.no_connection)
|
||||
updateViews()
|
||||
}
|
||||
}
|
||||
// private fun requestRateInfo() {
|
||||
// if (UtilHelper.isOnline(context as Activity)) {
|
||||
// LOG.i(TAG, "requestRateInfo")
|
||||
//
|
||||
// val cryptoId: String = when (ctx.blockchain) {
|
||||
// Blockchain.Bitcoin -> "bitcoin"
|
||||
// Blockchain.BitcoinTestNet -> "bitcoin"
|
||||
// Blockchain.Ethereum -> "ethereum"
|
||||
// Blockchain.EthereumTestNet -> "ethereum"
|
||||
// Blockchain.Token -> "ethereum"
|
||||
// Blockchain.NftToken -> "ethereum"
|
||||
// Blockchain.BitcoinCash -> "bitcoin-cash"
|
||||
// Blockchain.Litecoin -> "litecoin"
|
||||
// Blockchain.Rootstock -> "bitcoin"
|
||||
// Blockchain.RootstockToken -> "bitcoin"
|
||||
// Blockchain.Cardano -> "cardano"
|
||||
// Blockchain.Ripple -> "ripple"
|
||||
// else -> {
|
||||
// throw Exception("Can''t get rate for blockchain " + ctx.blockchainName)
|
||||
// }
|
||||
// }
|
||||
// serverApiCommon.requestRateInfo(cryptoId)
|
||||
// } else {
|
||||
// ctx.error = getString(R.string.no_connection)
|
||||
// updateViews()
|
||||
// }
|
||||
// }
|
||||
|
||||
private fun startVerify(tag: Tag?) {
|
||||
try {
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package com.tangem.ui.fragment
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.data.network.ServerApiCommon
|
||||
import com.tangem.wallet.TangemContext
|
||||
|
||||
class LoadedWalletViewModel : ViewModel() {
|
||||
private var serverApiCommon: ServerApiCommon = ServerApiCommon()
|
||||
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
// private var rate = MutableLiveData<Float>()
|
||||
//
|
||||
// fun getRateInfo(ctx: TangemContext): LiveData<Float> {
|
||||
// this.ctx = ctx
|
||||
// rate = MutableLiveData()
|
||||
// requestRateInfo()
|
||||
// return rate
|
||||
// }
|
||||
|
||||
private val rate: MutableLiveData<Float> by lazy {
|
||||
MutableLiveData<Float>().also {
|
||||
requestRateInfo()
|
||||
}
|
||||
}
|
||||
|
||||
fun getRateInfo(ctx: TangemContext): LiveData<Float> {
|
||||
this.ctx = ctx
|
||||
return rate
|
||||
}
|
||||
|
||||
private fun requestRateInfo() {
|
||||
serverApiCommon.setRateInfoListener {
|
||||
val rate = it.priceUsd.toFloat()
|
||||
this.rate.value = rate
|
||||
}
|
||||
// TODO - move requestRateInfo to CoinEngine
|
||||
val cryptoId: String = when (ctx.blockchain) {
|
||||
Blockchain.Bitcoin -> "bitcoin"
|
||||
Blockchain.BitcoinTestNet -> "bitcoin"
|
||||
Blockchain.Ethereum -> "ethereum"
|
||||
Blockchain.EthereumTestNet -> "ethereum"
|
||||
Blockchain.Token -> "ethereum"
|
||||
Blockchain.NftToken -> "ethereum"
|
||||
Blockchain.BitcoinCash -> "bitcoin-cash"
|
||||
Blockchain.Litecoin -> "litecoin"
|
||||
Blockchain.Rootstock -> "bitcoin"
|
||||
Blockchain.RootstockToken -> "bitcoin"
|
||||
Blockchain.Cardano -> "cardano"
|
||||
Blockchain.Ripple -> "ripple"
|
||||
else -> {
|
||||
throw Exception("Can''t get rate for blockchain " + ctx.blockchainName)
|
||||
}
|
||||
}
|
||||
serverApiCommon.requestRateInfo(cryptoId)
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
// getRateInfo(ctx).removeObservers()
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ import com.tangem.data.network.ServerApiCommon
|
|||
import com.tangem.wallet.BuildConfig
|
||||
|
||||
class MainViewModel : ViewModel() {
|
||||
private var serverApiCommon: ServerApiCommon = ServerApiCommon()
|
||||
|
||||
private var versionName = MutableLiveData<String>()
|
||||
|
||||
fun getVersionName(): LiveData<String> {
|
||||
|
|
@ -17,8 +19,7 @@ class MainViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
private fun requestVersionName() {
|
||||
val apiHelper = ServerApiCommon()
|
||||
apiHelper.setLastVersionListener { response ->
|
||||
serverApiCommon.setLastVersionListener { response ->
|
||||
try {
|
||||
if (response.isNullOrEmpty())
|
||||
return@setLastVersionListener
|
||||
|
|
@ -32,6 +33,6 @@ class MainViewModel : ViewModel() {
|
|||
E.printStackTrace()
|
||||
}
|
||||
}
|
||||
apiHelper.requestLastVersion()
|
||||
serverApiCommon.requestLastVersion()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.tangem.ui.activity.LoadedWalletActivity">
|
||||
|
||||
<fragment
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/loaded_wallet_fragment"
|
||||
android:name="com.tangem.ui.fragment.LoadedWallet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:layout="@layout/fr_loaded_wallet"/>
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.tangem.ui.activity.LoadedWalletActivity">
|
||||
|
||||
<fragment
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/loaded_wallet_fragment"
|
||||
android:name="com.tangem.ui.fragment.LoadedWalletFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:layout="@layout/fr_loaded_wallet"/>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
android:background="@color/white"
|
||||
android:orientation="vertical"
|
||||
android:padding="0dp"
|
||||
tools:context="com.tangem.ui.fragment.LoadedWallet"
|
||||
tools:context="com.tangem.ui.fragment.LoadedWalletFragment"
|
||||
tools:ignore="contentDescription"
|
||||
tools:showIn="@layout/activity_loaded_wallet">
|
||||
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@
|
|||
<string name="new_app_version">There is a new application version: %1$s</string>
|
||||
<string name="update">Update</string>
|
||||
|
||||
<!-- LoadedWalletActivity, LoadedWallet -->
|
||||
<!-- LoadedWalletActivity, LoadedWalletFragment -->
|
||||
<string name="wallet_empty">The wallet is empty</string>
|
||||
<string name="no_compatible_wallet">No compatible wallets installed</string>
|
||||
<string name="please_wait_while_previous">Please wait while previous transaction is confirmed in blockchain</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue