Skip to content

Commit 57f9b7f

Browse files
authoredMar 13, 2018
Merge pull request #22 from EbenezerGH/app-to-library-module
Big Commit.. sorry, not sorry. create library module, move classes a…
2 parents 3219833 + 8398655 commit 57f9b7f

25 files changed

+202
-93
lines changed
 

‎.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/modules.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app/build.gradle

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,19 @@ android {
2525
dependencies {
2626
implementation fileTree(dir: 'libs', include: ['*.jar'])
2727

28-
/**
29-
Because RxAndroid releases are few and far between, it is recommended you also
30-
explicitly depend on RxJava's latest version for bug fixes and new features.
31-
*/
32-
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
33-
implementation 'io.reactivex.rxjava2:rxjava:2.0.9'
34-
35-
/**
36-
* Android Studio by default will not recognize a lot of generated Dagger 2 code as
37-
* legitimate classes, but adding the android-apt plugin will add these files into the
38-
* IDE class path and enable you to have more visibility.
39-
*/
40-
compile 'com.google.dagger:dagger:2.4'
41-
annotationProcessor "com.google.dagger:dagger-compiler:2.4"
42-
43-
// google
44-
implementation 'com.android.support:design:26.1.0'
45-
46-
// gson
47-
compile 'com.google.code.gson:gson:2.8.0'
48-
49-
// retrofit
50-
compile 'com.squareup.retrofit2:retrofit:2.2.0'
51-
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
52-
compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
28+
// kotlin
29+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
5330

5431
// google
5532
implementation 'com.android.support:appcompat-v7:26.1.0'
33+
implementation 'com.android.support:design:26.1.0'
5634
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
57-
compile 'com.android.support:recyclerview-v7:26.1.0'
58-
59-
// kotlin
60-
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
6135

6236
// tests
6337
testImplementation 'junit:junit:4.12'
6438
androidTestImplementation 'com.android.support.test:runner:1.0.1'
6539
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
40+
41+
// todo call library from https://jitpack.io/ into a main project
42+
implementation project(':etherscanapi')
6643
}

‎app/src/main/java/jfyg/etherscan/helloetherescan/HelloEtherscanApplication.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package jfyg.etherscan.helloetherescan
22

33
import android.app.Application
4+
import jfyg.etherscanapi.ApiKey
45

56
class HelloEtherscanApplication : Application() {
67
override fun onCreate() {

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

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,21 @@ package jfyg.etherscan.helloetherescan
33
import android.os.Bundle
44
import android.support.v7.app.AppCompatActivity
55
import android.util.Log
6-
import io.reactivex.android.schedulers.AndroidSchedulers
7-
import io.reactivex.schedulers.Schedulers
8-
import jfyg.etherscan.helloetherescan.ethereum.EthereumStat
9-
import jfyg.etherscan.helloetherescan.model.EtherPriceModel
10-
import jfyg.etherscan.helloetherescan.network.responses.MainResponse
11-
import jfyg.etherscan.helloetherescan.network.RestClient
12-
6+
import jfyg.etherscanapi.stats.EthereumStat
137
import kotlinx.android.synthetic.main.activity_main.*
148

15-
//TODO: clean up and write tests
16-
class MainActivity : AppCompatActivity() {
17-
private val TAG = javaClass.name!!
189

19-
var etherPrice = EtherPriceModel()
10+
class MainActivity : AppCompatActivity() {
11+
private val stat = EthereumStat()
2012

2113
override fun onCreate(savedInstanceState: Bundle?) {
2214
super.onCreate(savedInstanceState)
2315
setContentView(R.layout.activity_main)
2416
setSupportActionBar(toolbar)
2517

26-
//~~~ For Testing
27-
/*
28-
var testing = EthereumStat()
2918
fab.setOnClickListener {
30-
//testing.getTotalSupply()
31-
//testing.getTotalSupplyInWei()
32-
testing.getLastPriceInUsd()
33-
testing.getLastPriceInBtc()
34-
//queryStats("stats", "ethPrice")
19+
Log.d("Ebenezer", stat.getLastPriceInBtc())
3520
}
36-
*/
37-
}
38-
39-
fun queryStats(module: String, action: String) {
40-
RestClient().getQuery()
41-
.getEtherStats(module, action, ApiKey.takeOff.callApiKey())
42-
.observeOn(AndroidSchedulers.mainThread())
43-
.subscribeOn(Schedulers.io())
44-
.subscribe(this::handleResponse, this::handleError)
45-
}
46-
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
54-
}
55-
56-
private fun handleError(error: Throwable) {
57-
Log.d(TAG, "The error " + error.message)
5821
}
5922

6023
}

‎build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4+
ext.kotlin_version = '1.2.30'
45
ext.kotlin_version = '1.1.51'
56
repositories {
67
google()

‎etherscanapi/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

‎etherscanapi/build.gradle

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android'
3+
4+
android {
5+
compileSdkVersion 26
6+
7+
defaultConfig {
8+
minSdkVersion 14
9+
targetSdkVersion 26
10+
versionCode 1
11+
versionName "1.0"
12+
13+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14+
}
15+
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
23+
}
24+
25+
26+
dependencies {
27+
implementation fileTree(include: ['*.jar'], dir: 'libs')
28+
29+
/**
30+
Because RxAndroid releases are few and far between, it is recommended you also
31+
explicitly depend on RxJava's latest version for bug fixes and new features.
32+
*/
33+
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
34+
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
35+
36+
// gson
37+
implementation 'com.google.code.gson:gson:2.8.0'
38+
39+
// retrofit
40+
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
41+
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
42+
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
43+
44+
// kotlin
45+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
46+
47+
// tests
48+
testImplementation 'junit:junit:4.12'
49+
androidTestImplementation 'com.android.support.test:runner:1.0.1'
50+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
51+
52+
repositories {
53+
mavenCentral()
54+
}
55+
56+
}

‎etherscanapi/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package jfyg.etherscanapi;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("jfyg.etherscanapi.test", appContext.getPackageName());
25+
}
26+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest
2+
package="jfyg.etherscanapi"/>

‎app/src/main/java/jfyg/etherscan/helloetherescan/ApiKey.kt renamed to ‎etherscanapi/src/main/java/jfyg/etherscanapi/ApiKey.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jfyg.etherscan.helloetherescan
1+
package jfyg.etherscanapi
22

33
import android.util.Log
44

@@ -18,7 +18,7 @@ class ApiKey private constructor() {
1818
Log.w("", "No api key seems to be added. No record of your queries will be kept in your " +
1919
"https://etherscan.io/ console")
2020
}
21-
return ApiKey.takeOff.apiKey
21+
return takeOff.apiKey
2222
}
2323

2424
fun setApiKey(apiKey: String) {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package jfyg.etherscanapi
2+
3+
import android.content.ContentValues.TAG
4+
import android.util.Log
5+
import io.reactivex.android.schedulers.AndroidSchedulers
6+
import io.reactivex.schedulers.Schedulers
7+
import jfyg.etherscanapi.model.EtherPriceModel
8+
import jfyg.etherscanapi.network.RestClient
9+
import jfyg.etherscanapi.responses.MainResponse
10+
11+
/**
12+
* //TODO documentation
13+
*/
14+
class Queries {
15+
private var etherPrice = EtherPriceModel()
16+
17+
fun stats(module: String, action: String) {
18+
RestClient().getQuery()
19+
.getEtherStats(module, action, ApiKey.takeOff.callApiKey())
20+
.observeOn(AndroidSchedulers.mainThread())
21+
.subscribeOn(Schedulers.io())
22+
.subscribe(this::handleResponse, this::handleError)
23+
}
24+
25+
private fun handleResponse(retrieveQuery: MainResponse) {
26+
etherPrice.status = retrieveQuery.status
27+
etherPrice.message = retrieveQuery.message
28+
etherPrice.ethBtc = retrieveQuery.etherPriceresult?.ethBtc
29+
etherPrice.ethBtcTimestamp = retrieveQuery.etherPriceresult?.ethBtcTimestamp
30+
etherPrice.ethUsd = retrieveQuery.etherPriceresult?.ethUsd
31+
etherPrice.ethUsdTimestamp = retrieveQuery.etherPriceresult?.ethUsdTimestamp
32+
}
33+
34+
private fun handleError(error: Throwable) {
35+
Log.d(TAG, "The error " + error.message)
36+
}
37+
38+
fun fetchEtherStats(): EtherPriceModel {
39+
return etherPrice
40+
}
41+
}

‎app/src/main/java/jfyg/etherscan/helloetherescan/model/BaseModel.kt renamed to ‎etherscanapi/src/main/java/jfyg/etherscanapi/model/BaseModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jfyg.etherscan.helloetherescan.model
1+
package jfyg.etherscanapi.model
22

33
open class BaseModel {
44
var status: String? = ""

‎app/src/main/java/jfyg/etherscan/helloetherescan/model/EtherPriceModel.kt renamed to ‎etherscanapi/src/main/java/jfyg/etherscanapi/model/EtherPriceModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jfyg.etherscan.helloetherescan.model
1+
package jfyg.etherscanapi.model
22

33
class EtherPriceModel : BaseModel() {
44
var ethBtc: String? = ""

‎app/src/main/java/jfyg/etherscan/helloetherescan/network/NetworkService.kt renamed to ‎etherscanapi/src/main/java/jfyg/etherscanapi/network/NetworkService.kt

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

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

‎app/src/main/java/jfyg/etherscan/helloetherescan/network/RestClient.kt renamed to ‎etherscanapi/src/main/java/jfyg/etherscanapi/network/RestClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jfyg.etherscan.helloetherescan.network
1+
package jfyg.etherscanapi.network
22

33
import retrofit2.Retrofit
44
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jfyg.etherscan.helloetherescan.network.responses
1+
package jfyg.etherscanapi.responses
22

33
import com.google.gson.annotations.SerializedName
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jfyg.etherscan.helloetherescan.network.responses
1+
package jfyg.etherscanapi.responses
22

33
import com.google.gson.annotations.SerializedName
44

Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
package jfyg.etherscan.helloetherescan.ethereum
1+
package jfyg.etherscanapi.stats
22

3+
import jfyg.etherscanapi.Queries
34

4-
import android.util.Log
5-
import jfyg.etherscan.helloetherescan.MainActivity
65

76
class EthereumStat : EthereumStatFunctions {
87

9-
var activity = MainActivity()
8+
private var query = Queries()
109

1110
override fun getTotalSupply(): Long? {
1211
val stats = "stats"
1312
val ethSupply = "ethSupply"
1413

15-
activity.queryStats(stats, ethSupply)
14+
query.stats(stats, ethSupply)
1615
return 0 //TODO: Figure out how to parse supply
1716
}
1817

@@ -21,26 +20,24 @@ class EthereumStat : EthereumStatFunctions {
2120
val stats = "stats"
2221
val ethSupply = "ethSupply"
2322

24-
activity.queryStats(stats, ethSupply)
23+
query.stats(stats, ethSupply)
2524
return 0 //TODO: Figure out how to parse supply
2625
}
2726

2827
override fun getLastPriceInUsd(): String? {
2928
val stats = "stats"
3029
val ethPrice = "ethprice"
3130

32-
activity.queryStats(stats, ethPrice)
33-
Log.d("Ebenezer", activity.etherPrice.ethUsd)
34-
return activity.etherPrice.ethUsd //TODO: Make this return Int
31+
query.stats(stats, ethPrice)
32+
return query.fetchEtherStats().ethUsd //TODO: Make this return Int
3533
}
3634

3735
override fun getLastPriceInBtc(): String? {
3836
val stats = "stats"
3937
val ethPrice = "ethprice"
4038

41-
activity.queryStats(stats, ethPrice)
42-
Log.d("Ebenezer", activity.etherPrice.ethBtc)
43-
return activity.etherPrice.ethBtc //TODO: Make this return Int
39+
query.stats(stats, ethPrice)
40+
return query.fetchEtherStats().ethBtc //TODO: Make this return Int
4441
}
4542

4643
}

‎app/src/main/java/jfyg/etherscan/helloetherescan/ethereum/EthereumStatFunctions.kt renamed to ‎etherscanapi/src/main/java/jfyg/etherscanapi/stats/EthereumStatFunctions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jfyg.etherscan.helloetherescan.ethereum
1+
package jfyg.etherscanapi.stats
22

33

44
interface EthereumStatFunctions {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">EtherscanApi</string>
3+
</resources>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package jfyg.etherscanapi;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11+
*/
12+
public class ExampleUnitTest {
13+
@Test
14+
public void addition_isCorrect() throws Exception {
15+
assertEquals(4, 2 + 2);
16+
}
17+
}

‎gradlew

100644100755
File mode changed.

‎settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':app'
1+
include ':app', ':etherscanapi'

0 commit comments

Comments
 (0)
Please sign in to comment.