Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 54fdc81
Showing
59 changed files
with
1,192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Built application files | ||
*.apk | ||
*.ap_ | ||
|
||
# Files for the Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Log Files | ||
*.log | ||
|
||
# Android Studio Navigation editor temp files | ||
.navigation/ | ||
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
.idea/ | ||
*.iml | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Code example for the conference talk: [Pragmatic Kotlin on Android](https://speakerdeck.com/mutexkid/pragmatic-kotlin-on-android) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
buildToolsVersion "26.0.1" | ||
defaultConfig { | ||
applicationId "com.example.joshskeen.stockwatcher" | ||
minSdkVersion 22 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
dataBinding.enabled = true | ||
kapt.generateStubs = true | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.0', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
implementation 'com.android.support:appcompat-v7:26.0.1' | ||
implementation 'com.android.support:design:26.0.1' | ||
implementation 'com.google.dagger:dagger:2.11' | ||
kapt 'com.google.dagger:dagger-compiler:2.11' | ||
kapt "com.android.databinding:compiler:3.0.0-beta2" | ||
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0' | ||
implementation 'com.android.support.constraint:constraint-layout:1.0.2' | ||
api 'org.glassfish:javax.annotation:10.0-b28' | ||
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' | ||
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.2' | ||
implementation 'com.squareup.retrofit2:converter-gson:2.3.0' | ||
implementation 'com.squareup.retrofit2:converter-gson:2.3.0' | ||
implementation 'com.jakewharton.timber:timber:4.5.1' | ||
testImplementation 'junit:junit:4.12' | ||
|
||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" | ||
} | ||
repositories { | ||
maven { | ||
url 'http://dl.bintray.com/kotlin/kotlin-eap-1.2' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/joshskeen/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/example/joshskeen/stockwatcher/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.joshskeen.stockwatcher; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.example.joshskeen.kointracker", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.example.joshskeen.stockwatcher"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:name="com.example.joshskeen.stockwatcher.StockWatcherApplication" | ||
android:allowBackup="false" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme" | ||
tools:ignore="GoogleAppIndexingWarning"> | ||
<activity android:name="com.example.joshskeen.stockwatcher.ui.StockInfoActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/example/joshskeen/stockwatcher/AppComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.joshskeen.stockwatcher | ||
|
||
import javax.inject.Singleton | ||
|
||
import dagger.Component | ||
import com.example.joshskeen.stockwatcher.ui.StockInfoFragment | ||
|
||
@Singleton | ||
@Component(modules = arrayOf(AppModule::class)) | ||
interface AppComponent { | ||
fun inject(fragment: StockInfoFragment) | ||
} |
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/example/joshskeen/stockwatcher/AppModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.example.joshskeen.stockwatcher | ||
|
||
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
import javax.inject.Singleton | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import com.example.joshskeen.stockwatcher.service.ContentTypeHeaderInterceptor | ||
import com.example.joshskeen.stockwatcher.service.ServiceConfig | ||
import com.example.joshskeen.stockwatcher.service.StockService | ||
import com.example.joshskeen.stockwatcher.service.repository.StockDataRepository | ||
|
||
|
||
private const val STOCK_SERVICE_ENDPOINT = "http://dev.markitondemand.com/MODApis/Api/v2/" | ||
private const val HTTP_READ_TIMEOUT = 60 | ||
private const val HTTP_CONNECT_TIMEOUT = 60 | ||
|
||
@Module | ||
internal class AppModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideStockDataRepository(stockService: StockService): StockDataRepository = | ||
StockDataRepository(stockService) | ||
|
||
@Provides | ||
fun provideStockService(retrofit: Retrofit): StockService = StockService(retrofit) | ||
|
||
@Provides | ||
fun provideServiceConfig() = ServiceConfig(STOCK_SERVICE_ENDPOINT) | ||
|
||
@Provides | ||
fun provideRetrofit(client: OkHttpClient, serviceConfig: ServiceConfig) = | ||
Retrofit.Builder() | ||
.baseUrl(serviceConfig.baseServiceUrl) | ||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
.client(client) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build()!! | ||
|
||
@Provides | ||
fun provideOkHttpClient(loggingInterceptor: HttpLoggingInterceptor) = OkHttpClient.Builder() | ||
.readTimeout(HTTP_READ_TIMEOUT.toLong(), TimeUnit.SECONDS) | ||
.connectTimeout(HTTP_CONNECT_TIMEOUT.toLong(), TimeUnit.SECONDS) | ||
.addInterceptor(loggingInterceptor) | ||
.addInterceptor(ContentTypeHeaderInterceptor()) | ||
.build() | ||
|
||
@Provides | ||
fun provideLoggingInterceptor() = HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY) | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/example/joshskeen/stockwatcher/StockWatcherApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.joshskeen.stockwatcher | ||
|
||
import android.app.Application | ||
|
||
class StockWatcherApplication : Application() { | ||
|
||
val appComponent: AppComponent by lazy { | ||
DaggerAppComponent.builder().appModule(AppModule()).build() | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/example/joshskeen/stockwatcher/extensions/ContextExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.joshskeen.stockwatcher.extensions | ||
|
||
import android.content.Context | ||
import android.support.v4.app.Fragment | ||
import com.example.joshskeen.stockwatcher.AppComponent | ||
import com.example.joshskeen.stockwatcher.StockWatcherApplication | ||
|
||
val Context.component: AppComponent | ||
get() = (applicationContext as StockWatcherApplication).appComponent | ||
|
||
val Fragment.component: AppComponent | ||
get() = activity.component |
2 changes: 2 additions & 0 deletions
2
app/src/main/java/com/example/joshskeen/stockwatcher/extensions/FragmentExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package com.example.joshskeen.stockwatcher.extensions | ||
|
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/example/joshskeen/stockwatcher/service/ContentTypeHeaderInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.joshskeen.stockwatcher.service | ||
|
||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
|
||
|
||
private const val CONTENT_TYPE = "Content-Type" | ||
private const val APPLICATION_JSON = "application/json" | ||
|
||
class ContentTypeHeaderInterceptor : Interceptor { | ||
|
||
override fun intercept(chain: Interceptor.Chain): Response { | ||
val request = chain | ||
.request() | ||
.newBuilder() | ||
.addHeader(CONTENT_TYPE, APPLICATION_JSON) | ||
.build() | ||
return chain.proceed(request) | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
app/src/main/java/com/example/joshskeen/stockwatcher/service/ServiceConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.example.joshskeen.stockwatcher.service | ||
|
||
|
||
data class ServiceConfig(val baseServiceUrl: String) |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/example/joshskeen/stockwatcher/service/StockInfoForSymbol.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.example.joshskeen.stockwatcher.service | ||
|
||
|
||
data class StockInfoForSymbol(val stockSymbol: StockSymbol, | ||
val stockInfoResponse: StockInfoResponse) |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/example/joshskeen/stockwatcher/service/StockInfoResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.example.joshskeen.stockwatcher.service | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class StockInfoResponse( | ||
@SerializedName("Status") | ||
private val status: String, | ||
@SerializedName("Name") | ||
private val name: String, | ||
@SerializedName("LastPrice") | ||
private val lastPrice: Double, | ||
@SerializedName("Change") | ||
private val change: Double, | ||
@SerializedName("ChangePercent") | ||
private val changePercent: Double, | ||
@SerializedName("MarketCap") | ||
private val marketCap: Long, | ||
@SerializedName("Volume") | ||
private val volume: Long, | ||
@SerializedName("ChangeYTD") | ||
private val changeYTD: Double, | ||
@SerializedName("ChangePercentYTD") | ||
private val changePercentYTD: Double, | ||
@SerializedName("High") | ||
private val high: Double, | ||
@SerializedName("Low") | ||
private val low: Double, | ||
@SerializedName("Open") | ||
private val open: Double) |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/example/joshskeen/stockwatcher/service/StockService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example.joshskeen.stockwatcher.service | ||
|
||
|
||
import io.reactivex.Observable | ||
import retrofit2.Retrofit | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
class StockService(retrofit: Retrofit) { | ||
|
||
private val service by lazy { retrofit.create(StockServiceInterface::class.java) } | ||
|
||
internal interface StockServiceInterface { | ||
@GET("Quote/json") | ||
fun stockInfo(@Query("symbol") symbol: String): Observable<StockInfoResponse> | ||
|
||
@GET("Lookup/json") | ||
fun lookupStock(@Query("input") symbol: String): Observable<List<StockSymbol>> | ||
} | ||
|
||
fun stockInfo(symbol: String): Observable<StockInfoResponse> = service.stockInfo(symbol) | ||
fun lookupStock(symbol: String): Observable<List<StockSymbol>> = service.lookupStock(symbol) | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/example/joshskeen/stockwatcher/service/StockSymbol.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.joshskeen.stockwatcher.service | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class StockSymbol( | ||
@SerializedName("Symbol") | ||
val symbol: String, | ||
@SerializedName("Name") | ||
val name: String) |
3 changes: 3 additions & 0 deletions
3
app/src/main/java/com/example/joshskeen/stockwatcher/service/StockSymbolError.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.example.joshskeen.stockwatcher.service | ||
|
||
data class StockSymbolError(override val message: String) : Exception() |
Oops, something went wrong.