Commit da5ee001 authored by pokkst's avatar pokkst

Rewrite complete. Further testing required.

parent a4a192c8
......@@ -32,6 +32,16 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.VerifySignatureActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
<activity android:name=".activity.ViewTransactionActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
<activity android:name=".activity.PaymentReceivedActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
......
......@@ -29,7 +29,6 @@ import java.util.*
class MainActivity : AppCompatActivity() {
lateinit var netManager: NetManager
private lateinit var createWalletBtn: Button
private lateinit var restoreWalletBtn: Button
lateinit var restore_wallet: FrameLayout
......@@ -56,31 +55,39 @@ class MainActivity : AppCompatActivity() {
private var receiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (Constants.ACTION_UPDATE_HOME_SCREEN_BALANCE == intent.action) {
this@MainActivity.displayMyBalance(WalletManager.getBalance(WalletManager.wallet).toFriendlyString())
this@MainActivity.refresh()
}
if (Constants.ACTION_UPDATE_HOME_SCREEN_THEME == intent.action) {
UIManager.determineTheme(this@MainActivity)
this@MainActivity.setContentView(R.layout.activity_main)
this@MainActivity.findViews()
this@MainActivity.prepareViews()
this@MainActivity.initListeners()
this@MainActivity.refresh()
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
instance = this
PrefsUtil.prefs = getSharedPreferences("app.crescentcash.src", Context.MODE_PRIVATE)
PrefsUtil.loadPrefs()
UIManager.determineTheme(this)
this.setContentView(R.layout.activity_main)
this.findViews()
this.prepareViews()
this.initListeners()
//FirebaseApp.initializeApp(this)
INSTANCE = this
PrefsUtil.prefs = getSharedPreferences("app.crescentcash.src", Context.MODE_PRIVATE)
PrefsUtil.loadPrefs()
//INSTANCE = this
NetManager.establishProxy()
SLPWalletHelper.setAPIKey()
this.netManager = NetManager()
//this.uiHelper.networkNodeText.setText(prefs.getString("networkNode", ""))
isNewUser = !File(INSTANCE.applicationInfo.dataDir + "/users_wallet.wallet").exists()
isNewUser = !File(this.applicationInfo.dataDir + "/users_wallet.wallet").exists()
if (isNewUser) {
this.newuser.visibility = View.VISIBLE
......@@ -98,7 +105,7 @@ class MainActivity : AppCompatActivity() {
if (cashAcct != "" && cashAcct.contains("#???")) {
val plainName = cashAcct.replace("#???", "")
WalletManager.registeredBlock = "???"
this.netManager.initialAccountIdentityCheck(plainName)
NetManager.initialAccountIdentityCheck(plainName)
WalletManager.timer = object : CountDownTimer(150000, 20) {
override fun onTick(millisUntilFinished: Long) {
......@@ -107,7 +114,7 @@ class MainActivity : AppCompatActivity() {
override fun onFinish() {
try {
netManager.checkForAccountIdentity(plainName)
NetManager.checkForAccountIdentity(plainName)
} catch (e: Exception) {
e.printStackTrace()
}
......@@ -117,13 +124,6 @@ class MainActivity : AppCompatActivity() {
}
}
val permissionHelper = PermissionHelper()
permissionHelper.askForPermissions(this, this)
val filter = IntentFilter()
filter.addAction(Constants.ACTION_UPDATE_HOME_SCREEN_BALANCE)
LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter)
}
private fun findViews() {
......@@ -161,18 +161,26 @@ class MainActivity : AppCompatActivity() {
this.receiveFabHome.setOnClickListener { this.displayReceive() }
this.sendFabHome.setOnClickListener { startSendActivity() }
this.btnViewHistory.setOnClickListener {
UIManager.startActivity(INSTANCE, HistoryActivity::class.java)
UIManager.startActivity(this, HistoryActivity::class.java)
}
this.btnViewTokens.setOnClickListener {
val tokensListActivity = Intent(INSTANCE, TokensListActivity::class.java)
val tokensListActivity = Intent(this, TokensListActivity::class.java)
tokensListActivity.putExtra(Constants.INTENT_BALANCE_DATA, WalletManager.findBitcoinInSLPList()?.amount?.toPlainString())
INSTANCE.startActivity(tokensListActivity)
this.startActivity(tokensListActivity)
}
this.openKeys.setOnClickListener { UIManager.startActivity(INSTANCE, SettingsActivity::class.java) }
this.openKeys.setOnClickListener { UIManager.startActivity(this, SettingsActivity::class.java) }
this.tipBCHBtn.setOnClickListener { openUrl("https://tipbitcoin.cash") }
this.coinspiceBtn.setOnClickListener { openUrl("https://coinspice.io") }
this.sideshiftAIBtn.setOnClickListener { openUrl("https://sideshift.ai/a/mmG1iwJRO") }
this.acceptbchBtn.setOnClickListener { openUrl("https://acceptbitcoin.cash") }
val permissionHelper = PermissionHelper()
permissionHelper.askForPermissions(this, this)
val filter = IntentFilter()
filter.addAction(Constants.ACTION_UPDATE_HOME_SCREEN_BALANCE)
filter.addAction(Constants.ACTION_UPDATE_HOME_SCREEN_THEME)
LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter)
}
private fun openUrl(url: String) {
......@@ -182,7 +190,7 @@ class MainActivity : AppCompatActivity() {
}
private fun startSendActivity() {
UIManager.startActivity(INSTANCE, SendActivity::class.java)
UIManager.startActivity(this, SendActivity::class.java)
}
private fun displayNewWallet() {
......@@ -190,7 +198,7 @@ class MainActivity : AppCompatActivity() {
new_wallet.visibility = View.VISIBLE
newuser.visibility = View.GONE
registerUserBtn.setOnClickListener { this.netManager.prepareWalletForRegistration(this) }
registerUserBtn.setOnClickListener { NetManager.prepareWalletForRegistration(this) }
}
private fun displayRestore() {
......@@ -198,7 +206,7 @@ class MainActivity : AppCompatActivity() {
restore_wallet.visibility = View.VISIBLE
new_wallet.visibility = View.GONE
newuser.visibility = View.GONE
verifyUserBtn.setOnClickListener { this.netManager.prepareWalletForVerification(this) }
verifyUserBtn.setOnClickListener { NetManager.prepareWalletForVerification(this) }
}
@UiThread
......@@ -260,19 +268,19 @@ class MainActivity : AppCompatActivity() {
val fiatBalances = when (UIManager.fiat) {
"USD" -> {
val priceUsd = INSTANCE.netManager.price
val priceUsd = NetManager.price
val balUsd = coinBal * priceUsd
"$" + df.format(balUsd)
}
"EUR" -> {
val priceEur = INSTANCE.netManager.priceEur
val priceEur = NetManager.priceEur
val balEur = coinBal * priceEur
"€" + df.format(balEur)
}
"AUD" -> {
val priceAud = INSTANCE.netManager.priceAud
val priceAud = NetManager.priceAud
val balAud = coinBal * priceAud
"AUD$" + df.format(balAud)
......@@ -280,7 +288,7 @@ class MainActivity : AppCompatActivity() {
else -> ""
}
INSTANCE.runOnUiThread {
this@MainActivity.runOnUiThread {
fiatBalTxt.text = fiatBalances
}
}
......@@ -312,7 +320,12 @@ class MainActivity : AppCompatActivity() {
}
companion object {
lateinit var INSTANCE: MainActivity
//lateinit var INSTANCE: MainActivity
var isNewUser = true
private lateinit var instance: MainActivity
fun getDataDir(): String {
return instance.applicationInfo.dataDir
}
}
}
......@@ -2,6 +2,7 @@ package app.crescentcash.src.activity
import android.content.Intent
import android.os.Bundle
import android.provider.ContactsContract
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
......@@ -18,18 +19,10 @@ class AdvancedSettingsActivity : AppCompatActivity() {
lateinit var networkNodeText: EditText
lateinit var btnScanPrivateKey: Button
private lateinit var btnShowAddresses: Button
lateinit var messageToVerify: EditText
lateinit var addressToVerify: EditText
lateinit var verifySignature: EditText
private lateinit var btnVerifySig: Button
lateinit var verifySigScreen: FrameLayout
private lateinit var btnShowVerifySigScreen: Button
private lateinit var btnScanMsgToVerify: ImageView
private lateinit var btnScanAddrToVerify: ImageView
private lateinit var btnScanSigToVerify: ImageView
private lateinit var btnShowUtxos: Button
lateinit var addOpReturnSwitch: Switch
lateinit var allowLegacyP2SHSwitch: Switch
private lateinit var btnShowVerifySigScreen: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -43,55 +36,26 @@ class AdvancedSettingsActivity : AppCompatActivity() {
private fun prepareViews() {
this.allowLegacyP2SHSwitch.isChecked = WalletManager.allowLegacyP2SH
this.addOpReturnSwitch.isChecked = WalletManager.addOpReturn
this.networkNodeText.setText(PrefsUtil.prefs.getString("networkNode", "").toString())
}
private fun findViews() {
networkNodeText = this.findViewById(R.id.nodeIP)
btnScanPrivateKey = this.findViewById(R.id.btnScanPrivateKey)
btnShowAddresses = this.findViewById(R.id.btnShowAddresses)
messageToVerify = this.findViewById(R.id.messageToVerify)
addressToVerify = this.findViewById(R.id.addressToVerify)
verifySignature = this.findViewById(R.id.verifySignature)
btnVerifySig = this.findViewById(R.id.btnVerifySig)
verifySigScreen = this.findViewById(R.id.verifyKeyScreen)
btnShowVerifySigScreen = this.findViewById(R.id.btnShowVerifyScreen)
btnScanMsgToVerify = this.findViewById(R.id.btnScanMessageToVerify)
btnScanAddrToVerify = this.findViewById(R.id.btnScanAddressToVerify)
btnScanSigToVerify = this.findViewById(R.id.btnScanSigToVerify)
btnShowUtxos = this.findViewById(R.id.btnShowUtxos)
allowLegacyP2SHSwitch = this.findViewById(R.id.allowLegacyP2SHSwitch)
addOpReturnSwitch = this.findViewById(R.id.addOpReturnSwitch)
btnShowVerifySigScreen = this.findViewById(R.id.btnShowVerifyScreen)
}
private fun initListeners() {
this.btnShowVerifySigScreen.setOnClickListener { UIManager.startActivity(this, VerifySignatureActivity::class.java) }
this.btnScanPrivateKey.setOnClickListener { UIManager.clickScanQR(this, Constants.REQUEST_CODE_SWEEP_SCAN) }
this.btnShowAddresses.setOnClickListener {
val keysListActivity = Intent(this, KeysListActivity::class.java)
startActivity(keysListActivity)
}
this.btnShowVerifySigScreen.setOnClickListener {
this.verifySigScreen.visibility = View.VISIBLE
}
this.btnVerifySig.setOnClickListener {
val message = messageToVerify.text.toString()
val address = addressToVerify.text.toString()
val signature = verifySignature.text.toString()
if (!TextUtils.isEmpty(message) && !TextUtils.isEmpty(address) && !TextUtils.isEmpty(signature)) {
if (address.contains("#")) {
object : Thread() {
override fun run() {
WalletManager.verify(this@AdvancedSettingsActivity, address, signature, message)
}
}.start()
} else {
WalletManager.verify(this@AdvancedSettingsActivity, address, signature, message)
}
}
}
this.btnScanMsgToVerify.setOnClickListener { UIManager.clickScanQR(this, Constants.REQUEST_CODE_SIG_VERIFY_MESSAGE_SCAN) }
this.btnScanAddrToVerify.setOnClickListener { UIManager.clickScanQR(this, Constants.REQUEST_CODE_SIG_VERIFY_ADDRESS_SCAN) }
this.btnScanSigToVerify.setOnClickListener { UIManager.clickScanQR(this, Constants.REQUEST_CODE_SIG_VERIFY_SIGNATURE_SCAN) }
val onTextChangeListener = object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
......
......@@ -5,7 +5,6 @@ import android.text.TextUtils
import android.widget.Button
import android.widget.EditText
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
......@@ -39,13 +38,13 @@ class DecryptWalletActivity : AppCompatActivity() {
val key = scrypt!!.deriveKey(password)
if (WalletManager.wallet.checkAESKey(key)) {
WalletManager.aesKey = key
UIManager.showToastMessage(MainActivity.INSTANCE, "Decrypted!")
UIManager.showToastMessage(this, "Decrypted!")
finish()
} else {
UIManager.showToastMessage(MainActivity.INSTANCE, "Invalid password.")
UIManager.showToastMessage(this, "Invalid password.")
}
} else {
UIManager.showToastMessage(MainActivity.INSTANCE, "Please enter your password.")
UIManager.showToastMessage(this, "Please enter your password.")
}
}
}
......
......@@ -10,7 +10,6 @@ import android.view.ViewGroup
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import app.crescentcash.src.MainActivity
import app.crescentcash.src.R
import app.crescentcash.src.manager.UIManager
import app.crescentcash.src.manager.WalletManager
......@@ -27,9 +26,7 @@ class HistoryActivity : AppCompatActivity() {
private lateinit var fabSend: FloatingActionButton
private lateinit var fabReceive: FloatingActionButton
private lateinit var txHistoryList: NonScrollListView
private lateinit var txInfo: FrameLayout
private lateinit var txInfoTV: TextView
private lateinit var btnViewTx: Button
private lateinit var no_tx_text: TextView
private lateinit var srlHistory: SwipeRefreshLayout
......@@ -51,9 +48,6 @@ class HistoryActivity : AppCompatActivity() {
fabSend = this.findViewById(R.id.fabSend)
fabReceive = this.findViewById(R.id.fabReceive)
txHistoryList = this.findViewById(R.id.txHistoryList)
txInfo = this.findViewById(R.id.txInfo)
txInfoTV = this.findViewById(R.id.txInfoTV)
btnViewTx = this.findViewById(R.id.btnViewTx)
no_tx_text = this.findViewById(R.id.no_tx_text)
srlHistory = this.findViewById(R.id.srlHistory)
}
......@@ -70,8 +64,9 @@ class HistoryActivity : AppCompatActivity() {
this.fabSend.setOnClickListener { startSendActivity() }
this.fabReceive.setOnClickListener { displayReceive() }
this.txHistoryList.setOnItemClickListener { parent, view, position, id ->
val tx = WalletManager.txList[position]
//displayTxWindow(tx)
val viewTxActivity = Intent(this, ViewTransactionActivity::class.java)
viewTxActivity.putExtra(Constants.INTENT_TRANSACTION_POSITION_DATA, position)
this.startActivity(viewTxActivity)
}
this.srlHistory.setOnRefreshListener { setArrayAdapter(WalletManager.wallet) }
}
......@@ -80,13 +75,13 @@ class HistoryActivity : AppCompatActivity() {
private fun startSendActivity() {
closeFabMenu()
UIManager.startActivity(MainActivity.INSTANCE, SendActivity::class.java)
UIManager.startActivity(this, SendActivity::class.java)
}
private fun showFabMenu() {
isFabOpen = true
fabReceive.animate().translationY(-MainActivity.INSTANCE.resources.getDimension(R.dimen.standard_105))
fabSend.animate().translationY(-MainActivity.INSTANCE.resources.getDimension(R.dimen.standard_155))
fabReceive.animate().translationY(-this.resources.getDimension(R.dimen.standard_105))
fabSend.animate().translationY(-this.resources.getDimension(R.dimen.standard_155))
}
fun closeFabMenu() {
......@@ -98,12 +93,9 @@ class HistoryActivity : AppCompatActivity() {
private fun displayReceive() {
closeFabMenu()
val cashAccount = PrefsUtil.prefs.getString("cashAccount", "")
//displayCashAccount(MainActivity.INSTANCE.walletHelper.wallet, cashAccount)
//sendWindow.visibility = View.GONE
//receiveWindow.visibility = View.VISIBLE
val receiveActivity = Intent(MainActivity.INSTANCE, ReceiveActivity::class.java)
val receiveActivity = Intent(this, ReceiveActivity::class.java)
receiveActivity.putExtra(Constants.INTENT_CASH_ACCOUNT_DATA, cashAccount)
MainActivity.INSTANCE.startActivity(receiveActivity)
this.startActivity(receiveActivity)
}
private fun setArrayAdapter(wallet: Wallet) {
......@@ -201,10 +193,10 @@ class HistoryActivity : AppCompatActivity() {
}
}
val itemsAdapter = object : SimpleAdapter(MainActivity.INSTANCE, txListFormatted, R.layout.transaction_list_cell, null, null) {
val itemsAdapter = object : SimpleAdapter(this, txListFormatted, R.layout.transaction_list_cell, null, null) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
// Get the Item from ListView
val view = LayoutInflater.from(MainActivity.INSTANCE).inflate(R.layout.transaction_list_cell, null)
val view = LayoutInflater.from(this@HistoryActivity).inflate(R.layout.transaction_list_cell, null)
val action = txListFormatted[position]["action"]
val satoshiDice = txListFormatted[position]["satoshidice"]
......@@ -258,7 +250,7 @@ class HistoryActivity : AppCompatActivity() {
return view
}
}
MainActivity.INSTANCE.runOnUiThread { txHistoryList.adapter = itemsAdapter }
this.runOnUiThread { txHistoryList.adapter = itemsAdapter }
} else {
srlHistory.visibility = View.GONE
no_tx_text.visibility = View.VISIBLE
......
......@@ -13,8 +13,8 @@ import android.view.ViewGroup
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import app.crescentcash.src.MainActivity
import app.crescentcash.src.R
import app.crescentcash.src.manager.NetManager
import app.crescentcash.src.manager.UIManager
import app.crescentcash.src.manager.WalletManager
import app.crescentcash.src.ui.NonScrollListView
......@@ -71,9 +71,9 @@ class KeysListActivity : AppCompatActivity() {
this.keysList.setOnItemLongClickListener { parent, view, position, id ->
val key = WalletManager.issuedKeysArrayList[position]["key"] ?: error("")
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
val clipboard = this.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(clip)
Toast.makeText(MainActivity.INSTANCE, "Copied address", Toast.LENGTH_SHORT).show()
Toast.makeText(this, "Copied address", Toast.LENGTH_SHORT).show()
true
}
}
......@@ -116,7 +116,7 @@ class KeysListActivity : AppCompatActivity() {
if (cashAcctInternal.toString().endsWith("#???")) {
object : Thread() {
override fun run() {
val cashAcct = MainActivity.INSTANCE.netManager.checkForCashAccount(ecKey, cashAcctTx.toString(), cashAcctInternal.toString().replace("#???", ""))
val cashAcct = NetManager.checkForCashAccount(ecKey, cashAcctTx.toString(), cashAcctInternal.toString().replace("#???", ""))
setCashAcctText(view, cashAcct)
}
}.start()
......@@ -124,7 +124,7 @@ class KeysListActivity : AppCompatActivity() {
if (cashAcctInternal == "") {
object : Thread() {
override fun run() {
val cashAcct = MainActivity.INSTANCE.netManager.reverseLookupCashAccount(cashAddr, legacyAddr)
val cashAcct = NetManager.reverseLookupCashAccount(cashAddr, legacyAddr)
setCashAcctText(view, cashAcct)
}
}.start()
......@@ -180,13 +180,7 @@ class KeysListActivity : AppCompatActivity() {
if (scanData != null) {
if (requestCode == Constants.REQUEST_CODE_IMPORT_SCAN) {
this.keyToImportText.setText(scanData)
} /* else if (requestCode == Constants.REQUEST_CODE_SIG_VERIFY_MESSAGE_SCAN) {
this.messageToVerify.setText(scanData)
} else if (requestCode == Constants.REQUEST_CODE_SIG_VERIFY_ADDRESS_SCAN) {
this.addressToVerify.setText(scanData)
} else if (requestCode == Constants.REQUEST_CODE_SIG_VERIFY_SIGNATURE_SCAN) {
this.verifySignature.setText(scanData)
}*/
}
}
}
}
......
......@@ -10,7 +10,6 @@ import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
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
......@@ -54,9 +53,9 @@ class ManageKeyActivity : AppCompatActivity() {
}
this.btnCopyPrivateKey.setOnClickListener {
val clip = ClipData.newPlainText("Address", WalletManager.currentEcKey.maybeDecrypt(WalletManager.aesKey).getPrivateKeyAsWiF(WalletManager.parameters))
val clipboard = MainActivity.INSTANCE.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipboard = this.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(clip)
Toast.makeText(MainActivity.INSTANCE, "Copied private key", Toast.LENGTH_SHORT).show()
Toast.makeText(this, "Copied private key", Toast.LENGTH_SHORT).show()
}
this.registerCashAcctBtn.setOnClickListener {
if (!TextUtils.isEmpty(newCashAcctName.text.toString())) {
......
......@@ -14,9 +14,9 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import app.crescentcash.src.MainActivity
import app.crescentcash.src.R
import app.crescentcash.src.hash.HashHelper
import app.crescentcash.src.manager.NetManager
import app.crescentcash.src.manager.UIManager
import app.crescentcash.src.manager.WalletManager
import app.crescentcash.src.utils.Constants
......@@ -98,7 +98,7 @@ class ReceiveActivity : AppCompatActivity() {
cashEmoji = "?"
println("CASH ACCOUNT UNCONFIRMED")
val cashAcctPlain = myCashHandle.text.toString().replace("#???", "")
MainActivity.INSTANCE.netManager.initialAccountIdentityCheck(cashAcctPlain)
NetManager.initialAccountIdentityCheck(cashAcctPlain)
}
myEmoji.text = cashEmoji
......@@ -189,7 +189,7 @@ class ReceiveActivity : AppCompatActivity() {
if (cashAcctTx != "null") {
try {
WalletManager.registeredBlockHash = MainActivity.INSTANCE.netManager.getTransactionData(WalletManager.registeredTxHash, "block_hash", "blockhash")
WalletManager.registeredBlockHash = NetManager.getTransactionData(WalletManager.registeredTxHash, "block_hash", "blockhash")
if (WalletManager.registeredBlock != "???") {
try {
......@@ -210,7 +210,7 @@ class ReceiveActivity : AppCompatActivity() {
} else {
try {
val cashAcctName = PrefsUtil.prefs.getString("cashAccount", "") as String
val cashAcctEmoji = MainActivity.INSTANCE.netManager.getCashAccountEmoji(cashAcctName)
val cashAcctEmoji = NetManager.getCashAccountEmoji(cashAcctName)
PrefsUtil.prefs.edit().putString("cashEmoji", cashAcctEmoji).apply()
this@ReceiveActivity.myEmoji.text = cashAcctEmoji
} catch (e: Exception) {
......
......@@ -15,7 +15,6 @@ import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
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
......@@ -51,9 +50,9 @@ class ReceiveSLPActivity : AppCompatActivity() {
private fun initListeners() {
this.copySlpAddr.setOnClickListener {
val clip: ClipData = if (currentAddrView) ClipData.newPlainText("My SLP address", "simpleledger:" + slpAddress.text.toString()) else ClipData.newPlainText("My BCH SLP address", "bitcoincash:" + slpAddress.text.toString())
val clipboard = MainActivity.INSTANCE.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipboard = this.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(clip)
Toast.makeText(MainActivity.INSTANCE, "Copied", Toast.LENGTH_SHORT).show()
Toast.makeText(this, "Copied", Toast.LENGTH_SHORT).show()
}
this.toggleAddr.setOnClickListener {
......
......@@ -7,10 +7,11 @@ import android.text.TextUtils
import android.view.View
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import app.crescentcash.src.MainActivity
import app.crescentcash.src.R
import app.crescentcash.src.listener.RecipientTextListener
import app.crescentcash.src.manager.NetManager
import app.crescentcash.src.manager.UIManager
import app.crescentcash.src.manager.WalletManager
import app.crescentcash.src.ui.RecipientEditText
......@@ -22,6 +23,7 @@ import org.bitcoinj.utils.MonetaryFormat
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.util.*
import kotlin.collections.ArrayList
class SendActivity : AppCompatActivity() {
private lateinit var tvRecipientAddress_AM: RecipientEditText
......@@ -83,7 +85,7 @@ class SendActivity : AppCompatActivity() {
}
val items = arrayOf(WalletManager.displayUnits, UIManager.fiat)
val adapter = ArrayAdapter(MainActivity.INSTANCE, R.layout.spinner_item, items)
val adapter = ArrayAdapter(this, R.layout.spinner_item, items)
sendTypeSpinner.adapter = adapter
when {
......@@ -125,7 +127,7 @@ class SendActivity : AppCompatActivity() {
this.btnSend_AM.onSlideCompleteListener = slideBCHListener
val listener: RecipientTextListener = object : RecipientTextListener {
override fun onUpdate() {
val clipboard = MainActivity.INSTANCE.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipboard = this@SendActivity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipboardText = clipboard.text.toString()
processScanOrPaste(clipboardText)
......@@ -174,7 +176,7 @@ class SendActivity : AppCompatActivity() {
}
println("Setting...")
MainActivity.INSTANCE.runOnUiThread { amountText.text = coins }
this.runOnUiThread { amountText.text = coins }
}
private fun showContactSelectionScreen() {
......@@ -186,13 +188,13 @@ class SendActivity : AppCompatActivity() {
fun displayRecipientAddress(recipientAddress: String?) {
if (recipientAddress != null) {
if (TextUtils.isEmpty(recipientAddress)) {
tvRecipientAddress_AM.hint = MainActivity.INSTANCE.resources.getString(R.string.receiver)
tvRecipientAddress_AM.hint = this.resources.getString(R.string.receiver)
} else {
tvRecipientAddress_AM.setText(recipientAddress)
}
} else {
tvRecipientAddress_AM.text = null
tvRecipientAddress_AM.hint = MainActivity.INSTANCE.resources.getString(R.string.receiver)
tvRecipientAddress_AM.hint = this.resources.getString(R.string.receiver)
}
}
......@@ -221,7 +223,7 @@ class SendActivity : AppCompatActivity() {
val address = uri.address
if (address.startsWith("http")) {
MainActivity.INSTANCE.runOnUiThread {
this.runOnUiThread {
this.displayRecipientAddress(address)
this.sendTypeSpinner.setSelection(0)
}
......@@ -261,6 +263,41 @@ class SendActivity : AppCompatActivity() {
}
}
private fun updateFiatBalance() {
object : Thread() {
override fun run() {
val coinBal = java.lang.Double.parseDouble(WalletManager.getBalance(WalletManager.wallet).toPlainString())
val df = DecimalFormat("#,###.##", DecimalFormatSymbols(Locale.US))
val fiatBalances = when (UIManager.fiat) {
"USD" -> {
val priceUsd = NetManager.price
val balUsd = coinBal * priceUsd
"$" + df.format(balUsd)
}
"EUR" -> {
val priceEur = NetManager.priceEur
val balEur = coinBal * priceEur
"€" + df.format(balEur)
}
"AUD" -> {
val priceAud = NetManager.priceAud
val balAud = coinBal * priceAud
"AUD$" + df.format(balAud)
}
else -> ""
}
runOnUiThread {
fiatBalTxtSend.text = fiatBalances
}
}
}.start()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode != Constants.REQUEST_CODE_GET_CONTACT) {
......@@ -302,41 +339,6 @@ class SendActivity : AppCompatActivity() {
}
}
private fun updateFiatBalance() {
object : Thread() {
override fun run() {
val coinBal = java.lang.Double.parseDouble(WalletManager.getBalance(WalletManager.wallet).toPlainString())
val df = DecimalFormat("#,###.##", DecimalFormatSymbols(Locale.US))
val fiatBalances = when (UIManager.fiat) {
"USD" -> {
val priceUsd = MainActivity.INSTANCE.netManager.price
val balUsd = coinBal * priceUsd
"$" + df.format(balUsd)
}
"EUR" -> {
val priceEur = MainActivity.