Updated on 2026-08-14
This commit is contained in:
parent
a38813b2be
commit
ba9506e48d
14 changed files with 122 additions and 53 deletions
|
|
@ -4,7 +4,6 @@ import android.content.ClipData
|
|||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
|
||||
/**
|
||||
|
|
@ -17,11 +16,7 @@ fun Context.copyToClipboard(value: Any, label: String = "") {
|
|||
clipboard.setPrimaryClip(clip)
|
||||
}
|
||||
|
||||
fun Fragment.shareText(text: String) {
|
||||
requireActivity().shareText(text)
|
||||
}
|
||||
|
||||
fun ComponentActivity.shareText(text: String) {
|
||||
fun Context.shareText(text: String) {
|
||||
val sendIntent: Intent = Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_TEXT, text)
|
||||
|
|
@ -29,4 +24,8 @@ fun ComponentActivity.shareText(text: String) {
|
|||
}
|
||||
val shareIntent = Intent.createChooser(sendIntent, null)
|
||||
startActivity(shareIntent)
|
||||
}
|
||||
|
||||
fun Fragment.shareText(text: String) {
|
||||
requireContext().shareText(text)
|
||||
}
|
||||
|
|
@ -7,10 +7,7 @@ import com.tangem.devkit.commons.Store
|
|||
import com.tangem.devkit.ucase.domain.actions.PersonalizeAction
|
||||
import com.tangem.devkit.ucase.domain.paramsManager.ActionCallback
|
||||
import com.tangem.devkit.ucase.variants.personalize.converter.PersonalizationConfigConverter
|
||||
import com.tangem.devkit.ucase.variants.personalize.converter.PersonalizationJsonConverter
|
||||
import com.tangem.devkit.ucase.variants.personalize.dto.PersonalizationConfig
|
||||
import com.tangem.devkit.ucase.variants.personalize.dto.PersonalizationJson
|
||||
import ru.dev.gbixahue.eu4d.lib.android.global.log.Log
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
|
|
@ -30,27 +27,6 @@ class PersonalizationItemsManager(
|
|||
action.executeMainAction(this, getAttrsForAction(tangemSdk), callback)
|
||||
}
|
||||
|
||||
fun importJsonConfig(jsonString: String) {
|
||||
if (jsonString.isEmpty()) return
|
||||
|
||||
val jsonDto = try {
|
||||
PersonalizationJson.getJsonConverter().fromJson(jsonString, PersonalizationJson::class.java)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(this, "Can't convert imported string to Json object. Error: $ex")
|
||||
return
|
||||
}
|
||||
|
||||
val config = PersonalizationJsonConverter().aToB(jsonDto)
|
||||
updateByItemList(converter.convert(config))
|
||||
}
|
||||
|
||||
fun exportJsonConfig(): String {
|
||||
val config = converter.convert(itemList, PersonalizationConfig.default())
|
||||
val jsonDto = PersonalizationJsonConverter().bToA(config)
|
||||
val jsonString = PersonalizationJson.getJsonConverter().toJson(jsonDto)
|
||||
return jsonString
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
fun onDestroy() {
|
||||
val config = converter.convert(itemList, PersonalizationConfig.default())
|
||||
|
|
|
|||
|
|
@ -71,9 +71,9 @@ class ItemsToPersonalizationConfig : ItemsToModel<PersonalizationConfig> {
|
|||
export.requireTerminalTxSignature = getTyped(SignHashExPropId.RequireTerminalTxSig)
|
||||
export.checkPIN3onCard = getTyped(SignHashExPropId.CheckPin3)
|
||||
export.itsToken = getTyped(TokenId.ItsToken)
|
||||
export.cardData.token_symbol = getTyped(TokenId.Symbol)
|
||||
export.cardData.token_contract_address = getTyped(TokenId.ContractAddress)
|
||||
export.cardData.token_decimal = getTyped(TokenId.Decimal)
|
||||
export.cardData.token_symbol = getTypedUnsafe(TokenId.Symbol)
|
||||
export.cardData.token_contract_address = getTypedUnsafe(TokenId.ContractAddress)
|
||||
export.cardData.token_decimal = getTypedUnsafe(TokenId.Decimal)
|
||||
export.cardData = export.cardData.apply { this.product_note = getTyped(ProductMaskId.Note) }
|
||||
export.cardData = export.cardData.apply { this.product_tag = getTyped(ProductMaskId.Tag) }
|
||||
export.cardData = export.cardData.apply { this.product_id_card = getTyped(ProductMaskId.IdCard) }
|
||||
|
|
@ -114,6 +114,10 @@ class ItemsToPersonalizationConfig : ItemsToModel<PersonalizationConfig> {
|
|||
return getTypedBy<Type>(valuesHolder, id)!!
|
||||
}
|
||||
|
||||
private inline fun <reified Type> getTypedUnsafe(id: Id): Type? {
|
||||
return getTypedBy<Type>(valuesHolder, id)
|
||||
}
|
||||
|
||||
private inline fun <reified Type> getTypedBy(holder: ConfigValuesHolder, id: Id): Type? {
|
||||
Log.d(this, "getTyped for id: $id")
|
||||
var typedValue = holder.get(id)?.get()
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import androidx.recyclerview.widget.DividerItemDecoration
|
|||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.transition.Fade
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.tangem.commands.Card
|
||||
import com.tangem.devkit.R
|
||||
import com.tangem.devkit._arch.structure.Id
|
||||
|
|
@ -25,6 +26,7 @@ import com.tangem.devkit.commons.DialogController
|
|||
import com.tangem.devkit.commons.view.MultiActionView
|
||||
import com.tangem.devkit.commons.view.ViewAction
|
||||
import com.tangem.devkit.extensions.copyToClipboard
|
||||
import com.tangem.devkit.extensions.shareText
|
||||
import com.tangem.devkit.extensions.view.beginDelayedTransition
|
||||
import com.tangem.devkit.ucase.domain.paramsManager.ItemsManager
|
||||
import com.tangem.devkit.ucase.domain.paramsManager.PayloadKey
|
||||
|
|
@ -132,6 +134,7 @@ class PersonalizationFragment : BaseCardActionFragment(), PersonalizationPresetV
|
|||
fun initImportExportJson(parent: ViewGroup) {
|
||||
val tvJsonExport = parent.findViewById<EditText>(R.id.et_json_export)
|
||||
val btnExportJson = parent.findViewById<Button>(R.id.btn_export_json)
|
||||
val presetManager = PersonalizationPresetManager(itemsManager, this)
|
||||
|
||||
tvJsonExport.setOnClickListener {
|
||||
val jsonString = tvJsonExport.text
|
||||
|
|
@ -139,13 +142,13 @@ class PersonalizationFragment : BaseCardActionFragment(), PersonalizationPresetV
|
|||
requireContext().copyToClipboard(jsonString, "Exported Json")
|
||||
}
|
||||
btnExportJson.setOnClickListener {
|
||||
tvJsonExport.setText(personalizationItemsManager.exportJsonConfig())
|
||||
tvJsonExport.setText(presetManager.exportJsonConfig())
|
||||
}
|
||||
|
||||
val tvJsonImport = parent.findViewById<EditText>(R.id.et_json_import)
|
||||
val btnImportJson = parent.findViewById<Button>(R.id.btn_import_json)
|
||||
btnImportJson.setOnClickListener {
|
||||
personalizationItemsManager.importJsonConfig(tvJsonImport.text.toString().trim())
|
||||
presetManager.importJsonConfig(tvJsonImport.text.toString().trim())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -168,11 +171,13 @@ class PersonalizationFragment : BaseCardActionFragment(), PersonalizationPresetV
|
|||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
val store = PersonalizationConfigStore(requireContext())
|
||||
val presetManager = PersonalizationPresetManager(itemsManager, store, this)
|
||||
val presetManager = PersonalizationPresetManager(itemsManager, this)
|
||||
val result = when (item.itemId) {
|
||||
R.id.action_reset -> presetManager.resetToDefault()
|
||||
R.id.action_save -> presetManager.savePreset()
|
||||
R.id.action_load -> presetManager.loadPreset()
|
||||
R.id.action_import_preset -> showImportPresetDialog(presetManager)
|
||||
R.id.action_share_preset -> shareText(presetManager.exportJsonConfig())
|
||||
R.id.action_reset -> presetManager.resetToDefault(store)
|
||||
R.id.action_save -> presetManager.savePreset(store)
|
||||
R.id.action_load -> presetManager.loadPreset(store)
|
||||
else -> null
|
||||
}
|
||||
return if (result == null) super.onOptionsItemSelected(item) else true
|
||||
|
|
@ -191,13 +196,16 @@ class PersonalizationFragment : BaseCardActionFragment(), PersonalizationPresetV
|
|||
override fun showSavePresetDialog(onOk: SafeValueChanged<String>) {
|
||||
val dlgController = DialogController()
|
||||
val dlg = dlgController.createAlert(requireActivity(), R.layout.dlg_personalization_preset_save)
|
||||
dlgController.view?.findViewById<TextInputLayout>(R.id.til_item)?.let {
|
||||
it.hint = getString(R.string.hint_enter_preset_name)
|
||||
}
|
||||
dlg.setTitle(R.string.menu_personalization_preset_save)
|
||||
dlg.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.btn_cancel)) { dialog, which -> }
|
||||
dlg.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.btn_ok)) { dialog, which ->
|
||||
val tvName = dlgController.view?.findViewById<EditText>(R.id.et_item)
|
||||
?: return@setButton
|
||||
val name = tvName.text.toString()
|
||||
if (name.isEmpty()) showSnackbar("Not saved")
|
||||
if (name.isEmpty()) showSnackbar(R.string.error_not_saved)
|
||||
else onOk.invoke(name)
|
||||
}
|
||||
dlgController.onShowCallback = {
|
||||
|
|
@ -235,4 +243,30 @@ class PersonalizationFragment : BaseCardActionFragment(), PersonalizationPresetV
|
|||
rvPresetNames.adapter = adapter
|
||||
dlgController.show()
|
||||
}
|
||||
|
||||
private fun showImportPresetDialog(presetManager: PersonalizationPresetManager) {
|
||||
val dlgController = DialogController()
|
||||
val dlg = dlgController.createAlert(requireActivity(), R.layout.dlg_personalization_preset_save)
|
||||
dlgController.view?.findViewById<TextInputLayout>(R.id.til_item)?.let {
|
||||
it.hint = getString(R.string.hint_paste)
|
||||
}
|
||||
dlg.setTitle(R.string.menu_personalization_preset_import)
|
||||
dlg.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.btn_cancel)) { dialog, which -> }
|
||||
dlg.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.btn_ok)) { dialog, which ->
|
||||
val tvName = dlgController.view?.findViewById<EditText>(R.id.et_item) ?: return@setButton
|
||||
val name = tvName.text.toString()
|
||||
if (name.isEmpty()) showSnackbar(R.string.error_nothing_to_import)
|
||||
else presetManager.importJsonConfig(name)
|
||||
}
|
||||
dlgController.onShowCallback = {
|
||||
dlgController.view?.findViewById<TextView>(R.id.et_item)?.let {
|
||||
post(150) {
|
||||
it.requestFocus()
|
||||
val imm = getSystemService(requireContext(), InputMethodManager::class.java)
|
||||
imm?.showSoftInput(it, InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
}
|
||||
dlgController.show()
|
||||
}
|
||||
}
|
||||
|
|
@ -4,22 +4,23 @@ import com.tangem.devkit.R
|
|||
import com.tangem.devkit.ucase.domain.paramsManager.ItemsManager
|
||||
import com.tangem.devkit.ucase.variants.personalize.PersonalizationConfigStore
|
||||
import com.tangem.devkit.ucase.variants.personalize.converter.PersonalizationConfigConverter
|
||||
import com.tangem.devkit.ucase.variants.personalize.converter.PersonalizationJsonConverter
|
||||
import com.tangem.devkit.ucase.variants.personalize.dto.PersonalizationConfig
|
||||
import com.tangem.devkit.ucase.variants.personalize.dto.PersonalizationJson
|
||||
|
||||
class PersonalizationPresetManager(
|
||||
private val itemsManager: ItemsManager,
|
||||
private val store: PersonalizationConfigStore,
|
||||
private val view: PersonalizationPresetView
|
||||
) {
|
||||
|
||||
fun resetToDefault() {
|
||||
fun resetToDefault(store: PersonalizationConfigStore) {
|
||||
val config = PersonalizationConfig.default()
|
||||
val converter = PersonalizationConfigConverter()
|
||||
itemsManager.updateByItemList(converter.convert(config))
|
||||
store.save(config)
|
||||
}
|
||||
|
||||
fun loadPreset() {
|
||||
fun loadPreset(store: PersonalizationConfigStore) {
|
||||
val presets = store.restoreAll()
|
||||
presets.remove(PersonalizationConfigStore.defaultKey)
|
||||
val namesList = presets.map { it.key }.toMutableList()
|
||||
|
|
@ -37,11 +38,34 @@ class PersonalizationPresetManager(
|
|||
})
|
||||
}
|
||||
|
||||
fun savePreset() {
|
||||
fun savePreset(store: PersonalizationConfigStore) {
|
||||
view.showSavePresetDialog { name ->
|
||||
val converter = PersonalizationConfigConverter()
|
||||
val config = converter.convert(itemsManager.getItems(), PersonalizationConfig.default())
|
||||
store.save(name, config)
|
||||
}
|
||||
}
|
||||
|
||||
fun importJsonConfig(jsonString: String) {
|
||||
if (jsonString.isEmpty()) return
|
||||
|
||||
val jsonDto = try {
|
||||
PersonalizationJson.getJsonConverter().fromJson(jsonString, PersonalizationJson::class.java)
|
||||
} catch (ex: Exception) {
|
||||
view.showSnackbar("Can't convert imported string to Json object. Error: $ex")
|
||||
return
|
||||
}
|
||||
|
||||
val config = PersonalizationJsonConverter().aToB(jsonDto)
|
||||
val converter = PersonalizationConfigConverter()
|
||||
itemsManager.updateByItemList(converter.convert(config))
|
||||
}
|
||||
|
||||
fun exportJsonConfig(): String {
|
||||
val converter = PersonalizationConfigConverter()
|
||||
val config = converter.convert(itemsManager.getItems(), PersonalizationConfig.default())
|
||||
val jsonDto = PersonalizationJsonConverter().bToA(config)
|
||||
val jsonString = PersonalizationJson.getJsonConverter().toJson(jsonDto)
|
||||
return jsonString
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue