From bd912318031d89dbcefbca9bd33feb62a70da515 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 13 Mar 2020 12:17:13 +0300 Subject: [PATCH] Updated on 2026-08-14 --- tangem-demo/build.gradle | 2 +- .../com/tangem/tangemtest/AppTangemDemo.kt | 19 ++- .../_main/entry_point/EntryPointFragment.kt | 46 +++--- .../tangem/tangemtest/_main/entry_point/rv.kt | 63 ++------ .../actions/ScanActionFragment.kt | 41 ----- .../actions/SignActionFragment.kt | 40 ----- .../card_use_cases/actions/actions.kt | 12 -- .../base/BaseCardActionFragment.kt | 53 ------- .../{ => models}/CardContext.kt | 2 +- .../models/params/manager/card_actions.kt | 64 ++++++++ .../models/params/manager/factory.kt | 19 +++ .../modifiers/after_action_modifiers.kt | 23 +++ .../modifiers/param_change_consequence.kt | 21 +++ .../models/params/manager/params_managers.kt | 87 +++++++++++ .../ui/BaseCardActionFragment.kt | 104 +++++++++++++ .../card_use_cases/ui/ScanActionFragment.kt | 14 ++ .../card_use_cases/ui/SignActionFragment.kt | 14 ++ .../ui/widgets/ParameterWidget.kt | 88 +++++++++++ .../view_models/ParamsViewModel.kt | 145 ++++++++++++++++++ .../tangem/tangemtest/commons/abstracts.kt | 4 - .../java/com/tangem/tangemtest/commons/di.kt | 17 -- .../tangem/tangemtest/commons/global_func.kt | 8 + .../com/tangem/tangemtest/commons/logs.kt | 8 + .../tangem/tangemtest/commons/navigation.kt | 18 ++- .../res/color/mtrl_fab_bg_color_selector.xml | 6 + .../mtrl_fab_icon_text_color_selector.xml | 6 + .../res/layout/activity_test_user_data.xml | 2 +- .../main/res/layout/fg_action_card_scan.xml | 40 +++++ .../main/res/layout/fg_action_card_sign.xml | 40 +++++ .../src/main/res/layout/fg_card_scan.xml | 17 -- .../src/main/res/layout/fg_card_sign.xml | 17 -- .../src/main/res/layout/m_delimiter_h.xml | 7 - .../src/main/res/layout/m_divider_h.xml | 6 + .../src/main/res/layout/m_divider_v.xml | 6 + .../src/main/res/layout/vh_actions.xml | 26 +--- .../res/layout/w_action_response_json.xml | 7 + .../main/res/layout/w_card_incoming_param.xml | 60 ++++++++ .../src/main/res/navigation/navigation.xml | 114 ++++++++++---- tangem-demo/src/main/res/values/colors.xml | 2 +- tangem-demo/src/main/res/values/dimens.xml | 9 ++ tangem-demo/src/main/res/values/strings.xml | 12 +- tangem-demo/src/main/res/values/styles.xml | 17 +- 42 files changed, 963 insertions(+), 343 deletions(-) delete mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/actions/ScanActionFragment.kt delete mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/actions/SignActionFragment.kt delete mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/actions/actions.kt delete mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/base/BaseCardActionFragment.kt rename tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/{ => models}/CardContext.kt (92%) create mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/card_actions.kt create mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/factory.kt create mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/modifiers/after_action_modifiers.kt create mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/modifiers/param_change_consequence.kt create mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/params_managers.kt create mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/BaseCardActionFragment.kt create mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/ScanActionFragment.kt create mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/SignActionFragment.kt create mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/widgets/ParameterWidget.kt create mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/view_models/ParamsViewModel.kt delete mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/commons/di.kt create mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/commons/global_func.kt create mode 100644 tangem-demo/src/main/java/com/tangem/tangemtest/commons/logs.kt create mode 100644 tangem-demo/src/main/res/color/mtrl_fab_bg_color_selector.xml create mode 100644 tangem-demo/src/main/res/color/mtrl_fab_icon_text_color_selector.xml create mode 100644 tangem-demo/src/main/res/layout/fg_action_card_scan.xml create mode 100644 tangem-demo/src/main/res/layout/fg_action_card_sign.xml delete mode 100644 tangem-demo/src/main/res/layout/fg_card_scan.xml delete mode 100644 tangem-demo/src/main/res/layout/fg_card_sign.xml delete mode 100644 tangem-demo/src/main/res/layout/m_delimiter_h.xml create mode 100644 tangem-demo/src/main/res/layout/m_divider_h.xml create mode 100644 tangem-demo/src/main/res/layout/m_divider_v.xml create mode 100644 tangem-demo/src/main/res/layout/w_action_response_json.xml create mode 100644 tangem-demo/src/main/res/layout/w_card_incoming_param.xml diff --git a/tangem-demo/build.gradle b/tangem-demo/build.gradle index 116ffff7cd..18050d7ecf 100644 --- a/tangem-demo/build.gradle +++ b/tangem-demo/build.gradle @@ -47,8 +47,8 @@ dependencies { implementation "androidx.navigation:navigation-fragment-ktx:2.2.1" 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 'com.google.code.gson:gson:2.8.6' + implementation 'com.github.gbIxaHue:eu4d:0.2.3' } diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/AppTangemDemo.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/AppTangemDemo.kt index cd3f9ace12..199844f32f 100644 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/AppTangemDemo.kt +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/AppTangemDemo.kt @@ -1,14 +1,21 @@ package com.tangem.tangemtest import android.app.Application -import com.tangem.tangemtest.card_use_cases.CardContext -import com.tangem.tangemtest.commons.DiManager +import com.tangem.tangemtest.commons.TangemLogger +import ru.dev.gbixahue.eu4d.lib.android.global.log.Log /** [REDACTED_AUTHOR] */ -class AppTangemDemo : Application(), DiManager { - private val cardContext: CardContext = CardContext() +class AppTangemDemo : Application() { - override fun getCardContext(): CardContext = cardContext -} \ No newline at end of file + override fun onCreate() { + super.onCreate() + + setLogger() + } + + private fun setLogger() { + Log.setLogger(TangemLogger()) + } +} diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/_main/entry_point/EntryPointFragment.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/_main/entry_point/EntryPointFragment.kt index 1537c2bd2c..ed27931b8a 100644 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/_main/entry_point/EntryPointFragment.kt +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/_main/entry_point/EntryPointFragment.kt @@ -7,14 +7,13 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.navigation.NavController import androidx.navigation.fragment.findNavController +import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.tangem.tangemtest.R -import com.tangem.tangemtest.card_use_cases.CardContext -import com.tangem.tangemtest.card_use_cases.actions.Action -import com.tangem.tangemtest.commons.NavigateAction +import com.tangem.tangemtest.commons.Action +import com.tangem.tangemtest.commons.NavigateOptions import com.tangem.tangemtest.commons.getDefaultNavigationOptions -import com.tangem.tangemtest.commons.getDiManager import kotlinx.android.synthetic.main.fg_entry_point.* /** @@ -31,32 +30,41 @@ class EntryPointFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - - val activity = activity ?: throw Exception("Fragment isn't associated with activity ") - - val cardContext = getDiManager().getCardContext().init(activity) - initRecyclerView(cardContext) + initRecyclerView() } - private fun initRecyclerView(cardContext: CardContext) { + private fun initRecyclerView() { + val layoutManager = LinearLayoutManager(activity) rvActions = rv_actions - rvActions.layoutManager = LinearLayoutManager(activity) - - val adapter = RvActionsAdapter(cardContext) { position, destinationId -> navigate(destinationId as Int) } - adapter.setItems(mutableListOf( - NavigateAction(Action.Scan(), R.id.nav_scan), - NavigateAction(Action.Sign(), R.id.nav_sign) - )) - rvActions.adapter = adapter + rvActions.layoutManager = layoutManager + rvActions.addItemDecoration(DividerItemDecoration(activity, layoutManager.orientation)) + rvActions.adapter = RvActionsAdapter { type, position, data -> navigate(data.destinationId) } } override fun onResume() { super.onResume() + val adapter: RvActionsAdapter = rvActions.adapter as? RvActionsAdapter ?: return - rvActions.adapter?.notifyDataSetChanged() + adapter.setItemList(getNavigateOptions()) + adapter.notifyDataSetChanged() } private fun navigate(destinationId: Int) { navController.navigate(destinationId, null, getDefaultNavigationOptions()) } + + private fun getNavigateOptions(): MutableList { + return mutableListOf( + NavigateOptions(Action.Scan, R.id.action_nav_entry_point_to_nav_scan), + NavigateOptions(Action.Sign, R.id.action_nav_entry_point_to_nav_sign), + NavigateOptions(Action.CreateWallet, R.id.action_nav_entry_point_to_nav_wallet_create), + NavigateOptions(Action.PurgeWallet, R.id.action_nav_entry_point_to_nav_wallet_purge), + NavigateOptions(Action.ReadIssuerData, R.id.action_nav_entry_point_to_nav_issuer_read_data), + NavigateOptions(Action.WriteIssuerData, R.id.action_nav_entry_point_to_nav_issuer_write_data), + NavigateOptions(Action.ReadIssuerExData, R.id.action_nav_entry_point_to_nav_issuer_read_ex_data), + NavigateOptions(Action.WriteIssuerExData, R.id.action_nav_entry_point_to_nav_issuer_write_ex_data), + NavigateOptions(Action.ReadUserData, R.id.action_nav_entry_point_to_nav_user_read_data), + NavigateOptions(Action.WriteUserData, R.id.action_nav_entry_point_to_nav_user_write_data) + ) + } } \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/_main/entry_point/rv.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/_main/entry_point/rv.kt index 6035bebb85..2d679953a9 100644 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/_main/entry_point/rv.kt +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/_main/entry_point/rv.kt @@ -1,69 +1,30 @@ package com.tangem.tangemtest._main.entry_point -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import android.widget.TextView -import androidx.recyclerview.widget.RecyclerView import com.tangem.tangemtest.R -import com.tangem.tangemtest.card_use_cases.CardContext -import com.tangem.tangemtest.card_use_cases.actions.Action -import com.tangem.tangemtest.commons.Bindable -import com.tangem.tangemtest.commons.NavigateAction +import com.tangem.tangemtest.commons.NavigateOptions +import ru.dev.gbixahue.eu4d.lib.android._android.views.recycler_view.RvAdapter +import ru.dev.gbixahue.eu4d.lib.android._android.views.recycler_view.RvCallback +import ru.dev.gbixahue.eu4d.lib.android._android.views.recycler_view.RvVH /** [REDACTED_AUTHOR] */ -typealias RvCallback = (Int, Any?) -> Unit +class RvActionsAdapter(callback: RvCallback) : RvAdapter(callback) { -class RvActionsAdapter( - private val cardContext: CardContext, - private val callback: RvCallback -) : RecyclerView.Adapter() { - - private val actionList = mutableListOf() - - fun setItems(list: MutableList) { - actionList.clear() - actionList.addAll(list) + override fun createViewHolder(view: View, listener: RvCallback?): RvActionsVH { + return RvActionsVH(view, listener) } - fun addToItems(list: MutableList) { - actionList.addAll(list) - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RvActionsVH { - val view = LayoutInflater.from(parent.context).inflate(R.layout.vh_actions, parent, false) - return RvActionsVH(view, cardContext.isVerified, callback) - } - - override fun getItemCount(): Int = actionList.size - - override fun onBindViewHolder(holder: RvActionsVH, position: Int) { - holder.bind(actionList[position]) - } + override fun getLayoutId(): Int = R.layout.vh_actions } -class RvActionsVH( - view: View, - private val cardIsVerified: Boolean, - private val callback: RvCallback -) : RecyclerView.ViewHolder(view), Bindable { - +class RvActionsVH(itemView: View, callback: RvCallback?) : RvVH(itemView, callback) { private val tvAction = itemView.findViewById(R.id.tv_title) - private val navigateRight = itemView.findViewById(R.id.tv_navigate_right) - override fun bind(data: NavigateAction) { - tvAction.text = tvAction.context.getString(data.action.resId) - itemView.setOnClickListener { callback(adapterPosition, data.destinationId) } - switchItemBackground(data.action) - } - - private fun switchItemBackground(action: Action) { - when (action) { - is Action.Scan -> { - } - else -> itemView.visibility = if (cardIsVerified) View.VISIBLE else View.GONE - } + override fun onDataBound(data: NavigateOptions) { + tvAction.text = tvAction.context.getString(data.name.resName) + itemView.setOnClickListener { invokeCallback() } } } \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/actions/ScanActionFragment.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/actions/ScanActionFragment.kt deleted file mode 100644 index f6a24b91ed..0000000000 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/actions/ScanActionFragment.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.tangem.tangemtest.card_use_cases.actions - -import android.os.Bundle -import android.view.View -import com.google.gson.Gson -import com.tangem.tangemtest.R -import com.tangem.tangemtest.card_use_cases.base.BaseCardActionFragment -import com.tangem.tangemtest.commons.postUI -import com.tangem.tasks.ScanEvent -import com.tangem.tasks.TaskEvent -import kotlinx.android.synthetic.main.fg_card_scan.* - -/** -[REDACTED_AUTHOR] - */ -class ScanActionFragment : BaseCardActionFragment() { - - override fun getLayoutId(): Int = R.layout.fg_card_scan - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - cardContext.reset() - cardContext.cardManager.scanCard { taskEvent -> - when (taskEvent) { - is TaskEvent.Event -> handleDataEvent(taskEvent.data) - is TaskEvent.Completion -> handleCompletionEvent(taskEvent) - } - } - } - - private fun handleDataEvent(event: ScanEvent) { - when (event) { - is ScanEvent.OnReadEvent -> { - cardContext.card = event.card - postUI { tv_card_cid.text = Gson().toJson(cardContext.card) } - } - is ScanEvent.OnVerifyEvent -> cardContext.isVerified = true - } - } -} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/actions/SignActionFragment.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/actions/SignActionFragment.kt deleted file mode 100644 index 51513df71f..0000000000 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/actions/SignActionFragment.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.tangem.tangemtest.card_use_cases.actions - -import android.os.Bundle -import android.view.View -import com.tangem.commands.SignResponse -import com.tangem.tangemtest.R -import com.tangem.tangemtest.card_use_cases.base.BaseCardActionFragment -import com.tangem.tangemtest.commons.postUI -import com.tangem.tasks.TaskEvent -import kotlinx.android.synthetic.main.fg_card_sign.* - -/** -[REDACTED_AUTHOR] - */ -class SignActionFragment : BaseCardActionFragment() { - - override fun getLayoutId(): Int = R.layout.fg_card_sign - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - val cardId = cardContext.requireCard().cardId - cardContext.cardManager.sign(createSampleHashes(), cardId) { taskEvent -> - when (taskEvent) { - is TaskEvent.Event -> handleDataEvent(taskEvent.data) - is TaskEvent.Completion -> handleCompletionEvent(taskEvent) - } - } - } - - private fun handleDataEvent(event: SignResponse) { - postUI { tv_sign_result.text = toJson(event) } - } - - private fun createSampleHashes(): Array { - val hash1 = ByteArray(32) { 1 } - val hash2 = ByteArray(32) { 2 } - return arrayOf(hash1, hash2) - } -} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/actions/actions.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/actions/actions.kt deleted file mode 100644 index 69fecafb54..0000000000 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/actions/actions.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.tangem.tangemtest.card_use_cases.actions - -import androidx.annotation.StringRes -import com.tangem.tangemtest.R - -/** -[REDACTED_AUTHOR] - */ -sealed class Action(@StringRes val resId: Int) { - class Scan: Action(R.string.action_card_scan) - class Sign: Action(R.string.action_card_sign) -} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/base/BaseCardActionFragment.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/base/BaseCardActionFragment.kt deleted file mode 100644 index aacbf2d2d7..0000000000 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/base/BaseCardActionFragment.kt +++ /dev/null @@ -1,53 +0,0 @@ -package com.tangem.tangemtest.card_use_cases.base - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.annotation.UiThread -import androidx.fragment.app.Fragment -import com.google.android.material.snackbar.BaseTransientBottomBar -import com.google.android.material.snackbar.Snackbar -import com.google.gson.Gson -import com.tangem.tangemtest.card_use_cases.CardContext -import com.tangem.tangemtest.commons.LayoutHolder -import com.tangem.tangemtest.commons.getDiManager -import com.tangem.tasks.TaskError -import com.tangem.tasks.TaskEvent - -/** -[REDACTED_AUTHOR] - */ -abstract class BaseCardActionFragment : Fragment(), LayoutHolder { - - protected lateinit var cardContext: CardContext - protected lateinit var mainView: View - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - mainView = inflater.inflate(getLayoutId(), container, false) - return mainView - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - cardContext = getDiManager().getCardContext() - } - - @UiThread - protected fun handleCompletionEvent(taskEvent: TaskEvent.Completion<*>) { - val error: TaskError = taskEvent.error ?: return - - when (error) { - is TaskError.UserCancelled -> showSnackbarMessage("Error: User was canceled") - else -> showSnackbarMessage("Description not implemented. code: ${error.code}") - } - - } - - protected fun showSnackbarMessage(message: String) { - Snackbar.make(mainView, message, BaseTransientBottomBar.LENGTH_SHORT).show() - } - - protected fun toJson(obj: Any): String = Gson().toJson(obj) - -} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/CardContext.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/CardContext.kt similarity index 92% rename from tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/CardContext.kt rename to tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/CardContext.kt index 2f37449a27..22af4ca879 100644 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/CardContext.kt +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/CardContext.kt @@ -1,4 +1,4 @@ -package com.tangem.tangemtest.card_use_cases +package com.tangem.tangemtest.card_use_cases.models import androidx.fragment.app.FragmentActivity import com.tangem.CardManager diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/card_actions.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/card_actions.kt new file mode 100644 index 0000000000..48cd4193a8 --- /dev/null +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/card_actions.kt @@ -0,0 +1,64 @@ +package com.tangem.tangemtest.card_use_cases.models.params.manager + +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.tasks.TaskEvent +import ru.dev.gbixahue.eu4d.lib.kotlin.stringOf + + +data class AttrForAction( + val cardManager: CardManager, + val paramsList: List, + val consequence: ParamsChangeConsequence? +) + +interface CardAction { + fun executeMainAction(attrs: AttrForAction, callback: ActionCallback) + fun getActionByTag(tag: TlvTag, attrs: AttrForAction): ((ActionCallback) -> Unit)? = null +} + +abstract class BaseCardAction : CardAction { + protected open fun handleResponse( + taskEvent: TaskEvent<*>, + modifier: AfterActionModification?, + attrs: AttrForAction, + callback: ActionCallback + ) { + val allModifiedParams = mutableListOf() + modifier?.modify(taskEvent, attrs.paramsList)?.forEach { parameter -> + allModifiedParams.add(parameter) + attrs.consequence?.affectChanges(parameter, attrs.paramsList)?.let { allModifiedParams.addAll(it) } + } + callback(taskEvent, allModifiedParams) + } +} + +class ScanAction : BaseCardAction() { + override fun executeMainAction(attrs: AttrForAction, callback: ActionCallback) { + attrs.cardManager.scanCard { handleResponse(it, AfterScanModifier(), attrs, callback) } + } +} + +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) } + } + + override fun getActionByTag(tag: TlvTag, attrs: AttrForAction): ((ActionCallback) -> Unit)? { + if (tag != TlvTag.CardId) return null + val pCardId = ParamsManager.findParameter(tag, attrs.paramsList) ?: return null + + return if (pCardId.data == null) { callback -> ScanAction().executeMainAction(attrs, callback) } else null + } + + private fun findHashes(): Array { + val hash1 = ByteArray(32) { 1 } + val hash2 = ByteArray(32) { 2 } + return arrayOf(hash1, hash2) + } +} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/factory.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/factory.kt new file mode 100644 index 0000000000..3458fcdfa1 --- /dev/null +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/factory.kt @@ -0,0 +1,19 @@ +package com.tangem.tangemtest.card_use_cases.models.params.manager + +import com.tangem.tangemtest.commons.Action +import ru.dev.gbixahue.eu4d.lib.kotlin.common.BaseTypedHolder + +/** +[REDACTED_AUTHOR] + */ +class ParamsManagerFactory : BaseTypedHolder() { + + companion object { + fun createFactory(): ParamsManagerFactory { + return ParamsManagerFactory().apply { + register(Action.Scan, ScanParamsManager()) + register(Action.Sign, SignParamsManager()) + } + } + } +} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/modifiers/after_action_modifiers.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/modifiers/after_action_modifiers.kt new file mode 100644 index 0000000000..e94abfa672 --- /dev/null +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/modifiers/after_action_modifiers.kt @@ -0,0 +1,23 @@ +package com.tangem.tangemtest.card_use_cases.models.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.tasks.ScanEvent +import com.tangem.tasks.TaskEvent + + +interface AfterActionModification { + fun modify(taskEvent: TaskEvent<*>, paramsList: List): List +} + +class AfterScanModifier : AfterActionModification { + override fun modify(taskEvent: TaskEvent<*>, paramsList: List): List { + val parameter = ParamsManager.findParameter(TlvTag.CardId, paramsList) ?: return listOf() + + return if (taskEvent is TaskEvent.Event && taskEvent.data is ScanEvent.OnReadEvent) { + parameter.data = (taskEvent.data as ScanEvent.OnReadEvent).card.cardId + listOf(parameter) + } else listOf() + } +} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/modifiers/param_change_consequence.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/modifiers/param_change_consequence.kt new file mode 100644 index 0000000000..8d60022226 --- /dev/null +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/modifiers/param_change_consequence.kt @@ -0,0 +1,21 @@ +package com.tangem.tangemtest.card_use_cases.models.params.manager.modifiers + +import com.tangem.common.tlv.TlvTag +import com.tangem.tangemtest.card_use_cases.models.params.manager.IncomingParameter + +/** +[REDACTED_AUTHOR] + */ +interface ParamsChangeConsequence { + fun affectChanges(changedParameter: IncomingParameter, paramsList: List): List +} + +class ExampleConsequenceForCardId : ParamsChangeConsequence { + override fun affectChanges(changedParameter: IncomingParameter, paramsList: List): List { + if (changedParameter.tlvTag != TlvTag.CardId) return listOf() + + val affectedList = paramsList.filter { it.tlvTag != changedParameter.tlvTag } + affectedList.forEach { it.data = changedParameter.data.hashCode() } + return affectedList + } +} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/params_managers.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/params_managers.kt new file mode 100644 index 0000000000..2ed9feb265 --- /dev/null +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/models/params/manager/params_managers.kt @@ -0,0 +1,87 @@ +package com.tangem.tangemtest.card_use_cases.models.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.tasks.TaskEvent + +/** +[REDACTED_AUTHOR] + */ + +class IncomingParameter(val tlvTag: TlvTag, var data: Any? = null) + +typealias ActionResponse = TaskEvent<*> +typealias AffectedList = List +typealias AffectedParamsCallback = (AffectedList) -> Unit +typealias ActionCallback = (ActionResponse, AffectedList) -> Unit + +interface ParamsManager { + + fun parameterChanged(tag: TlvTag, value: Any?, callback: AffectedParamsCallback? = null) + fun getParams(): List + fun invokeMainAction(cardManager: CardManager, callback: ActionCallback) + fun getActionByTag(tag: TlvTag, cardManager: CardManager): ((ActionCallback) -> Unit)? + + companion object { + fun findParameter(tlvTag: TlvTag, paramsList: List) + : IncomingParameter? = paramsList.firstOrNull { it.tlvTag == tlvTag } + } +} + +abstract class BaseParamsManager(protected val action: CardAction) : ParamsManager { + + protected val paramsList: List by lazy { createParamsList() } + + abstract fun createParamsList(): List + + override fun parameterChanged(tag: TlvTag, value: Any?, callback: AffectedParamsCallback?) { + if (paramsList.isEmpty()) return + val foundParam = findParameter(tag, paramsList) ?: return + + foundParam.data = value + applyChangesByAffectedParams(foundParam, callback) + } + + override fun getParams(): MutableList = paramsList.toMutableList() + + // Use it if current parameter needs to be affect any other parameters + protected open fun applyChangesByAffectedParams(param: IncomingParameter, callback: AffectedParamsCallback?) { + getChangeConsequence()?.affectChanges(param, paramsList)?.let { callback?.invoke(it) } + } + + protected open fun getChangeConsequence(): ParamsChangeConsequence? = null + + protected fun getAttrsForAction(cardManager: CardManager) + : AttrForAction = AttrForAction(cardManager, paramsList, getChangeConsequence()) +} + +class ScanParamsManager : BaseParamsManager(ScanAction()) { + override fun createParamsList(): List { + return listOf(IncomingParameter(TlvTag.CardId, null)) + } + + override fun invokeMainAction(cardManager: CardManager, callback: ActionCallback) { + action.executeMainAction(getAttrsForAction(cardManager), callback) + } + + override fun getActionByTag(tag: TlvTag, cardManager: CardManager): ((ActionCallback) -> Unit)? = null +} + +class SignParamsManager : BaseParamsManager(SignAction()) { + override fun createParamsList(): List { + return listOf( + IncomingParameter(TlvTag.CardId, null), + IncomingParameter(TlvTag.TransactionOutHash, "") + ) + } + + override fun invokeMainAction(cardManager: CardManager, callback: ActionCallback) { + action.executeMainAction(getAttrsForAction(cardManager), callback) + } + + override fun getActionByTag(tag: TlvTag, cardManager: CardManager): ((ActionCallback) -> Unit)? { + return action.getActionByTag(tag, getAttrsForAction(cardManager)) + } +} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/BaseCardActionFragment.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/BaseCardActionFragment.kt new file mode 100644 index 0000000000..34cff55ae5 --- /dev/null +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/BaseCardActionFragment.kt @@ -0,0 +1,104 @@ +package com.tangem.tangemtest.card_use_cases.ui + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.fragment.app.viewModels +import androidx.lifecycle.Observer +import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton +import com.google.android.material.snackbar.BaseTransientBottomBar +import com.google.android.material.snackbar.Snackbar +import com.tangem.tangemtest.R +import com.tangem.tangemtest.card_use_cases.ui.widgets.ParameterWidget +import com.tangem.tangemtest.card_use_cases.view_models.ParamsViewModel +import com.tangem.tangemtest.commons.Action +import com.tangem.tangemtest.commons.LayoutHolder +import ru.dev.gbixahue.eu4d.lib.android.global.log.Log + +/** +[REDACTED_AUTHOR] + */ +abstract class BaseCardActionFragment : Fragment(), LayoutHolder { + + protected lateinit var mainView: View + protected val incomingParamsContainer: ViewGroup by lazy { + mainView.findViewById(R.id.ll_incoming_params_container) + } + + protected val viewModel: ParamsViewModel by viewModels() + + 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") + val activity = activity ?: return + + try { + viewModel.init(activity, getAction()) + initFab() + val widgetList = createWidgets() + subscribeToViewModelChanges(widgetList) + } catch (e: Exception) { + Log.e(this, e) + showSnackbarMessage(e.toString()) + } + } + + private fun initFab() { + Log.d(this, "initFab") + val fab = mainView.findViewById(R.id.fab_action) ?: return + + fab.setText(getAction().resName) + fab.setOnClickListener { viewModel.invokeMainAction() } + } + + private fun createWidgets(): MutableList { + Log.d(this, "createWidgets") + + val widgetList = mutableListOf() + viewModel.getInitialParams()?.forEach { param -> + val widget = ParameterWidget(inflateParamView(incomingParamsContainer), param) + widget.onParameterValueChanged = { viewModel.userChangedParameter(it) } + widget.onParameterAction = viewModel.getParameterAction(param.tlvTag) + widgetList.add(widget) + } + return widgetList + } + + private fun subscribeToViewModelChanges(widgetList: MutableList) { + Log.d(this, "subscribeToViewModelChanges") + + viewModel.ldResponse.observe(viewLifecycleOwner, Observer { + Log.d(this, "action response: ${if (it.length > 50) it.substring(0..50) else it}") + mainView.findViewById(R.id.tv_action_response_json).text = it + }) + viewModel.ldError.observe(viewLifecycleOwner, Observer { showSnackbarMessage(it) }) + viewModel.ldIncomingParameter.observe(viewLifecycleOwner, Observer { param -> + Log.d(this, "parameter changed from VM - name: ${param.tlvTag.name}, value:${param.data}") + widgetList.firstOrNull { it.tlvTag == param.tlvTag }?.changeParamValue(param.data) + }) + } + + protected fun showSnackbarMessage(message: String) { + Snackbar.make(mainView, message, BaseTransientBottomBar.LENGTH_SHORT).show() + } + + private fun inflateParamView(where: ViewGroup): View { + 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 + } + + abstract fun getAction(): Action +} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/ScanActionFragment.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/ScanActionFragment.kt new file mode 100644 index 0000000000..5b11212866 --- /dev/null +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/ScanActionFragment.kt @@ -0,0 +1,14 @@ +package com.tangem.tangemtest.card_use_cases.ui + +import com.tangem.tangemtest.R +import com.tangem.tangemtest.commons.Action + +/** +[REDACTED_AUTHOR] + */ +class ScanActionFragment : BaseCardActionFragment() { + + override fun getLayoutId(): Int = R.layout.fg_action_card_scan + + override fun getAction(): Action = Action.Scan +} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/SignActionFragment.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/SignActionFragment.kt new file mode 100644 index 0000000000..82dee2a968 --- /dev/null +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/SignActionFragment.kt @@ -0,0 +1,14 @@ +package com.tangem.tangemtest.card_use_cases.ui + +import com.tangem.tangemtest.R +import com.tangem.tangemtest.commons.Action + +/** +[REDACTED_AUTHOR] + */ +class SignActionFragment : BaseCardActionFragment() { + + override fun getLayoutId(): Int = R.layout.fg_action_card_sign + + override fun getAction(): Action = Action.Sign +} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/widgets/ParameterWidget.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/widgets/ParameterWidget.kt new file mode 100644 index 0000000000..925fe91335 --- /dev/null +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/ui/widgets/ParameterWidget.kt @@ -0,0 +1,88 @@ +package com.tangem.tangemtest.card_use_cases.ui.widgets + +import android.text.Editable +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.tangem.common.tlv.TlvTag +import com.tangem.tangemtest.R +import com.tangem.tangemtest.card_use_cases.models.params.manager.IncomingParameter +import com.tangem.tangemtest.commons.Action +import ru.dev.gbixahue.eu4d.lib.android.global.log.Log +import ru.dev.gbixahue.eu4d.lib.kotlin.stringOf + +/** +[REDACTED_AUTHOR] + */ +class ParameterWidget(parent: View, private val model: IncomingParameter) { + + private val tvName: TextView = parent.findViewById(R.id.tv_param_name) + private val etValue: EditText = parent.findViewById(R.id.tv_param_value) + private val btnAction: Button = parent.findViewById(R.id.btn_action) + private val valueWatcher: TextWatcher by lazy { getWatcher() } + + val tlvTag: TlvTag = model.tlvTag + + private var parameterActionStorage: (() -> Unit)? = null + var onParameterAction: (() -> Unit)? = null + set(value) { + TransitionManager.beginDelayedTransition(etValue.parent as ViewGroup, AutoTransition()) + if (value != null) { + parameterActionStorage = value + setActionButtonTitle() + btnAction.visibility = View.VISIBLE + } else { + btnAction.visibility = View.GONE + } + field = value + } + + var onParameterValueChanged: ((IncomingParameter) -> Unit)? = null + + init { + tvName.text = model.tlvTag.name + etValue.addTextChangedListener(valueWatcher) + btnAction.setOnClickListener { onParameterAction?.invoke() } + } + + private fun setActionButtonTitle() { + val action = when (model.tlvTag) { + TlvTag.CardId -> Action.Scan + else -> Action.Unknown + } + btnAction.setText(action.resName) + } + + private fun getWatcher(): TextWatcher { + return object : TextWatcher { + override fun afterTextChanged(s: Editable?) { + val newValue = stringOf(s) + onParameterAction = if (newValue.isEmpty() && onParameterAction == null) parameterActionStorage + else null + model.data = newValue + onParameterValueChanged?.invoke(model) + } + + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} + + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} + } + } + + fun changeParamValue(data: Any?, silent: Boolean = true) { + Log.d(this, "changeParamValue: tag: $tlvTag, value: $data") + if (silent) { + etValue.removeTextChangedListener(valueWatcher) + etValue.setText(stringOf(data)) + etValue.addTextChangedListener(valueWatcher) + } else { + etValue.setText(stringOf(data)) + } + onParameterAction = null + } +} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/view_models/ParamsViewModel.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/view_models/ParamsViewModel.kt new file mode 100644 index 0000000000..407c9e2056 --- /dev/null +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/card_use_cases/view_models/ParamsViewModel.kt @@ -0,0 +1,145 @@ +package com.tangem.tangemtest.card_use_cases.view_models + +import androidx.annotation.UiThread +import androidx.fragment.app.FragmentActivity +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.google.gson.GsonBuilder +import com.tangem.common.tlv.TlvTag +import com.tangem.tangemtest.card_use_cases.models.CardContext +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.models.params.manager.ParamsManagerFactory +import com.tangem.tangemtest.commons.Action +import com.tangem.tangemtest.commons.performAction +import com.tangem.tangemtest.commons.postUI +import com.tangem.tasks.ScanEvent +import com.tangem.tasks.TaskError +import com.tangem.tasks.TaskEvent + +/** +[REDACTED_AUTHOR] + */ +class ParamsViewModel : ViewModel() { + val ldResponse: MutableLiveData = MutableLiveData() + val ldError: MutableLiveData = MutableLiveData() + val ldIncomingParameter: MutableLiveData = MutableLiveData() + + lateinit var ldCardContext: MutableLiveData + private set + + private lateinit var ldParamsManager: LiveData + private lateinit var notifier: Notifier + + // call before any subscriptions + fun init(context: FragmentActivity, action: Action) { + if (::ldCardContext.isInitialized && ::ldParamsManager.isInitialized) return + + val factory = ParamsManagerFactory.createFactory() + val manager = factory.get(action) ?: throw NotImplementedError( + "ParamsManager for the ${context.getString(action.resName)} not implemented yet") + + ldParamsManager = MutableLiveData(manager) + ldCardContext = MutableLiveData(CardContext().init(context)) + notifier = Notifier(this) + } + + fun getInitialParams(): List? { + return ldParamsManager.value?.getParams() + } + + fun userChangedParameter(param: IncomingParameter) { + parameterChanged(param.tlvTag, param.data) + } + + private fun parameterChanged(tlvTag: TlvTag, value: Any?) { + ldParamsManager.value?.parameterChanged(tlvTag, value) { notifier.notifyParameterChanges(it) } + } + + //invokes Scan, Sign etc... + fun invokeMainAction() { + performAction(ldParamsManager.value, ldCardContext.value?.cardManager) { paramsManager, cardManager -> + paramsManager.invokeMainAction(cardManager) { response, listOfChangedParams -> + notifier.handleActionResult(response, listOfChangedParams) + } + } + } + + fun getParameterAction(tag: TlvTag): (() -> Unit)? { + val paramsManager = ldParamsManager.value ?: return null + val cardManager = ldCardContext.value?.cardManager ?: return null + val parameterFunction = paramsManager.getActionByTag(tag, cardManager) ?: return null + + return { + parameterFunction { response, listOfChangedParams -> + notifier.handleActionResult(response, listOfChangedParams) + } + } + } +} + +internal class Notifier(private val vm: ParamsViewModel) { + + private val gsonConverter = GsonBuilder().setPrettyPrinting().create() + private var notShowedError: TaskError? = null + + fun handleActionResult(response: TaskEvent<*>, list: List) { + postUI { notifyParameterChanges(list) } + handleResponse(response) + } + + @UiThread + fun notifyParameterChanges(list: List) { + list.forEach { vm.ldIncomingParameter.value = it } + } + + fun handleResponse(response: TaskEvent<*>) { + val taskEvent = response as? TaskEvent<*> ?: return + + postUI { + when (taskEvent) { + is TaskEvent.Completion -> handleCompletionEvent(taskEvent) + is TaskEvent.Event -> handleDataEvent(taskEvent.data) + } + } + } + + @UiThread + private fun handleDataEvent(event: Any?) { + when (event) { + is ScanEvent.OnReadEvent -> { + val cardContext = vm.ldCardContext.value ?: return + + cardContext.card = event.card + vm.ldCardContext.value = cardContext + vm.ldResponse.value = gsonConverter.toJson(event) + } + is ScanEvent.OnVerifyEvent -> { + val cardContext = vm.ldCardContext.value ?: return + + cardContext.isVerified = true + vm.ldCardContext.value = cardContext + + } + else -> vm.ldResponse.value = gsonConverter.toJson(event) + } + + } + + @UiThread + private fun handleCompletionEvent(taskEvent: TaskEvent.Completion<*>) { + val error: TaskError = taskEvent.error ?: return + when (error) { + is TaskError.UserCancelled -> { + if (notShowedError == null) { + vm.ldError.value = "User was cancelled" + } else { + vm.ldError.value = "Error description not implemented. Code: ${notShowedError!!.code}" + notShowedError = null + } + } + else -> notShowedError = error + } + } +} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/commons/abstracts.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/commons/abstracts.kt index 3ca51329f8..b58468b10e 100644 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/commons/abstracts.kt +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/commons/abstracts.kt @@ -5,8 +5,4 @@ package com.tangem.tangemtest.commons */ interface LayoutHolder { fun getLayoutId(): Int -} - -interface Bindable { - fun bind(data: T) } \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/commons/di.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/commons/di.kt deleted file mode 100644 index fdea2ad5af..0000000000 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/commons/di.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.tangem.tangemtest.commons - -import android.content.Context -import androidx.fragment.app.Fragment -import com.tangem.tangemtest.card_use_cases.CardContext - -/** -[REDACTED_AUTHOR] - */ - -interface DiManager { - fun getCardContext(): CardContext -} - -fun Context.getDiManager(): DiManager = applicationContext as DiManager - -fun Fragment.getDiManager(): DiManager = activity?.applicationContext as DiManager \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/commons/global_func.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/commons/global_func.kt new file mode 100644 index 0000000000..7a19cf981f --- /dev/null +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/commons/global_func.kt @@ -0,0 +1,8 @@ +package com.tangem.tangemtest.commons + +/** +[REDACTED_AUTHOR] + */ +fun performAction(a: A?, b: B?, action: (A, B) -> Unit) { + if (a != null && b != null) action(a, b) +} \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/commons/logs.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/commons/logs.kt new file mode 100644 index 0000000000..0d903aa79a --- /dev/null +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/commons/logs.kt @@ -0,0 +1,8 @@ +package com.tangem.tangemtest.commons + +import ru.dev.gbixahue.eu4d.lib.android.global.log.CLogger + +/** +[REDACTED_AUTHOR] + */ +class TangemLogger : CLogger("TangemDemo") \ No newline at end of file diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/commons/navigation.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/commons/navigation.kt index 0ad3b205ff..c4acf6935e 100644 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/commons/navigation.kt +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/commons/navigation.kt @@ -1,9 +1,9 @@ package com.tangem.tangemtest.commons +import androidx.annotation.StringRes import androidx.navigation.NavOptions import androidx.navigation.navOptions import com.tangem.tangemtest.R -import com.tangem.tangemtest.card_use_cases.actions.Action /** [REDACTED_AUTHOR] @@ -20,4 +20,18 @@ fun getDefaultNavigationOptions(): NavOptions { } } -data class NavigateAction(val action: Action, val destinationId: Int) \ No newline at end of file +data class NavigateOptions(val name: Action, val destinationId: Int) + +enum class Action(@StringRes val resName: Int) { + Scan(R.string.action_card_scan), + Sign(R.string.action_card_sign), + CreateWallet(R.string.action_wallet_create), + PurgeWallet(R.string.action_wallet_purge), + ReadIssuerData(R.string.action_issuer_read_data), + WriteIssuerData(R.string.action_issuer_write_data), + ReadIssuerExData(R.string.action_issuer_read_ex_data), + WriteIssuerExData(R.string.action_issuer_write_ex_data), + ReadUserData(R.string.action_user_read_data), + WriteUserData(R.string.action_user_write_data), + Unknown(R.string.unknown), +} \ No newline at end of file diff --git a/tangem-demo/src/main/res/color/mtrl_fab_bg_color_selector.xml b/tangem-demo/src/main/res/color/mtrl_fab_bg_color_selector.xml new file mode 100644 index 0000000000..50497e70d6 --- /dev/null +++ b/tangem-demo/src/main/res/color/mtrl_fab_bg_color_selector.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tangem-demo/src/main/res/color/mtrl_fab_icon_text_color_selector.xml b/tangem-demo/src/main/res/color/mtrl_fab_icon_text_color_selector.xml new file mode 100644 index 0000000000..f02e7d7348 --- /dev/null +++ b/tangem-demo/src/main/res/color/mtrl_fab_icon_text_color_selector.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tangem-demo/src/main/res/layout/activity_test_user_data.xml b/tangem-demo/src/main/res/layout/activity_test_user_data.xml index 261a6efd64..7b571ab9b6 100644 --- a/tangem-demo/src/main/res/layout/activity_test_user_data.xml +++ b/tangem-demo/src/main/res/layout/activity_test_user_data.xml @@ -93,7 +93,7 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tangem-demo/src/main/res/layout/fg_action_card_sign.xml b/tangem-demo/src/main/res/layout/fg_action_card_sign.xml new file mode 100644 index 0000000000..2a3ad5529a --- /dev/null +++ b/tangem-demo/src/main/res/layout/fg_action_card_sign.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tangem-demo/src/main/res/layout/fg_card_scan.xml b/tangem-demo/src/main/res/layout/fg_card_scan.xml deleted file mode 100644 index e8efc318bc..0000000000 --- a/tangem-demo/src/main/res/layout/fg_card_scan.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/tangem-demo/src/main/res/layout/fg_card_sign.xml b/tangem-demo/src/main/res/layout/fg_card_sign.xml deleted file mode 100644 index ea78e82cdb..0000000000 --- a/tangem-demo/src/main/res/layout/fg_card_sign.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/tangem-demo/src/main/res/layout/m_delimiter_h.xml b/tangem-demo/src/main/res/layout/m_delimiter_h.xml deleted file mode 100644 index 4cf2bb6fbf..0000000000 --- a/tangem-demo/src/main/res/layout/m_delimiter_h.xml +++ /dev/null @@ -1,7 +0,0 @@ - - \ No newline at end of file diff --git a/tangem-demo/src/main/res/layout/m_divider_h.xml b/tangem-demo/src/main/res/layout/m_divider_h.xml new file mode 100644 index 0000000000..4a5dbcbae5 --- /dev/null +++ b/tangem-demo/src/main/res/layout/m_divider_h.xml @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/tangem-demo/src/main/res/layout/m_divider_v.xml b/tangem-demo/src/main/res/layout/m_divider_v.xml new file mode 100644 index 0000000000..dd56a750c9 --- /dev/null +++ b/tangem-demo/src/main/res/layout/m_divider_v.xml @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/tangem-demo/src/main/res/layout/vh_actions.xml b/tangem-demo/src/main/res/layout/vh_actions.xml index e1ebc1d1a6..52f7d4a9bf 100644 --- a/tangem-demo/src/main/res/layout/vh_actions.xml +++ b/tangem-demo/src/main/res/layout/vh_actions.xml @@ -2,30 +2,20 @@ - - + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:text="Action method" /> \ No newline at end of file diff --git a/tangem-demo/src/main/res/layout/w_action_response_json.xml b/tangem-demo/src/main/res/layout/w_action_response_json.xml new file mode 100644 index 0000000000..bbd0eee8ae --- /dev/null +++ b/tangem-demo/src/main/res/layout/w_action_response_json.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/tangem-demo/src/main/res/layout/w_card_incoming_param.xml b/tangem-demo/src/main/res/layout/w_card_incoming_param.xml new file mode 100644 index 0000000000..8e60a09379 --- /dev/null +++ b/tangem-demo/src/main/res/layout/w_card_incoming_param.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + +