Skip to content

Commit 987fec6

Browse files
authored
Merge pull request #31 from EbenezerGH/clean-up
Handle some tech debt
2 parents 8dc78e0 + 18c5618 commit 987fec6

File tree

21 files changed

+228
-183
lines changed

21 files changed

+228
-183
lines changed

app/src/main/AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="jfyg.etherscan.helloetherescan">
44

5+
<uses-permission android:name="android.permission.INTERNET"/>
6+
57
<application
68
android:name=".HelloEtherscanApplication"
79
android:allowBackup="true"
@@ -22,6 +24,4 @@
2224
</activity>
2325
</application>
2426

25-
<uses-permission android:name="android.permission.INTERNET"/>
26-
2727
</manifest>
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package jfyg.etherscan.helloetherescan
22

33
import android.app.Application
4-
import jfyg.etherscanapi.ApiKey
4+
import jfyg.ApiKey
55

66
class HelloEtherscanApplication : Application() {
77
override fun onCreate() {
88
super.onCreate()
9+
10+
//************************************************ Used To Test Library
911
ApiKey.takeOff.setApiKey("1I7CRNU2QIU253UBPFVB5UV2C2PBDURAIYZ")
1012
}
1113
}

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

+16-3
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,34 @@ package jfyg.etherscan.helloetherescan
33
import android.os.Bundle
44
import android.support.v7.app.AppCompatActivity
55
import android.util.Log
6-
import jfyg.etherscanapi.stats.EthereumStat
6+
import jfyg.stat.Stat
77
import kotlinx.android.synthetic.main.activity_main.*
88

99

1010
class MainActivity : AppCompatActivity() {
11-
private val stat = EthereumStat()
11+
private val TAG = javaClass.name
1212

1313
override fun onCreate(savedInstanceState: Bundle?) {
1414
super.onCreate(savedInstanceState)
1515
setContentView(R.layout.activity_main)
1616
setSupportActionBar(toolbar)
1717

18+
//************************************************ Used To Test Library
19+
val stat = Stat() //TODO #29
20+
1821
fab.setOnClickListener {
19-
Log.d("Ebenezer", stat.getLastPriceInBtc())
22+
23+
Log.d(TAG, "The Status is ${stat.getNetworkStatus()}")
24+
Log.d(TAG, "The Message is ${stat.getNetworkMessage()}")
25+
Log.d(TAG, "The current price of Ether in Btc: ${stat.getLastPriceInBtc()}")
26+
Log.d(TAG, "Timestamp price in Btc: ${stat.getBtcTimestamp()}")
27+
Log.d(TAG, "Timestamp price in Ether: ${stat.getEthTimestamp()}")
28+
Log.d(TAG, "The current price of Ether in Usd: ${stat.getLastPriceInUsd()}")
29+
Log.d(TAG, "The total supply of Ether: ${stat.getTotalSupply()}")
30+
Log.d(TAG, "The total supply of Ether in Wei: ${stat.getTotalSupplyInWei()}")
31+
2032
}
2133
}
2234

35+
2336
}

app/src/main/res/values/strings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<resources>
2-
<string name="app_name">Hello Ethere Scan</string>
2+
<string name="app_name">Hello Etherscan</string>
33
<string name="action_settings">Settings</string>
44

55
<string name="base_url">http://api.etherscan.io/</string>

etherscanapi/src/main/java/jfyg/etherscanapi/ApiKey.kt renamed to etherscanapi/src/main/java/jfyg/ApiKey.kt

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
package jfyg.etherscanapi
1+
package jfyg
22

33
import android.util.Log
44

