Updated on 2026-08-14
This commit is contained in:
parent
7700a1250e
commit
64a7baa2c0
19 changed files with 155 additions and 216 deletions
|
|
@ -3,17 +3,14 @@ package com.tangem.tangemtest
|
|||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.CardManager
|
||||
import com.tangem.TangemSdk
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.tangem_sdk_new.extensions.init
|
||||
import com.tangem.tangemtest.extensions.create
|
||||
import com.tangem.tasks.ScanEvent
|
||||
import com.tangem.tasks.TaskError
|
||||
import com.tangem.tasks.TaskEvent
|
||||
import kotlinx.android.synthetic.main.old_activity_main.*
|
||||
|
||||
class Old_MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var cardManager: CardManager
|
||||
private lateinit var tangemSdk: TangemSdk
|
||||
private lateinit var cardId: String
|
||||
private lateinit var issuerData: ByteArray
|
||||
private lateinit var issuerDataSignature: ByteArray
|
||||
|
|
@ -23,66 +20,50 @@ class Old_MainActivity : AppCompatActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.old_activity_main)
|
||||
|
||||
cardManager = CardManager.init(this)
|
||||
tangemSdk = TangemSdk.init(this)
|
||||
|
||||
btn_scan?.setOnClickListener { _ ->
|
||||
cardManager.scanCard { taskEvent ->
|
||||
tangemSdk.scanCard { taskEvent ->
|
||||
when (taskEvent) {
|
||||
is TaskEvent.Event -> {
|
||||
when (taskEvent.data) {
|
||||
is ScanEvent.OnReadEvent -> {
|
||||
// Handle returned card data
|
||||
cardId = (taskEvent.data as ScanEvent.OnReadEvent).card.cardId
|
||||
runOnUiThread {
|
||||
tv_card_cid?.text = cardId
|
||||
btn_create_wallet.isEnabled = true
|
||||
}
|
||||
}
|
||||
is ScanEvent.OnVerifyEvent -> {
|
||||
//Handle card verification
|
||||
runOnUiThread {
|
||||
tv_card_cid?.text = cardId
|
||||
btn_sign.isEnabled = true
|
||||
btn_read_issuer_data.isEnabled = true
|
||||
btn_read_issuer_extra_data.isEnabled = true
|
||||
btn_write_issuer_data.isEnabled = true
|
||||
btn_purge_wallet.isEnabled = true
|
||||
btn_create_wallet.isEnabled = true
|
||||
}
|
||||
}
|
||||
is CompletionResult.Success -> {
|
||||
// Handle returned card data
|
||||
val card = taskEvent.data
|
||||
cardId = card.cardId
|
||||
runOnUiThread {
|
||||
tv_card_cid?.text = cardId
|
||||
btn_create_wallet.isEnabled = true
|
||||
tv_card_cid?.text = cardId
|
||||
btn_sign.isEnabled = true
|
||||
btn_read_issuer_data.isEnabled = true
|
||||
btn_read_issuer_extra_data.isEnabled = true
|
||||
btn_write_issuer_data.isEnabled = true
|
||||
btn_purge_wallet.isEnabled = true
|
||||
btn_create_wallet.isEnabled = true
|
||||
|
||||
}
|
||||
}
|
||||
is TaskEvent.Completion -> {
|
||||
if (taskEvent.error != null) {
|
||||
if (taskEvent.error is TaskError.UserCancelled) {
|
||||
// Handle case when user cancelled manually
|
||||
}
|
||||
// Handle other errors
|
||||
}
|
||||
// Handle completion
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
btn_sign?.setOnClickListener { _ ->
|
||||
cardManager.sign(
|
||||
tangemSdk.sign(
|
||||
createSampleHashes(),
|
||||
cardId) {
|
||||
when (it) {
|
||||
is TaskEvent.Completion -> {
|
||||
if (it.error != null) runOnUiThread { tv_card_cid?.text = it.error!!::class.simpleName }
|
||||
is CompletionResult.Failure -> {
|
||||
runOnUiThread { tv_card_cid?.text = it.error::class.simpleName }
|
||||
}
|
||||
is TaskEvent.Event -> runOnUiThread { tv_card_cid?.text = cardId + "was used to sign sample hashes." }
|
||||
is CompletionResult.Success -> runOnUiThread { tv_card_cid?.text = cardId + "was used to sign sample hashes." }
|
||||
}
|
||||
}
|
||||
}
|
||||
btn_read_issuer_data?.setOnClickListener { _ ->
|
||||
cardManager.readIssuerData(cardId) {
|
||||
tangemSdk.readIssuerData(cardId) {
|
||||
when (it) {
|
||||
is TaskEvent.Completion -> {
|
||||
if (it.error != null) runOnUiThread { tv_card_cid?.text = it.error!!::class.simpleName }
|
||||
is CompletionResult.Failure -> {
|
||||
runOnUiThread { tv_card_cid?.text = it.error::class.simpleName }
|
||||
}
|
||||
is TaskEvent.Event -> runOnUiThread {
|
||||
is CompletionResult.Success -> runOnUiThread {
|
||||
btn_write_issuer_data.isEnabled = true
|
||||
tv_card_cid?.text = it.data.issuerData.contentToString()
|
||||
issuerData = it.data.issuerData
|
||||
|
|
@ -92,27 +73,27 @@ class Old_MainActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
btn_write_issuer_data?.setOnClickListener { _ ->
|
||||
cardManager.writeIssuerData(
|
||||
tangemSdk.writeIssuerData(
|
||||
cardId,
|
||||
issuerData,
|
||||
issuerDataSignature) {
|
||||
when (it) {
|
||||
is TaskEvent.Completion -> {
|
||||
if (it.error != null) runOnUiThread { tv_card_cid?.text = it.error!!::class.simpleName }
|
||||
is CompletionResult.Failure -> {
|
||||
runOnUiThread { tv_card_cid?.text = it.error::class.simpleName }
|
||||
}
|
||||
is TaskEvent.Event -> runOnUiThread {
|
||||
is CompletionResult.Success -> runOnUiThread {
|
||||
tv_card_cid?.text = it.data.cardId
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
btn_read_issuer_extra_data?.setOnClickListener { _ ->
|
||||
cardManager.readIssuerExtraData(cardId) {
|
||||
tangemSdk.readIssuerExtraData(cardId) {
|
||||
when (it) {
|
||||
is TaskEvent.Completion -> {
|
||||
if (it.error != null) runOnUiThread { tv_card_cid?.text = it.error!!::class.simpleName }
|
||||
is CompletionResult.Failure -> {
|
||||
runOnUiThread { tv_card_cid?.text = it.error::class.simpleName }
|
||||
}
|
||||
is TaskEvent.Event -> runOnUiThread {
|
||||
is CompletionResult.Success -> runOnUiThread {
|
||||
issuerDataCounter = (it.data.issuerDataCounter ?: 0) + 1
|
||||
btn_write_issuer_data.isEnabled = true
|
||||
tv_card_cid?.text = "Read ${it.data.issuerData.size} bytes of data."
|
||||
|
|
@ -121,26 +102,26 @@ class Old_MainActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
btn_purge_wallet?.setOnClickListener { _ ->
|
||||
cardManager.purgeWallet(
|
||||
tangemSdk.purgeWallet(
|
||||
cardId) {
|
||||
when (it) {
|
||||
is TaskEvent.Completion -> {
|
||||
if (it.error != null) runOnUiThread { tv_card_cid?.text = it.error!!::class.simpleName }
|
||||
is CompletionResult.Failure -> {
|
||||
runOnUiThread { tv_card_cid?.text = it.error::class.simpleName }
|
||||
}
|
||||
is TaskEvent.Event -> runOnUiThread {
|
||||
is CompletionResult.Success -> runOnUiThread {
|
||||
tv_card_cid?.text = it.data.status.name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
btn_create_wallet?.setOnClickListener { _ ->
|
||||
cardManager.createWallet(
|
||||
tangemSdk.createWallet(
|
||||
cardId) {
|
||||
when (it) {
|
||||
is TaskEvent.Completion -> {
|
||||
if (it.error != null) runOnUiThread { tv_card_cid?.text = it.error!!::class.simpleName }
|
||||
is CompletionResult.Failure -> {
|
||||
runOnUiThread { tv_card_cid?.text = it.error::class.simpleName }
|
||||
}
|
||||
is TaskEvent.Event -> runOnUiThread {
|
||||
is CompletionResult.Success -> runOnUiThread {
|
||||
tv_card_cid?.text = it.data.status.name
|
||||
btn_sign.isEnabled = true
|
||||
btn_read_issuer_data.isEnabled = true
|
||||
|
|
|
|||
|
|
@ -5,14 +5,11 @@ import android.view.View
|
|||
import android.widget.CompoundButton
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.CardManager
|
||||
import com.tangem.commands.ReadUserDataResponse
|
||||
import com.tangem.commands.WriteUserDataResponse
|
||||
import com.tangem.common.CardEnvironment
|
||||
import com.tangem.CardEnvironment
|
||||
import com.tangem.SessionError
|
||||
import com.tangem.TangemSdk
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.tangem_sdk_new.extensions.init
|
||||
import com.tangem.tasks.ScanEvent
|
||||
import com.tangem.tasks.TaskError
|
||||
import com.tangem.tasks.TaskEvent
|
||||
import kotlinx.android.synthetic.main.activity_test_user_data.*
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
|
|
@ -21,7 +18,7 @@ import java.nio.charset.StandardCharsets
|
|||
*/
|
||||
class TestUserDataActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var cardManager: CardManager
|
||||
private lateinit var tangemSdk: TangemSdk
|
||||
private lateinit var writeOptions: WriteOptions
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
@ -33,31 +30,15 @@ class TestUserDataActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun init() {
|
||||
cardManager = CardManager.init(this)
|
||||
tangemSdk = TangemSdk.init(this)
|
||||
|
||||
btn_scan?.setOnClickListener { _ ->
|
||||
cardManager.scanCard { taskEvent ->
|
||||
tangemSdk.scanCard { taskEvent ->
|
||||
when (taskEvent) {
|
||||
is TaskEvent.Event -> {
|
||||
when (taskEvent.data) {
|
||||
is ScanEvent.OnReadEvent -> {
|
||||
// Handle returned card data
|
||||
writeOptions.cardId = (taskEvent.data as ScanEvent.OnReadEvent).card.cardId
|
||||
runOnUiThread { showReadWriteSection(true) }
|
||||
}
|
||||
is ScanEvent.OnVerifyEvent -> {
|
||||
//Handle card verification
|
||||
}
|
||||
}
|
||||
}
|
||||
is TaskEvent.Completion -> {
|
||||
if (taskEvent.error != null) {
|
||||
if (taskEvent.error is TaskError.UserCancelled) {
|
||||
// Handle case when user cancelled manually
|
||||
}
|
||||
// Handle other errors
|
||||
}
|
||||
// Handle completion
|
||||
is CompletionResult.Success -> {
|
||||
// Handle returned card data
|
||||
writeOptions.cardId = taskEvent.data.cardId
|
||||
runOnUiThread { showReadWriteSection(true) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -66,7 +47,7 @@ class TestUserDataActivity : AppCompatActivity() {
|
|||
btn_write.setOnClickListener {
|
||||
if (writeOptions.cardId == null) return@setOnClickListener
|
||||
|
||||
cardManager.writeUserData(
|
||||
tangemSdk.writeUserData(
|
||||
writeOptions.cardId!!,
|
||||
writeOptions.userData,
|
||||
writeOptions.userProtectedData,
|
||||
|
|
@ -74,16 +55,9 @@ class TestUserDataActivity : AppCompatActivity() {
|
|||
writeOptions.userProtectedCounter
|
||||
) {
|
||||
when (it) {
|
||||
is TaskEvent.Completion -> handleError(tv_write_result, it.error)
|
||||
is TaskEvent.Event -> {
|
||||
runOnUiThread {
|
||||
val data = it.data as? WriteUserDataResponse
|
||||
if (data == null) {
|
||||
tv_write_result.text = "Response doesn't match"
|
||||
return@runOnUiThread
|
||||
}
|
||||
tv_write_result?.text = "Success"
|
||||
}
|
||||
is CompletionResult.Failure -> handleError(tv_write_result, it.error)
|
||||
is CompletionResult.Success -> {
|
||||
runOnUiThread { tv_write_result?.text = "Success" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -92,28 +66,24 @@ class TestUserDataActivity : AppCompatActivity() {
|
|||
btn_read.setOnClickListener {
|
||||
if (writeOptions.cardId == null) return@setOnClickListener
|
||||
|
||||
cardManager.readUserData(writeOptions.cardId!!) {
|
||||
tangemSdk.readUserData(writeOptions.cardId!!) {
|
||||
when (it) {
|
||||
is TaskEvent.Completion -> handleError(tv_read_result, it.error)
|
||||
is TaskEvent.Event -> {
|
||||
is CompletionResult.Failure -> handleError(tv_write_result, it.error)
|
||||
is CompletionResult.Success -> {
|
||||
runOnUiThread {
|
||||
val data = it.data as? ReadUserDataResponse
|
||||
if (data == null) {
|
||||
tv_read_result.text = "Response doesn't match"
|
||||
return@runOnUiThread
|
||||
}
|
||||
|
||||
tv_read_result?.text = "Success"
|
||||
|
||||
writeOptions.userData = data.userData
|
||||
writeOptions.userProtectedData = data.userProtectedData
|
||||
writeOptions.userCounter = data.userCounter
|
||||
writeOptions.userProtectedCounter = data.userProtectedCounter
|
||||
writeOptions.userData = it.data.userData
|
||||
writeOptions.userProtectedData = it.data.userProtectedData
|
||||
writeOptions.userCounter = it.data.userCounter
|
||||
writeOptions.userProtectedCounter = it.data.userProtectedCounter
|
||||
|
||||
tv_card_cid.text = data.cardId
|
||||
tv_data.text = String(data.userData, StandardCharsets.US_ASCII)
|
||||
tv_protected_data.text = String(data.userProtectedData, StandardCharsets.US_ASCII)
|
||||
tv_counter.text = data.userCounter.toString()
|
||||
tv_protected_counter.text = data.userProtectedCounter.toString()
|
||||
tv_card_cid.text = it.data.cardId
|
||||
tv_data.text = String(it.data.userData, StandardCharsets.US_ASCII)
|
||||
tv_protected_data.text = String(it.data.userProtectedData, StandardCharsets.US_ASCII)
|
||||
tv_counter.text = it.data.userCounter.toString()
|
||||
tv_protected_counter.text = it.data.userProtectedCounter.toString()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -122,11 +92,10 @@ class TestUserDataActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleError(tv: TextView, error: TaskError?) {
|
||||
val er = error ?: return
|
||||
if (er is TaskError.UserCancelled) return
|
||||
private fun handleError(tv: TextView, error: SessionError) {
|
||||
if (error is SessionError.UserCancelled) return
|
||||
|
||||
runOnUiThread { tv.text = er::class.simpleName }
|
||||
runOnUiThread { tv.text = error::class.simpleName }
|
||||
}
|
||||
|
||||
private fun initWriteOptions() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.tangemtest.ucase.domain.actions
|
||||
|
||||
import com.tangem.CardManager
|
||||
import com.tangem.TangemSdk
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.tangemtest._arch.structure.Id
|
||||
import com.tangem.tangemtest._arch.structure.Payload
|
||||
import com.tangem.tangemtest._arch.structure.PayloadHolder
|
||||
|
|
@ -8,7 +9,6 @@ import com.tangem.tangemtest._arch.structure.abstraction.Item
|
|||
import com.tangem.tangemtest.ucase.domain.paramsManager.ActionCallback
|
||||
import com.tangem.tangemtest.ucase.domain.paramsManager.triggers.afterAction.AfterActionModification
|
||||
import com.tangem.tangemtest.ucase.domain.paramsManager.triggers.changeConsequence.ItemsChangeConsequence
|
||||
import com.tangem.tasks.TaskEvent
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
|
|
@ -17,7 +17,7 @@ import com.tangem.tasks.TaskEvent
|
|||
* and then processing the response. It also allows you to extract the main action as a lambda expression
|
||||
*/
|
||||
data class AttrForAction(
|
||||
val cardManager: CardManager,
|
||||
val tangemSdk: TangemSdk,
|
||||
val itemList: List<Item>,
|
||||
val payload: Payload,
|
||||
val consequence: ItemsChangeConsequence?
|
||||
|
|
@ -31,16 +31,16 @@ interface Action {
|
|||
abstract class BaseAction : Action {
|
||||
protected open fun handleResult(
|
||||
payload: PayloadHolder,
|
||||
taskEvent: TaskEvent<*>,
|
||||
commandResult: CompletionResult<*>,
|
||||
modifier: AfterActionModification?,
|
||||
attrs: AttrForAction,
|
||||
callback: ActionCallback
|
||||
) {
|
||||
val modifiedItems = mutableListOf<Item>()
|
||||
modifier?.modify(payload, taskEvent, attrs.itemList)?.forEach { item ->
|
||||
modifier?.modify(payload, commandResult, attrs.itemList)?.forEach { item ->
|
||||
modifiedItems.add(item)
|
||||
attrs.consequence?.affectChanges(payload, item, attrs.itemList)?.let { modifiedItems.addAll(it) }
|
||||
}
|
||||
callback(taskEvent, modifiedItems)
|
||||
callback(commandResult, modifiedItems)
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ class DepersonalizeAction : BaseAction() {
|
|||
val item = attrs.itemList.findDataItem(TlvId.CardId) ?: return
|
||||
val cardId = item.viewModel.data as? String ?: return
|
||||
|
||||
attrs.cardManager.depersonalize(cardId) { handleResult(payload, it, null, attrs, callback) }
|
||||
attrs.tangemSdk.depersonalize(cardId) { handleResult(payload, it, null, attrs, callback) }
|
||||
}
|
||||
|
||||
override fun getActionByTag(payload: PayloadHolder, id: Id, attrs: AttrForAction): ((ActionCallback) -> Unit)? {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class PersonalizeAction : BaseAction() {
|
|||
val personalizeConfig = PersonalizeConfigConverter().convert(itemList, PersonalizeConfig())
|
||||
val cardConfig = PersonalizeConfigToCardConfig().convert(personalizeConfig)
|
||||
|
||||
attrs.cardManager.personalize(cardConfig, issuer, manufacturer, acquirer) {
|
||||
attrs.tangemSdk.personalize(cardConfig, issuer, manufacturer, acquirer) {
|
||||
handleResult(payload, it, null, attrs, callback)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ import com.tangem.tangemtest.ucase.domain.paramsManager.triggers.afterAction.Aft
|
|||
*/
|
||||
class ScanAction : BaseAction() {
|
||||
override fun executeMainAction(payload: PayloadHolder, attrs: AttrForAction, callback: ActionCallback) {
|
||||
attrs.cardManager.scanCard { handleResult(payload, it, AfterScanModifier(), attrs, callback) }
|
||||
attrs.tangemSdk.scanCard { handleResult(payload, it, AfterScanModifier(), attrs, callback) }
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ class SignAction : BaseAction() {
|
|||
val hash = dataForHashing.getData() as? ByteArray ?: return
|
||||
val cardId = attrs.itemList.findDataItem(TlvId.CardId)?.viewModel?.data ?: return
|
||||
|
||||
attrs.cardManager.sign(arrayOf(hash), stringOf(cardId)) { handleResult(payload, it, null, attrs, callback) }
|
||||
attrs.tangemSdk.sign(arrayOf(hash), stringOf(cardId)) { handleResult(payload, it, null, attrs, callback) }
|
||||
}
|
||||
|
||||
override fun getActionByTag(payload: PayloadHolder, id: Id, attrs: AttrForAction): ((ActionCallback) -> Unit)? {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
package com.tangem.tangemtest.ucase.domain.paramsManager
|
||||
|
||||
import com.tangem.CardManager
|
||||
import com.tangem.TangemSdk
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.tangemtest._arch.structure.Id
|
||||
import com.tangem.tangemtest._arch.structure.Payload
|
||||
import com.tangem.tangemtest._arch.structure.PayloadHolder
|
||||
import com.tangem.tangemtest._arch.structure.abstraction.Item
|
||||
import com.tangem.tangemtest.ucase.domain.paramsManager.triggers.changeConsequence.ItemsChangeConsequence
|
||||
import com.tangem.tasks.TaskEvent
|
||||
|
||||
typealias ActionResponse = TaskEvent<*>
|
||||
typealias ActionResponse = CompletionResult<*>
|
||||
typealias AffectedList = List<Item>
|
||||
typealias AffectedItemsCallback = (AffectedList) -> Unit
|
||||
typealias ActionCallback = (ActionResponse, AffectedList) -> Unit
|
||||
|
|
@ -20,8 +20,8 @@ interface ItemsManager : PayloadHolder {
|
|||
|
||||
fun itemChanged(id: Id, value: Any?, callback: AffectedItemsCallback? = null)
|
||||
fun getItems(): List<Item>
|
||||
fun invokeMainAction(cardManager: CardManager, callback: ActionCallback)
|
||||
fun getActionByTag(id: Id, cardManager: CardManager): ((ActionCallback) -> Unit)?
|
||||
fun invokeMainAction(tangemSdk: TangemSdk, callback: ActionCallback)
|
||||
fun getActionByTag(id: Id, tangemSdk: TangemSdk): ((ActionCallback) -> Unit)?
|
||||
fun attachPayload(payload: Payload)
|
||||
|
||||
val consequence: ItemsChangeConsequence?
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.tangem.tangemtest.ucase.domain.paramsManager.managers
|
||||
|
||||
import com.tangem.CardManager
|
||||
import com.tangem.TangemSdk
|
||||
import com.tangem.tangemtest._arch.structure.Id
|
||||
import com.tangem.tangemtest._arch.structure.Payload
|
||||
import com.tangem.tangemtest._arch.structure.abstraction.Item
|
||||
|
|
@ -33,7 +33,7 @@ abstract class BaseItemsManager(protected val action: Action) : ItemsManager {
|
|||
|
||||
override fun getItems(): MutableList<Item> = itemList.toMutableList()
|
||||
|
||||
override fun getActionByTag(id: Id, cardManager: CardManager): ((ActionCallback) -> Unit)? = null
|
||||
override fun getActionByTag(id: Id, tangemSdk: TangemSdk): ((ActionCallback) -> Unit)? = null
|
||||
|
||||
override fun attachPayload(payload: Payload) {
|
||||
payload.forEach { this.payload[it.key] = it.value }
|
||||
|
|
@ -44,8 +44,8 @@ abstract class BaseItemsManager(protected val action: Action) : ItemsManager {
|
|||
consequence?.affectChanges(this, param, itemList)?.let { callback?.invoke(it) }
|
||||
}
|
||||
|
||||
protected fun getAttrsForAction(cardManager: CardManager)
|
||||
: AttrForAction = AttrForAction(cardManager, itemList, payload, consequence)
|
||||
protected fun getAttrsForAction(tangemSdk: TangemSdk)
|
||||
: AttrForAction = AttrForAction(tangemSdk, itemList, payload, consequence)
|
||||
|
||||
abstract fun createItemsList(): List<Item>
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.tangem.tangemtest.ucase.domain.paramsManager.managers
|
||||
|
||||
import com.tangem.CardManager
|
||||
import com.tangem.TangemSdk
|
||||
import com.tangem.tangemtest._arch.structure.Id
|
||||
import com.tangem.tangemtest._arch.structure.abstraction.Item
|
||||
import com.tangem.tangemtest._arch.structure.impl.EditTextItem
|
||||
|
|
@ -16,11 +16,11 @@ class DepersonalizeItemsManager : BaseItemsManager(DepersonalizeAction()) {
|
|||
return listOf(EditTextItem(TlvId.CardId, null))
|
||||
}
|
||||
|
||||
override fun invokeMainAction(cardManager: CardManager, callback: ActionCallback) {
|
||||
action.executeMainAction(this, getAttrsForAction(cardManager), callback)
|
||||
override fun invokeMainAction(tangemSdk: TangemSdk, callback: ActionCallback) {
|
||||
action.executeMainAction(this, getAttrsForAction(tangemSdk), callback)
|
||||
}
|
||||
|
||||
override fun getActionByTag(id: Id, cardManager: CardManager): ((ActionCallback) -> Unit)? {
|
||||
return action.getActionByTag(this, id, getAttrsForAction(cardManager))
|
||||
override fun getActionByTag(id: Id, tangemSdk: TangemSdk): ((ActionCallback) -> Unit)? {
|
||||
return action.getActionByTag(this, id, getAttrsForAction(tangemSdk))
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.tangem.tangemtest.ucase.domain.paramsManager.managers
|
||||
|
||||
import com.tangem.CardManager
|
||||
import com.tangem.TangemSdk
|
||||
import com.tangem.tangemtest._arch.structure.abstraction.Item
|
||||
import com.tangem.tangemtest.ucase.domain.actions.PersonalizeAction
|
||||
import com.tangem.tangemtest.ucase.domain.paramsManager.ActionCallback
|
||||
|
|
@ -11,7 +11,7 @@ import com.tangem.tangemtest.ucase.domain.paramsManager.ActionCallback
|
|||
class PersonalizeItemsManager : BaseItemsManager(PersonalizeAction()) {
|
||||
override fun createItemsList(): List<Item> = listOf()
|
||||
|
||||
override fun invokeMainAction(cardManager: CardManager, callback: ActionCallback) {
|
||||
action.executeMainAction(this, getAttrsForAction(cardManager), callback)
|
||||
override fun invokeMainAction(tangemSdk: TangemSdk, callback: ActionCallback) {
|
||||
action.executeMainAction(this, getAttrsForAction(tangemSdk), callback)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.tangem.tangemtest.ucase.domain.paramsManager.managers
|
||||
|
||||
import com.tangem.CardManager
|
||||
import com.tangem.TangemSdk
|
||||
import com.tangem.tangemtest._arch.structure.abstraction.Item
|
||||
import com.tangem.tangemtest.ucase.domain.actions.ScanAction
|
||||
import com.tangem.tangemtest.ucase.domain.paramsManager.ActionCallback
|
||||
|
|
@ -11,7 +11,7 @@ import com.tangem.tangemtest.ucase.domain.paramsManager.ActionCallback
|
|||
class ScanItemsManager : BaseItemsManager(ScanAction()) {
|
||||
override fun createItemsList(): List<Item> = listOf()
|
||||
|
||||
override fun invokeMainAction(cardManager: CardManager, callback: ActionCallback) {
|
||||
action.executeMainAction(this, getAttrsForAction(cardManager), callback)
|
||||
override fun invokeMainAction(tangemSdk: TangemSdk, callback: ActionCallback) {
|
||||
action.executeMainAction(this, getAttrsForAction(tangemSdk), callback)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.tangem.tangemtest.ucase.domain.paramsManager.managers
|
||||
|
||||
import com.tangem.CardManager
|
||||
import com.tangem.TangemSdk
|
||||
import com.tangem.tangemtest._arch.structure.Id
|
||||
import com.tangem.tangemtest._arch.structure.abstraction.Item
|
||||
import com.tangem.tangemtest._arch.structure.impl.EditTextItem
|
||||
|
|
@ -24,11 +24,11 @@ class SignItemsManager : BaseItemsManager(SignAction()) {
|
|||
)
|
||||
}
|
||||
|
||||
override fun invokeMainAction(cardManager: CardManager, callback: ActionCallback) {
|
||||
action.executeMainAction(this, getAttrsForAction(cardManager), callback)
|
||||
override fun invokeMainAction(tangemSdk: TangemSdk, callback: ActionCallback) {
|
||||
action.executeMainAction(this, getAttrsForAction(tangemSdk), callback)
|
||||
}
|
||||
|
||||
override fun getActionByTag(id: Id, cardManager: CardManager): ((ActionCallback) -> Unit)? {
|
||||
return action.getActionByTag(this, id, getAttrsForAction(cardManager))
|
||||
override fun getActionByTag(id: Id, tangemSdk: TangemSdk): ((ActionCallback) -> Unit)? {
|
||||
return action.getActionByTag(this, id, getAttrsForAction(tangemSdk))
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package com.tangem.tangemtest.ucase.domain.paramsManager.triggers.afterAction
|
||||
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.tangemtest._arch.structure.PayloadHolder
|
||||
import com.tangem.tangemtest._arch.structure.abstraction.Item
|
||||
import com.tangem.tasks.TaskEvent
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
|
|
@ -12,5 +12,5 @@ import com.tangem.tasks.TaskEvent
|
|||
* Returns a list of items that have been modified
|
||||
*/
|
||||
interface AfterActionModification {
|
||||
fun modify(payload: PayloadHolder, taskEvent: TaskEvent<*>, itemList: List<Item>): List<Item>
|
||||
fun modify(payload: PayloadHolder, commandResult: CompletionResult<*>, itemList: List<Item>): List<Item>
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.tangem.tangemtest.ucase.domain.paramsManager.triggers.afterAction
|
|||
|
||||
import com.tangem.commands.Card
|
||||
import com.tangem.commands.CardStatus
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.tangemtest._arch.structure.PayloadHolder
|
||||
import com.tangem.tangemtest._arch.structure.abstraction.Item
|
||||
import com.tangem.tangemtest._arch.structure.abstraction.findDataItem
|
||||
|
|
@ -9,17 +10,16 @@ import com.tangem.tangemtest.ucase.domain.paramsManager.PayloadKey
|
|||
import com.tangem.tangemtest.ucase.tunnel.ActionView
|
||||
import com.tangem.tangemtest.ucase.tunnel.CardError
|
||||
import com.tangem.tangemtest.ucase.variants.TlvId
|
||||
import com.tangem.tasks.ScanEvent
|
||||
import com.tangem.tasks.TaskEvent
|
||||
|
||||
import ru.dev.gbixahue.eu4d.lib.android.global.threading.postUI
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class AfterScanModifier : AfterActionModification {
|
||||
override fun modify(payload: PayloadHolder, taskEvent: TaskEvent<*>, itemList: List<Item>): List<Item> {
|
||||
override fun modify(payload: PayloadHolder, commandResult: CompletionResult<*>, itemList: List<Item>): List<Item> {
|
||||
val foundItem = itemList.findDataItem(TlvId.CardId) ?: return listOf()
|
||||
val card = smartCast(taskEvent)?.card ?: return listOf()
|
||||
val card = smartCast(commandResult) ?: return listOf()
|
||||
val actionView = payload.get(PayloadKey.actionView) as? ActionView ?: return listOf()
|
||||
|
||||
return if (isNotPersonalized(card)) {
|
||||
|
|
@ -34,8 +34,8 @@ class AfterScanModifier : AfterActionModification {
|
|||
}
|
||||
}
|
||||
|
||||
private fun smartCast(taskEvent: TaskEvent<*>): ScanEvent.OnReadEvent? {
|
||||
return (taskEvent as? TaskEvent.Event)?.data as? ScanEvent.OnReadEvent
|
||||
private fun smartCast(commandResult: CompletionResult<*>): Card? {
|
||||
return (commandResult as? CompletionResult.Success<Card>)?.data
|
||||
}
|
||||
|
||||
private fun isNotPersonalized(card: Card): Boolean = card.status == CardStatus.NotPersonalized
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import androidx.lifecycle.Observer
|
|||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.snackbar.BaseTransientBottomBar
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.tangem.CardManager
|
||||
import com.tangem.TangemSdk
|
||||
import com.tangem.tangem_sdk_new.extensions.init
|
||||
import com.tangem.tangemtest.R
|
||||
import com.tangem.tangemtest._arch.structure.Id
|
||||
|
|
@ -56,7 +56,7 @@ abstract class BaseCardActionFragment : Fragment(), LayoutHolder, ActionView {
|
|||
Log.d(this, "onViewCreated")
|
||||
|
||||
viewLifecycleOwner.lifecycle.addObserver(paramsVM)
|
||||
paramsVM.setCardManager(CardManager.init(requireActivity()))
|
||||
paramsVM.setCardManager(TangemSdk.init(requireActivity()))
|
||||
paramsVM.attachToPayload(mutableMapOf(PayloadKey.actionView to this as ActionView))
|
||||
initFab()
|
||||
showActionFab(false)
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@ package com.tangem.tangemtest.ucase.ui
|
|||
import androidx.annotation.UiThread
|
||||
import androidx.lifecycle.*
|
||||
import com.google.gson.Gson
|
||||
import com.tangem.CardManager
|
||||
import com.tangem.SessionError
|
||||
import com.tangem.TangemSdk
|
||||
import com.tangem.commands.Card
|
||||
import com.tangem.commands.CommandResponse
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.tangemtest._arch.SingleLiveEvent
|
||||
import com.tangem.tangemtest._arch.structure.Id
|
||||
import com.tangem.tangemtest._arch.structure.Payload
|
||||
|
|
@ -13,9 +16,6 @@ import com.tangem.tangemtest.commons.performAction
|
|||
import com.tangem.tangemtest.ucase.domain.paramsManager.ItemsManager
|
||||
import com.tangem.tangemtest.ucase.domain.responses.GsonInitializer
|
||||
import com.tangem.tangemtest.ucase.tunnel.ViewScreen
|
||||
import com.tangem.tasks.ScanEvent
|
||||
import com.tangem.tasks.TaskError
|
||||
import com.tangem.tasks.TaskEvent
|
||||
import ru.dev.gbixahue.eu4d.lib.android.global.log.Log
|
||||
|
||||
/**
|
||||
|
|
@ -37,10 +37,10 @@ class ParamsViewModel(private val itemsManager: ItemsManager) : ViewModel(), Lif
|
|||
val seChangedItems: MutableLiveData<List<Item>> = SingleLiveEvent()
|
||||
|
||||
private val notifier: Notifier = Notifier(this)
|
||||
private lateinit var cardManager: CardManager
|
||||
private lateinit var tangemSdk: TangemSdk
|
||||
|
||||
fun setCardManager(cardManager: CardManager) {
|
||||
this.cardManager = cardManager
|
||||
fun setCardManager(tangemSdk: TangemSdk) {
|
||||
this.tangemSdk = tangemSdk
|
||||
}
|
||||
|
||||
fun userChangedItem(id: Id, value: Any?) {
|
||||
|
|
@ -53,7 +53,7 @@ class ParamsViewModel(private val itemsManager: ItemsManager) : ViewModel(), Lif
|
|||
|
||||
//invokes Scan, Sign etc...
|
||||
fun invokeMainAction() {
|
||||
performAction(itemsManager, cardManager) { paramsManager, cardManager ->
|
||||
performAction(itemsManager, tangemSdk) { paramsManager, cardManager ->
|
||||
paramsManager.invokeMainAction(cardManager) { response, listOfChangedParams ->
|
||||
notifier.handleActionResult(response, listOfChangedParams)
|
||||
}
|
||||
|
|
@ -61,7 +61,7 @@ class ParamsViewModel(private val itemsManager: ItemsManager) : ViewModel(), Lif
|
|||
}
|
||||
|
||||
fun getItemAction(id: Id): (() -> Unit)? {
|
||||
val itemFunction = itemsManager.getActionByTag(id, cardManager) ?: return null
|
||||
val itemFunction = itemsManager.getActionByTag(id, tangemSdk) ?: return null
|
||||
|
||||
return {
|
||||
itemFunction { response, listOfChangedParams ->
|
||||
|
|
@ -84,10 +84,10 @@ class ParamsViewModel(private val itemsManager: ItemsManager) : ViewModel(), Lif
|
|||
|
||||
internal class Notifier(private val vm: ParamsViewModel) {
|
||||
|
||||
private var notShowedError: TaskError? = null
|
||||
private var notShowedError: SessionError? = null
|
||||
private val gson: Gson = GsonInitializer().gson
|
||||
|
||||
fun handleActionResult(response: TaskEvent<*>, list: List<Item>) {
|
||||
fun handleActionResult(response: CompletionResult<*>, list: List<Item>) {
|
||||
if (list.isNotEmpty()) notifyItemsChanged(list)
|
||||
handleResponse(response)
|
||||
}
|
||||
|
|
@ -97,48 +97,37 @@ internal class Notifier(private val vm: ParamsViewModel) {
|
|||
vm.seChangedItems.postValue(list)
|
||||
}
|
||||
|
||||
fun handleResponse(response: TaskEvent<*>) {
|
||||
val taskEvent = response as? TaskEvent<*> ?: return
|
||||
fun handleResponse(response: CompletionResult<*>) {
|
||||
val commandResponse = response as? CompletionResult<CommandResponse> ?: return
|
||||
|
||||
when (taskEvent) {
|
||||
is TaskEvent.Completion -> handleCompletionEvent(taskEvent)
|
||||
is TaskEvent.Event -> handleDataEvent(taskEvent.data)
|
||||
when (commandResponse) {
|
||||
is CompletionResult.Failure -> handleError(commandResponse.error)
|
||||
is CompletionResult.Success -> handleDataEvent(commandResponse.data)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleDataEvent(event: Any?) {
|
||||
when (event) {
|
||||
is ScanEvent.OnReadEvent -> {
|
||||
vm.ldCard.postValue(event.card)
|
||||
vm.ldReadResponse.postValue(gson.toJson(event))
|
||||
private fun handleDataEvent(data: CommandResponse?) {
|
||||
when (data) {
|
||||
is Card -> {
|
||||
vm.ldCard.postValue(data)
|
||||
vm.ldReadResponse.postValue(gson.toJson(data))
|
||||
}
|
||||
is ScanEvent.OnVerifyEvent -> {
|
||||
vm.ldIsVerified.postValue(true)
|
||||
}
|
||||
else -> vm.ldResponse.postValue(gson.toJson(event))
|
||||
else -> vm.ldResponse.postValue(gson.toJson(data))
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleCompletionEvent(taskEvent: TaskEvent.Completion<*>) {
|
||||
if (taskEvent.error == null) {
|
||||
Log.d(this, "error = null")
|
||||
if (notShowedError != null) {
|
||||
vm.seError.postValue("${notShowedError!!::class.simpleName}")
|
||||
notShowedError = null
|
||||
}
|
||||
} else {
|
||||
Log.d(this, "error = ${taskEvent.error}")
|
||||
when (taskEvent.error) {
|
||||
is TaskError.UserCancelled -> {
|
||||
if (notShowedError == null) {
|
||||
vm.seError.postValue("User canceled the action")
|
||||
} else {
|
||||
vm.seError.postValue("${notShowedError!!::class.simpleName}")
|
||||
notShowedError = null
|
||||
}
|
||||
private fun handleError(error: SessionError) {
|
||||
Log.d(this, "error = ${error}")
|
||||
when (error) {
|
||||
is SessionError.UserCancelled -> {
|
||||
if (notShowedError == null) {
|
||||
vm.seError.postValue("User canceled the action")
|
||||
} else {
|
||||
vm.seError.postValue("${notShowedError!!::class.simpleName}")
|
||||
notShowedError = null
|
||||
}
|
||||
else -> notShowedError = taskEvent.error
|
||||
}
|
||||
else -> notShowedError = error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package com.tangem.tangemtest.ucase.variants.personalize.dto
|
||||
|
||||
import com.tangem.KeyPair
|
||||
import com.tangem.commands.personalization.entities.Acquirer
|
||||
import com.tangem.commands.personalization.entities.Issuer
|
||||
import com.tangem.commands.personalization.entities.Manufacturer
|
||||
import com.tangem.common.KeyPair
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import androidx.lifecycle.Observer
|
|||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.snackbar.BaseTransientBottomBar
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.tangem.CardManager
|
||||
import com.tangem.TangemSdk
|
||||
import com.tangem.tangem_sdk_new.extensions.init
|
||||
import com.tangem.tangemtest.R
|
||||
import com.tangem.tangemtest._arch.structure.Id
|
||||
|
|
@ -70,7 +70,7 @@ class PersonalizeFragment : Fragment(), ActionView {
|
|||
personalizeVM.toggleDescriptionVisibility(it)
|
||||
})
|
||||
|
||||
val cardManager = CardManager.init(requireActivity())
|
||||
val cardManager = TangemSdk.init(requireActivity())
|
||||
paramsVM.setCardManager(cardManager)
|
||||
paramsVM.ldResponse.observe(viewLifecycleOwner, Observer {
|
||||
Log.d(this, "action response: ${if (it.length > 50) it.substring(0..50) else it}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue