diff --git a/app/src/main/java/org/gnucash/android/export/xml/GncXmlExporter.java b/app/src/main/java/org/gnucash/android/export/xml/GncXmlExporter.java index 0deb60637..60f2bf740 100644 --- a/app/src/main/java/org/gnucash/android/export/xml/GncXmlExporter.java +++ b/app/src/main/java/org/gnucash/android/export/xml/GncXmlExporter.java @@ -647,16 +647,9 @@ private void exportPrices(XmlSerializer xmlSerializer) throws IOException { Timber.i("export prices"); xmlSerializer.startTag(null, TAG_PRICEDB); xmlSerializer.attribute(null, ATTR_KEY_VERSION, "1"); - Cursor cursor = mPricesDbAdapter.fetchAllRecords(); - try { - while (cursor.moveToNext()) { - Price price = mPricesDbAdapter.buildModelInstance(cursor); - exportPrice(xmlSerializer, price); - } - } finally { - if (cursor != null) { - cursor.close(); - } + List prices = mPricesDbAdapter.getAllRecords(); + for (Price price : prices) { + exportPrice(xmlSerializer, price); } xmlSerializer.endTag(null, TAG_PRICEDB); } @@ -669,8 +662,8 @@ private void exportPrice(XmlSerializer xmlSerializer, Price price) throws IOExce xmlSerializer.text(price.getUID()); xmlSerializer.endTag(null, TAG_PRICE_ID); // commodity - String commodityId = price.getCommodityUID(); - Commodity commodity = mCommoditiesDbAdapter.getRecord(commodityId); + String commodityUID = price.getCommodityUID(); + Commodity commodity = mCommoditiesDbAdapter.getRecord(commodityUID); xmlSerializer.startTag(null, TAG_PRICE_COMMODITY); xmlSerializer.startTag(null, TAG_COMMODITY_SPACE); xmlSerializer.text(commodity.getNamespace()); diff --git a/app/src/main/kotlin/org/gnucash/android/model/Price.kt b/app/src/main/kotlin/org/gnucash/android/model/Price.kt index 8953eff71..aff6d96d9 100644 --- a/app/src/main/kotlin/org/gnucash/android/model/Price.kt +++ b/app/src/main/kotlin/org/gnucash/android/model/Price.kt @@ -11,24 +11,23 @@ import java.text.NumberFormat * Model for commodity prices */ class Price : BaseModel { - var commodity: Commodity? = null - var currency: Commodity? = null - var date: Timestamp + var commodity: Commodity + var currency: Commodity + var date: Timestamp = TimestampHelper.getTimestampFromNow() var source: String? = null var type: String? = null - constructor() : this(null, null) + constructor() : this(Commodity.DEFAULT_COMMODITY, Commodity.DEFAULT_COMMODITY) /** * Create new instance with the GUIDs of the commodities * - * @param commodity the origin commodity - * @param currency the target commodity + * @param commodity1 the origin commodity + * @param commodity2 the target commodity */ - constructor(commodity: Commodity?, currency: Commodity?) { - this.commodity = commodity - this.currency = currency - date = TimestampHelper.getTimestampFromNow() + constructor(commodity1: Commodity, commodity2: Commodity) { + this.commodity = commodity1 + this.currency = commodity2 } /** @@ -38,7 +37,7 @@ class Price : BaseModel { * @param commodity2 the target commodity * @param exchangeRate exchange rate between the commodities */ - constructor(commodity1: Commodity?, commodity2: Commodity?, exchangeRate: BigDecimal) : + constructor(commodity1: Commodity, commodity2: Commodity, exchangeRate: BigDecimal) : this(commodity1, commodity2) { // Store 0.1234 as 1234/10000 valueNum = exchangeRate.unscaledValue().toLong()