Add the functionality in TransactionsFragment to filter transactions by Equivalent Value range, taking into account the currency precision.

master
Severiano Jaramillo 2019-02-07 13:20:24 -06:00
parent abfbed91f5
commit d68b34f973
2 changed files with 18 additions and 9 deletions

View File

@ -103,6 +103,8 @@ class FilterOptionsDialog : DialogFragment() {
private var mBalancesDetailsAdapter: BalancesDetailsAdapter? = null
private lateinit var mCurrency: Currency
/**
* DatePicker message handler.
*/
@ -243,16 +245,20 @@ class FilterOptionsDialog : DialogFragment() {
llEquivalentValue.visibility = if(isChecked) View.GONE else View.VISIBLE }
cbEquivalentValue.isChecked = arguments!!.getBoolean(KEY_FILTER_EQUIVALENT_VALUE_ALL, true)
// TODO obtain user selected currency
val currencySymbol = "usd"
mCurrency = Currency.getInstance(currencySymbol)
etFromEquivalentValue = view.findViewById(R.id.etFromEquivalentValue)
val fromEquivalentValue = arguments!!.getLong(KEY_FILTER_FROM_EQUIVALENT_VALUE, 0)
val fromEquivalentValue = arguments!!.getLong(KEY_FILTER_FROM_EQUIVALENT_VALUE, 0) /
Math.pow(10.0, mCurrency.defaultFractionDigits.toDouble()).toLong()
etFromEquivalentValue.setText("$fromEquivalentValue", TextView.BufferType.EDITABLE)
etToEquivalentValue = view.findViewById(R.id.etToEquivalentValue)
val toEquivalentValue = arguments!!.getLong(KEY_FILTER_TO_EQUIVALENT_VALUE, 0)
val toEquivalentValue = arguments!!.getLong(KEY_FILTER_TO_EQUIVALENT_VALUE, 0) /
Math.pow(10.0, mCurrency.defaultFractionDigits.toDouble()).toLong()
etToEquivalentValue.setText("$toEquivalentValue", TextView.BufferType.EDITABLE)
// TODO obtain user selected currency
val currencySymbol = "usd"
tvEquivalentValueSymbol = view.findViewById(R.id.tvEquivalentValueSymbol)
tvEquivalentValueSymbol.text = currencySymbol.toUpperCase()
@ -317,9 +323,11 @@ class FilterOptionsDialog : DialogFragment() {
val filterEquivalentValueAll = cbEquivalentValue.isChecked
val filterFromEquivalentValue = etFromEquivalentValue.text.toString().toLong()
val filterFromEquivalentValue = etFromEquivalentValue.text.toString().toLong() *
Math.pow(10.0, mCurrency.defaultFractionDigits.toDouble()).toLong()
var filterToEquivalentValue = etToEquivalentValue.text.toString().toLong()
var filterToEquivalentValue = etToEquivalentValue.text.toString().toLong() *
Math.pow(10.0, mCurrency.defaultFractionDigits.toDouble()).toLong()
// Make sure ToEquivalentValue is at least 50 units bigger than FromEquivalentValue
if (!filterEquivalentValueAll && filterToEquivalentValue < filterFromEquivalentValue + 50) {

View File

@ -53,7 +53,7 @@ class TransactionsFragment : Fragment(), FilterOptionsDialog.OnFilterOptionsSele
private var filterAsset = "BTS"
private var filterEquivalentValueAll = true
private var filterFromEquivalentValue = 0L
private var filterToEquivalentValue = 50L
private var filterToEquivalentValue = 5000L
private var filterAgoriseFees = true
private var mDisposables = CompositeDisposable()
@ -176,8 +176,9 @@ class TransactionsFragment : Fragment(), FilterOptionsDialog.OnFilterOptionsSele
continue
// // Filter by equivalent value
// if (!filterEquivalentValueAll && (transferDetail.fiatAmount < filterFromEquivalentValue || transferDetail.fiatAmount > filterToEquivalentValue))
// continue
if (!filterEquivalentValueAll && ((transferDetail.fiatAmount ?: -1 ) < filterFromEquivalentValue
|| (transferDetail.fiatAmount ?: -1) > filterToEquivalentValue))
continue
// Filter transactions sent to agorise
if (filterAgoriseFees && transferDetail.to.equals("agorise"))