Skip to content

Commit

Permalink
ledger fixes (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorokin0andrey authored Oct 9, 2024
1 parent f54f11d commit 840c601
Show file tree
Hide file tree
Showing 19 changed files with 218 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ fun String.withVerificationIcon(context: Context): CharSequence {
builder.append(" X")
builder.setSpan(ImageSpanCompat(drawable), builder.length - 1, builder.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
return builder
}
}

fun String.isPrintableAscii(): Boolean {
return this.all { it.code in 32..126 }
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PushScreen: BaseFragment(R.layout.fragment_notifications_enable) {
button.setOnClickListener { requestPermission() }

val offsetMedium = requireContext().getDimensionPixelSize(uikit.R.dimen.offsetMedium)
val offsetLarge = requireContext().getDimensionPixelSize(uikit.R.dimen.offsetLarge)

ViewCompat.setOnApplyWindowInsetsListener(view) { _, insets ->
val systemBarInsets = insets.getInsets(WindowInsetsCompat.Type.statusBars() + WindowInsetsCompat.Type.navigationBars())
Expand All @@ -45,7 +46,7 @@ class PushScreen: BaseFragment(R.layout.fragment_notifications_enable) {
}

button.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = systemBarInsets.bottom + offsetMedium
bottomMargin = systemBarInsets.bottom + offsetLarge
}
insets
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package com.tonapps.tonkeeper.ui.screen.init.step
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.core.widget.NestedScrollView
import androidx.recyclerview.widget.RecyclerView
import com.tonapps.blockchain.ton.extensions.toRawAddress
import com.tonapps.tonkeeper.ui.screen.init.InitEvent
import com.tonapps.tonkeeper.ui.screen.init.InitRoute
import com.tonapps.tonkeeper.ui.screen.init.InitViewModel
import com.tonapps.tonkeeper.ui.screen.init.list.AccountItem
Expand All @@ -19,43 +17,44 @@ import uikit.base.BaseFragment
import uikit.extensions.applyNavBottomPadding
import uikit.extensions.collectFlow
import uikit.extensions.getDimensionPixelSize
import uikit.extensions.pinToBottomInsets

class SelectScreen: BaseFragment(R.layout.fragment_init_select) {
class SelectScreen : BaseFragment(R.layout.fragment_init_select) {

private val initViewModel: InitViewModel by viewModel(ownerProducer = { requireParentFragment() })

private val adapter = Adapter { account, checked ->
initViewModel.toggleAccountSelection(account.address.toRawAddress(), checked)
}

private lateinit var scrollView: NestedScrollView
private lateinit var containerView: View
private lateinit var listView: RecyclerView
private lateinit var button: Button
private lateinit var buttonContainerView: View

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

scrollView = view.findViewById(R.id.scroll)
containerView = view.findViewById(R.id.container)

listView = view.findViewById(R.id.accounts)
listView.adapter = adapter
listView.applyNavBottomPadding(requireContext().getDimensionPixelSize(uikit.R.dimen.offsetMedium))
listView.applyNavBottomPadding(requireContext().getDimensionPixelSize(uikit.R.dimen.offsetLarge))

button = view.findViewById(R.id.button)
button.setOnClickListener {
initViewModel.nextStep(requireContext(), InitRoute.SelectAccount)
}

buttonContainerView = view.findViewById(R.id.button_container)
buttonContainerView.applyNavBottomPadding(requireContext().getDimensionPixelSize(uikit.R.dimen.offsetLarge))

collectFlow(initViewModel.uiTopOffset) {
view.updatePadding(top = it)
containerView.updatePadding(top = it)
}

collectFlow(initViewModel.accountsFlow, ::setItems)

ViewCompat.setOnApplyWindowInsetsListener(view) { _, insets ->
val insetsNav = insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom
val bottom = insetsNav + requireContext().getDimensionPixelSize(uikit.R.dimen.offsetMedium)
listView.updatePadding(bottom = bottom)
button.translationY = -bottom.toFloat()
insets
}
}

private fun setItems(items: List<AccountItem>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.tonapps.tonkeeper.ui.screen.ledger.pair

import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.lifecycle.lifecycleScope
import com.tonapps.tonkeeper.extensions.toast
import com.tonapps.tonkeeper.ui.screen.ledger.steps.LedgerConnectionFragment
Expand All @@ -15,7 +14,9 @@ import kotlinx.coroutines.launch
import org.koin.androidx.viewmodel.ext.android.activityViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
import uikit.base.BaseFragment
import uikit.extensions.applyNavBottomPadding
import uikit.extensions.collectFlow
import uikit.extensions.getDimensionPixelSize
import uikit.navigation.Navigation.Companion.navigation
import uikit.widget.LoadableButton

Expand All @@ -34,10 +35,14 @@ class PairLedgerScreen : BaseFragment(R.layout.fragment_ledger_pair), BaseFragme
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

view.findViewById<View>(R.id.container)
.applyNavBottomPadding(requireContext().getDimensionPixelSize(uikit.R.dimen.offsetMedium))

continueButton = view.findViewById(R.id.continue_button)

view.findViewById<View>(R.id.close).setOnClickListener { finish() }
view.findViewById<View>(R.id.cancel).setOnClickListener { finish() }
continueButton.isEnabled = false
continueButton.setOnClickListener {
lifecycleScope.launch(Dispatchers.IO) { connectionViewModel.getConnectData() }
}
Expand All @@ -51,21 +56,25 @@ class PairLedgerScreen : BaseFragment(R.layout.fragment_ledger_pair), BaseFragme
}

private fun onEvent(event: LedgerEvent) {
when(event) {
when (event) {
is LedgerEvent.Ready -> {
continueButton.isEnabled = event.isReady
}

is LedgerEvent.Loading -> {
continueButton.isLoading = event.loading
}

is LedgerEvent.Error -> {
navigation?.toast(event.message)
}

is LedgerEvent.Next -> {
rootViewModel.connectLedger(event.connectData, event.accounts)
finish()
}
else -> { }

else -> {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import com.tonapps.tonkeeperx.R
import kotlinx.coroutines.launch
import org.koin.androidx.viewmodel.ext.android.viewModel
import uikit.base.BaseFragment
import uikit.extensions.applyNavBottomPadding
import uikit.extensions.collectFlow
import uikit.extensions.getDimensionPixelSize
import uikit.navigation.Navigation.Companion.navigation
import java.math.BigInteger

Expand All @@ -39,6 +41,8 @@ class LedgerProofScreen : BaseFragment(R.layout.fragment_ledger_sign), BaseFragm
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

view.findViewById<View>(R.id.container)
.applyNavBottomPadding(requireContext().getDimensionPixelSize(uikit.R.dimen.offsetMedium))

view.findViewById<View>(R.id.close).setOnClickListener { finish() }
view.findViewById<View>(R.id.cancel).setOnClickListener { finish() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import kotlinx.coroutines.launch
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.ton.cell.Cell
import uikit.base.BaseFragment
import uikit.extensions.applyNavBottomPadding
import uikit.extensions.collectFlow
import uikit.extensions.getDimensionPixelSize
import uikit.navigation.Navigation.Companion.navigation

class LedgerSignScreen: BaseFragment(R.layout.fragment_ledger_sign), BaseFragment.Modal {
Expand All @@ -39,6 +41,8 @@ class LedgerSignScreen: BaseFragment(R.layout.fragment_ledger_sign), BaseFragmen
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

view.findViewById<View>(R.id.container)
.applyNavBottomPadding(requireContext().getDimensionPixelSize(uikit.R.dimen.offsetMedium))

view.findViewById<View>(R.id.close).setOnClickListener { finish() }
view.findViewById<View>(R.id.cancel).setOnClickListener { finish() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.util.TypedValue
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.content.ContextCompat
import androidx.core.content.PermissionChecker
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import com.tonapps.tonkeeper.ui.screen.ledger.steps.list.Adapter
Expand All @@ -27,7 +24,6 @@ import com.tonapps.wallet.localization.Localization
import org.koin.androidx.viewmodel.ext.android.viewModel
import uikit.dialog.alert.AlertDialog
import uikit.extensions.collectFlow
import uikit.extensions.context
import uikit.extensions.dp
import uikit.extensions.hasPermission

Expand Down Expand Up @@ -64,6 +60,10 @@ class LedgerConnectionFragment : Fragment(R.layout.fragment_ledger_steps) {
private lateinit var ledgerDisplayView: LinearLayout
private lateinit var ledgerDisplayText: TextView

private var blFadeAnim: ObjectAnimator? = null
private var displayFadeAnim: ObjectAnimator? = null
private var translationX: ObjectAnimator? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand Down Expand Up @@ -132,10 +132,14 @@ class LedgerConnectionFragment : Fragment(R.layout.fragment_ledger_steps) {
}

private fun promptEnableBluetooth() {
val bluetoothAdapter: BluetoothAdapter? = BluetoothAdapter.getDefaultAdapter()
if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled) {
val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
enableBluetoothLauncher.launch(enableBtIntent)
if (isPermissionGranted()) {
val bluetoothAdapter: BluetoothAdapter? = BluetoothAdapter.getDefaultAdapter()
if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled) {
val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
enableBluetoothLauncher.launch(enableBtIntent)
}
} else {
requestPermissionLauncher.launch(blePermissions)
}
}

Expand All @@ -151,54 +155,73 @@ class LedgerConnectionFragment : Fragment(R.layout.fragment_ledger_steps) {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
hasPermission(Manifest.permission.BLUETOOTH_SCAN) && hasPermission(Manifest.permission.BLUETOOTH_CONNECT)
} else {
hasPermission(Manifest.permission.BLUETOOTH) && hasPermission(Manifest.permission.BLUETOOTH_ADMIN) && hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)
hasPermission(Manifest.permission.BLUETOOTH) && hasPermission(Manifest.permission.BLUETOOTH_ADMIN) && hasPermission(
Manifest.permission.ACCESS_FINE_LOCATION
)
}
}

private fun animateView(currentStep: LedgerStep) {
val interpolator = AccelerateDecelerateInterpolator()
val animInterpolator = AccelerateDecelerateInterpolator()

blFadeAnim?.cancel()
displayFadeAnim?.cancel()
translationX?.cancel()

if (currentStep == LedgerStep.CONNECT) {
val blFadeAnim =
blFadeAnim =
ObjectAnimator.ofFloat(bluetoothIconView, "alpha", bluetoothIconView.alpha, 1f)
blFadeAnim.duration = 300
blFadeAnim.startDelay = 200
blFadeAnim.interpolator = interpolator
blFadeAnim.start()

val displayFadeAnim =
.apply {
duration = 300
startDelay = 200
interpolator = animInterpolator
start()
}

displayFadeAnim =
ObjectAnimator.ofFloat(ledgerDisplayView, "alpha", ledgerDisplayView.alpha, 0f)
displayFadeAnim.duration = 300
displayFadeAnim.interpolator = interpolator
displayFadeAnim.start()

val translationX = ObjectAnimator.ofFloat(
ledgerView, "translationX", ledgerView.translationX, 24f.dp
)
translationX.duration = 300
translationX.startDelay = 200
translationX.interpolator = interpolator
translationX.start()
.apply {
duration = 300
interpolator = animInterpolator
start()
}

translationX =
ObjectAnimator.ofFloat(ledgerView, "translationX", ledgerView.translationX, 24f.dp)
.apply {
duration = 300
startDelay = 200
interpolator = animInterpolator
start()
}
} else {
val blFadeAnim =
blFadeAnim =
ObjectAnimator.ofFloat(bluetoothIconView, "alpha", bluetoothIconView.alpha, 0f)
blFadeAnim.duration = 300
blFadeAnim.interpolator = interpolator
blFadeAnim.start()
.apply {
duration = 300
interpolator = animInterpolator
start()
}

val displayFadeAnim =
displayFadeAnim =
ObjectAnimator.ofFloat(ledgerDisplayView, "alpha", ledgerDisplayView.alpha, 1f)
displayFadeAnim.duration = 300
displayFadeAnim.startDelay = 150
displayFadeAnim.interpolator = interpolator
displayFadeAnim.start()

val translationX = ObjectAnimator.ofFloat(
ledgerView, "translationX", ledgerView.translationX, (-42f).dp
)
translationX.duration = 350
translationX.interpolator = interpolator
translationX.start()
.apply {
duration = 300
startDelay = 150
interpolator = animInterpolator
start()
}

translationX = ObjectAnimator.ofFloat(
ledgerView,
"translationX",
ledgerView.translationX,
(-42f).dp
).apply {
duration = 350
interpolator = animInterpolator
start()
}
}
}

Expand Down
Loading

0 comments on commit 840c601

Please sign in to comment.