Commit 0b7f6cb3 authored by pokkst's avatar pokkst

Adds Street Mode. This masks your balance and prevents emptying wallet.

Removes Google services.
parent 748c1d3a
......@@ -3,8 +3,6 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs.kotlin'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
android {
compileSdkVersion 29
......@@ -55,7 +53,5 @@ dependencies {
implementation('com.squareup.okhttp3:okhttp:3.12.0') {
exclude group: 'com.squareup.okio', module: 'okio'
}
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
}
\ No newline at end of file
......@@ -20,7 +20,6 @@ import app.crescentcash.src.utils.Constants
import app.crescentcash.src.utils.PermissionHelper
import app.crescentcash.src.utils.PrefsUtil
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
......@@ -82,7 +81,6 @@ class MainActivity : AppCompatActivity() {
this.findViews()
this.prepareViews()
this.initListeners()
FirebaseApp.initializeApp(this)
NetManager.establishProxy()
WalletManager.setAPIKey()
......@@ -253,7 +251,11 @@ class MainActivity : AppCompatActivity() {
}
}
balance.text = balanceText
if(UIManager.streetModeEnabled) {
balance.text = "########"
} else {
balance.text = balanceText
}
}
}
......@@ -287,7 +289,11 @@ class MainActivity : AppCompatActivity() {
}
this@MainActivity.runOnUiThread {
fiatBalTxt.text = fiatBalances
if(UIManager.streetModeEnabled) {
fiatBalTxt.text = "####"
} else {
fiatBalTxt.text = fiatBalances
}
}
}
}.start()
......
......@@ -7,6 +7,7 @@ import android.text.TextUtils
import android.view.View
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import app.crescentcash.src.R
import app.crescentcash.src.listener.RecipientTextListener
......@@ -114,6 +115,11 @@ class SendActivity : AppCompatActivity() {
} else {
View.GONE
}
if(UIManager.streetModeEnabled) {
this.setMaxCoins.isEnabled = false
this.setMaxCoins.backgroundTintList = ContextCompat.getColorStateList(this, R.color.gray)
}
}
private fun initListeners() {
......@@ -145,30 +151,30 @@ class SendActivity : AppCompatActivity() {
WalletManager.sendType = WalletManager.displayUnits
sendTypeSpinner.setSelection(0)
PrefsUtil.prefs.edit().putString("sendType", WalletManager.sendType).apply()
val coins = if (WalletManager.selectedUtxos.size == 0) {
bchBalSend.text.toString().replace(" ${WalletManager.displayUnits}", "").replace(",", "")
var balBch: Double = if (WalletManager.selectedUtxos.size == 0) {
java.lang.Double.parseDouble(WalletManager.getBalance(WalletManager.wallet).toPlainString())
} else {
var balBch: Double = java.lang.Double.parseDouble(WalletManager.getMaxValueOfSelectedUtxos().toPlainString())
val unit = WalletManager.displayUnits
when (unit) {
MonetaryFormat.CODE_BTC -> {
UIManager.formatBalanceNoUnit(balBch, "#.########")
}
MonetaryFormat.CODE_MBTC -> {
balBch *= 1000
UIManager.formatBalanceNoUnit(balBch, "#.#####")
}
MonetaryFormat.CODE_UBTC -> {
balBch *= 1000000
UIManager.formatBalanceNoUnit(balBch, "#.##")
}
"sats" -> {
balBch *= 100000000
UIManager.formatBalanceNoUnit(balBch, "#")
}
else -> UIManager.formatBalanceNoUnit(balBch, "#.########")
java.lang.Double.parseDouble(WalletManager.getMaxValueOfSelectedUtxos().toPlainString())
}
val unit = WalletManager.displayUnits
val coins = when (unit) {
MonetaryFormat.CODE_BTC -> {
UIManager.formatBalanceNoUnit(balBch, "#.########")
}
MonetaryFormat.CODE_MBTC -> {
balBch *= 1000
UIManager.formatBalanceNoUnit(balBch, "#.#####")
}
MonetaryFormat.CODE_UBTC -> {
balBch *= 1000000
UIManager.formatBalanceNoUnit(balBch, "#.##")
}
"sats" -> {
balBch *= 100000000
UIManager.formatBalanceNoUnit(balBch, "#")
}
else -> UIManager.formatBalanceNoUnit(balBch, "#.########")
}
println("Setting...")
......@@ -255,7 +261,11 @@ class SendActivity : AppCompatActivity() {
}
}
bchBalSend.text = balanceText
if(UIManager.streetModeEnabled) {
bchBalSend.text = "########"
} else {
bchBalSend.text = balanceText
}
}
}
......@@ -288,7 +298,11 @@ class SendActivity : AppCompatActivity() {
}
runOnUiThread {
fiatBalTxtSend.text = fiatBalances
if(UIManager.streetModeEnabled) {
fiatBalTxtSend.text = "####"
} else {
fiatBalTxtSend.text = fiatBalances
}
}
}
}.start()
......
......@@ -37,6 +37,7 @@ class SettingsActivity : AppCompatActivity() {
lateinit var encryptWalletSwitch: Switch
lateinit var useTorSwitch: Switch
private lateinit var copyXpubBtn: ImageView
lateinit var streetModeSwitch: Switch
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -50,6 +51,7 @@ class SettingsActivity : AppCompatActivity() {
private fun prepareViews() {
this.nightModeSwitch.isChecked = UIManager.nightModeEnabled
this.showFiatSwitch.isChecked = UIManager.showFiat
this.streetModeSwitch.isChecked = UIManager.streetModeEnabled
this.encryptWalletSwitch.isChecked = WalletManager.encrypted
this.useTorSwitch.isChecked = WalletManager.useTor
this.autoSendAmount.text = PrefsUtil.prefs.getFloat("maximumAutomaticSend", 0.00f).toString()
......@@ -68,6 +70,7 @@ class SettingsActivity : AppCompatActivity() {
encryptWalletSwitch = this.findViewById(R.id.encryptWalletSwitch)
useTorSwitch = this.findViewById(R.id.useTorSwitch)
copyXpubBtn = this.findViewById(R.id.copyXpubBtn)
streetModeSwitch = this.findViewById(R.id.streetModeSwitch)
}
private fun initListeners() {
......@@ -114,6 +117,12 @@ class SettingsActivity : AppCompatActivity() {
PrefsUtil.prefs.edit().putBoolean("useTor", WalletManager.useTor).apply()
}
this.streetModeSwitch.setOnCheckedChangeListener { buttonView, isChecked ->
UIManager.streetModeEnabled = isChecked
PrefsUtil.prefs.edit().putBoolean("streetMode", UIManager.streetModeEnabled).apply()
val intent = Intent(Constants.ACTION_UPDATE_HOME_SCREEN_BALANCE)
LocalBroadcastManager.getInstance(this@SettingsActivity).sendBroadcast(intent)
}
val decimalFormatter = DecimalFormat("#.########", DecimalFormatSymbols(Locale.US))
this.autoSendAmount.text = decimalFormatter.format(WalletManager.maximumAutomaticSend)
......
......@@ -24,6 +24,7 @@ class UIManager {
var emojis = intArrayOf(128123, 128018, 128021, 128008, 128014, 128004, 128022, 128016, 128042, 128024, 128000, 128007, 128063, 129415, 128019, 128039, 129414, 129417, 128034, 128013, 128031, 128025, 128012, 129419, 128029, 128030, 128375, 127803, 127794, 127796, 127797, 127809, 127808, 127815, 127817, 127819, 127820, 127822, 127826, 127827, 129373, 129381, 129365, 127805, 127798, 127812, 129472, 129370, 129408, 127850, 127874, 127853, 127968, 128663, 128690, 9973, 9992, 128641, 128640, 8986, 9728, 11088, 127752, 9730, 127880, 127872, 9917, 9824, 9829, 9830, 9827, 128083, 128081, 127913, 128276, 127925, 127908, 127911, 127928, 127930, 129345, 128269, 128367, 128161, 128214, 9993, 128230, 9999, 128188, 128203, 9986, 128273, 128274, 128296, 128295, 9878, 9775, 128681, 128099, 127838)
var nightModeEnabled = false
var showFiat = true
var streetModeEnabled = false
fun formatBalance(amount: Double, pattern: String): String {
val formatter = DecimalFormat(pattern, DecimalFormatSymbols(Locale.US))
......
......@@ -11,6 +11,7 @@ class PrefsUtil {
fun loadPrefs() {
UIManager.nightModeEnabled = prefs.getBoolean("nightMode", false)
UIManager.streetModeEnabled = prefs.getBoolean("streetMode", false)
UIManager.showFiat = prefs.getBoolean("showFiat", true)
UIManager.fiat = prefs.getString("fiat", "USD") as String
WalletManager.displayUnits = prefs.getString("displayUnit", MonetaryFormat.CODE_BTC) as String
......
......@@ -341,6 +341,46 @@
android:layout_height="wrap_content"
android:minHeight="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:text="Street Mode"
android:textColor="?attr/textColor"
android:textColorHighlight="@color/colorAccentDark"
android:textIsSelectable="true"
android:textSize="18sp" />
<Switch
android:id="@+id/streetModeSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Mask your balance"
android:textColor="?attr/textColor"
android:textColorHighlight="@color/colorAccentDark"
android:textIsSelectable="true"
android:textSize="12sp" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="15dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
......
......@@ -12,4 +12,5 @@
<color name="statusBarLight">#fff</color>
<color name="navBarDark">#252525</color>
<color name="navBarLight">#fff</color>
<color name="gray">#777777</color>
</resources>
\ No newline at end of file
......@@ -10,11 +10,8 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0"
classpath 'com.google.gms:google-services:4.3.2'
classpath 'io.fabric.tools:gradle:1.31.1' // Crashlytics plugin
}
}
......
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