@@ -7,40 +7,50 @@ import android.view.Menu
7
7
import android.view.MenuItem
8
8
import io.reactivex.android.schedulers.AndroidSchedulers
9
9
import io.reactivex.schedulers.Schedulers
10
- import jfyg.etherscan.helloetherescan.network.responses.BaseResponse
10
+ import jfyg.etherscan.helloetherescan.ethereum.EthereumStat
11
+ import jfyg.etherscan.helloetherescan.model.EtherPriceModel
12
+ import jfyg.etherscan.helloetherescan.network.responses.MainResponse
11
13
import jfyg.etherscan.helloetherescan.network.RestClient
12
14
13
15
import kotlinx.android.synthetic.main.activity_main.*
14
-
16
+ // TODO: clean up and write tests
15
17
class MainActivity : AppCompatActivity () {
16
18
private val TAG = javaClass.name!!
19
+
20
+ var etherPrice = EtherPriceModel ()
21
+
17
22
override fun onCreate (savedInstanceState : Bundle ? ) {
18
23
super .onCreate(savedInstanceState)
19
24
setContentView(R .layout.activity_main)
20
25
setSupportActionBar(toolbar)
21
26
27
+ var testing = EthereumStat ()
22
28
23
29
fab.setOnClickListener {
24
- queryPrice(" 1I7CRNU2QIU253UBPFVB5UV2C2PBDURAIY" )
30
+ // testing.getTotalSupply()
31
+ // testing.getTotalSupplyInWei()
32
+ testing.getLastPriceInUsd()
33
+ testing.getLastPriceInBtc()
34
+ // queryStats("stats", "ethPrice")
25
35
}
26
36
}
27
37
28
- private fun queryPrice (apiKey : String ) {
38
+ fun queryStats (module : String , action : String ) {
39
+ // pass apikey that will save in preferences or singleton or something.. or application class
29
40
RestClient ().getQuery()
30
- .getEtherStats(" stats " , " ethprice " , apiKey )
41
+ .getEtherStats(module, action, " 1I7CRNU2QIU253UBPFVB5UV2C2PBDURAIYZ " )
31
42
.observeOn(AndroidSchedulers .mainThread())
32
43
.subscribeOn(Schedulers .io())
33
44
.subscribe(this ::handleResponse, this ::handleError)
34
45
}
35
46
36
- private fun handleResponse (retrieveQuery : BaseResponse ) {
37
- Log .d(TAG , " status: " + retrieveQuery.status)
38
- Log .d(TAG , " message: " + retrieveQuery.message)
39
- Log .d(TAG , " Eth in Btc: " + retrieveQuery.etherPriceresult?.ethBtc)
40
- Log .d(TAG , " Eth in Btc Timestamp: " + retrieveQuery.etherPriceresult?.ethBtcTimestamp)
41
- Log .d(TAG , " Eth in Usd: " + retrieveQuery.etherPriceresult?.ethUsd)
42
- Log .d(TAG , " Eth in Usd Timestamp: " + retrieveQuery.etherPriceresult?.ethUsdTimestamp)
43
- // Log.d(TAG, "Eth supply: " + retrieveQuery.etherSupplyResult)
47
+ private fun handleResponse (retrieveQuery : MainResponse ) {
48
+ etherPrice.status = retrieveQuery.status
49
+ etherPrice.message = retrieveQuery.message
50
+ etherPrice.ethBtc = retrieveQuery.etherPriceresult?.ethBtc
51
+ etherPrice.ethBtcTimestamp = retrieveQuery.etherPriceresult?.ethBtcTimestamp
52
+ etherPrice.ethUsd = retrieveQuery.etherPriceresult?.ethUsd
53
+ etherPrice.ethUsdTimestamp = retrieveQuery.etherPriceresult?.ethUsdTimestamp
44
54
}
45
55
46
56
private fun handleError (error : Throwable ) {
@@ -62,4 +72,5 @@ class MainActivity : AppCompatActivity() {
62
72
else -> super .onOptionsItemSelected(item)
63
73
}
64
74
}
65
- }
75
+
76
+ }
0 commit comments