Commit d36b9290 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 16c7ac54
......@@ -37,11 +37,21 @@
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
<activity android:name=".activity.SendSLPActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
<activity android:name=".activity.ReceiveActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
<activity android:name=".activity.ReceiveSLPActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
<activity android:name=".activity.SettingsActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
......@@ -72,6 +82,16 @@
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
<activity android:name=".activity.HistoryActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
<activity android:name=".activity.TokensListActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
......
......@@ -117,51 +117,6 @@ class MainActivity : AppCompatActivity() {
this.uiHelper.restore_wallet.visibility = View.GONE
this.uiHelper.newuser.visibility = View.VISIBLE
}
this.uiHelper.sendSLPWindow.visibility == View.VISIBLE -> {
this.uiHelper.sendSLPWindow.visibility = View.GONE
this.uiHelper.clearSend()
}
this.uiHelper.receiveWindowSLP.visibility == View.VISIBLE -> this.uiHelper.receiveWindowSLP.visibility = View.GONE
this.uiHelper.txInfo.visibility == View.VISIBLE -> this.uiHelper.txInfo.visibility = View.GONE
/*this.uiHelper.utxosScreen.visibility == View.VISIBLE -> {
this.walletHelper.selectedUtxos = ArrayList()
this.uiHelper.utxosScreen.visibility = View.GONE
}
this.uiHelper.encryptScreen.visibility == View.VISIBLE -> {
WalletHelper.encrypted = false
this.uiHelper.encryptWalletSwitch.isChecked = WalletHelper.encrypted
this.prefs.edit().putBoolean("useEncryption", WalletHelper.encrypted).apply()
this.uiHelper.encryptScreen.visibility = View.GONE
}*/
/*this.uiHelper.manageKeyScreen.visibility == View.VISIBLE -> {
this.uiHelper.messageToSignText.text = null
this.uiHelper.signatureText.text = null
this.uiHelper.manageKeyScreen.visibility = View.GONE
}
this.uiHelper.keysScreen.visibility == View.VISIBLE -> {
this.uiHelper.keyToImportText.text = null
this.uiHelper.keysScreen.visibility = View.GONE
}
this.uiHelper.verifySigScreen.visibility == View.VISIBLE -> {
this.uiHelper.messageToVerify.text = null
this.uiHelper.addressToVerify.text = null
this.uiHelper.verifySignature.text = null
this.uiHelper.verifySigScreen.visibility = View.GONE
}
this.uiHelper.advancedSettings.visibility == View.VISIBLE -> {
this.prefs.edit().putString("networkNode", this.uiHelper.networkNodeText.text.toString()).apply()
this.uiHelper.advancedSettings.visibility = View.GONE
}
this.uiHelper.walletSettings.visibility == View.VISIBLE -> {
this.walletHelper.maximumAutomaticSend = this.uiHelper.autoSendAmount.text.toString().toFloat()
this.prefs.edit().putFloat("maximumAutomaticSend", this.walletHelper.maximumAutomaticSend).apply()
this.uiHelper.walletSettings.visibility = View.GONE
}*/
this.uiHelper.slpBalancesWindow.visibility == View.VISIBLE -> this.uiHelper.slpBalancesWindow.visibility = View.GONE
this.uiHelper.bitcoinWindow.visibility == View.VISIBLE -> {
this.uiHelper.bitcoinWindow.visibility = View.GONE
this.uiHelper.closeFabMenu()
}
else -> {
val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_HOME)
......
......@@ -96,8 +96,11 @@ class ReceiveActivity : AppCompatActivity() {
private fun displayEmoji() {
var cashEmoji = MainActivity.INSTANCE.prefs.getString("cashEmoji", "")
if (myCashHandle.text.contains("#???")) {
if (myCashHandle.text.toString().contains("#???")) {
cashEmoji = "?"
val cashAcctPlain = myCashHandle.text.toString().replace("#???", "")
MainActivity.INSTANCE.netHelper.initialAccountIdentityCheck(cashAcctPlain)
}
myEmoji.text = cashEmoji
......@@ -125,24 +128,6 @@ class ReceiveActivity : AppCompatActivity() {
} else {
this.btcAddress.text = "Loading..."
}
}
private fun displayCashAccount(wallet: Wallet, cashAccount: String?) {
myCashHandle.text = cashAccount
val bchAddress: String
if (MainActivity.INSTANCE.walletHelper.walletKit != null) {
bchAddress = MainActivity.INSTANCE.walletHelper.wallet.currentReceiveAddress().toString()
btcAddress.text = bchAddress.replace(MainActivity.INSTANCE.walletHelper.parameters.cashAddrPrefix + ":", "")
generateQR(bchAddress, R.id.btcQR, false)
} else {
bchAddress = "Loading..."
btcAddress.text = bchAddress
}
if (srlContent_AM.isRefreshing) srlContent_AM.isRefreshing = false
}
private fun generateQR(textToConvert: String, viewID: Int, slp: Boolean) {
......
package app.crescentcash.src.activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Matrix
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.get
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.AppManager
import app.crescentcash.src.manager.UIManager
import app.crescentcash.src.manager.WalletManager
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.wallet.WalletHelper
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.zxing.BarcodeFormat
import com.google.zxing.WriterException
import com.journeyapps.barcodescanner.BarcodeEncoder
import org.bitcoinj.core.CashAddressFactory
import org.bitcoinj.core.ECKey
import org.bitcoinj.core.TransactionOutput
import org.bitcoinj.utils.MonetaryFormat
import org.bitcoinj.wallet.Wallet
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.util.*
class ReceiveSLPActivity : AppCompatActivity() {
private lateinit var copySlpAddr: ImageView
private lateinit var slpAddress: TextView
private var currentAddrView = true
private lateinit var toggleAddr: ImageButton
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.setContentView(R.layout.receive_slp)
this.findViews()
this.prepareViews(savedInstanceState)
this.initListeners()
}
private fun prepareViews(savedInstanceState: Bundle?) {
UIManager.determineTheme(this)
this.displayReceiveSLP()
}
private fun findViews() {
copySlpAddr = this.findViewById(R.id.copySlpAddr)
slpAddress = this.findViewById(R.id.slpAddress)
toggleAddr = this.findViewById(R.id.toggleAddr)
}
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
clipboard.setPrimaryClip(clip)
Toast.makeText(MainActivity.INSTANCE, "Copied", Toast.LENGTH_SHORT).show()
}
this.toggleAddr.setOnClickListener {
this.currentAddrView = !this.currentAddrView
this.displayReceiveSLP()
}
}
private fun generateQR(textToConvert: String, viewID: Int, slp: Boolean) {
try {
val encoder = BarcodeEncoder()
val qrCode = encoder.encodeBitmap(textToConvert, BarcodeFormat.QR_CODE, 1024, 1024)
val coinLogo: Bitmap? = if (!slp)
drawableToBitmap(this.resources.getDrawable(R.drawable.logo_bch))
else
drawableToBitmap(this.resources.getDrawable(R.drawable.logo_slp))
val merge = overlayBitmapToCenter(qrCode, coinLogo!!)
(this.findViewById<View>(viewID) as ImageView).setImageBitmap(merge)
} catch (e: WriterException) {
e.printStackTrace()
}
}
/*
I'm absolutely terrible with Bitmap and image generation shit. Always have been.
Shout-out to StackOverflow for some of this.
*/
private fun overlayBitmapToCenter(bitmap1: Bitmap, bitmap2: Bitmap): Bitmap {
val bitmap1Width = bitmap1.width
val bitmap1Height = bitmap1.height
val bitmap2Width = bitmap2.width
val bitmap2Height = bitmap2.height
val marginLeft = (bitmap1Width * 0.5 - bitmap2Width * 0.5).toFloat()
val marginTop = (bitmap1Height * 0.5 - bitmap2Height * 0.5).toFloat()
val overlayBitmap = Bitmap.createBitmap(bitmap1Width, bitmap1Height, bitmap1.config)
val canvas = Canvas(overlayBitmap)
canvas.drawBitmap(bitmap1, Matrix(), null)
canvas.drawBitmap(bitmap2, marginLeft, marginTop, null)
return overlayBitmap
}
private fun drawableToBitmap(drawable: Drawable): Bitmap? {
val bitmap: Bitmap? = if (drawable.intrinsicWidth <= 0 || drawable.intrinsicHeight <= 0) {
Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888) // Single color bitmap will be created of 1x1 pixel
} else {
Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
}
if (drawable is BitmapDrawable) {
if (drawable.bitmap != null) {
return drawable.bitmap
}
}
val canvas = Canvas(bitmap!!)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
return bitmap
}
private fun displayReceiveSLP() {
if (MainActivity.INSTANCE.walletHelper.walletKit != null) {
val address = if (currentAddrView)
MainActivity.INSTANCE.walletHelper.getSLPWallet().slpAddress
else
MainActivity.INSTANCE.walletHelper.getSLPWallet().bchAddress
slpAddress.text = address.replace("simpleledger:", "").replace(MainActivity.INSTANCE.walletHelper.parameters.cashAddrPrefix + ":", "")
if (currentAddrView)
generateQR(address, R.id.slpQR, true)
else
generateQR(address, R.id.slpQR, false)
} else {
slpAddress.text = "Loading..."
}
}
companion object {
}
}
......@@ -58,6 +58,7 @@ class SendActivity : AppCompatActivity() {
private lateinit var contactsBtn: ImageButton
lateinit var opReturnText: EditText
lateinit var opReturnBox: LinearLayout
private lateinit var qrScan: ImageView
val recipient: String
get() = tvRecipientAddress_AM.text.toString().trim { it <= ' ' }
......@@ -87,6 +88,7 @@ class SendActivity : AppCompatActivity() {
contactsBtn = this.findViewById(R.id.contactsBtn)
opReturnText = this.findViewById(R.id.opReturnText)
opReturnBox = this.findViewById(R.id.opReturnBox)
qrScan = this.findViewById(R.id.qrScan)
}
private fun prepareViews(savedInstanceState: Bundle?) {
......@@ -195,6 +197,7 @@ class SendActivity : AppCompatActivity() {
this.tvRecipientAddress_AM.addListener(listener)
this.donateBtn.setOnClickListener { this.displayRecipientAddress(Constants.DONATION_ADDRESS) }
this.qrScan.setOnClickListener { UIManager.clickScanQR(this, Constants.REQUEST_CODE_SCAN_PAY_TO) }
}
private fun setMaxCoins() {
......@@ -320,7 +323,7 @@ class SendActivity : AppCompatActivity() {
if(data != null) {
val scanData = data.getStringExtra(Constants.QR_SCAN_RESULT)
if (scanData != null) {
if (requestCode == Constants.REQUEST_CODE_SCAN_PAY_TO || requestCode == Constants.REQUEST_CODE_SCAN_PAY_SLP_TO) {
if (requestCode == Constants.REQUEST_CODE_SCAN_PAY_TO) {
this.processScanOrPaste(scanData)
} else if (requestCode == Constants.REQUEST_CODE_SWEEP_SCAN) {
WalletManager.sweepWallet(scanData)
......
package app.crescentcash.src.activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.provider.ContactsContract
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.annotation.UiThread
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.get
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import app.crescentcash.src.MainActivity
import app.crescentcash.src.R
import app.crescentcash.src.listener.RecipientTextListener
import app.crescentcash.src.manager.AppManager
import app.crescentcash.src.manager.UIManager
import app.crescentcash.src.manager.WalletManager
import app.crescentcash.src.qr.QRHelper
import app.crescentcash.src.ui.NonScrollListView
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.wallet.WalletHelper
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.common.util.concurrent.ListenableFuture
import com.ncorti.slidetoact.SlideToActView
import org.bitcoinj.core.CashAddressFactory
import org.bitcoinj.core.ECKey
import org.bitcoinj.core.TransactionOutput
import org.bitcoinj.protocols.payments.PaymentProtocolException
import org.bitcoinj.protocols.payments.PaymentSession
import org.bitcoinj.utils.MonetaryFormat
import org.bitcoinj.wallet.Wallet
import java.math.BigDecimal
import java.math.RoundingMode
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.util.*
import java.util.concurrent.ExecutionException
class SendSLPActivity : AppCompatActivity() {
private lateinit var setMaxSLP: Button
lateinit var slpAmount: TextView
lateinit var slpRecipientAddress: TextView
private lateinit var slp_qrScan: ImageView
lateinit var sendSLPBtn: SlideToActView
private lateinit var slpUnit: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.setContentView(R.layout.send_slp)
this.findViews()
this.prepareViews(savedInstanceState)
this.initListeners()
}
private fun findViews() {
sendSLPBtn = this.findViewById(R.id.sendSLPBtn)
setMaxSLP = this.findViewById(R.id.setMaxSLP)
slpUnit = this.findViewById(R.id.slpUnit)
slpAmount = this.findViewById(R.id.slpAmount)
slpRecipientAddress = this.findViewById(R.id.slpRecipientAddress)
slp_qrScan = this.findViewById(R.id.slp_qrScan)
}
private fun prepareViews(savedInstanceState: Bundle?) {
UIManager.determineTheme(this)
this.slpUnit.text = if (savedInstanceState == null) {
val extras = intent.extras
if(extras == null) {
""
} else {
extras.getString(Constants.INTENT_TOKEN_TICKER_DATA)
}
} else {
savedInstanceState.getSerializable(Constants.INTENT_TOKEN_TICKER_DATA).toString()
}
}
private fun initListeners() {
this.setMaxSLP.setOnClickListener {
val walletHelper = MainActivity.INSTANCE.walletHelper
slpAmount.text = walletHelper.tokenListInfo[walletHelper.currentTokenPosition].amount.toPlainString()
}
val slideSLPListener: SlideToActView.OnSlideCompleteListener = object : SlideToActView.OnSlideCompleteListener {
override fun onSlideComplete(view: SlideToActView) {
if (!TextUtils.isEmpty(slpRecipientAddress.text) && !TextUtils.isEmpty(slpAmount.text)) {
if (!slpRecipientAddress.text.toString().contains("#")) {
val tokenId = MainActivity.INSTANCE.walletHelper.currentTokenId
val tokenPos = MainActivity.INSTANCE.walletHelper.currentTokenPosition
val tokenInfo = MainActivity.INSTANCE.walletHelper.tokenListInfo[tokenPos]
val amt = BigDecimal(java.lang.Double.parseDouble(slpAmount.text.toString())).setScale(tokenInfo.decimals!!, RoundingMode.HALF_UP)
println(amt.toPlainString())
MainActivity.INSTANCE.walletHelper.sendToken(this@SendSLPActivity, tokenId, amt, slpRecipientAddress.text.toString())
} else {
this@SendSLPActivity.runOnUiThread { UIManager.showToastMessage(this@SendSLPActivity, "SLP CashAccts are not supported.") }
}
}
}
}
this.sendSLPBtn.onSlideCompleteListener = slideSLPListener
this.slp_qrScan.setOnClickListener { UIManager.clickScanQR(this, Constants.REQUEST_CODE_SCAN_PAY_SLP_TO) }
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(data != null) {
val scanData = data.getStringExtra(Constants.QR_SCAN_RESULT)
if (scanData != null) {
if (requestCode == Constants.REQUEST_CODE_SCAN_PAY_SLP_TO) {
val uri = URIHelper(this, scanData, true)
} else if (requestCode == Constants.REQUEST_CODE_SWEEP_SCAN) {
WalletManager.sweepWallet(scanData)
} /*else if (requestCode == Constants.REQUEST_CODE_IMPORT_SCAN) {
this.uiHelper.keyToImportText.setText(scanData)
} else if (requestCode == Constants.REQUEST_CODE_SIG_VERIFY_MESSAGE_SCAN) {
this.uiHelper.messageToVerify.setText(scanData)
} else if (requestCode == Constants.REQUEST_CODE_SIG_VERIFY_ADDRESS_SCAN) {
this.uiHelper.addressToVerify.setText(scanData)
} else if (requestCode == Constants.REQUEST_CODE_SIG_VERIFY_SIGNATURE_SCAN) {
this.uiHelper.verifySignature.setText(scanData)
}*/
}
}
}
companion object {
}
}
package app.crescentcash.src.activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.get
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import app.crescentcash.src.MainActivity
import app.crescentcash.src.R
import app.crescentcash.src.manager.AppManager
import app.crescentcash.src.manager.UIManager
import app.crescentcash.src.manager.WalletManager
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.wallet.SLPWalletHelper
import app.crescentcash.src.wallet.WalletHelper
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.luminiasoft.ethereum.blockiesandroid.BlockiesIdenticon
import com.ncorti.slidetoact.SlideToActView
import org.bitcoinj.core.CashAddressFactory
import org.bitcoinj.core.ECKey
import org.bitcoinj.core.TransactionOutput
import org.bitcoinj.utils.MonetaryFormat
import org.bitcoinj.wallet.Wallet
import java.lang.Double
import java.math.BigDecimal
import java.math.RoundingMode
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.util.*
class TokensListActivity : AppCompatActivity() {
private lateinit var srlSLP: SwipeRefreshLayout
private lateinit var fabReceiveSLP: FloatingActionButton
private lateinit var slpList: NonScrollListView
lateinit var bchBalanceSLP: TextView
private lateinit var no_tx_text_slp: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.setContentView(R.layout.slp_balances)
this.findViews()
this.prepareViews(savedInstanceState)
this.initListeners()
}
private fun prepareViews(savedInstanceState: Bundle?) {
UIManager.determineTheme(this)
bchBalanceSLP.text = if (savedInstanceState == null) {
val extras = intent.extras
if(extras == null) {
""
} else {
extras.getString(Constants.INTENT_BALANCE_DATA)
}
} else {
savedInstanceState.getSerializable(Constants.INTENT_BALANCE_DATA).toString()
}
}
private fun findViews() {
no_tx_text_slp = this.findViewById(R.id.no_tx_text_slp)
fabReceiveSLP = this.findViewById(R.id.fabReceiveSLP)
bchBalanceSLP = this.findViewById(R.id.bchBalanceSLP)
srlSLP = this.findViewById(R.id.srlSLP)
slpList = this.findViewById(R.id.slpList)
}
private fun initListeners() {
this.srlSLP.setOnRefreshListener { this.refreshSLP() }
this.fabReceiveSLP.setOnClickListener {
UIManager.startActivity(MainActivity.INSTANCE, ReceiveSLPActivity::class.java)
}
this.slpList.setOnItemClickListener { parent, view, position, id ->
val walletHelper = MainActivity.INSTANCE.walletHelper
walletHelper.currentTokenPosition = position
walletHelper.currentTokenId = walletHelper.tokenListInfo[walletHelper.currentTokenPosition].tokenId
val sendSlpActivity = Intent(this, SendSLPActivity::class.java)
sendSlpActivity.putExtra(Constants.INTENT_TOKEN_TICKER_DATA, walletHelper.tokenListInfo[walletHelper.currentTokenPosition].ticker)
this.startActivity(sendSlpActivity)
}
}
fun refreshSLP() {
setSLPList()
if (srlSLP.isRefreshing) srlSLP.isRefreshing = false
}
private fun setSLPList() {
val walletHelper = MainActivity.INSTANCE.walletHelper
walletHelper.getSLPWallet().refreshBalance()
if (walletHelper.balances.isNotEmpty()) {
walletHelper.tokenList = ArrayList()
walletHelper.tokenListInfo = ArrayList()
val amtOfTokens = walletHelper.balances.size
if (amtOfTokens >= 2) {
srlSLP.visibility = View.VISIBLE
no_tx_text_slp.visibility = View.GONE
for (x in 0 until amtOfTokens) {
/*
SLP SDK includes BCH in the balance list, with a tokenHash of "" so we check shortly after gathering all of the data if the hash does not equal "" before adding
*/
val datum = HashMap<String, String>()
val tokenName = walletHelper.balances[x].name
val tokenTicker = walletHelper.balances[x].ticker
val tokenHash = walletHelper.balances[x].tokenId
val balance = walletHelper.balances[x].amount.toPlainString()
val amt = BigDecimal(java.lang.Double.parseDouble(balance)).setScale(walletHelper.balances[x].decimals!!, RoundingMode.HALF_UP)
datum["token"] = tokenName!!
datum["tokenHash"] = tokenHash
datum["tokenTicker"] = tokenTicker!!
datum["balance"] = amt.toPlainString()
if (tokenHash != "") {
walletHelper.tokenList.add(datum)
walletHelper.tokenListInfo.add(walletHelper.balances[x])
}
}
val itemsAdapter = object : SimpleAdapter(this, walletHelper.tokenList, R.layout.list_view_activity, null, null) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
// Get the Item from ListView
val view = LayoutInflater.from(this@TokensListActivity).inflate(R.layout.list_view_activity, null)
val slpBlockiesAddress = SLPWalletHelper.blockieAddressFromTokenId(walletHelper.tokenList[position]["tokenHash"]
?: error(""))
val slpImage = view.findViewById<BlockiesIdenticon>(R.id.slpImage)
val slpIcon = view.findViewById<ImageView>(R.id.slpWithIcon)
object : Thread() {
override fun run() {
try {
val tokenHash = walletHelper.tokenList[position]["tokenHash"]
val exists = MainActivity.INSTANCE.resources.getIdentifier("slp$tokenHash", "drawable", MainActivity.INSTANCE.packageName) != 0
if (exists) {
val drawable = MainActivity.INSTANCE.resources.getDrawable(MainActivity.INSTANCE.resources.getIdentifier("slp$tokenHash", "drawable", MainActivity.INSTANCE.packageName))
MainActivity.INSTANCE.runOnUiThread {
slpIcon.setImageDrawable(drawable)
slpImage.visibility = View.GONE
slpIcon.visibility = View.VISIBLE
}
} else {
slpImage.setAddress(slpBlockiesAddress)
slpImage.setCornerRadius(128f)
}
} catch (e: Exception) {
slpImage.setAddress(slpBlockiesAddress)
slpImage.setCornerRadius(128f)
}
}
}.start()
// Initialize a TextView for ListView each Item
val text1 = view.findViewById<TextView>(R.id.text1)
val text2 = view.findViewById<TextView>(R.id.text2)
val text3 = view.findViewById<TextView>(R.id.text3)
// Set the text color of TextView (ListView Item)
text1.text = walletHelper.tokenList[position]["token"].toString()
text2.text = walletHelper.tokenList[position]["balance"].toString()
text3.text = walletHelper.tokenList[position]["tokenTicker"].toString()
if (UIHelper.nightModeEnabled) {
text1.setTextColor(Color.WHITE)
text2.setTextColor(Color.GRAY)
text3.setTextColor(Color.WHITE)
} else {
text1.setTextColor(Color.BLACK)
text3.setTextColor(Color.BLACK)
}
text2.ellipsize = TextUtils.TruncateAt.END
text2.maxLines = 1