Skip to content

Commit 49134c5

Browse files
kernel0xIgor Molev
authored andcommitted
init
0 parents  commit 49134c5

File tree

101 files changed

+3041
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+3041
-0
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
7+
[*.{kt, kts}]
8+
indent_size = 2
9+
insert_final_newline = false
10+
max_line_length = 120

.gitignore

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea
5+
/.idea/caches
6+
/.idea/libraries
7+
/.idea/modules.xml
8+
/.idea/workspace.xml
9+
/.idea/navEditor.xml
10+
/.idea/assetWizardSettings.xml
11+
.DS_Store
12+
/build
13+
/captures
14+
.externalNativeBuild
15+
16+
## Build generated
17+
build/
18+
DerivedData
19+
build.xcarchive
20+
21+
## Various settings
22+
*.pbxuser
23+
!default.pbxuser
24+
*.mode1v3
25+
!default.mode1v3
26+
*.mode2v3
27+
!default.mode2v3
28+
*.perspectivev3
29+
!default.perspectivev3
30+
xcuserdata
31+
32+
## Other
33+
*.xccheckout
34+
*.moved-aside
35+
*.xcuserstate
36+
*.xcscmblueprint
37+
38+
## Obj-C/Swift specific
39+
*.hmap
40+
*.ipa
41+
42+
# CocoaPods
43+
Pods/
44+
45+
#Node Modules
46+
node_modules
47+
48+
# Firebase
49+
AndroidApp/google-services.json

AndroidApp/.gitignore

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

AndroidApp/build.gradle

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
5+
android {
6+
compileSdkVersion 28
7+
defaultConfig {
8+
applicationId "com.kernel.kmpproject"
9+
minSdkVersion 21
10+
targetSdkVersion 28
11+
versionCode 1
12+
versionName "1.0"
13+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14+
}
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
22+
packagingOptions {
23+
exclude("META-INF/*.kotlin_module")
24+
}
25+
}
26+
27+
dependencies {
28+
implementation fileTree(dir: 'libs', include: ['*.jar'])
29+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
30+
implementation 'androidx.appcompat:appcompat:1.1.0'
31+
implementation 'androidx.core:core-ktx:1.0.2'
32+
testImplementation 'junit:junit:4.12'
33+
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
34+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
35+
36+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.1'
37+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.1'
38+
39+
implementation project(':SharedCode')
40+
41+
implementation "android.arch.lifecycle:extensions:1.1.1"
42+
implementation "android.arch.lifecycle:viewmodel:1.1.1"
43+
44+
implementation("dev.icerock.moko:mvvm:0.3.1")
45+
46+
implementation 'androidx.multidex:multidex:2.0.0'
47+
androidTestImplementation('androidx.multidex:multidex-instrumentation:2.0.0') {
48+
exclude group: 'com.android.support', module: 'multidex'
49+
}
50+
51+
implementation 'androidx.recyclerview:recyclerview:1.1.0'
52+
}

AndroidApp/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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.kernel.kmpproject">
4+
5+
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
7+
8+
<application
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:roundIcon="@mipmap/ic_launcher_round"
13+
android:supportsRtl="true"
14+
android:name=".ui.App"
15+
android:theme="@style/AppTheme">
16+
<activity android:name=".ui.main.MainActivity">
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.kernel.kmpproject.ui
2+
3+
import androidx.multidex.MultiDexApplication
4+
5+
open class App : MultiDexApplication() {
6+
7+
override fun onCreate() {
8+
super.onCreate()
9+
}
10+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.kernel.kmpproject.ui.main
2+
3+
import android.os.Bundle
4+
import android.widget.Toast
5+
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.lifecycle.ViewModelProviders
7+
import com.kernel.kmpproject.R
8+
import com.kernel.kmpproject.ui.indexes.*
9+
import com.kernel.kmpproject.ui.main.adapter.IndexesAdapter
10+
import kotlinx.android.synthetic.main.activity_main.*
11+
12+
class MainActivity : AppCompatActivity() {
13+
14+
private lateinit var viewModel: IndexesViewModel
15+
private var adapter: IndexesAdapter = IndexesAdapter { viewModel.getQuote(it.ticker) }
16+
17+
override fun onCreate(savedInstanceState: Bundle?) {
18+
super.onCreate(savedInstanceState)
19+
setContentView(R.layout.activity_main)
20+
21+
recycler.adapter = adapter
22+
23+
viewModel = ViewModelProviders.of(this).get(IndexesViewModel::class.java)
24+
observeViewState()
25+
26+
viewModel.getMajorIndexes()
27+
}
28+
29+
private fun observeViewState() {
30+
viewModel.getViewData.addObserver { updateViewState(it) }
31+
}
32+
33+
private fun updateViewState(state: IndexesViewState) = runOnUiThread {
34+
when (state) {
35+
is Loading -> {
36+
Toast.makeText(this, "Loading...", Toast.LENGTH_SHORT).show()
37+
}
38+
is Error -> {
39+
Toast.makeText(this, state.message, Toast.LENGTH_LONG).show()
40+
}
41+
is ShowMajorIndexes -> {
42+
adapter.items = state.indexes
43+
}
44+
is ShowQuote -> {
45+
Toast.makeText(this, state.quote.dayLow + " - " + state.quote.dayHigh, Toast.LENGTH_LONG).show()
46+
}
47+
}
48+
}
49+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.kernel.kmpproject.ui.main.adapter
2+
3+
import android.view.LayoutInflater
4+
import android.view.ViewGroup
5+
import androidx.recyclerview.widget.RecyclerView
6+
import com.kernel.kmpproject.R
7+
import com.kernel.kmpproject.domain.model.Index
8+
import kotlinx.android.synthetic.main.item_index.view.*
9+
10+
class IndexViewHolder(view: ViewGroup) :
11+
RecyclerView.ViewHolder(LayoutInflater.from(view.context).inflate(R.layout.item_index, view, false)) {
12+
13+
fun bind(index: Index) {
14+
with(itemView) {
15+
changes.text = index.changes.toString()
16+
indexName.text = index.indexName
17+
ticker.text = index.ticker
18+
price.text = index.price.toString()
19+
}
20+
}
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.kernel.kmpproject.ui.main.adapter
2+
3+
import android.view.ViewGroup
4+
import androidx.recyclerview.widget.RecyclerView
5+
import com.kernel.kmpproject.domain.model.Index
6+
import com.kernel.kmpproject.domain.model.Indexes
7+
import kotlinx.coroutines.Job
8+
9+
class IndexesAdapter(private val listener: (Index) -> Unit) : RecyclerView.Adapter<IndexViewHolder>() {
10+
11+
var items: Indexes = emptyList()
12+
set(value) {
13+
field = value
14+
notifyDataSetChanged()
15+
}
16+
17+
override fun getItemCount() = items.size
18+
19+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IndexViewHolder {
20+
return IndexViewHolder(parent)
21+
}
22+
23+
override fun onBindViewHolder(holder: IndexViewHolder, position: Int) {
24+
holder.bind(items[position])
25+
holder.itemView.setOnClickListener {
26+
listener.invoke(items[position])
27+
}
28+
}
29+
}
30+

0 commit comments

Comments
 (0)