Skip to content

Commit

Permalink
bug fixeds
Browse files Browse the repository at this point in the history
  • Loading branch information
polstianka committed Dec 4, 2024
1 parent 3fc77ec commit 732e016
Show file tree
Hide file tree
Showing 26 changed files with 211 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ data class Theme(

private val supportedThemes = mutableListOf<Theme>()

fun clear() {
supportedThemes.clear()
}

fun getByKey(key: String): Theme {
return supportedThemes.firstOrNull { it.key == key } ?: supportedThemes.first()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.res.Configuration
import android.os.Build
import android.os.StrictMode
import android.util.Log
import android.webkit.CookieManager
import androidx.camera.camera2.Camera2Config
import androidx.camera.core.CameraXConfig
import com.facebook.drawee.backends.pipeline.Fresco
Expand Down Expand Up @@ -68,10 +69,7 @@ class App: Application(), CameraXConfig.Provider, KoinComponent {
}

super.onCreate()
Theme.add("blue", uikit.R.style.Theme_App_Blue, title = "Deep Blue")
Theme.add("dark", uikit.R.style.Theme_App_Dark, title = "Dark")
Theme.add("light", uikit.R.style.Theme_App_Light, true, "Light")
Theme.add("system", 0, title = getString(Localization.system))
updateThemes()

instance = this

Expand All @@ -84,6 +82,14 @@ class App: Application(), CameraXConfig.Provider, KoinComponent {
initFresco()
}

fun updateThemes() {
Theme.clear()
Theme.add("blue", uikit.R.style.Theme_App_Blue, title = getString(Localization.theme_deep_blue))
Theme.add("dark", uikit.R.style.Theme_App_Dark, title = getString(Localization.theme_dark))
Theme.add("light", uikit.R.style.Theme_App_Light, true, title = getString(Localization.theme_light))
Theme.add("system", 0, title = getString(Localization.system))
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
applyConfiguration(newConfig)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.tonapps.tonkeeper.extensions

import android.annotation.SuppressLint
import com.tonapps.wallet.data.account.entities.WalletEntity
import uikit.widget.webview.WebViewFixed

@SuppressLint("RequiresFeature")
fun WebViewFixed.setWallet(wallet: WalletEntity) {
val walletId = wallet.id.replace("-", "")
setProfileName(walletId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@ package com.tonapps.tonkeeper.ui.component

import android.content.Context
import android.util.AttributeSet
import android.webkit.CookieManager
import android.webkit.WebSettings
import android.webkit.WebStorage
import android.webkit.WebView
import androidx.webkit.WebViewCompat
import com.tonapps.wallet.data.account.entities.WalletEntity
import uikit.widget.webview.bridge.BridgeWebView
import java.io.File

class TonConnectWebView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.webViewStyle,
) : BridgeWebView(context, attrs, defStyle) {


fun setWallet(wallet: WalletEntity) {

init {
isVerticalScrollBarEnabled = false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class WordEditText @JvmOverloads constructor(
) : AppCompatEditText(context, attrs, defStyle) {

var doOnTextChanged: ((Editable) -> Unit)? = null
var doOnFocusChanged: ((Boolean) -> Unit)? = null

private val scope: CoroutineScope?
get() = findViewTreeLifecycleOwner()?.lifecycleScope
Expand All @@ -48,6 +49,7 @@ class WordEditText @JvmOverloads constructor(
} else {
checkValue()
}
doOnFocusChanged?.invoke(hasFocus)
}
setOnKeyListener { _, keyCode, event ->
if (keyCode != KeyEvent.KEYCODE_DEL || text?.isNotBlank() == true || event.action != KeyEvent.ACTION_UP) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.webkit.WebResourceRequest
import android.webkit.WebSettings
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
Expand All @@ -18,55 +18,31 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import androidx.lifecycle.lifecycleScope
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import androidx.webkit.WebSettingsCompat
import androidx.webkit.WebViewFeature
import com.facebook.drawee.backends.pipeline.Fresco
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.tonapps.extensions.appVersionName
import com.tonapps.extensions.bestMessage
import com.tonapps.extensions.toUriOrNull
import com.tonapps.tonkeeper.core.AnalyticsHelper
import com.tonapps.tonkeeper.deeplink.DeepLink
import com.tonapps.tonkeeper.deeplink.DeepLinkRoute
import com.tonapps.tonkeeper.extensions.copyToClipboard
import com.tonapps.tonkeeper.extensions.loadSquare
import com.tonapps.tonkeeper.extensions.normalizeTONSites
import com.tonapps.tonkeeper.extensions.setWallet
import com.tonapps.tonkeeper.extensions.toast
import com.tonapps.tonkeeper.extensions.withUtmSource
import com.tonapps.tonkeeper.koin.walletViewModel
import com.tonapps.tonkeeper.manager.tonconnect.ConnectRequest
import com.tonapps.tonkeeper.manager.tonconnect.TonConnect
import com.tonapps.tonkeeper.manager.tonconnect.TonConnectManager
import com.tonapps.tonkeeper.manager.tonconnect.bridge.BridgeException
import com.tonapps.tonkeeper.manager.tonconnect.bridge.JsonBuilder
import com.tonapps.tonkeeper.manager.tonconnect.bridge.model.BridgeError
import com.tonapps.tonkeeper.manager.tonconnect.bridge.model.BridgeEvent
import com.tonapps.tonkeeper.manager.tonconnect.bridge.model.BridgeMethod
import com.tonapps.tonkeeper.popup.ActionSheet
import com.tonapps.tonkeeper.ui.base.InjectedTonConnectScreen
import com.tonapps.tonkeeper.ui.base.WalletContextScreen
import com.tonapps.tonkeeper.ui.component.TonConnectWebView
import com.tonapps.tonkeeper.ui.screen.root.RootActivity
import com.tonapps.tonkeeper.ui.screen.root.RootViewModel
import com.tonapps.tonkeeper.ui.screen.send.transaction.SendTransactionScreen
import com.tonapps.tonkeeperx.R
import com.tonapps.uikit.color.tabBarActiveIconColor
import com.tonapps.uikit.icon.UIKitIcon
import com.tonapps.wallet.api.API
import com.tonapps.wallet.data.account.entities.WalletEntity
import com.tonapps.wallet.data.core.entity.SignRequestEntity
import com.tonapps.wallet.data.dapps.entities.AppConnectEntity
import com.tonapps.wallet.localization.Localization
import kotlinx.coroutines.launch
import org.json.JSONArray
import org.json.JSONObject
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.activityViewModel
import org.koin.core.parameter.parametersOf
import uikit.drawable.HeaderDrawable
import uikit.extensions.activity
import uikit.extensions.collectFlow
import uikit.widget.webview.WebViewFixed
import uikit.widget.webview.bridge.BridgeWebView
import java.util.concurrent.CancellationException

class DAppScreen(wallet: WalletEntity): InjectedTonConnectScreen(R.layout.fragment_dapp, wallet) {

Expand Down Expand Up @@ -167,6 +143,10 @@ class DAppScreen(wallet: WalletEntity): InjectedTonConnectScreen(R.layout.fragme
closeView.setOnClickListener { finish() }

webView = view.findViewById(R.id.web_view)
if (viewModel.isDarkTheme && WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) {
WebSettingsCompat.setAlgorithmicDarkeningAllowed(webView.settings, true)
}

webView.setWallet(wallet)
webView.settings.useWideViewPort = true
webView.settings.loadWithOverviewMode = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import com.facebook.drawee.backends.pipeline.Fresco
import com.tonapps.extensions.appVersionName
import com.tonapps.extensions.filterList
import com.tonapps.extensions.toUriOrNull
import com.tonapps.tonkeeper.extensions.isDarkMode
import com.tonapps.tonkeeper.extensions.loadSquare
import com.tonapps.tonkeeper.manager.tonconnect.TonConnectManager
import com.tonapps.tonkeeper.manager.tonconnect.bridge.JsonBuilder
import com.tonapps.tonkeeper.manager.tonconnect.bridge.model.BridgeError
import com.tonapps.tonkeeper.ui.base.BaseWalletVM
import com.tonapps.tonkeeper.ui.base.InjectedTonConnectScreen
import com.tonapps.tonkeeper.worker.DAppPushToggleWorker
import com.tonapps.tonkeeperx.R
import com.tonapps.wallet.data.account.entities.WalletEntity
import com.tonapps.wallet.data.dapps.DAppsRepository
import com.tonapps.wallet.data.dapps.entities.AppConnectEntity
import com.tonapps.wallet.data.dapps.entities.AppEntity
import com.tonapps.wallet.data.settings.SettingsRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
Expand All @@ -38,8 +41,13 @@ class DAppViewModel(
private val tonConnectManager: TonConnectManager,
override val url: Uri,
private val dAppsRepository: DAppsRepository,
private val settingsRepository: SettingsRepository,
): InjectedTonConnectScreen.ViewModel(app, wallet, tonConnectManager) {

val isDarkTheme: Boolean
get() = settingsRepository.theme.resId == uikit.R.style.Theme_App_Dark || context.isDarkMode


fun mute() {
DAppPushToggleWorker.run(
context = context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class EventsScreen(wallet: WalletEntity) : MainScreen.Child(R.layout.fragment_ma
setListState(state.uiItems) {
if (!state.loading && !state.isFooterLoading) {
setLoading(false)
} else {

}
}
}
Expand Down Expand Up @@ -177,10 +179,8 @@ class EventsScreen(wallet: WalletEntity) : MainScreen.Child(R.layout.fragment_ma

private fun setListState(uiItems: List<HistoryItem>, commitCallback: Runnable) {
legacyAdapter.submitList(uiItems, commitCallback)
if (refreshView.visibility != View.VISIBLE) {
emptyView.visibility = View.GONE
refreshView.visibility = View.VISIBLE
}
emptyView.visibility = View.GONE
refreshView.visibility = View.VISIBLE
}

override fun getRecyclerView(): RecyclerView? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ import uikit.navigation.Navigation.Companion.navigation
import uikit.widget.ColumnLayout
import uikit.widget.LoaderView
import uikit.widget.RowLayout
import uikit.widget.TextHeaderView

// TODO Need to refactor this screen
class WordsScreen: BaseFragment(R.layout.fragment_init_words) {

private val initViewModel: InitViewModel by viewModel(ownerProducer = { requireParentFragment() })
Expand All @@ -62,6 +64,10 @@ class WordsScreen: BaseFragment(R.layout.fragment_init_words) {
private lateinit var suggestionsView: RowLayout
private lateinit var words24View: AppCompatTextView
private lateinit var words12View: AppCompatTextView
private lateinit var titleView: TextHeaderView

private val isVisibleSuggestions: Boolean
get() = suggestionsView.visibility == View.VISIBLE && suggestionsView.alpha > 0f

private val wordInputs: List<WordEditText> by lazy {
contentView.getViews().filterIsInstance<WordEditText>()
Expand All @@ -70,6 +76,8 @@ class WordsScreen: BaseFragment(R.layout.fragment_init_words) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

titleView = view.findViewById(R.id.header_title)

words24View = view.findViewById(R.id.words_24)
words24View.setOnClickListener { setWordsCount(WORDS24) }

Expand All @@ -88,14 +96,17 @@ class WordsScreen: BaseFragment(R.layout.fragment_init_words) {
loaderView.setColor(requireContext().iconPrimaryColor)

for ((index, wordInput) in wordInputs.withIndex()) {
val isLast = index == wordInputs.size - 1
wordInput.doOnFocusChanged = { onFocusChange(index, it) }
wordInput.doOnTextChanged = { onTextChanged(index, it) }
wordInput.imeOptions = if (isLast) EditorInfo.IME_ACTION_DONE else EditorInfo.IME_ACTION_NEXT
wordInput.imeOptions = if (isLastIndex(index)) EditorInfo.IME_ACTION_DONE else EditorInfo.IME_ACTION_NEXT
wordInput.setOnEditorActionListener { _, actionId, _ ->
if (isLast && actionId == EditorInfo.IME_ACTION_DONE) {
if (actionId == EditorInfo.IME_ACTION_NEXT && isVisibleSuggestions && suggestionsView.childCount == 1) {
autoSetWord(index)
}
if (isLastIndex(index) && actionId == EditorInfo.IME_ACTION_DONE) {
next()
true
} else if (isLast && actionId == EditorInfo.IME_ACTION_NEXT) {
} else if (isLastIndex(index) && actionId == EditorInfo.IME_ACTION_NEXT) {
nextInput(index)
true
} else {
Expand All @@ -121,6 +132,10 @@ class WordsScreen: BaseFragment(R.layout.fragment_init_words) {
}
}

private fun isLastIndex(index: Int): Boolean {
return wordsCount - 1 == index
}

private fun setWordsCount(count: Int) {
if (wordsCount == count || count != WORDS24 && count != WORDS12) {
return
Expand All @@ -129,11 +144,16 @@ class WordsScreen: BaseFragment(R.layout.fragment_init_words) {
words24View.setBackgroundResource(uikit.R.drawable.bg_content_tint_16)
words12View.background = null
wordsCount = count
titleView.desciption = getString(Localization.import_wallet_description)
wordInputs[11].imeOptions = EditorInfo.IME_ACTION_NEXT
} else {
words12View.setBackgroundResource(uikit.R.drawable.bg_content_tint_16)
words24View.background = null
titleView.desciption = getString(Localization.import_wallet_description).replace("24", "12")
wordInputs[23].imeOptions = EditorInfo.IME_ACTION_NEXT
}
wordsCount = count
wordInputs[count - 1].imeOptions = EditorInfo.IME_ACTION_DONE
updateVisibleInputs()
}

Expand All @@ -150,6 +170,19 @@ class WordsScreen: BaseFragment(R.layout.fragment_init_words) {
scrollView.scrollView(nextView, false)
}

private fun autoSetWord(index: Int) {
val inputView = wordInputs.getOrNull(index) ?: return
val text = inputView.text.toString()
lifecycleScope.launch(Dispatchers.IO) {
val word = TonMnemonic.findWord(text)
if (!word.isNullOrBlank()) {
withContext(Dispatchers.Main) {
inputView.setText(word)
}
}
}
}

private fun next() {
lifecycleScope.launch {
val words = getMnemonic()
Expand Down Expand Up @@ -184,6 +217,14 @@ class WordsScreen: BaseFragment(R.layout.fragment_init_words) {
wordInputs.forEach { it.isEnabled = true }
}

private fun onFocusChange(index: Int, hasFocus: Boolean) {
if (hasFocus) {
checkSuggestions(index, wordInputs[index].text.toString())
} else {
suggestionsView.visibility = View.GONE
}
}

private fun onTextChanged(index: Int, editable: Editable) {
if (index == 0) {
val words = TonMnemonic.parseMnemonic(editable.toString())
Expand All @@ -203,16 +244,16 @@ class WordsScreen: BaseFragment(R.layout.fragment_init_words) {
}

private fun checkSuggestions(index: Int, text: String) {
if (!wordInputs[index].isFocused) {
suggestionsView.visibility = View.GONE
return
}
if (text.isEmpty()) {
if (!wordInputs[index].isFocused || text.isEmpty()) {
suggestionsView.visibility = View.GONE
} else {
lifecycleScope.launch(Dispatchers.IO) {
val words = TonMnemonic.findWords(text).take(3)
setSuggestions(index, words)
if (words.size == 1 && words.first().equals(text, true)) {
setSuggestions(index, emptyList())
} else {
setSuggestions(index, words)
}
}
}
}
Expand Down Expand Up @@ -249,9 +290,9 @@ class WordsScreen: BaseFragment(R.layout.fragment_init_words) {

val nextFocusInput = inputView.focusSearch(View.FOCUS_DOWN) as? WordEditText

if (nextFocusInput != null) {
if (nextFocusInput != null && nextFocusInput.visibility == View.VISIBLE) {
nextFocusInput.requestFocus()
if (index > 20) {
if (index > (wordsCount - 4)) {
scrollView.scrollDown(true)
} else {
scrollView.scrollView(
Expand Down
Loading

0 comments on commit 732e016

Please sign in to comment.