Skip to content

Commit 357f94e

Browse files
authored
Merge pull request #5 from EbenezerGH/wireframe2
Wireframe2
2 parents b833fbf + 9c637a2 commit 357f94e

File tree

7 files changed

+118
-22
lines changed

7 files changed

+118
-22
lines changed

app/src/main/java/jfyg/etherscan/helloetherescan/MainActivity.kt

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,50 @@ import android.view.Menu
77
import android.view.MenuItem
88
import io.reactivex.android.schedulers.AndroidSchedulers
99
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
1113
import jfyg.etherscan.helloetherescan.network.RestClient
1214

1315
import kotlinx.android.synthetic.main.activity_main.*
14-
16+
//TODO: clean up and write tests
1517
class MainActivity : AppCompatActivity() {
1618
private val TAG = javaClass.name!!
19+
20+
var etherPrice = EtherPriceModel()
21+
1722
override fun onCreate(savedInstanceState: Bundle?) {
1823
super.onCreate(savedInstanceState)
1924
setContentView(R.layout.activity_main)
2025
setSupportActionBar(toolbar)
2126

27+
var testing = EthereumStat()
2228

2329
fab.setOnClickListener {
24-
queryPrice("1I7CRNU2QIU253UBPFVB5UV2C2PBDURAIY")
30+
//testing.getTotalSupply()
31+
//testing.getTotalSupplyInWei()
32+
testing.getLastPriceInUsd()
33+
testing.getLastPriceInBtc()
34+
//queryStats("stats", "ethPrice")
2535
}
2636
}
2737

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
2940
RestClient().getQuery()
30-
.getEtherStats("stats", "ethprice", apiKey)
41+
.getEtherStats(module, action, "1I7CRNU2QIU253UBPFVB5UV2C2PBDURAIYZ")
3142
.observeOn(AndroidSchedulers.mainThread())
3243
.subscribeOn(Schedulers.io())
3344
.subscribe(this::handleResponse, this::handleError)
3445
}
3546

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
4454
}
4555

4656
private fun handleError(error: Throwable) {
@@ -62,4 +72,5 @@ class MainActivity : AppCompatActivity() {
6272
else -> super.onOptionsItemSelected(item)
6373
}
6474
}
65-
}
75+
76+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package jfyg.etherscan.helloetherescan.ethereum
2+
3+
4+
import android.util.Log
5+
import jfyg.etherscan.helloetherescan.MainActivity
6+
7+
class EthereumStat : EthereumStatFunctions {
8+
9+
var activity = MainActivity()
10+
11+
override fun getTotalSupply(): Long? {
12+
val stats = "stats"
13+
val ethSupply = "ethSupply"
14+
15+
activity.queryStats(stats, ethSupply)
16+
return 0 //TODO: Figure out how to parse supply
17+
}
18+
19+
20+
override fun getTotalSupplyInWei(): Int? {
21+
val stats = "stats"
22+
val ethSupply = "ethSupply"
23+
24+
activity.queryStats(stats, ethSupply)
25+
return 0 //TODO: Figure out how to parse supply
26+
}
27+
28+
override fun getLastPriceInUsd(): String? {
29+
val stats = "stats"
30+
val ethPrice = "ethprice"
31+
32+
activity.queryStats(stats, ethPrice)
33+
Log.d("Ebenezer", activity.etherPrice.ethUsd)
34+
return activity.etherPrice.ethUsd //TODO: Make this return Int
35+
}
36+
37+
override fun getLastPriceInBtc(): String? {
38+
val stats = "stats"
39+
val ethPrice = "ethprice"
40+
41+
activity.queryStats(stats, ethPrice)
42+
Log.d("Ebenezer", activity.etherPrice.ethBtc)
43+
return activity.etherPrice.ethBtc //TODO: Make this return Int
44+
}
45+
46+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package jfyg.etherscan.helloetherescan.ethereum
2+
3+
4+
interface EthereumStatFunctions {
5+
6+
/**
7+
* Return Total Supply of Ether
8+
*/
9+
fun getTotalSupply(): Long?
10+
11+
/**
12+
* Return Total Supply of Ether in Wei
13+
*/
14+
fun getTotalSupplyInWei(): Int?
15+
16+
/**
17+
* Return Last price of ether in Btc
18+
*/
19+
fun getLastPriceInBtc(): String?
20+
21+
/**
22+
* Return Last price of ether in Usd
23+
*/
24+
fun getLastPriceInUsd(): String?
25+
26+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package jfyg.etherscan.helloetherescan.model
2+
3+
open class BaseModel {
4+
var status: String? = ""
5+
var message: String? = ""
6+
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package jfyg.etherscan.helloetherescan.model
2+
3+
class EtherPriceModel : BaseModel() {
4+
var ethBtc: String? = ""
5+
var ethBtcTimestamp: String? = ""
6+
var ethUsd: String? = ""
7+
var ethUsdTimestamp: String? = ""
8+
9+
}

app/src/main/java/jfyg/etherscan/helloetherescan/network/NetworkService.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package jfyg.etherscan.helloetherescan.network
22

3-
import io.reactivex.Observable
4-
import jfyg.etherscan.helloetherescan.network.responses.BaseResponse
3+
import io.reactivex.Single
4+
import jfyg.etherscan.helloetherescan.network.responses.MainResponse
55
import retrofit2.http.GET
66
import retrofit2.http.Query
77

@@ -13,5 +13,5 @@ interface NetworkService {
1313
@GET("api")
1414
fun getEtherStats(@Query("module") module: String,
1515
@Query("action") action: String,
16-
@Query("apikey") apikey: String): Observable<BaseResponse>
16+
@Query("apikey") apikey: String): Single<MainResponse>
1717
}

app/src/main/java/jfyg/etherscan/helloetherescan/network/responses/BaseResponse.kt renamed to app/src/main/java/jfyg/etherscan/helloetherescan/network/responses/MainResponse.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName
55
/**
66
* Base response that all queries will utilize
77
*/
8-
open class BaseResponse {
8+
class MainResponse {
99

1010
@SerializedName("status")
1111
var status: String = ""
@@ -14,9 +14,6 @@ open class BaseResponse {
1414
var message: String = ""
1515

1616
@SerializedName("result")
17-
open var etherPriceresult: EtherPriceResponse? = null
17+
var etherPriceresult: EtherPriceResponse? = null
1818

19-
//TODO: Figure out how to handle the same response name coming in from different queries
20-
//@SerializedName("result")
21-
//open var etherSupplyResult: String = ""
2219
}

0 commit comments

Comments
 (0)