Updated on 2026-08-14

This commit is contained in:
Tangem 2020-03-19 10:56:33 +03:00
parent 58462ba360
commit ad014e143e
13 changed files with 84 additions and 82 deletions

View file

@ -48,9 +48,10 @@ dependencies {
implementation "androidx.navigation:navigation-ui-ktx:2.2.1"
implementation "androidx.recyclerview:recyclerview:1.2.0-alpha01"
implementation "com.google.android.material:material:1.2.0-alpha05"
implementation "androidx.viewpager2:viewpager2:1.0.0"
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.github.gbIxaHue:eu4d:0.2.3'
implementation 'com.github.gbIxaHue:eu4d:0.3.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.6'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'

View file

@ -1,4 +1,4 @@
package com.tangem.tangemtest.card_use_cases.models
package com.tangem.tangemtest.card_use_cases.domain
import androidx.fragment.app.FragmentActivity
import com.tangem.CardManager

View file

@ -1,10 +1,13 @@
package com.tangem.tangemtest.card_use_cases.models.params.manager
package com.tangem.tangemtest.card_use_cases.domain.card_action
import com.tangem.CardManager
import com.tangem.common.tlv.TlvTag
import com.tangem.tangemtest.card_use_cases.models.params.manager.modifiers.AfterActionModification
import com.tangem.tangemtest.card_use_cases.models.params.manager.modifiers.AfterScanModifier
import com.tangem.tangemtest.card_use_cases.models.params.manager.modifiers.ParamsChangeConsequence
import com.tangem.tangemtest.card_use_cases.domain.params_manager.ActionCallback
import com.tangem.tangemtest.card_use_cases.domain.params_manager.IncomingParameter
import com.tangem.tangemtest.card_use_cases.domain.params_manager.findParameter
import com.tangem.tangemtest.card_use_cases.domain.params_manager.modifiers.AfterActionModification
import com.tangem.tangemtest.card_use_cases.domain.params_manager.modifiers.AfterScanModifier
import com.tangem.tangemtest.card_use_cases.domain.params_manager.modifiers.ParamsChangeConsequence
import com.tangem.tasks.TaskEvent
import ru.dev.gbixahue.eu4d.lib.kotlin.stringOf
@ -49,9 +52,12 @@ class ScanAction : BaseCardAction() {
class SignAction : BaseCardAction() {
override fun executeMainAction(attrs: AttrForAction, callback: ActionCallback) {
val hashes = findHashes()
val cardId = ParamsManager.findParameter(TlvTag.CardId, attrs.paramsList)?.data
attrs.cardManager.sign(hashes, stringOf(cardId)) { handleResponse(it, null, attrs, callback) }
val dataForHashing = attrs.paramsList.findParameter(TlvTag.TransactionOutHash) ?: return
val arHashes = createHashes(stringOf(dataForHashing.data))
val cardId = attrs.paramsList.findParameter(TlvTag.CardId)?.data ?: return
attrs.cardManager.sign(arHashes, stringOf(cardId)) { handleResponse(it, null, attrs, callback) }
}
override fun getActionByTag(tag: TlvTag, attrs: AttrForAction): ((ActionCallback) -> Unit)? {
@ -61,9 +67,7 @@ class SignAction : BaseCardAction() {
}
}
private fun findHashes(): Array<ByteArray> {
val hash1 = ByteArray(32) { 1 }
val hash2 = ByteArray(32) { 2 }
return arrayOf(hash1, hash2)
private fun createHashes(value: String): Array<ByteArray> {
return arrayOf(value.toByteArray())
}
}

View file

@ -1,4 +1,4 @@
package com.tangem.tangemtest.card_use_cases.models.params.manager
package com.tangem.tangemtest.card_use_cases.domain.params_manager
import com.tangem.tangemtest.commons.ActionType
import ru.dev.gbixahue.eu4d.lib.kotlin.common.BaseTypedHolder

View file

@ -1,8 +1,8 @@
package com.tangem.tangemtest.card_use_cases.models.params.manager.modifiers
package com.tangem.tangemtest.card_use_cases.domain.params_manager.modifiers
import com.tangem.common.tlv.TlvTag
import com.tangem.tangemtest.card_use_cases.models.params.manager.IncomingParameter
import com.tangem.tangemtest.card_use_cases.models.params.manager.ParamsManager
import com.tangem.tangemtest.card_use_cases.domain.params_manager.IncomingParameter
import com.tangem.tangemtest.card_use_cases.domain.params_manager.findParameter
import com.tangem.tasks.ScanEvent
import com.tangem.tasks.TaskEvent
@ -19,7 +19,7 @@ interface AfterActionModification {
class AfterScanModifier : AfterActionModification {
override fun modify(taskEvent: TaskEvent<*>, paramsList: List<IncomingParameter>): List<IncomingParameter> {
val parameter = ParamsManager.findParameter(TlvTag.CardId, paramsList) ?: return listOf()
val parameter = paramsList.findParameter(TlvTag.CardId) ?: return listOf()
return if (taskEvent is TaskEvent.Event && taskEvent.data is ScanEvent.OnReadEvent) {
parameter.data = (taskEvent.data as ScanEvent.OnReadEvent).card.cardId

View file

@ -1,7 +1,7 @@
package com.tangem.tangemtest.card_use_cases.models.params.manager.modifiers
package com.tangem.tangemtest.card_use_cases.domain.params_manager.modifiers
import com.tangem.common.tlv.TlvTag
import com.tangem.tangemtest.card_use_cases.models.params.manager.IncomingParameter
import com.tangem.tangemtest.card_use_cases.domain.params_manager.IncomingParameter
/**
[REDACTED_AUTHOR]

View file

@ -1,9 +1,12 @@
package com.tangem.tangemtest.card_use_cases.models.params.manager
package com.tangem.tangemtest.card_use_cases.domain.params_manager
import com.tangem.CardManager
import com.tangem.common.tlv.TlvTag
import com.tangem.tangemtest.card_use_cases.models.params.manager.ParamsManager.Companion.findParameter
import com.tangem.tangemtest.card_use_cases.models.params.manager.modifiers.ParamsChangeConsequence
import com.tangem.tangemtest.card_use_cases.domain.card_action.AttrForAction
import com.tangem.tangemtest.card_use_cases.domain.card_action.CardAction
import com.tangem.tangemtest.card_use_cases.domain.card_action.ScanAction
import com.tangem.tangemtest.card_use_cases.domain.card_action.SignAction
import com.tangem.tangemtest.card_use_cases.domain.params_manager.modifiers.ParamsChangeConsequence
import com.tangem.tasks.TaskEvent
/**
@ -26,10 +29,10 @@ interface ParamsManager {
fun invokeMainAction(cardManager: CardManager, callback: ActionCallback)
fun getActionByTag(tag: TlvTag, cardManager: CardManager): ((ActionCallback) -> Unit)?
companion object {
fun findParameter(tlvTag: TlvTag, paramsList: List<IncomingParameter>)
: IncomingParameter? = paramsList.firstOrNull { it.tlvTag == tlvTag }
}
}
fun List<IncomingParameter>.findParameter(tag: TlvTag): IncomingParameter? {
return firstOrNull { it.tlvTag == tag }
}
abstract class BaseParamsManager(protected val action: CardAction) : ParamsManager {
@ -40,7 +43,7 @@ abstract class BaseParamsManager(protected val action: CardAction) : ParamsManag
override fun parameterChanged(tag: TlvTag, value: Any?, callback: AffectedParamsCallback?) {
if (paramsList.isEmpty()) return
val foundParam = findParameter(tag, paramsList) ?: return
val foundParam = paramsList.findParameter(tag) ?: return
foundParam.data = value
applyChangesByAffectedParams(foundParam, callback)
@ -75,7 +78,7 @@ class SignParamsManager : BaseParamsManager(SignAction()) {
override fun createParamsList(): List<IncomingParameter> {
return listOf(
IncomingParameter(TlvTag.CardId, null),
IncomingParameter(TlvTag.TransactionOutHash, "")
IncomingParameter(TlvTag.TransactionOutHash, "Data used for hashing")
)
}

View file

@ -15,8 +15,8 @@ import com.google.android.material.snackbar.Snackbar
import com.tangem.CardManager
import com.tangem.tangem_sdk_new.extensions.init
import com.tangem.tangemtest.R
import com.tangem.tangemtest.card_use_cases.models.params.manager.ParamsManager
import com.tangem.tangemtest.card_use_cases.models.params.manager.ParamsManagerFactory
import com.tangem.tangemtest.card_use_cases.domain.params_manager.ParamsManager
import com.tangem.tangemtest.card_use_cases.domain.params_manager.ParamsManagerFactory
import com.tangem.tangemtest.card_use_cases.ui.widgets.ParameterWidget
import com.tangem.tangemtest.card_use_cases.view_models.ActionViewModelFactory
import com.tangem.tangemtest.card_use_cases.view_models.ParamsViewModel
@ -29,14 +29,20 @@ import ru.dev.gbixahue.eu4d.lib.kotlin.common.LayoutHolder
*/
abstract class BaseCardActionFragment : Fragment(), LayoutHolder {
protected val mainView: View by lazy { view!! }
protected val incomingParamsContainer: ViewGroup by lazy {
mainView.findViewById<LinearLayout>(R.id.ll_incoming_params_container)
}
protected val viewModel: ParamsViewModel by viewModels { ActionViewModelFactory(paramsManager) }
protected lateinit var mainView: View
private val paramsManager: ParamsManager by lazy { ParamsManagerFactory.createFactory().get(getAction())!! }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
Log.d(this, "onCreateView")
mainView = inflater.inflate(getLayoutId(), container, false)
return mainView
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Log.d(this, "onViewCreated")
@ -87,12 +93,12 @@ abstract class BaseCardActionFragment : Fragment(), LayoutHolder {
Snackbar.make(mainView, message, BaseTransientBottomBar.LENGTH_SHORT).show()
}
private fun inflateParamView(where: ViewGroup): View {
private fun inflateParamView(where: ViewGroup): ViewGroup {
val inflater = LayoutInflater.from(where.context)
val view = inflater.inflate(R.layout.w_card_incoming_param, where, false)
where.addView(view)
inflater.inflate(R.layout.m_divider_h, where, true)
return view
return view as ViewGroup
}
abstract fun getAction(): ActionType

View file

@ -5,13 +5,13 @@ import android.text.TextWatcher
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.transition.AutoTransition
import androidx.transition.TransitionManager
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import com.tangem.common.tlv.TlvTag
import com.tangem.tangemtest.R
import com.tangem.tangemtest.card_use_cases.models.params.manager.IncomingParameter
import com.tangem.tangemtest.card_use_cases.domain.params_manager.IncomingParameter
import com.tangem.tangemtest.commons.ActionType
import ru.dev.gbixahue.eu4d.lib.android.global.log.Log
import ru.dev.gbixahue.eu4d.lib.kotlin.stringOf
@ -19,7 +19,7 @@ import ru.dev.gbixahue.eu4d.lib.kotlin.stringOf
/**
[REDACTED_AUTHOR]
*/
class ParameterWidget(parent: View, model: IncomingParameter) {
class ParameterWidget(private val parent: ViewGroup, model: IncomingParameter) {
val tlvTag: TlvTag = model.tlvTag
@ -30,8 +30,8 @@ class ParameterWidget(parent: View, model: IncomingParameter) {
toggleActionBtnVisibility()
}
private val tvName: TextView = parent.findViewById(R.id.tv_param_name)
private val etValue: EditText = parent.findViewById(R.id.tv_param_value)
private val tilValue: TextInputLayout = parent.findViewById(R.id.til_param)
private val etValue: TextInputEditText = parent.findViewById(R.id.et_param)
private val btnAction: Button = parent.findViewById(R.id.btn_action)
private val valueWatcher: TextWatcher by lazy { getWatcher() }
@ -39,7 +39,7 @@ class ParameterWidget(parent: View, model: IncomingParameter) {
private var value: Any? = model.data
init {
tvName.text = model.tlvTag.name
tilValue.hint = model.tlvTag.name
etValue.setText(stringOf(model.data))
etValue.addTextChangedListener(valueWatcher)
btnAction.setOnClickListener { onActionBtnClickListener?.invoke() }
@ -86,7 +86,7 @@ class ParameterWidget(parent: View, model: IncomingParameter) {
private fun toggleActionBtnVisibility() {
fun switchVisibilityState(newState: Int) {
actionBtnVisibilityState = newState
TransitionManager.beginDelayedTransition(etValue.parent as ViewGroup, AutoTransition())
TransitionManager.beginDelayedTransition(parent, AutoTransition())
btnAction.visibility = actionBtnVisibilityState
}
when {

View file

@ -9,8 +9,8 @@ import com.tangem.CardManager
import com.tangem.commands.Card
import com.tangem.common.tlv.TlvTag
import com.tangem.tangemtest._arch.SingleLiveEvent
import com.tangem.tangemtest.card_use_cases.models.params.manager.IncomingParameter
import com.tangem.tangemtest.card_use_cases.models.params.manager.ParamsManager
import com.tangem.tangemtest.card_use_cases.domain.params_manager.IncomingParameter
import com.tangem.tangemtest.card_use_cases.domain.params_manager.ParamsManager
import com.tangem.tangemtest.commons.performAction
import com.tangem.tasks.ScanEvent
import com.tangem.tasks.TaskError

View file

@ -22,7 +22,11 @@
</LinearLayout>
<include layout="@layout/w_action_response_json" />
<include
layout="@layout/w_action_response_json"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/def_indent" />
</LinearLayout>

View file

@ -22,7 +22,11 @@
</LinearLayout>
<include layout="@layout/w_action_response_json" />
<include
layout="@layout/w_action_response_json"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/def_indent" />
</LinearLayout>

View file

@ -3,47 +3,27 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="48dp">
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_param_name"
style="@style/TvParamNameStyle"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_param"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLines="2"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/include4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Param name" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.37" />
<include
android:id="@+id/include4"
layout="@layout/m_divider_h"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<EditText
android:id="@+id/tv_param_value"
style="@style/EtParamValueStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/tv_param_name"
app:layout_constraintEnd_toStartOf="@+id/btn_action"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toTopOf="@+id/tv_param_name"
tools:text="Param value" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_param"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/btn_action"