Commit 41cba4a0 authored by pokkst's avatar pokkst

Fix bug with Cash Account label being stuck as ___#??? even when confirmed....

Fix bug with Cash Account label being stuck as ___#??? even when confirmed. Fix issue where changing theme would reset syncing label on home screen back to "Syncing..." when the wallet was in fact already synced.
parent 78c329bb
......@@ -21,6 +21,7 @@ import app.crescentcash.src.utils.PermissionHelper
import app.crescentcash.src.utils.PrefsUtil
import app.crescentcash.src.wallet.SLPWalletHelper
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.firebase.FirebaseApp
import org.bitcoinj.utils.MonetaryFormat
import java.io.File
import java.text.DecimalFormat
......@@ -64,13 +65,17 @@ class MainActivity : AppCompatActivity() {
this@MainActivity.prepareViews()
this@MainActivity.initListeners()
this@MainActivity.refresh()
if(!UIManager.isDisplayingDownload) {
this@MainActivity.syncPct.text = ""
}
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
instance = this
dataDirectory = applicationInfo.dataDir
PrefsUtil.prefs = getSharedPreferences("app.crescentcash.src", Context.MODE_PRIVATE)
PrefsUtil.loadPrefs()
UIManager.determineTheme(this)
......@@ -78,15 +83,10 @@ class MainActivity : AppCompatActivity() {
this.findViews()
this.prepareViews()
this.initListeners()
//FirebaseApp.initializeApp(this)
//INSTANCE = this
FirebaseApp.initializeApp(this)
NetManager.establishProxy()
SLPWalletHelper.setAPIKey()
//this.uiHelper.networkNodeText.setText(prefs.getString("networkNode", ""))
isNewUser = !File(this.applicationInfo.dataDir + "/users_wallet.wallet").exists()
if (isNewUser) {
......@@ -105,7 +105,7 @@ class MainActivity : AppCompatActivity() {
if (cashAcct != "" && cashAcct.contains("#???")) {
val plainName = cashAcct.replace("#???", "")
WalletManager.registeredBlock = "???"
NetManager.initialAccountIdentityCheck(plainName)
NetManager.initialAccountIdentityCheck(this, plainName)
WalletManager.timer = object : CountDownTimer(150000, 20) {
override fun onTick(millisUntilFinished: Long) {
......@@ -114,7 +114,7 @@ class MainActivity : AppCompatActivity() {
override fun onFinish() {
try {
NetManager.checkForAccountIdentity(plainName)
NetManager.checkForAccountIdentity(this@MainActivity, plainName)
} catch (e: Exception) {
e.printStackTrace()
}
......@@ -216,7 +216,6 @@ class MainActivity : AppCompatActivity() {
if (!status) {
syncPct.text = ""
}
}
private fun displayReceive() {
......@@ -319,13 +318,13 @@ class MainActivity : AppCompatActivity() {
}
}
companion object {
//lateinit var INSTANCE: MainActivity
var isNewUser = true
private lateinit var instance: MainActivity
lateinit var dataDirectory: String
fun getDataDir(): String {
return instance.applicationInfo.dataDir
return dataDirectory
}
}
}
package app.crescentcash.src.activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.*
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Matrix
......@@ -13,6 +11,7 @@ import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import app.crescentcash.src.R
import app.crescentcash.src.hash.HashHelper
......@@ -33,6 +32,15 @@ class ReceiveActivity : AppCompatActivity() {
private lateinit var myEmoji: TextView
private lateinit var srlContent_AM: SwipeRefreshLayout
private var cashAccount: String? = ""
private var receiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (Constants.ACTION_UPDATE_CASH_ACCOUNT_LABEL == intent.action) {
this@ReceiveActivity.cashAccount = PrefsUtil.prefs.getString("cashAccount", "")
this@ReceiveActivity.displayCashAccount()
this@ReceiveActivity.calculateEmoji()
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -89,18 +97,14 @@ class ReceiveActivity : AppCompatActivity() {
clipboard.setPrimaryClip(clip)
UIManager.showToastMessage(this, "Copied")
}
val filter = IntentFilter()
filter.addAction(Constants.ACTION_UPDATE_CASH_ACCOUNT_LABEL)
LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter)
}
private fun displayEmoji() {
var cashEmoji = PrefsUtil.prefs.getString("cashEmoji", "")
if (myCashHandle.text.toString().contains("#???")) {
cashEmoji = "?"
println("CASH ACCOUNT UNCONFIRMED")
val cashAcctPlain = myCashHandle.text.toString().replace("#???", "")
NetManager.initialAccountIdentityCheck(cashAcctPlain)
}
val cashEmoji = PrefsUtil.prefs.getString("cashEmoji", "")
myEmoji.text = cashEmoji
if (srlContent_AM.isRefreshing) srlContent_AM.isRefreshing = false
......@@ -110,6 +114,12 @@ class ReceiveActivity : AppCompatActivity() {
fun displayCashAccount() {
myCashHandle.text = cashAccount
if (myCashHandle.text.toString().contains("#???")) {
println("CASH ACCOUNT UNCONFIRMED")
val cashAcctPlain = myCashHandle.text.toString().replace("#???", "")
NetManager.initialAccountIdentityCheck(this, cashAcctPlain)
}
if (WalletManager.walletKit != null) {
this.btcAddress.text = WalletManager.wallet.currentReceiveAddress().toString()
btcAddress.text = this.btcAddress.text.toString().replace(WalletManager.parameters.cashAddrPrefix + ":", "")
......@@ -196,6 +206,7 @@ class ReceiveActivity : AppCompatActivity() {
val emoji = HashHelper().getCashAccountEmoji(WalletManager.registeredBlockHash, WalletManager.registeredTxHash)
PrefsUtil.prefs.edit().putString("cashEmoji", emoji).apply()
this@ReceiveActivity.myEmoji.text = emoji
this@ReceiveActivity.displayEmoji()
} catch (e: Exception) {
this@ReceiveActivity.myEmoji.text = "?"
}
......
package app.crescentcash.src.manager
import android.app.Activity
import android.content.Intent
import android.os.CountDownTimer
import android.text.TextUtils
import android.view.View
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import app.crescentcash.src.MainActivity
import app.crescentcash.src.activity.SendActivity
import app.crescentcash.src.async.AsyncTaskVerifyWallet
......@@ -77,7 +80,7 @@ class NetManager {
override fun onFinish() {
try {
checkForAccountIdentity(activity.handle.text.toString())
checkForAccountIdentity(activity, activity.handle.text.toString())
} catch (e: Exception) {
e.printStackTrace()
}
......@@ -254,7 +257,7 @@ class NetManager {
return emoji
}
fun initialAccountIdentityCheck(name: String) {
fun initialAccountIdentityCheck(activity: Activity, name: String) {
object : Thread() {
override fun run() {
if (WalletManager.registeredBlock == "null" || WalletManager.registeredBlock == "???") {
......@@ -278,8 +281,8 @@ class NetManager {
val emoji = hashHelper.getCashAccountEmoji(WalletManager.registeredBlockHash, WalletManager.registeredTxHash)
PrefsUtil.prefs.edit().putString("cashAccount", identifier).apply()
PrefsUtil.prefs.edit().putString("cashEmoji", emoji).apply()
println(identifier)
println(emoji)
val intent = Intent(Constants.ACTION_UPDATE_CASH_ACCOUNT_LABEL)
LocalBroadcastManager.getInstance(activity).sendBroadcast(intent)
}
}
} catch (e: NullPointerException) {
......@@ -292,7 +295,7 @@ class NetManager {
}.start()
}
fun checkForAccountIdentity(name: String) {
fun checkForAccountIdentity(activity: Activity, name: String) {
object : Thread() {
override fun run() {
if (WalletManager.registeredBlock == "null" || WalletManager.registeredBlock == "???") {
......@@ -322,8 +325,8 @@ class NetManager {
val emoji = hashHelper.getCashAccountEmoji(WalletManager.registeredBlockHash, WalletManager.registeredTxHash)
PrefsUtil.prefs.edit().putString("cashAccount", identifier).apply()
PrefsUtil.prefs.edit().putString("cashEmoji", emoji).apply()
println(identifier)
println(emoji)
val intent = Intent(Constants.ACTION_UPDATE_CASH_ACCOUNT_LABEL)
LocalBroadcastManager.getInstance(activity).sendBroadcast(intent)
}
}
} catch (e: NullPointerException) {
......
......@@ -24,4 +24,5 @@ object Constants {
var ACTION_CLEAR_SEND = "SendActivity.CLEAR_SEND"
var ACTION_UPDATE_HOME_SCREEN_BALANCE = "MainActivity.UPDATE_HOME_SCREEN_BALANCE"
var ACTION_UPDATE_HOME_SCREEN_THEME = "MainActivity.UPDATE_HOME_SCREEN_THEME"
var ACTION_UPDATE_CASH_ACCOUNT_LABEL = "ReceiveActivity.ACTION_UPDATE_CASH_ACCOUNT_LABEL"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment