From 18f7754cce97d32c9f2534ee9a03abaa7d9685f3 Mon Sep 17 00:00:00 2001 From: Prem Nirmal Date: Sat, 18 Jun 2022 11:11:13 +0100 Subject: [PATCH] fix sorting bug and make price format lighter on memory --- app/build.gradle | 4 +- .../premnirmal/ticker/network/data/Quote.kt | 250 +++++++++--------- .../premnirmal/ticker/widget/WidgetData.kt | 3 +- app/version.properties | 4 +- 4 files changed, 133 insertions(+), 128 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7b76c967..1c108552 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,9 +43,9 @@ def getOldGitVersion = { -> def stdout = new ByteArrayOutputStream() exec { if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', 'Powershell', "git tag --sort=-committerdate | Select-Object -first 8 | Select-Object -last 1" + commandLine 'cmd', '/c', 'Powershell', "git tag --sort=-committerdate | Select-Object -first 10 | Select-Object -last 1" } else { - commandLine 'sh', '-c', "git tag --sort=-committerdate | head -8 | tail -1" + commandLine 'sh', '-c', "git tag --sort=-committerdate | head -10 | tail -1" } standardOutput = stdout } diff --git a/app/src/main/kotlin/com/github/premnirmal/ticker/network/data/Quote.kt b/app/src/main/kotlin/com/github/premnirmal/ticker/network/data/Quote.kt index 93aa5a72..f90f1068 100644 --- a/app/src/main/kotlin/com/github/premnirmal/ticker/network/data/Quote.kt +++ b/app/src/main/kotlin/com/github/premnirmal/ticker/network/data/Quote.kt @@ -55,7 +55,9 @@ data class Quote constructor( var marketCap: Long? = null val priceFormat: PriceFormat - get() = currencyCodes[currencyCode] ?: PriceFormat(currencyCode, currencyCode) + get() = currencyCodes[currencyCode]?.let { + PriceFormat(currencyCode = currencyCode, symbol = it, prefix = suffixCurrencies[it] ?: true) + } ?: PriceFormat(currencyCode, currencyCode) fun hasAlertAbove(): Boolean = this.properties != null && this.properties!!.alertAbove > 0.0f && this.properties!!.alertAbove < this.lastTradePrice @@ -199,129 +201,133 @@ data class Quote constructor( companion object { - private val currencyCodes: Map by lazy { + private val currencyCodes: Map by lazy { mapOf( - "USD" to PriceFormat("USD", "$"), - "CAD" to PriceFormat("CAD", "$"), - "EUR" to PriceFormat("EUR", "€"), - "AED" to PriceFormat("AED", "د.إ.‏"), - "AFN" to PriceFormat("AFN", "؋"), - "ALL" to PriceFormat("ALL", "Lek"), - "AMD" to PriceFormat("AMD", "դր."), - "ARS" to PriceFormat("ARS", "$"), - "AUD" to PriceFormat("AUD", "$"), - "AZN" to PriceFormat("AZN", "ман."), - "BAM" to PriceFormat("BAM", "KM"), - "BDT" to PriceFormat("BDT", "৳"), - "BGN" to PriceFormat("BGN", "лв."), - "BHD" to PriceFormat("BHD", "د.ب.‏"), - "BIF" to PriceFormat("BIF", "FBu"), - "BND" to PriceFormat("BND", "$"), - "BOB" to PriceFormat("BOB", "Bs"), - "BRL" to PriceFormat("BRL", "R$"), - "BWP" to PriceFormat("BWP", "P"), - "BYN" to PriceFormat("BYN", "руб."), - "BZD" to PriceFormat("BZD", "$"), - "CDF" to PriceFormat("CDF", "FrCD"), - "CHF" to PriceFormat("CHF", "CHF"), - "CLP" to PriceFormat("CLP", "$"), - "CNY" to PriceFormat("CNY", "CN¥"), - "COP" to PriceFormat("COP", "$"), - "CRC" to PriceFormat("CRC", "₡"), - "CVE" to PriceFormat("CVE", "CV$"), - "CZK" to PriceFormat("CZK", "Kč"), - "DJF" to PriceFormat("DJF", "Fdj"), - "DKK" to PriceFormat("DKK", "kr"), - "DOP" to PriceFormat("DOP", "RD$"), - "DZD" to PriceFormat("DZD", "د.ج.‏"), - "EEK" to PriceFormat("EEK", "kr"), - "EGP" to PriceFormat("EGP", "ج.م.‏"), - "ERN" to PriceFormat("ERN", "Nfk"), - "ETB" to PriceFormat("ETB", "Br"), - "GBP" to PriceFormat("GBP", "£"), - "GBp" to PriceFormat("GBp", "p", prefix = false), - "GEL" to PriceFormat("GEL", "GEL"), - "GHS" to PriceFormat("GHS", "GH₵"), - "GNF" to PriceFormat("GNF", "FG"), - "GTQ" to PriceFormat("GTQ", "Q"), - "HKD" to PriceFormat("HKD", "$"), - "HNL" to PriceFormat("HNL", "L"), - "HRK" to PriceFormat("HRK", "kn"), - "HUF" to PriceFormat("HUF", "Ft"), - "IDR" to PriceFormat("IDR", "Rp"), - "ILS" to PriceFormat("ILS", "₪"), - "INR" to PriceFormat("INR", "₹"), - "IQD" to PriceFormat("IQD", "د.ع.‏"), - "IRR" to PriceFormat("IRR", "﷼"), - "ISK" to PriceFormat("ISK", "kr"), - "JMD" to PriceFormat("JMD", "$"), - "JOD" to PriceFormat("JOD", "د.أ.‏"), - "JPY" to PriceFormat("JPY", "¥"), - "KES" to PriceFormat("KES", "Ksh"), - "KHR" to PriceFormat("KHR", "៛"), - "KMF" to PriceFormat("KMF", "FC"), - "KRW" to PriceFormat("KRW", "₩"), - "KWD" to PriceFormat("KWD", "د.ك.‏"), - "KZT" to PriceFormat("KZT", "тңг."), - "LBP" to PriceFormat("LBP", "ل.ل.‏"), - "LKR" to PriceFormat("LKR", "SLRe"), - "LTL" to PriceFormat("LTL", "Lt"), - "LVL" to PriceFormat("LVL", "Ls"), - "LYD" to PriceFormat("LYD", "د.ل.‏"), - "MAD" to PriceFormat("MAD", "د.م.‏"), - "MDL" to PriceFormat("MDL", "MDL"), - "MGA" to PriceFormat("MGA", "MGA"), - "MKD" to PriceFormat("MKD", "MKD"), - "MMK" to PriceFormat("MMK", "K"), - "MOP" to PriceFormat("MOP", "MOP$"), - "MUR" to PriceFormat("MUR", "MURs"), - "MXN" to PriceFormat("MXN", "$"), - "MYR" to PriceFormat("MYR", "RM"), - "MZN" to PriceFormat("MZN", "MTn"), - "NAD" to PriceFormat("NAD", "N$"), - "NGN" to PriceFormat("NGN", "₦"), - "NIO" to PriceFormat("NIO", "C$"), - "NOK" to PriceFormat("NOK", "kr"), - "NPR" to PriceFormat("NPR", "नेरू"), - "NZD" to PriceFormat("NZD", "$"), - "OMR" to PriceFormat("OMR", "ر.ع.‏"), - "PAB" to PriceFormat("PAB", "B/."), - "PEN" to PriceFormat("PEN", "S/."), - "PHP" to PriceFormat("PHP", "₱"), - "PKR" to PriceFormat("PKR", "₨"), - "PLN" to PriceFormat("PLN", "zł"), - "PYG" to PriceFormat("PYG", "₲"), - "QAR" to PriceFormat("QAR", "ر.ق.‏"), - "RON" to PriceFormat("RON", "RON"), - "RSD" to PriceFormat("RSD", "дин."), - "RUB" to PriceFormat("RUB", "₽."), - "RWF" to PriceFormat("RWF", "FR"), - "SAR" to PriceFormat("SAR", "ر.س.‏"), - "SDG" to PriceFormat("SDG", "SDG"), - "SEK" to PriceFormat("SEK", "kr"), - "SGD" to PriceFormat("SGD", "$"), - "SOS" to PriceFormat("SOS", "Ssh"), - "SYP" to PriceFormat("SYP", "ل.س.‏"), - "THB" to PriceFormat("THB", "฿"), - "TND" to PriceFormat("TND", "د.ت.‏"), - "TOP" to PriceFormat("TOP", "T$"), - "TRY" to PriceFormat("TRY", "TL"), - "TTD" to PriceFormat("TTD", "$"), - "TWD" to PriceFormat("TWD", "NT$"), - "TZS" to PriceFormat("TZS", "TSh"), - "UAH" to PriceFormat("UAH", "₴"), - "UGX" to PriceFormat("UGX", "USh"), - "UYU" to PriceFormat("UYU", "$"), - "UZS" to PriceFormat("UZS", "UZS"), - "VEF" to PriceFormat("VEF", "Bs.F."), - "VND" to PriceFormat("VND", "₫"), - "XAF" to PriceFormat("XAF", "FCFA"), - "XOF" to PriceFormat("XOF", "CFA"), - "YER" to PriceFormat("YER", "ر.ي.‏"), - "ZAR" to PriceFormat("ZAR", "R"), - "ZMK" to PriceFormat("ZMK", "ZK"), - "ZWL" to PriceFormat("ZWL", "ZWL$") + "USD" to "$", + "CAD" to "$", + "EUR" to "€", + "AED" to "د.إ.‏", + "AFN" to "؋", + "ALL" to "Lek", + "AMD" to "դր.", + "ARS" to "$", + "AUD" to "$", + "AZN" to "ман.", + "BAM" to "KM", + "BDT" to "৳", + "BGN" to "лв.", + "BHD" to "د.ب.‏", + "BIF" to "FBu", + "BND" to "$", + "BOB" to "Bs", + "BRL" to "R$", + "BWP" to "P", + "BYN" to "руб.", + "BZD" to "$", + "CDF" to "FrCD", + "CHF" to "CHF", + "CLP" to "$", + "CNY" to "CN¥", + "COP" to "$", + "CRC" to "₡", + "CVE" to "CV$", + "CZK" to "Kč", + "DJF" to "Fdj", + "DKK" to "kr", + "DOP" to "RD$", + "DZD" to "د.ج.‏", + "EEK" to "kr", + "EGP" to "ج.م.‏", + "ERN" to "Nfk", + "ETB" to "Br", + "GBP" to "£", + "GBp" to "p", + "GEL" to "GEL", + "GHS" to "GH₵", + "GNF" to "FG", + "GTQ" to "Q", + "HKD" to "$", + "HNL" to "L", + "HRK" to "kn", + "HUF" to "Ft", + "IDR" to "Rp", + "ILS" to "₪", + "INR" to "₹", + "IQD" to "د.ع.‏", + "IRR" to "﷼", + "ISK" to "kr", + "JMD" to "$", + "JOD" to "د.أ.‏", + "JPY" to "¥", + "KES" to "Ksh", + "KHR" to "៛", + "KMF" to "FC", + "KRW" to "₩", + "KWD" to "د.ك.‏", + "KZT" to "тңг.", + "LBP" to "ل.ل.‏", + "LKR" to "SLRe", + "LTL" to "Lt", + "LVL" to "Ls", + "LYD" to "د.ل.‏", + "MAD" to "د.م.‏", + "MDL" to "MDL", + "MGA" to "MGA", + "MKD" to "MKD", + "MMK" to "K", + "MOP" to "MOP$", + "MUR" to "MURs", + "MXN" to "$", + "MYR" to "RM", + "MZN" to "MTn", + "NAD" to "N$", + "NGN" to "₦", + "NIO" to "C$", + "NOK" to "kr", + "NPR" to "नेरू", + "NZD" to "$", + "OMR" to "ر.ع.‏", + "PAB" to "B/.", + "PEN" to "S/.", + "PHP" to "₱", + "PKR" to "₨", + "PLN" to "zł", + "PYG" to "₲", + "QAR" to "ر.ق.‏", + "RON" to "RON", + "RSD" to "дин.", + "RUB" to "₽.", + "RWF" to "FR", + "SAR" to "ر.س.‏", + "SDG" to "SDG", + "SEK" to "kr", + "SGD" to "$", + "SOS" to "Ssh", + "SYP" to "ل.س.‏", + "THB" to "฿", + "TND" to "د.ت.‏", + "TOP" to "T$", + "TRY" to "TL", + "TTD" to "$", + "TWD" to "NT$", + "TZS" to "TSh", + "UAH" to "₴", + "UGX" to "USh", + "UYU" to "$", + "UZS" to "UZS", + "VEF" to "Bs.F.", + "VND" to "₫", + "XAF" to "FCFA", + "XOF" to "CFA", + "YER" to "ر.ي.‏", + "ZAR" to "R", + "ZMK" to "ZK", + "ZWL" to "ZWL$" ) } + + private val suffixCurrencies: Map by lazy { + mapOf("GBp" to true) + } } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/github/premnirmal/ticker/widget/WidgetData.kt b/app/src/main/kotlin/com/github/premnirmal/ticker/widget/WidgetData.kt index b5e5b3ec..1af984b1 100644 --- a/app/src/main/kotlin/com/github/premnirmal/ticker/widget/WidgetData.kt +++ b/app/src/main/kotlin/com/github/premnirmal/ticker/widget/WidgetData.kt @@ -17,7 +17,6 @@ import com.github.premnirmal.tickerwidget.R import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import javax.inject.Inject -import kotlin.math.absoluteValue class WidgetData { @@ -267,7 +266,7 @@ class WidgetData { tickerList.map { stocksProvider.getStock(it) } .forEach { quote -> quote?.let { quoteList.add(it) } } if (autoSortEnabled()) { - quoteList.sortedByDescending { it.changeInPercent } + quoteList.sortByDescending { it.changeInPercent } } return quoteList } diff --git a/app/version.properties b/app/version.properties index 11481bdc..ee41c657 100644 --- a/app/version.properties +++ b/app/version.properties @@ -1,3 +1,3 @@ # this file is purely for f-droid because it cannot infer the version name/code from the git tag -versionName=3.9.783 -versionCode=300900783 \ No newline at end of file +versionName=3.9.784 +versionCode=300900784 \ No newline at end of file