Verified Commit 0d2601fb authored by Sarath's avatar Sarath
Browse files

Sats/BTC toggle option in whirlpool screens

parent 6086ec8e
......@@ -587,6 +587,16 @@ public class BalanceActivity extends SamouraiActivity {
// LocalBroadcastManager.getInstance(BalanceActivity.this).registerReceiver(receiver, filter);
AppUtil.getInstance(BalanceActivity.this).checkTimeOut();
try {
boolean isSatPrefs = PrefsUtil.getInstance(getApplicationContext()).getValue(PrefsUtil.IS_SAT,false);
if(isSatPrefs != balanceViewModel.getSatState().getValue()){
balanceViewModel.toggleSat();
}
} catch (Exception e) {
LogUtil.error(TAG,e);
}
//
// Intent intent = new Intent("com.samourai.wallet.MainActivity2.RESTART_SERVICE");
// LocalBroadcastManager.getInstance(BalanceActivity.this).sendBroadcast(intent);
......
......@@ -53,9 +53,11 @@ class WhirlPoolHomeViewModel : ViewModel() {
private val mixingBalanceLive = MutableLiveData(0L)
private val totalBalanceLive = MutableLiveData(0L)
private val whirlpoolOnboarded = MutableLiveData(false)
private val displaySats = MutableLiveData(false)
val mixingLive: LiveData<List<WhirlpoolUtxo>> get() = mixing
val remixLive: LiveData<List<WhirlpoolUtxo>> get() = remixing
val displaySatsLive: LiveData<Boolean> get() = displaySats
val remixBalance: LiveData<Long> get() = remixBalanceLive
val mixingBalance: LiveData<Long> get() = mixingBalanceLive
val mixTransactionsList: LiveData<Map<WhirlpoolAccount,List<Tx>>> get() = mixTransactions
......@@ -89,7 +91,7 @@ class WhirlPoolHomeViewModel : ViewModel() {
}
}, {
})
compositeDisposable.add(disposable)
compositeDisposable.add(disposable)
viewModelScope.launch(Dispatchers.Default){
......@@ -251,4 +253,12 @@ class WhirlPoolHomeViewModel : ViewModel() {
WhirlpoolAccount.PREMIX to premixList
))
}
fun toggleSats(boolean: Boolean?=null) {
if(boolean!=null){
this.displaySats.value = boolean
}else{
this.displaySats.value = !(this.displaySats.value ?: false)
}
}
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ import android.widget.EditText
import android.widget.LinearLayout
import android.widget.Toast
import androidx.activity.viewModels
import androidx.lifecycle.Observer
import androidx.lifecycle.viewModelScope
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.viewpager.widget.ViewPager
......@@ -31,6 +32,7 @@ import com.samourai.wallet.send.cahoots.ManualCahootsActivity
import com.samourai.wallet.service.JobRefreshService
import com.samourai.wallet.util.FormatsUtil
import com.samourai.wallet.util.LogUtil
import com.samourai.wallet.util.PrefsUtil
import com.samourai.wallet.utxos.PreSelectUtil
import com.samourai.wallet.utxos.UTXOSActivity
import com.samourai.wallet.whirlpool.fragments.SectionsPagerAdapter
......@@ -78,6 +80,8 @@ class WhirlpoolHome : SamouraiActivity() {
val whirlpoolDialog = WhirlpoolDialog()
whirlpoolDialog.show(supportFragmentManager, whirlpoolDialog.tag)
}
val displaySats = PrefsUtil.getInstance(applicationContext).getValue(PrefsUtil.IS_SAT,false)
whirlPoolHomeViewModel.toggleSats(displaySats)
binding.viewPager.addOnPageChangeListener(pageListener)
val filterDisplay = IntentFilter(BalanceActivity.DISPLAY_INTENT)
LocalBroadcastManager.getInstance(this@WhirlpoolHome)
......@@ -94,9 +98,11 @@ class WhirlpoolHome : SamouraiActivity() {
var hasMixUtxos = false;
if (AndroidWhirlpoolWalletService.getInstance().whirlpoolWallet.isPresent) {
hasMixUtxos =
AndroidWhirlpoolWalletService.getInstance().whirlpoolWallet.get().utxoSupplier.findUtxos(WhirlpoolAccount.PREMIX, WhirlpoolAccount.POSTMIX).isEmpty()
AndroidWhirlpoolWalletService.getInstance().whirlpoolWallet.get().utxoSupplier.findUtxos(
WhirlpoolAccount.PREMIX,
WhirlpoolAccount.POSTMIX
).isEmpty()
}
LogUtil.debug(TAG, "checkOnboardStatus: ${postmix && premix && hasMixUtxos}")
withContext(Dispatchers.Main) {
if (whirlPoolHomeViewModel.onboardStatus.value != postmix && premix && hasMixUtxos) {
whirlPoolHomeViewModel.setOnBoardingStatus(postmix && premix && hasMixUtxos)
......@@ -115,41 +121,52 @@ class WhirlpoolHome : SamouraiActivity() {
tabs.setupWithViewPager(viewPager)
whirlPoolHomeViewModel.remixBalance.observe(this, {
if (viewPager.currentItem == 3) {
binding.whirlpoolToolbar.title = FormatsUtil.formatBTC(it)
setBalance(3)
}
})
whirlPoolHomeViewModel.totalBalance.observe(this, {
if (viewPager.currentItem == 0) {
binding.whirlpoolToolbar.title = FormatsUtil.formatBTC(it)
setBalance(0)
}
})
whirlPoolHomeViewModel.mixingBalance.observe(this, {
if (viewPager.currentItem == 1) {
binding.whirlpoolToolbar.title = FormatsUtil.formatBTC(it)
setBalance(1)
}
})
//Show mixing/remixing count in tabs title
whirlPoolHomeViewModel.mixingLive.observe(this,{
if(it.isNotEmpty()){
whirlPoolHomeViewModel.mixingLive.observe(this, {
if (it.isNotEmpty()) {
tabs.getTabAt(1)?.text = "$mixingStr (${it.size})"
}else{
} else {
tabs.getTabAt(1)?.text = mixingStr
}
})
whirlPoolHomeViewModel.remixLive.observe(this,{
if(it.isNotEmpty()){
whirlPoolHomeViewModel.remixLive.observe(this, {
if (it.isNotEmpty()) {
tabs.getTabAt(2)?.text = "$remixingStr (${it.size})"
}else{
} else {
tabs.getTabAt(2)?.text = remixingStr
}
})
binding.toolbar.setOnClickListener {
whirlPoolHomeViewModel.toggleSats()
PrefsUtil.getInstance(applicationContext).setValue(PrefsUtil.IS_SAT,whirlPoolHomeViewModel.displaySatsLive.value ?:false)
}
binding.whirlpoolToolbar.setOnClickListener {
whirlPoolHomeViewModel.toggleSats()
PrefsUtil.getInstance(applicationContext).setValue(PrefsUtil.IS_SAT,whirlPoolHomeViewModel.displaySatsLive.value ?:false)
}
try {
validateIntentAndStartNewPool()
} catch (ex: Exception) {
}
whirlPoolHomeViewModel.displaySatsLive.observe(this, Observer {
setBalance(binding.viewPager.currentItem)
})
checkOnboardStatus()
}
......@@ -168,32 +185,39 @@ class WhirlpoolHome : SamouraiActivity() {
}
override fun onPageSelected(position: Int) {
var balance = 0L;
when (position) {
0 -> {
binding.whirlpoolAmountCaption.text = "Total Balance"
whirlPoolHomeViewModel.totalBalance.value?.let {
balance = it
}
setBalance(position)
}
override fun onPageScrollStateChanged(state: Int) {}
}
fun setBalance(position: Int) {
var balance = 0L;
when (position) {
0 -> {
binding.whirlpoolAmountCaption.text = "Total Balance"
whirlPoolHomeViewModel.totalBalance.value?.let {
balance = it
}
1 -> {
binding.whirlpoolAmountCaption.text = "Total in Progress Balance "
whirlPoolHomeViewModel.mixingBalance.value?.let {
balance = it
}
}
1 -> {
binding.whirlpoolAmountCaption.text = "Total in Progress Balance "
whirlPoolHomeViewModel.mixingBalance.value?.let {
balance = it
}
2 -> {
binding.whirlpoolAmountCaption.text = "Total Remixable Balance "
whirlPoolHomeViewModel.remixBalance.value?.let {
balance = it
}
}
2 -> {
binding.whirlpoolAmountCaption.text = "Total Remixable Balance "
whirlPoolHomeViewModel.remixBalance.value?.let {
balance = it
}
}
binding.whirlpoolToolbar.title = FormatsUtil.formatBTC(balance)
binding.toolbar.title = FormatsUtil.formatBTC(balance)
}
override fun onPageScrollStateChanged(state: Int) {}
val showSats = whirlPoolHomeViewModel.displaySatsLive.value ?: false;
val balanceString =
if (showSats) FormatsUtil.formatSats(balance) else FormatsUtil.formatBTC(balance)
binding.whirlpoolToolbar.title = balanceString
binding.toolbar.title = balanceString
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
......@@ -372,6 +396,6 @@ class WhirlpoolHome : SamouraiActivity() {
companion object {
const val NEWPOOL_REQ_CODE = 6102
private const val TAG = "WhirlpoolHome"
}
}
}
\ No newline at end of file
package com.samourai.wallet.whirlpool.adapters
import android.annotation.SuppressLint
import android.content.Context
import android.text.format.DateUtils
import android.transition.ChangeBounds
......@@ -35,6 +36,7 @@ class MixTxAdapter(private val mContext: Context) :
private var postMixTxs: List<Tx> = listOf()
private var preMixTxs: List<Tx> = listOf()
private val VIEW_SECTION = 0
var displaySats= false
private val disposables = CompositeDisposable()
private var listener: ((tx:Tx)->Unit )? = null
private val mDiffer = AsyncListDiffer(this, DIFF_CALLBACK)
......@@ -65,7 +67,7 @@ class MixTxAdapter(private val mContext: Context) :
}
override fun onBindViewHolder(holder: TxViewHolder, position: Int) {
val isSatPrefs = PrefsUtil.getInstance(mContext).getValue(PrefsUtil.IS_SAT, false)
val tx = mDiffer.currentList[position]
val isPremix = this.preMixTxs.contains(tx)
if (tx!!.section == null) {
......@@ -98,7 +100,7 @@ class MixTxAdapter(private val mContext: Context) :
)
)
holder.tvAmount?.setTextColor(ContextCompat.getColor(mContext, R.color.white))
val amountStr = "-${if (isSatPrefs) FormatsUtil.formatSats(_amount) else FormatsUtil.formatBTC(
val amountStr = "-${if (displaySats) FormatsUtil.formatSats(_amount) else FormatsUtil.formatBTC(
_amount
)}"
holder.tvAmount?.text = amountStr
......@@ -118,7 +120,7 @@ class MixTxAdapter(private val mContext: Context) :
)
)
val amount =
if (isSatPrefs) FormatsUtil.formatSats(_amount) else FormatsUtil.formatBTC(
if (displaySats) FormatsUtil.formatSats(_amount) else FormatsUtil.formatBTC(
_amount
)
holder.tvAmount?.text = amount
......@@ -306,6 +308,14 @@ class MixTxAdapter(private val mContext: Context) :
}
}
@SuppressLint("NotifyDataSetChanged")
fun displaySats(it: Boolean?) {
it?.let {
this.displaySats = it
this.notifyDataSetChanged()
}
}
companion object {
private const val MAX_CONFIRM_COUNT = 3
val DIFF_CALLBACK: DiffUtil.ItemCallback<Tx?> = object : DiffUtil.ItemCallback<Tx?>() {
......
package com.samourai.wallet.whirlpool.fragments
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -21,18 +22,19 @@ class MixListAdapter : RecyclerView.Adapter<MixListAdapter.ViewHolder>() {
private lateinit var itemMixUtxoBinding: ItemMixUtxoBinding
var onClick: (utxo: WhirlpoolUtxo) -> Unit = {}
private var displaySats = false
var onMixingButtonClickListener: (utxo: WhirlpoolUtxo) -> Unit = {}
private val mDiffer = AsyncListDiffer(this, DIFF_CALLBACK)
private val scope = CoroutineScope(Dispatchers.Default) + SupervisorJob()
class ViewHolder(private val viewBinding: ItemMixUtxoBinding) :
inner class ViewHolder(private val viewBinding: ItemMixUtxoBinding) :
RecyclerView.ViewHolder(viewBinding.root) {
fun bind(utxo: WhirlpoolUtxo) {
val utxoState = utxo.utxoState
val output = utxo.utxo
val progressbar = viewBinding.mixProgressBar
viewBinding.mixAmount.text = FormatsUtil.formatBTC(output.value)
viewBinding.mixAmount.text = if(displaySats) FormatsUtil.formatSats(output.value) else FormatsUtil.formatBTC(output.value)
if (utxoState != null && utxoState.mixProgress != null) {
viewBinding.mixProgressMessage.visibility = View.VISIBLE
viewBinding.mixProgressMessage.text = utxoState.mixProgress.mixStep.message
......@@ -88,6 +90,11 @@ class MixListAdapter : RecyclerView.Adapter<MixListAdapter.ViewHolder>() {
}
@SuppressLint("NotifyDataSetChanged")
fun setDisplaySats(sat:Boolean){
displaySats = sat
this.notifyDataSetChanged()
}
fun updateList(utxos: List<WhirlpoolUtxo>) {
scope.launch (Dispatchers.Default){
try {
......
......@@ -98,6 +98,9 @@ class MixListFragment : Fragment() {
}
})
viewModel.displaySatsLive.observe(viewLifecycleOwner, {
mixListAdapter.setDisplaySats(it)
})
mixListAdapter.setOnClickListener {
val mixDetailsBottomSheet =
MixDetailsBottomSheet.newInstance(it.utxo.tx_hash, it.utxo.tx_output_n)
......
......@@ -14,6 +14,7 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.lifecycle.viewModelScope
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.recyclerview.widget.DividerItemDecoration
......@@ -26,6 +27,7 @@ import com.samourai.wallet.api.Tx
import com.samourai.wallet.databinding.WhirlpoolIntroViewBinding
import com.samourai.wallet.home.BalanceActivity
import com.samourai.wallet.tx.TxDetailsActivity
import com.samourai.wallet.util.PrefsUtil
import com.samourai.wallet.whirlpool.WhirlPoolHomeViewModel
import com.samourai.wallet.whirlpool.WhirlpoolHome.Companion.NEWPOOL_REQ_CODE
import com.samourai.wallet.whirlpool.adapters.MixTxAdapter
......@@ -38,7 +40,7 @@ import kotlinx.coroutines.withContext
class TransactionsFragment : Fragment() {
private val whirlPoolHomeViewModel: WhirlPoolHomeViewModel by activityViewModels()
lateinit var adapter: MixTxAdapter
private var adapter: MixTxAdapter? = null;
lateinit var recyclerView: RecyclerView
lateinit var containerLayout: FrameLayout
private var swipeRefreshLayout: SwipeRefreshLayout? = null
......@@ -74,7 +76,10 @@ class TransactionsFragment : Fragment() {
adapter = MixTxAdapter(
view.context,
)
adapter.setClickListener { tx ->
val displaySats =
PrefsUtil.getInstance(requireActivity()).getValue(PrefsUtil.IS_SAT, false)
adapter?.displaySats = displaySats
adapter?.setClickListener { tx ->
val txIntent = Intent(requireContext(), TxDetailsActivity::class.java)
txIntent.putExtra("TX", tx.toJSON().toString())
txIntent.putExtra("_account", WhirlpoolAccount.POSTMIX.accountIndex)
......@@ -100,7 +105,7 @@ class TransactionsFragment : Fragment() {
preMix.addAll(filteredPremix)
}
}
adapter.setTx(postMix,preMix)
adapter?.setTx(postMix,preMix)
})
}
})
......@@ -186,6 +191,9 @@ class TransactionsFragment : Fragment() {
whirlPoolHomeViewModel.listRefreshStatus.observe(viewLifecycleOwner, {
swipeRefreshLayout?.isRefreshing = it
})
whirlPoolHomeViewModel.displaySatsLive.observe(viewLifecycleOwner, { satPref->
adapter?.displaySats(satPref)
})
containerLayout.addView(swipeRefreshLayout)
return containerLayout
}
......
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