Skip to content

Commit

Permalink
TickerView text color fix, and use triggerable property for real-time…
Browse files Browse the repository at this point in the history
… fetching
  • Loading branch information
premnirmal committed Jun 17, 2022
1 parent ec1be2c commit d365865
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 17 deletions.
272 changes: 272 additions & 0 deletions app/schemas/com.github.premnirmal.ticker.repo.QuotesDB/5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
"formatVersion": 1,
"database": {
"version": 5,
"identityHash": "ec8f6bc5f9d19d93d6861d8887d86747",
"entities": [
{
"tableName": "QuoteRow",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`symbol` TEXT NOT NULL, `name` TEXT NOT NULL, `last_trade_price` REAL NOT NULL, `change_percent` REAL NOT NULL, `change` REAL NOT NULL, `exchange` TEXT NOT NULL, `currency` TEXT NOT NULL, `is_post_market` INTEGER NOT NULL, `annual_dividend_rate` REAL NOT NULL, `annual_dividend_yield` REAL NOT NULL, `dayHigh` REAL, `dayLow` REAL, `previousClose` REAL NOT NULL, `open` REAL, `regularMarketVolume` REAL, `peRatio` REAL, `fiftyTwoWeekLowChange` REAL, `fiftyTwoWeekLowChangePercent` REAL, `fiftyTwoWeekHighChange` REAL, `fiftyTwoWeekHighChangePercent` REAL, `fiftyTwoWeekLow` REAL, `fiftyTwoWeekHigh` REAL, `dividendDate` REAL, `earningsDate` REAL, `marketCap` REAL, `isTradeable` INTEGER, `isTriggerable` INTEGER, PRIMARY KEY(`symbol`))",
"fields": [
{
"fieldPath": "symbol",
"columnName": "symbol",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "lastTradePrice",
"columnName": "last_trade_price",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "changeInPercent",
"columnName": "change_percent",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "change",
"columnName": "change",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "stockExchange",
"columnName": "exchange",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "currency",
"columnName": "currency",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isPostMarket",
"columnName": "is_post_market",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "annualDividendRate",
"columnName": "annual_dividend_rate",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "annualDividendYield",
"columnName": "annual_dividend_yield",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "dayHigh",
"columnName": "dayHigh",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "dayLow",
"columnName": "dayLow",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "previousClose",
"columnName": "previousClose",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "open",
"columnName": "open",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "regularMarketVolume",
"columnName": "regularMarketVolume",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "peRatio",
"columnName": "peRatio",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "fiftyTwoWeekLowChange",
"columnName": "fiftyTwoWeekLowChange",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "fiftyTwoWeekLowChangePercent",
"columnName": "fiftyTwoWeekLowChangePercent",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "fiftyTwoWeekHighChange",
"columnName": "fiftyTwoWeekHighChange",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "fiftyTwoWeekHighChangePercent",
"columnName": "fiftyTwoWeekHighChangePercent",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "fiftyTwoWeekLow",
"columnName": "fiftyTwoWeekLow",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "fiftyTwoWeekHigh",
"columnName": "fiftyTwoWeekHigh",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "dividendDate",
"columnName": "dividendDate",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "earningsDate",
"columnName": "earningsDate",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "marketCap",
"columnName": "marketCap",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "isTradeable",
"columnName": "isTradeable",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "isTriggerable",
"columnName": "isTriggerable",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"symbol"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "HoldingRow",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `quote_symbol` TEXT NOT NULL, `shares` REAL NOT NULL, `price` REAL NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "quoteSymbol",
"columnName": "quote_symbol",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "shares",
"columnName": "shares",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "price",
"columnName": "price",
"affinity": "REAL",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "PropertiesRow",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `properties_quote_symbol` TEXT NOT NULL, `notes` TEXT NOT NULL, `alert_above` REAL NOT NULL, `alert_below` REAL NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "quoteSymbol",
"columnName": "properties_quote_symbol",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "notes",
"columnName": "notes",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "alertAbove",
"columnName": "alert_above",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "alertBelow",
"columnName": "alert_below",
"affinity": "REAL",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"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, 'ec8f6bc5f9d19d93d6861d8887d86747')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.github.premnirmal.ticker.repo.StocksStorage
import com.github.premnirmal.ticker.repo.migrations.MIGRATION_1_2
import com.github.premnirmal.ticker.repo.migrations.MIGRATION_2_3
import com.github.premnirmal.ticker.repo.migrations.MIGRATION_3_4
import com.github.premnirmal.ticker.repo.migrations.MIGRATION_4_5
import com.github.premnirmal.ticker.widget.WidgetDataProvider
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -65,6 +66,7 @@ class AppModule(private val app: StocksApp) {
.addMigrations(MIGRATION_1_2)
.addMigrations(MIGRATION_2_3)
.addMigrations(MIGRATION_3_4)
.addMigrations(MIGRATION_4_5)
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class StocksApi {
quote.trailingPE = this.trailingPE
quote.marketState = this.marketState
quote.tradeable = this.tradeable
quote.triggerable = this.triggerable
quote.fiftyTwoWeekLowChange = this.fiftyTwoWeekLowChange
quote.fiftyTwoWeekLowChangePercent = this.fiftyTwoWeekLowChangePercent
quote.fiftyTwoWeekHighChange = this.fiftyTwoWeekHighChange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ data class Quote constructor(
var trailingPE: Float? = 0.0f
var marketState: String = ""
var tradeable: Boolean = false
var triggerable: Boolean = false
var fiftyTwoWeekLowChange: Float? = 0.0f
var fiftyTwoWeekLowChangePercent: Float? = 0.0f
var fiftyTwoWeekHighChange: Float? = 0.0f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ data class YahooQuoteNet(
val marketState: String,
@SerializedName("tradeable")
val tradeable: Boolean,
@SerializedName("triggerable")
val triggerable: Boolean,
@SerializedName("fiftyTwoWeekLowChange")
val fiftyTwoWeekLowChange: Float?,
@SerializedName("fiftyTwoWeekLowChangePercent")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ class QuoteDetailViewModel(application: Application) : AndroidViewModel(applicat
)
)
}
details.add(
QuoteDetail(
R.string.quote_details_dividend_rate,
dividendInfo()
)
)
if (annualDividendRate > 0f && annualDividendYield > 0f) {
details.add(
QuoteDetail(
R.string.quote_details_dividend_rate,
dividendInfo()
)
)
}
dividendDate?.let {
details.add(
QuoteDetail(
Expand Down Expand Up @@ -154,14 +156,14 @@ class QuoteDetailViewModel(application: Application) : AndroidViewModel(applicat
) {
viewModelScope.launch {
do {
var tradeable = false
var triggerable = false
val result = stocksProvider.fetchStock(symbol, allowCache = false)
if (result.wasSuccessful) {
tradeable = result.data.tradeable
triggerable = result.data.triggerable
_quote.emit(result)
}
delay(IStocksProvider.DEFAULT_INTERVAL_MS)
} while (isActive && result.wasSuccessful && tradeable)
} while (isActive && result.wasSuccessful && triggerable)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class PortfolioViewModel : ViewModel() {

fun fetchPortfolioInRealTime() = flow<List<Quote>> {
do {
var tradeable = false
var triggerable = false
val result = stocksProvider.fetch(false)
if (result.wasSuccessful) {
tradeable = result.data.any { it.tradeable }
triggerable = result.data.any { it.triggerable }
emit(result.data)
}
delay(IStocksProvider.DEFAULT_INTERVAL_MS)
} while (result.wasSuccessful && tradeable)
} while (result.wasSuccessful && triggerable)
}.flowOn(Dispatchers.Default)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.github.premnirmal.ticker.repo.data.QuoteRow

@Database(
entities = [QuoteRow::class, HoldingRow::class, PropertiesRow::class],
version = 4,
version = 5,
exportSchema = true
)
abstract class QuotesDB : RoomDatabase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ class StocksStorage {
this.dividendDate?.toFloat(),
this.earningsTimestamp?.toFloat(),
this.marketCap?.toFloat(),
this.tradeable
this.tradeable,
this.triggerable
)
}

Expand Down Expand Up @@ -182,6 +183,7 @@ class StocksStorage {
quote.earningsTimestamp = this.earningsDate?.toLong()
quote.marketCap = this.marketCap?.toLong()
quote.tradeable = this.isTradeable ?: false
quote.triggerable = this.isTriggerable ?: false
return quote
}

Expand Down
Loading

0 comments on commit d365865

Please sign in to comment.