5+
/**
6+
* Retrieves and stores the user's Api key
7+
*/
58
class ApiKey private constructor() {
9+
private val TAG = javaClass.name
10+
11+
private var apiKey: String? = null
12+
613
private object Holder {
714
val TakeOff = ApiKey()
815
}
@@ -11,11 +18,9 @@ class ApiKey private constructor() {
1118
val takeOff: ApiKey by lazy { Holder.TakeOff }
1219
}
1320

14-
private var apiKey: String? = null
15-
1621
fun callApiKey(): String? {
1722
if (apiKey == null) {
18-
Log.w("", "No api key seems to be added. No record of your queries will be kept in your " +
23+
Log.w(TAG, "No api key seems to be added. No record of your queries will be kept in your " +
1924
"https://etherscan.io/ console")
2025
}
2126
return takeOff.apiKey

etherscanapi/src/main/java/jfyg/etherscanapi/Queries.kt

-41
This file was deleted.

etherscanapi/src/main/java/jfyg/etherscanapi/model/BaseModel.kt

-7
This file was deleted.

etherscanapi/src/main/java/jfyg/etherscanapi/model/EtherPriceModel.kt

-9
This file was deleted.

etherscanapi/src/main/java/jfyg/etherscanapi/responses/EtherPriceResponse.kt

-21
This file was deleted.

etherscanapi/src/main/java/jfyg/etherscanapi/responses/MainResponse.kt

-19
This file was deleted.

etherscanapi/src/main/java/jfyg/etherscanapi/stats/EthereumStat.kt

-43
This file was deleted.

etherscanapi/src/main/java/jfyg/etherscanapi/stats/EthereumStatFunctions.kt

-26
This file was deleted.

etherscanapi/src/main/java/jfyg/etherscanapi/network/NetworkService.kt renamed to etherscanapi/src/main/java/jfyg/network/NetworkService.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package jfyg.etherscanapi.network
1+
package jfyg.network
22

33
import io.reactivex.Single
4-
import jfyg.etherscanapi.responses.MainResponse
4+
import jfyg.response.MainResponse
55
import retrofit2.http.GET
66
import retrofit2.http.Query
77

@@ -14,4 +14,5 @@ interface NetworkService {
1414
fun getEtherStats(@Query("module") module: String,
1515
@Query("action") action: String,
1616
@Query("apikey") apikey: String?): Single<MainResponse>
17+
1718
}

etherscanapi/src/main/java/jfyg/etherscanapi/network/RestClient.kt renamed to etherscanapi/src/main/java/jfyg/network/RestClient.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jfyg.etherscanapi.network
1+
package jfyg.network
22

33
import retrofit2.Retrofit
44
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
@@ -10,8 +10,7 @@ import com.google.gson.GsonBuilder
1010
*/
1111
class RestClient {
1212

13-
//TODO: Retrieve baseUrl from string resources
14-
private var baseUrl: String = "http://api.etherscan.io/"
13+
private var baseUrl: String = "http://api.etherscan.io/" //TODO: #28
1514
private var networkService: NetworkService
1615

1716
init {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package jfyg.queries
2+
3+
import android.util.Log
4+
import io.reactivex.android.schedulers.AndroidSchedulers
5+
import io.reactivex.disposables.Disposable
6+
import io.reactivex.schedulers.Schedulers
7+
import jfyg.ApiKey
8+
import jfyg.network.RestClient
9+
import jfyg.response.MainResponse
10+
11+
/**
12+
* A mediator between the responses and errors that come from every query
13+
*/
14+
class Queries : StatQueries {
15+
private val TAG = javaClass.name
16+
17+
private var statInfo = MainResponse()
18+
19+
override fun stats(module: String, action: String): Disposable =
20+
RestClient().getQuery()
21+
.getEtherStats(module, action, ApiKey.takeOff.callApiKey())
22+
.observeOn(AndroidSchedulers.mainThread())
23+
.subscribeOn(Schedulers.io())
24+
.subscribe(this::handleResponse, this::handleError)
25+
26+
27+
override fun handleResponse(response: MainResponse) {
28+
statInfo = response
29+
}
30+
31+
private fun handleError(error: Throwable) {
32+
Log.d(TAG, "The error " + error.message)
33+
}
34+
35+
fun fetchStatResponse(): MainResponse? = statInfo
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package jfyg.queries
2+
3+
import io.reactivex.disposables.Disposable
4+
import jfyg.response.MainResponse
5+
6+
interface StatQueries {
7+
8+
fun stats(module: String, action: String): Disposable?
9+
10+
fun handleResponse(response: MainResponse)
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package jfyg.response
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
/**
6+
* Base response that all queries will utilize
7+
*/
8+
class MainResponse {
9+
10+
var status: String? = null
11+
12+
var message: String? = null
13+
14+
@SerializedName("result") //TODO Issue #26
15+
var statResult: StatResponse? = null
16+
17+
}

0 commit comments

Comments
 (0)