From d68b34f973b435aa0300e65ad69ad66bf33b852a Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Thu, 7 Feb 2019 13:20:24 -0600 Subject: [PATCH] Add the functionality in TransactionsFragment to filter transactions by Equivalent Value range, taking into account the currency precision. --- .../fragments/FilterOptionsDialog.kt | 20 +++++++++++++------ .../fragments/TransactionsFragment.kt | 7 ++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/FilterOptionsDialog.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/FilterOptionsDialog.kt index 9aa3be3..e83d7c7 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/FilterOptionsDialog.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/FilterOptionsDialog.kt @@ -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) { diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/TransactionsFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/TransactionsFragment.kt index 2682cf0..64d318c 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/TransactionsFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/TransactionsFragment.kt @@ -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"))