Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Japan example app #108

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions exampleApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
Expand All @@ -12,7 +12,7 @@ android {
defaultConfig {
applicationId "it.trade.android.exampleapp"
minSdkVersion 19
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -29,11 +29,11 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation project(':tradeit-android-sdk')
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
androidTestImplementation 'com.android.support:support-annotations:28.0.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-web:3.0.2'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.action.ViewActions;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.test.suitebuilder.annotation.LargeTest;
import android.widget.Button;
import android.widget.EditText;

Expand Down
1 change: 1 addition & 0 deletions exampleAppJapan/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
40 changes: 40 additions & 0 deletions exampleAppJapan/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
defaultConfig {
applicationId "it.trade.android.japanapp"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += "src/main/kotlin"
test.java.srcDirs += "src/test/kotlin"
androidTest.java.srcDirs += "src/androidTest/kotlin"
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation project(':tradeit-android-sdk')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
21 changes: 21 additions & 0 deletions exampleAppJapan/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package it.trade.android.japanapp

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("it.trade.android.japanapp", appContext.packageName)
}
}
21 changes: 21 additions & 0 deletions exampleAppJapan/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.trade.android.japanapp">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package it.trade.android.japanapp

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import it.trade.android.japanapp.R
import it.trade.android.japanapp.ui.orderinput.OrderInputFragment

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.replace(R.id.container, OrderInputFragment.newInstance())
.commitNow()
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package it.trade.android.japanapp.ui.orderinput

import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.opengl.Visibility
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import it.trade.android.japanapp.R
import kotlinx.android.synthetic.main.order_input_fragment.*
import kotlinx.android.synthetic.main.order_input_fragment.view.*

class OrderInputFragment : Fragment() {

companion object {
fun newInstance() = OrderInputFragment()
}

private lateinit var viewModel: OrderInputViewModel

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View {
return inflater.inflate(R.layout.order_input_fragment, container, false)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel = ViewModelProviders.of(activity!!).get(OrderInputViewModel::class.java)
// TODO: Use the ViewModel
falnatsheh marked this conversation as resolved.
Show resolved Hide resolved
viewModel.getOrderModel().observe(this, Observer { orderForm ->
orderForm?.run {
tvSymbolName.text = symbol.name
tvSymbol.text = "${symbol.symbol} ${symbol.exchange}"
tvCurrentTime.text = "13:00"

tvPrice.text = String.format("%,.0f", symbol.price)
val change = String.format("%+,.0f", priceChange)
val percentage = String.format("%+.2f", priceChangePercentage * 100)
tvPriceChange.text = "$change ($percentage%)"

tvBuyingPower.text = String.format("%,.0f", buyingPower.availableCash)
tvNisaLimit.text = String.format("(NISA) %,.0f", buyingPower.availableNisaLimit)

etQuantity.setText(String.format("%d", orderInfo.quantity))
etPrice.setText(String.format("%.0f", orderInfo.limitPrice))

val lower = String.format("%,.0f", symbol.priceLowerLimit)
val upper = String.format("%,.0f", symbol.priceUpperLimit)
tvPriceLimit.text = "(値幅制限 $lower-$upper)"
val estimated = String.format("%,.0f", estimatedValue)
tvEstimatedValue.text = "$estimated 円"
}
})
btQuantityPlus.setOnClickListener {
viewModel.increaseQuantity()
}
btQuantityMinus.setOnClickListener {
viewModel.decreaseQuantity()
}
btPricePlus.setOnClickListener {
viewModel.increasePrice()
}
btPriceMinus.setOnClickListener {
viewModel.decreasePrice()
}
btLimit.isChecked = true
btMarket.isChecked = false
btMarket.setOnClickListener {
btLimit.isChecked = false
Copy link

@falnatsheh falnatsheh Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any thoughts on having btLimit and btMarket boolean in the ViewModel vs here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are actually the button itself, here we're make it selected or not. however it can be made more concise or nature if keep the status in viewModel and linked them together. I'll try

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the model turns out a better solution. I've got a OrderType in my OrderInfo already.

btMarket.isChecked = true
togglePriceType()
}
btLimit.setOnClickListener {
btLimit.isChecked = true
btMarket.isChecked = false
togglePriceType()
}
}

private fun togglePriceType() {
if (btLimit.isChecked) {
priceInput.visibility = View.VISIBLE
tvPriceLimit.visibility = View.VISIBLE
} else {
priceInput.visibility = View.GONE
tvPriceLimit.visibility = View.GONE
}
}

}
Loading