-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added option to show the wallet value of a given bitcoin address.
Removed toast message for clicking on error icon on widgets, as this stopped working. Now show configuration screen with error message.
- Loading branch information
Showing
25 changed files
with
446 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
244 changes: 244 additions & 0 deletions
244
bitcoin/schemas/com.brentpanther.bitcoinwidget.db.WidgetDatabase/6.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 6, | ||
"identityHash": "01c616eedee5c021678bbc985446b3ac", | ||
"entities": [ | ||
{ | ||
"tableName": "Widget", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `widgetId` INTEGER NOT NULL, `widgetType` TEXT NOT NULL, `exchange` TEXT NOT NULL, `coin` TEXT NOT NULL, `currency` TEXT NOT NULL, `coinCustomId` TEXT, `coinCustomName` TEXT, `currencyCustomName` TEXT, `showExchangeLabel` INTEGER NOT NULL, `showCoinLabel` INTEGER NOT NULL, `showIcon` INTEGER NOT NULL, `numDecimals` INTEGER NOT NULL, `currencySymbol` TEXT, `theme` TEXT NOT NULL, `nightMode` TEXT NOT NULL, `coinUnit` TEXT, `currencyUnit` TEXT, `customIcon` TEXT, `portraitTextSize` INTEGER, `landscapeTextSize` INTEGER, `lastValue` TEXT, `amountHeld` REAL, `address` TEXT, `showAmountLabel` INTEGER NOT NULL, `useInverse` INTEGER NOT NULL, `lastUpdated` INTEGER NOT NULL, `state` TEXT NOT NULL)", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "widgetId", | ||
"columnName": "widgetId", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "widgetType", | ||
"columnName": "widgetType", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "exchange", | ||
"columnName": "exchange", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "coin", | ||
"columnName": "coin", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "currency", | ||
"columnName": "currency", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "coinCustomId", | ||
"columnName": "coinCustomId", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "coinCustomName", | ||
"columnName": "coinCustomName", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "currencyCustomName", | ||
"columnName": "currencyCustomName", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "showExchangeLabel", | ||
"columnName": "showExchangeLabel", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "showCoinLabel", | ||
"columnName": "showCoinLabel", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "showIcon", | ||
"columnName": "showIcon", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "numDecimals", | ||
"columnName": "numDecimals", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "currencySymbol", | ||
"columnName": "currencySymbol", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "theme", | ||
"columnName": "theme", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "nightMode", | ||
"columnName": "nightMode", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "coinUnit", | ||
"columnName": "coinUnit", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "currencyUnit", | ||
"columnName": "currencyUnit", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "customIcon", | ||
"columnName": "customIcon", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "portraitTextSize", | ||
"columnName": "portraitTextSize", | ||
"affinity": "INTEGER", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "landscapeTextSize", | ||
"columnName": "landscapeTextSize", | ||
"affinity": "INTEGER", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "lastValue", | ||
"columnName": "lastValue", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "amountHeld", | ||
"columnName": "amountHeld", | ||
"affinity": "REAL", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "address", | ||
"columnName": "address", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "showAmountLabel", | ||
"columnName": "showAmountLabel", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "useInverse", | ||
"columnName": "useInverse", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "lastUpdated", | ||
"columnName": "lastUpdated", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "state", | ||
"columnName": "state", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": true, | ||
"columnNames": [ | ||
"id" | ||
] | ||
}, | ||
"indices": [ | ||
{ | ||
"name": "index_Widget_widgetId", | ||
"unique": true, | ||
"columnNames": [ | ||
"widgetId" | ||
], | ||
"orders": [], | ||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_Widget_widgetId` ON `${TABLE_NAME}` (`widgetId`)" | ||
} | ||
], | ||
"foreignKeys": [] | ||
}, | ||
{ | ||
"tableName": "Configuration", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `refresh` INTEGER NOT NULL, `consistentSize` INTEGER NOT NULL, `dataMigrationVersion` INTEGER NOT NULL)", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "refresh", | ||
"columnName": "refresh", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "consistentSize", | ||
"columnName": "consistentSize", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "dataMigrationVersion", | ||
"columnName": "dataMigrationVersion", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": true, | ||
"columnNames": [ | ||
"id" | ||
] | ||
}, | ||
"indices": [], | ||
"foreignKeys": [] | ||
} | ||
], | ||
"views": [], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '01c616eedee5c021678bbc985446b3ac')" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 20 additions & 3 deletions
23
...oin/src/main/java/com/brentpanther/bitcoinwidget/strategy/data/ValueWidgetDataStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,32 @@ | ||
package com.brentpanther.bitcoinwidget.strategy.data | ||
|
||
import com.brentpanther.bitcoinwidget.WidgetState | ||
import com.brentpanther.bitcoinwidget.exchange.ExchangeHelper | ||
|
||
class ValueWidgetDataStrategy(widgetId: Int) : PriceWidgetDataStrategy(widgetId) { | ||
|
||
override fun setData(value: String) { | ||
widget?.apply { | ||
val valueDouble = value.toDoubleOrNull() ?: 0.0 | ||
val amountHeld = amountHeld ?: 0.0 | ||
lastValue = (valueDouble * amountHeld).toString() | ||
val amountHeld = amountHeld | ||
lastValue = when { | ||
amountHeld != null -> (valueDouble * amountHeld).toString() | ||
address != null -> { | ||
val url = "https://blockchain.info/q/addressbalance/$address" | ||
val response = ExchangeHelper.getString(url) | ||
if ("error" in response) { | ||
state = WidgetState.INVALID_ADDRESS | ||
lastValue | ||
} | ||
else { | ||
val balance = response.toDoubleOrNull() ?: throw IllegalStateException() | ||
(valueDouble * balance * .00000001).toString() | ||
} | ||
} | ||
else -> lastValue | ||
} | ||
lastUpdated = System.currentTimeMillis() | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.