Commit 74c01987 authored by pokkst's avatar pokkst

[HEAVY WIP] Continue refactor and rewrite the entire app so most screens...

[HEAVY WIP] Continue refactor and rewrite the entire app so most screens utilize their own activity for better code structure, and performance.
parent d36b9290
......@@ -62,6 +62,11 @@
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
<activity android:name=".activity.DecryptWalletActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
<activity android:name=".activity.AdvancedSettingsActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
......
......@@ -16,11 +16,13 @@ import app.crescentcash.src.net.NetHelper
import app.crescentcash.src.ui.UIHelper
import app.crescentcash.src.utils.Constants
import app.crescentcash.src.utils.PermissionHelper
import app.crescentcash.src.utils.PrefsUtil
import app.crescentcash.src.wallet.SLPWalletHelper
import app.crescentcash.src.wallet.WalletHelper
import com.google.firebase.FirebaseApp
import com.google.zxing.integration.android.IntentIntegrator
import org.bitcoinj.core.Transaction
import org.bitcoinj.utils.MonetaryFormat
import java.io.File
import java.util.*
......@@ -31,7 +33,6 @@ class MainActivity : AppCompatActivity() {
lateinit var netHelper: NetHelper
lateinit var txList: ArrayList<Transaction>
lateinit var prefs: SharedPreferences
var started = false
override fun onCreate(savedInstanceState: Bundle?) {
......@@ -40,14 +41,16 @@ class MainActivity : AppCompatActivity() {
started = false
INSTANCE = this
AppManager.walletManager = WalletManager()
this.prefs = getSharedPreferences("app.crescentcash.src", Context.MODE_PRIVATE)
UIHelper.nightModeEnabled = prefs.getBoolean("nightMode", false)
UIHelper.showFiat = prefs.getBoolean("showFiat", true)
UIManager.fiat = prefs.getString("fiat", "USD") as String
WalletHelper.addOpReturn = prefs.getBoolean("addOpReturn", false)
WalletHelper.encrypted = prefs.getBoolean("useEncryption", false)
WalletHelper.useTor = prefs.getBoolean("useTor", false)
WalletHelper.allowLegacyP2SH = prefs.getBoolean("allowLegacyP2SH", false)
PrefsUtil.prefs = getSharedPreferences("app.crescentcash.src", Context.MODE_PRIVATE)
UIHelper.nightModeEnabled = PrefsUtil.prefs.getBoolean("nightMode", false)
UIHelper.showFiat = PrefsUtil.prefs.getBoolean("showFiat", true)
UIManager.fiat = PrefsUtil.prefs.getString("fiat", "USD") as String
WalletManager.displayUnits = PrefsUtil.prefs.getString("displayUnit", MonetaryFormat.CODE_BTC) as String
WalletManager.sendType = PrefsUtil.prefs.getString("sendType", WalletManager.displayUnits) as String
WalletManager.addOpReturn = PrefsUtil.prefs.getBoolean("addOpReturn", false)
WalletManager.encrypted = PrefsUtil.prefs.getBoolean("useEncryption", false)
WalletManager.useTor = PrefsUtil.prefs.getBoolean("useTor", false)
WalletManager.allowLegacyP2SH = PrefsUtil.prefs.getBoolean("allowLegacyP2SH", false)
UIManager.determineTheme(this)
SLPWalletHelper.setAPIKey()
......@@ -65,14 +68,14 @@ class MainActivity : AppCompatActivity() {
this.uiHelper.newuser.visibility = View.VISIBLE
} else {
val hasSLPWallet = this.prefs.getBoolean("hasSLPWallet", false)
val hasSLPWallet = PrefsUtil.prefs.getBoolean("hasSLPWallet", false)
if (hasSLPWallet)
this.walletHelper.setupSLPWallet(null, true)
WalletManager.setupSLPWallet(this, null, true)
this.walletHelper.setupWalletKit(null, "", false)
this.uiHelper.displayDownloadContent(true)
val cashAcct = prefs.getString("cashAccount", "")!!
val cashAcct = PrefsUtil.prefs.getString("cashAccount", "")!!
if (cashAcct != "" && cashAcct.contains("#???")) {
val plainName = cashAcct.replace("#???", "")
......
......@@ -25,6 +25,7 @@ import app.crescentcash.src.qr.QRHelper
import app.crescentcash.src.ui.NonScrollListView
import app.crescentcash.src.ui.UIHelper
import app.crescentcash.src.utils.Constants
import app.crescentcash.src.utils.PrefsUtil
import app.crescentcash.src.wallet.WalletHelper
import com.google.android.material.floatingactionbutton.FloatingActionButton
import org.bitcoinj.core.CashAddressFactory
......@@ -55,6 +56,7 @@ class AdvancedSettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
UIManager.determineTheme(this)
this.setContentView(R.layout.advanced_settings)
this.findViews()
this.prepareViews()
......@@ -62,9 +64,8 @@ class AdvancedSettingsActivity : AppCompatActivity() {
}
private fun prepareViews() {
UIManager.determineTheme(this)
this.allowLegacyP2SHSwitch.isChecked = WalletHelper.allowLegacyP2SH
this.addOpReturnSwitch.isChecked = WalletHelper.addOpReturn
this.allowLegacyP2SHSwitch.isChecked = WalletManager.allowLegacyP2SH
this.addOpReturnSwitch.isChecked = WalletManager.addOpReturn
}
private fun findViews() {
......@@ -103,11 +104,11 @@ class AdvancedSettingsActivity : AppCompatActivity() {
if(address.contains("#")) {
object: Thread() {
override fun run() {
WalletManager().verify(address, signature, message)
WalletManager().verify(this@AdvancedSettingsActivity, address, signature, message)
}
}.start()
} else {
WalletManager().verify(address, signature, message)
WalletManager().verify(this@AdvancedSettingsActivity, address, signature, message)
}
}
}
......@@ -119,7 +120,7 @@ class AdvancedSettingsActivity : AppCompatActivity() {
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(s: Editable?) {
println(networkNodeText.text.toString())
MainActivity.INSTANCE.prefs.edit().putString("networkNode", networkNodeText.text.toString()).apply()
PrefsUtil.prefs.edit().putString("networkNode", networkNodeText.text.toString()).apply()
}
}
this.networkNodeText.addTextChangedListener(onTextChangeListener)
......@@ -128,15 +129,15 @@ class AdvancedSettingsActivity : AppCompatActivity() {
}
this.allowLegacyP2SHSwitch.setOnCheckedChangeListener { buttonView, isChecked ->
if (MainActivity.INSTANCE.started) {
WalletHelper.allowLegacyP2SH = isChecked
MainActivity.INSTANCE.prefs.edit().putBoolean("allowLegacyP2SH", WalletHelper.allowLegacyP2SH).apply()
WalletManager.allowLegacyP2SH = isChecked
PrefsUtil.prefs.edit().putBoolean("allowLegacyP2SH", WalletManager.allowLegacyP2SH).apply()
}
}
this.addOpReturnSwitch.setOnCheckedChangeListener { buttonView, isChecked ->
if (MainActivity.INSTANCE.started) {
WalletHelper.addOpReturn = isChecked
MainActivity.INSTANCE.prefs.edit().putBoolean("addOpReturn", WalletHelper.addOpReturn).apply()
WalletManager.addOpReturn = isChecked
PrefsUtil.prefs.edit().putBoolean("addOpReturn", WalletManager.addOpReturn).apply()
}
}
}
......
package app.crescentcash.src.activity
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import app.crescentcash.src.MainActivity
import app.crescentcash.src.R
import app.crescentcash.src.manager.UIManager
import app.crescentcash.src.manager.WalletManager
import app.crescentcash.src.ui.UIHelper
import app.crescentcash.src.wallet.WalletHelper
import org.bitcoinj.crypto.KeyCrypterScrypt
import org.bitcoinj.utils.MonetaryFormat
import java.net.InetSocketAddress
import java.net.Proxy
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.util.*
class DecryptWalletActivity : AppCompatActivity() {
lateinit var unlockPassword: EditText
lateinit var unlockBtn: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
UIManager.determineTheme(this)
this.setContentView(R.layout.unlock_wallet)
this.findViews()
this.prepareViews()
this.initListeners()
}
private fun prepareViews() {
}
private fun findViews() {
unlockPassword = this.findViewById(R.id.unlockPassword)
unlockBtn = this.findViewById(R.id.unlockBtn)
}
private fun initListeners() {
this.unlockBtn.setOnClickListener {
if (!TextUtils.isEmpty(unlockPassword.text)) {
val password = unlockPassword.text.toString()
val scrypt = WalletManager.wallet.keyCrypter
val key = scrypt!!.deriveKey(password)
if (WalletManager.wallet.checkAESKey(key)) {
WalletManager.aesKey = key
UIManager.showToastMessage(MainActivity.INSTANCE, "Decrypted!")
finish()
} else {
UIManager.showToastMessage(MainActivity.INSTANCE, "Invalid password.")
}
} else {
UIManager.showToastMessage(MainActivity.INSTANCE, "Please enter your password.")
}
}
}
companion object {
}
}
......@@ -9,6 +9,7 @@ import androidx.appcompat.app.AppCompatActivity
import app.crescentcash.src.MainActivity
import app.crescentcash.src.R
import app.crescentcash.src.manager.UIManager
import app.crescentcash.src.manager.WalletManager
import app.crescentcash.src.ui.UIHelper
import app.crescentcash.src.wallet.WalletHelper
import org.bitcoinj.crypto.KeyCrypterScrypt
......@@ -26,6 +27,7 @@ class EncryptWalletActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
UIManager.determineTheme(this)
this.setContentView(R.layout.encrypt_screen)
this.findViews()
this.prepareViews()
......@@ -33,7 +35,6 @@ class EncryptWalletActivity : AppCompatActivity() {
}
private fun prepareViews() {
UIManager.determineTheme(this)
}
private fun findViews() {
......@@ -49,11 +50,11 @@ class EncryptWalletActivity : AppCompatActivity() {
UIManager.showToastMessage(this, "Encrypting...")
val password = encryptionPassword.text.toString()
val scrypt = KeyCrypterScrypt(WalletHelper.SCRYPT_PARAMETERS)
val scrypt = KeyCrypterScrypt(WalletManager.SCRYPT_PARAMETERS)
val key = scrypt.deriveKey(password)
MainActivity.INSTANCE.walletHelper.wallet.encrypt(scrypt, key)
WalletManager.wallet.encrypt(scrypt, key)
UIManager.showToastMessage(this, "Encrypted wallet!")
MainActivity.INSTANCE.walletHelper.aesKey = key
WalletManager.aesKey = key
finish()
} else {
UIManager.showToastMessage(this, "Passwords do not match.")
......
......@@ -17,6 +17,7 @@ import app.crescentcash.src.manager.WalletManager
import app.crescentcash.src.ui.NonScrollListView
import app.crescentcash.src.ui.UIHelper
import app.crescentcash.src.utils.Constants
import app.crescentcash.src.utils.PrefsUtil
import com.google.android.material.floatingactionbutton.FloatingActionButton
import org.bitcoinj.utils.MonetaryFormat
import org.bitcoinj.wallet.Wallet
......@@ -35,6 +36,7 @@ class HistoryActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
UIManager.determineTheme(this)
this.setContentView(R.layout.history)
this.findViews()
this.prepareViews()
......@@ -42,7 +44,6 @@ class HistoryActivity : AppCompatActivity() {
}
private fun prepareViews() {
UIManager.determineTheme(this)
}
private fun findViews() {
......@@ -72,7 +73,7 @@ class HistoryActivity : AppCompatActivity() {
val tx = MainActivity.INSTANCE.txList[position]
//displayTxWindow(tx)
}
this.srlHistory.setOnRefreshListener { setArrayAdapter(MainActivity.INSTANCE.walletHelper.wallet) }
this.srlHistory.setOnRefreshListener { setArrayAdapter(WalletManager.wallet) }
}
private var isFabOpen: Boolean = false
......@@ -97,7 +98,7 @@ class HistoryActivity : AppCompatActivity() {
private fun displayReceive() {
closeFabMenu()
val cashAccount = MainActivity.INSTANCE.prefs.getString("cashAccount", "")
val cashAccount = PrefsUtil.prefs.getString("cashAccount", "")
//displayCashAccount(MainActivity.INSTANCE.walletHelper.wallet, cashAccount)
//sendWindow.visibility = View.GONE
//receiveWindow.visibility = View.VISIBLE
......@@ -130,7 +131,7 @@ class HistoryActivity : AppCompatActivity() {
val value = tx.getValue(wallet)
val datum = HashMap<String, String>()
var amountDbl = java.lang.Double.parseDouble(value.toPlainString().replace("-", ""))
val unit = MainActivity.INSTANCE.walletHelper.displayUnits
val unit = WalletManager.displayUnits
var amountStr = ""
if (value.isPositive) {
......
......@@ -25,6 +25,7 @@ import app.crescentcash.src.qr.QRHelper
import app.crescentcash.src.ui.NonScrollListView
import app.crescentcash.src.ui.UIHelper
import app.crescentcash.src.utils.Constants
import app.crescentcash.src.utils.PrefsUtil
import app.crescentcash.src.wallet.WalletHelper
import com.google.android.material.floatingactionbutton.FloatingActionButton
import org.bitcoinj.core.CashAddressFactory
......@@ -45,6 +46,7 @@ class KeysListActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
UIManager.determineTheme(this)
this.setContentView(R.layout.keys_screen)
this.findViews()
this.prepareViews()
......@@ -52,7 +54,6 @@ class KeysListActivity : AppCompatActivity() {
}
private fun prepareViews() {
UIManager.determineTheme(this)
}
private fun findViews() {
......@@ -78,9 +79,8 @@ class KeysListActivity : AppCompatActivity() {
}
}
this.keysList.setOnItemLongClickListener { parent, view, position, id ->
val walletHelper = MainActivity.INSTANCE.walletHelper
val key = AppManager.walletManager.issuedKeysArrayList[position]["key"] ?: error("")
val clip = ClipData.newPlainText("Address", CashAddressFactory.create().getFromBase58(walletHelper.parameters, key.toAddress(walletHelper.parameters).toString()).toString())
val clip = ClipData.newPlainText("Address", CashAddressFactory.create().getFromBase58(WalletManager.parameters, key.toAddress(WalletManager.parameters).toString()).toString())
val clipboard = MainActivity.INSTANCE.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(clip)
Toast.makeText(MainActivity.INSTANCE, "Copied address", Toast.LENGTH_SHORT).show()
......@@ -95,16 +95,15 @@ class KeysListActivity : AppCompatActivity() {
}
private fun setKeysList() {
val walletHelper = MainActivity.INSTANCE.walletHelper
if (walletHelper.wallet.issuedReceiveKeys.isNotEmpty()) {
if (WalletManager.wallet.issuedReceiveKeys.isNotEmpty()) {
AppManager.walletManager.issuedKeysArrayList = ArrayList()
for(key in walletHelper.wallet.issuedReceiveKeys) {
for(key in WalletManager.wallet.issuedReceiveKeys) {
val datum = HashMap<String, ECKey>()
datum["key"] = key
AppManager.walletManager.issuedKeysArrayList.add(datum)
}
for(key in walletHelper.wallet.importedKeys) {
for(key in WalletManager.wallet.importedKeys) {
val datum = HashMap<String, ECKey>()
datum["key"] = key
AppManager.walletManager.issuedKeysArrayList.add(datum)
......@@ -115,11 +114,11 @@ class KeysListActivity : AppCompatActivity() {
val view = LayoutInflater.from(parent.context).inflate(R.layout.key_cell, null)
val ecKey = AppManager.walletManager.issuedKeysArrayList[position]["key"]
if(ecKey != null) {
val legacyAddr = ecKey.toAddress(MainActivity.INSTANCE.walletHelper.parameters).toString()
val params = MainActivity.INSTANCE.walletHelper.parameters
val legacyAddr = ecKey.toAddress(WalletManager.parameters).toString()
val params = WalletManager.parameters
val cashAddr = CashAddressFactory.create().getFromBase58(params, legacyAddr).toString().replace(params.cashAddrPrefix + ":", "")
val cashAcctInternal = MainActivity.INSTANCE.prefs.getString("cashacct_$legacyAddr", "")
val cashAcctTx = MainActivity.INSTANCE.prefs.getString("cashacct_tx_$legacyAddr", "")
val cashAcctInternal = PrefsUtil.prefs.getString("cashacct_$legacyAddr", "")
val cashAcctTx = PrefsUtil.prefs.getString("cashacct_tx_$legacyAddr", "")
if(position == 0) {
setCashAcctText(view, "")
......
......@@ -24,6 +24,7 @@ import app.crescentcash.src.qr.QRHelper
import app.crescentcash.src.ui.NonScrollListView
import app.crescentcash.src.ui.UIHelper
import app.crescentcash.src.utils.Constants
import app.crescentcash.src.utils.PrefsUtil
import app.crescentcash.src.wallet.WalletHelper
import com.google.android.material.floatingactionbutton.FloatingActionButton
import org.bitcoinj.core.CashAddressFactory
......@@ -45,6 +46,7 @@ class ManageKeyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
UIManager.determineTheme(this)
this.setContentView(R.layout.manage_key_screen)
this.findViews()
this.prepareViews()
......@@ -52,7 +54,6 @@ class ManageKeyActivity : AppCompatActivity() {
}
private fun prepareViews() {
UIManager.determineTheme(this)
}
private fun findViews() {
......@@ -72,19 +73,17 @@ class ManageKeyActivity : AppCompatActivity() {
}
}
this.btnCopyPrivateKey.setOnClickListener {
val walletHelper = MainActivity.INSTANCE.walletHelper
val clip = ClipData.newPlainText("Address", WalletManager.currentEcKey.maybeDecrypt(walletHelper.aesKey).getPrivateKeyAsWiF(walletHelper.parameters))
val clip = ClipData.newPlainText("Address", WalletManager.currentEcKey.maybeDecrypt(WalletManager.aesKey).getPrivateKeyAsWiF(WalletManager.parameters))
val clipboard = MainActivity.INSTANCE.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(clip)
Toast.makeText(MainActivity.INSTANCE, "Copied private key", Toast.LENGTH_SHORT).show()
}
this.registerCashAcctBtn.setOnClickListener {
if(!TextUtils.isEmpty(newCashAcctName.text.toString())) {
val walletHelper = MainActivity.INSTANCE.walletHelper
val key = WalletManager.currentEcKey
val address = key.toAddress(walletHelper.parameters).toBase58()
val address = key.toAddress(WalletManager.parameters).toBase58()
val txHash = WalletManager.registerCashAccount(key, newCashAcctName.text.toString())
val editor = MainActivity.INSTANCE.prefs.edit()
val editor = PrefsUtil.prefs.edit()
editor.putString("cashacct_$address", "${newCashAcctName.text}#???")
editor.putString("cashacct_tx_$address", txHash)
editor.apply()
......
......@@ -30,6 +30,7 @@ import app.crescentcash.src.qr.QRHelper
import app.crescentcash.src.ui.NonScrollListView
import app.crescentcash.src.ui.UIHelper
import app.crescentcash.src.utils.Constants
import app.crescentcash.src.utils.PrefsUtil
import app.crescentcash.src.wallet.WalletHelper
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.zxing.BarcodeFormat
......@@ -54,6 +55,7 @@ class ReceiveActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
UIManager.determineTheme(this)
this.setContentView(R.layout.receive)
this.findViews()
this.prepareViews(savedInstanceState)
......@@ -61,7 +63,6 @@ class ReceiveActivity : AppCompatActivity() {
}
private fun prepareViews(savedInstanceState: Bundle?) {
UIManager.determineTheme(this)
this.calculateEmoji()
this.displayEmoji()
this.displayCashAccount(savedInstanceState)
......@@ -78,7 +79,7 @@ class ReceiveActivity : AppCompatActivity() {
private fun initListeners() {
this.ivCopy_AM.setOnClickListener {
val cashAccount = MainActivity.INSTANCE.prefs.getString("cashAccount", "")
val cashAccount = PrefsUtil.prefs.getString("cashAccount", "")
val clip = ClipData.newPlainText("My Cash Acct", cashAccount + "; " + myEmoji.text)
val clipboard = this.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(clip)
......@@ -86,7 +87,7 @@ class ReceiveActivity : AppCompatActivity() {
}
this.copyBtcAddr.setOnClickListener {
val clip: ClipData = ClipData.newPlainText("My BCH address", MainActivity.INSTANCE.walletHelper.parameters.cashAddrPrefix + ":" + btcAddress.text.toString())
val clip: ClipData = ClipData.newPlainText("My BCH address", WalletManager.parameters.cashAddrPrefix + ":" + btcAddress.text.toString())
val clipboard = this.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(clip)
UIManager.showToastMessage(this, "Copied")
......@@ -94,7 +95,7 @@ class ReceiveActivity : AppCompatActivity() {
}
private fun displayEmoji() {
var cashEmoji = MainActivity.INSTANCE.prefs.getString("cashEmoji", "")
var cashEmoji = PrefsUtil.prefs.getString("cashEmoji", "")
if (myCashHandle.text.toString().contains("#???")) {
cashEmoji = "?"
......@@ -121,9 +122,9 @@ class ReceiveActivity : AppCompatActivity() {
savedInstanceState.getSerializable(Constants.INTENT_CASH_ACCOUNT_DATA).toString()
}
if (MainActivity.INSTANCE.walletHelper.walletKit != null) {
this.btcAddress.text = MainActivity.INSTANCE.walletHelper.wallet.currentReceiveAddress().toString()
btcAddress.text = this.btcAddress.text.toString().replace(MainActivity.INSTANCE.walletHelper.parameters.cashAddrPrefix + ":", "")
if (WalletManager.walletKit != null) {
this.btcAddress.text = WalletManager.wallet.currentReceiveAddress().toString()
btcAddress.text = this.btcAddress.text.toString().replace(WalletManager.parameters.cashAddrPrefix + ":", "")
generateQR(this.btcAddress.text.toString(), R.id.btcQR, false)
} else {
this.btcAddress.text = "Loading..."
......@@ -189,13 +190,13 @@ class ReceiveActivity : AppCompatActivity() {
}
private fun calculateEmoji() {
val hasEmoji = MainActivity.INSTANCE.prefs.getString("cashEmoji", "")
val hasEmoji = PrefsUtil.prefs.getString("cashEmoji", "")
if (hasEmoji != null) {
if (hasEmoji == "?" || hasEmoji == "") {
object : Thread() {
override fun run() {
val cashAcctTx = MainActivity.INSTANCE.prefs.getString("cashAcctTx", "null") as String
val cashAcctTx = PrefsUtil.prefs.getString("cashAcctTx", "null") as String
MainActivity.INSTANCE.walletHelper.registeredTxHash = cashAcctTx
if (cashAcctTx != "null") {
......@@ -205,7 +206,7 @@ class ReceiveActivity : AppCompatActivity() {
if (MainActivity.INSTANCE.walletHelper.registeredBlock != "???") {
try {
val emoji = HashHelper().getCashAccountEmoji(MainActivity.INSTANCE.walletHelper.registeredBlockHash, MainActivity.INSTANCE.walletHelper.registeredTxHash)
MainActivity.INSTANCE.prefs.edit().putString("cashEmoji", emoji).apply()
PrefsUtil.prefs.edit().putString("cashEmoji", emoji).apply()
this@ReceiveActivity.myEmoji.text = emoji
} catch (e: Exception) {
this@ReceiveActivity.myEmoji.text = "?"
......@@ -220,9 +221,9 @@ class ReceiveActivity : AppCompatActivity() {
}
} else {
try {
val cashAcctName = MainActivity.INSTANCE.prefs.getString("cashAccount", "") as String
val cashAcctName = PrefsUtil.prefs.getString("cashAccount", "") as String
val cashAcctEmoji = MainActivity.INSTANCE.netHelper.getCashAccountEmoji(cashAcctName)
MainActivity.INSTANCE.prefs.edit().putString("cashEmoji", cashAcctEmoji).apply()
PrefsUtil.prefs.edit().putString("cashEmoji", cashAcctEmoji).apply()
this@ReceiveActivity.myEmoji.text = cashAcctEmoji
} catch (e: Exception) {
e.printStackTrace()
......
......@@ -52,6 +52,7 @@ class ReceiveSLPActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
UIManager.determineTheme(this)
this.setContentView(R.layout.receive_slp)
this.findViews()
this.prepareViews(savedInstanceState)
......@@ -59,7 +60,6 @@ class ReceiveSLPActivity : AppCompatActivity() {
}
private fun prepareViews(savedInstanceState: Bundle?) {
UIManager.determineTheme(this)
this.displayReceiveSLP()
}
......@@ -142,13 +142,13 @@ class ReceiveSLPActivity : AppCompatActivity() {
}
private fun displayReceiveSLP() {
if (MainActivity.INSTANCE.walletHelper.walletKit != null) {
if (WalletManager.walletKit != null) {
val address = if (currentAddrView)
MainActivity.INSTANCE.walletHelper.getSLPWallet().slpAddress
WalletManager.getSLPWallet().slpAddress
else
MainActivity.INSTANCE.walletHelper.getSLPWallet().bchAddress
WalletManager.getSLPWallet().bchAddress
slpAddress.text = address.replace("simpleledger:", "").replace(MainActivity.INSTANCE.walletHelper.parameters.cashAddrPrefix + ":", "")
slpAddress.text = address.replace("simpleledger:", "").replace(WalletManager.parameters.cashAddrPrefix + ":", "")
if (currentAddrView)
generateQR(address, R.id.slpQR, true)
......
......@@ -30,6 +30,7 @@ import app.crescentcash.src.ui.RecipientEditText
import app.crescentcash.src.ui.UIHelper
import app.crescentcash.src.uri.URIHelper
import app.crescentcash.src.utils.Constants
import app.crescentcash.src.utils.PrefsUtil
import app.crescentcash.src.wallet.WalletHelper
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.common.util.concurrent.ListenableFuture
......@@ -70,6 +71,7 @@ class SendActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
UIManager.determineTheme(this)
this.setContentView(R.layout.send)
this.findViews()
this.prepareViews(savedInstanceState)
......@@ -92,8 +94,7 @@ class SendActivity : AppCompatActivity() {
}
private fun prepareViews(savedInstanceState: Bundle?) {
UIManager.determineTheme(this)
this.displayMyBalance(MainActivity.INSTANCE.walletHelper.getBalance(MainActivity.INSTANCE.walletHelper.wallet).toFriendlyString())
this.displayMyBalance(WalletManager.getBalance(WalletManager.wallet).toFriendlyString())
balance = if (savedInstanceState == null) {
val extras = intent.extras
if(extras == null) {
......@@ -108,7 +109,7 @@ class SendActivity : AppCompatActivity() {
if (UIHelper.showFiat) {
object : Thread() {
override fun run() {
val coinBal = java.lang.Double.parseDouble(MainActivity.INSTANCE.walletHelper.getBalance(MainActivity.INSTANCE.walletHelper.wallet).toPlainString())
val coinBal = java.lang.Double.parseDouble(WalletManager.getBalance(WalletManager.wallet).toPlainString())
val df = DecimalFormat("#,###.##", DecimalFormatSymbols(Locale.US))
val fiatBalances = when (UIManager.fiat) {
......@@ -142,25 +143,25 @@ class SendActivity : AppCompatActivity() {
fiatBalTxtSend.text = ""
}
val items = arrayOf(MainActivity.INSTANCE.walletHelper.displayUnits, UIManager.fiat)
val items = arrayOf(WalletManager.displayUnits, UIManager.fiat)
val adapter = ArrayAdapter(MainActivity.INSTANCE, R.layout.spinner_item, items)
sendTypeSpinner.adapter = adapter
when {
MainActivity.INSTANCE.walletHelper.sendType == MainActivity.INSTANCE.walletHelper.displayUnits -> sendTypeSpinner.setSelection(0)
MainActivity.INSTANCE.walletHelper.sendType == UIManager.fiat -> sendTypeSpinner.setSelection(1)
WalletManager.sendType == WalletManager.displayUnits -> sendTypeSpinner.setSelection(0)
WalletManager.sendType == UIManager.fiat -> sendTypeSpinner.setSelection(1)
}
sendTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, v: View, position: Int, id: Long) {
when (position) {
0 -> MainActivity.INSTANCE.walletHelper.sendType = MainActivity.INSTANCE.walletHelper.displayUnits
1 -> MainActivity.INSTANCE.walletHelper.sendType = UIManager.fiat
0 -> WalletManager.sendType = WalletManager.displayUnits
1 -> WalletManager.sendType = UIManager.fiat
}
MainActivity.INSTANCE.prefs.edit().putString("sendType", MainActivity.INSTANCE.walletHelper.sendType).apply()
println(MainActivity.INSTANCE.walletHelper.sendType)
PrefsUtil.prefs.edit().putString("sendType", WalletManager.sendType).apply()
println(WalletManager.sendType)
}
override fun onNothingSelected(parent: AdapterView<*>) {
......@@ -168,7 +169,7 @@ class SendActivity : AppCompatActivity() {
}
}
opReturnBox.visibility = if(WalletHelper.addOpReturn) {
opReturnBox.visibility = if(WalletManager.addOpReturn) {
View.VISIBLE
} else {
View.GONE
......@@ -178,7 +179,7 @@ class SendActivity : AppCompatActivity() {
private fun initListeners() {
val slideBCHListener: SlideToActView.OnSlideCompleteListener = object : SlideToActView.OnSlideCompleteListener {
override fun onSlideComplete(view: SlideToActView) {
MainActivity.INSTANCE.walletHelper.send(this@SendActivity)
WalletManager.send(this@SendActivity)
}
}
......@@ -201,15 +202,15 @@ class SendActivity : AppCompatActivity() {
}
private fun setMaxCoins() {
MainActivity.INSTANCE.walletHelper.sendType = MainActivity.INSTANCE.walletHelper.displayUnits
WalletManager.sendType = WalletManager.displayUnits
sendTypeSpinner.setSelection(0)
MainActivity.INSTANCE.prefs.edit().putString("sendType", MainActivity.INSTANCE.walletHelper.sendType).apply()
PrefsUtil.prefs.edit().putString("sendType", WalletManager.sendType).apply()
var coins = if(WalletManager.selectedUtxos.size == 0) {
balance
} else {
var balBch: Double = java.lang.Double.parseDouble(WalletManager.getMaxValueOfSelectedUtxos().toPlainString())
val unit = MainActivity.INSTANCE.walletHelper.displayUnits
val unit = WalletManager.displayUnits
when (unit) {
MonetaryFormat.CODE_BTC -> {
UIManager.formatBalanceNoUnit(balBch, "#,###.########")
......@@ -282,10 +283,10 @@ class SendActivity : AppCompatActivity() {
this.sendTypeSpinner.setSelection(0)
}
MainActivity.INSTANCE.walletHelper.sendType = MainActivity.INSTANCE.walletHelper.displayUnits
MainActivity.INSTANCE.prefs.edit().putString("sendType", MainActivity.INSTANCE.walletHelper.sendType).apply()
WalletManager.sendType = WalletManager.displayUnits
PrefsUtil