Skip to content

Commit fcafa54

Browse files
author
Javier Arroyo
committed
[JS App WORKING]
Now iOS not works Merge branch 'master' into develop/JsApp # Conflicts: # build.gradle # gradle/wrapper/gradle-wrapper.properties # settings.gradle
2 parents 15ec44e + f1b29bd commit fcafa54

File tree

13 files changed

+174
-108
lines changed

13 files changed

+174
-108
lines changed

.idea/codeStyles/Project.xml

+109
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaFxApp/database/database.db

12 KB
Binary file not shown.

JsApp/src/main/kotlin/com/jarroyo/sharedcode/jsapp/Application.kt

+44-81
Original file line numberDiff line numberDiff line change
@@ -10,101 +10,64 @@ import react.dom.button
1010
import react.dom.div
1111
import react.dom.h3
1212
import react.dom.p
13+
import com.jarroyo.sharedcode.di.InjectorCommon
14+
import com.jarroyo.sharedcode.domain.model.CurrentWeather
15+
import com.jarroyo.sharedcode.domain.model.Location
16+
import com.jarroyo.sharedcode.presentation.WeatherPresenter
17+
import com.jarroyo.sharedcode.presentation.WeatherView
18+
import org.w3c.dom.HTMLButtonElement
19+
import org.w3c.dom.HTMLInputElement
20+
import org.w3c.dom.HTMLParagraphElement
21+
import kotlin.browser.document
1322

14-
class Application : RComponent<ApplicationProps, RState>() {
23+
class Application : RComponent<ApplicationProps, RState>(), WeatherView {
1524

16-
//lateinit var mPresenter: WeatherPresenter
25+
lateinit var mPresenter: WeatherPresenter
1726

1827
override fun RBuilder.render() {
19-
div(classes = "container") {
20-
div(classes = "header clearfix") {
21-
h3 { +"Kotlin Multiplatform Example" }
22-
}
23-
child(hello(), props = props)
24-
}
28+
initPresenter()
29+
configView()
30+
}
2531

26-
//getData()
32+
private fun initPresenter() {
33+
mPresenter = InjectorCommon.provideWeatherPresenter()
34+
mPresenter.attachView(this)
2735
}
2836

29-
private fun getData() {
30-
GlobalScope.launch {
31-
val weatherApi: WeatherApi by kotlin.lazy { WeatherApi() }
32-
//WeatherRepository(weatherApi).getCurrentWeather(Location("Andorra"), success ={}, failure = {} )
37+
private fun configView(){
38+
39+
val buttonGetWeather = document.getElementById("buttonGetWeather") as HTMLButtonElement
40+
buttonGetWeather.onclick = {
41+
val locationTextArea = document.getElementById("locationTextArea") as HTMLInputElement
42+
val locationName = locationTextArea.value
43+
44+
if (!locationName.isNullOrEmpty()) {
45+
mPresenter.getCurrentWeather(Location(locationName))
46+
} else {
47+
val descriptionLabel = document.getElementById("descriptionLabel") as HTMLParagraphElement
48+
descriptionLabel.textContent = "Enter a location to GetWeather"
49+
}
3350
}
3451
}
3552

36-
private fun initPresenter() {
37-
//mPresenter = InjectorCommon.provideWeatherPresenter()
38-
//mPresenter.attachView(this)
39-
//
40-
// mPresenter.getCurrentWeather(Location("Andorra"))
53+
override fun onSuccessGetCurrentWeather(currentWeather: CurrentWeather) {
54+
console.log(currentWeather)
55+
val tempMaxLabel = document.getElementById("tempMaxLabel") as HTMLParagraphElement
56+
val tempMinLabel = document.getElementById("tempMinLabel") as HTMLParagraphElement
57+
val descriptionLabel = document.getElementById("descriptionLabel") as HTMLParagraphElement
4158

59+
tempMaxLabel.textContent = "Temp. Max ${currentWeather.main?.temp_max.toString()} ºC"
60+
tempMinLabel.textContent = "Temp. Min ${currentWeather.main?.temp_min.toString()} ºC"
61+
descriptionLabel.textContent = "Description: ${currentWeather.weather?.get(0)?.description}"
4262
}
4363

44-
// override fun onSuccessGetCurrentWeather(currentWeather: CurrentWeather) {
45-
// //Platform.runLater {
46-
// // tempMaxLabel.text = "Temp. Max ${currentWeather.main?.temp_max.toString()} ºC"
47-
// // tempMinLabel.text = "Temp. Min ${currentWeather.main?.temp_min.toString()} ºC"
48-
// // descriptionLabel.text = "Description: ${currentWeather.weather?.get(0)?.description}"
49-
// //}
50-
// }
51-
//
52-
// override fun onErrorGetCurrentWeather(throwable: Throwable) {
53-
// }
54-
//
55-
// override fun showHideLoading(visible: Boolean) {
56-
// }
57-
//
58-
// private fun showDialog(title: String, header: String = "", content: String = "") {
59-
// //Platform.runLater {
60-
// // val alert = Alert(AlertType.WARNING)
61-
// // alert.title = title
62-
// // alert.headerText = header
63-
// // alert.contentText = content
64-
//
65-
// // alert.showAndWait()
66-
// //}
67-
// }
68-
//
69-
// private fun refreshLocationList(locationModelList: List<LocationModel>) {
70-
// // Platform.runLater {
71-
// // var locationListParsed = arrayListOf<Location>()
72-
//
73-
// // for (locationModel in locationModelList) {
74-
// // var location = Location(locationModel.city_name, locationModel.country ?: "Uknown")
75-
// // locationListParsed.add(location)
76-
// // }
77-
//
78-
// // if (locationListParsed.isNotEmpty()) {
79-
// // val cityName = locationListParsed?.last().cityName
80-
//
81-
// // val array = arrayOfNulls<Location>(locationListParsed.size)
82-
// // listView.items.clear()
83-
// // listView.items.addAll(locationListParsed.toArray(array))
84-
// // listView.refresh()
85-
// // }
86-
//
87-
// //}
88-
// }
89-
}
64+
override fun onErrorGetCurrentWeather(throwable: Throwable) {
65+
}
9066

91-
fun hello() = functionalComponent<ApplicationProps> { props ->
92-
val (name, setName) = useState(null as String?)
93-
94-
div {
95-
p { +if (name == null) "Search your weather" else "Hello, $name" }
96-
button(classes = "btn btn-primary") {
97-
+"Fetch"
98-
attrs {
99-
onClickFunction = {
100-
GlobalScope.launch {
101-
console.log(props)
102-
//val name = props.networkRepository.getGreeting("web")
103-
//setName(name.message)
104-
}
105-
}
106-
}
107-
}
67+
override fun showHideLoading(visible: Boolean) {
68+
}
69+
70+
private fun showDialog(title: String, header: String = "", content: String = "") {
10871
}
10972
}
11073

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ And add and save on SQLDelight database your favourite locations:
2424

2525
<img src="https://github.com/jarroyoesp/KotlinMultiPlatform/blob/master/images/AndroidCaptureLocationList.png" width="200">
2626

27-
### iOS App - iOSApp Branch
28-
If you choose the branch iOSApp you can see this app:
27+
### iOS App
28+
29+
Open XCode and select the project:
2930

3031
<img src="https://github.com/jarroyoesp/KotlinMultiPlatform/blob/master/images/iOS_App.png" width="200">
3132

SharedCode/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ kotlin {
113113
}
114114

115115
iosMain.dependencies {
116-
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version'
116+
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
117117

118118
// COROUTINE
119119
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutine_version"

SharedCode/src/androidMain/kotlin/com/jarroyo/sharedcode/source/disk/SQLDriver.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ actual class DbArgs(
1010
var context: Context
1111
)
1212

13-
actual fun getSqlDriver(dbArgs: DbArgs): SqlDriver {
13+
actual fun getSqlDriver(dbArgs: DbArgs): SqlDriver? {
1414
val driver: SqlDriver = AndroidSqliteDriver(Database.Schema, dbArgs.context, "test.db")
1515
return driver
1616
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.jarroyo.sharedcode.source.disk
22

3-
import com.squareup.sqldelight.db.SqlDriver
43
import com.jarroyo.sharedcode.Database
4+
import com.squareup.sqldelight.db.SqlDriver
55
import com.squareup.sqldelight.drivers.ios.NativeSqliteDriver
66

77
actual class DbArgs(
88
)
99

10-
actual fun getSqlDriver(dbArgs: DbArgs): SqlDriver {
10+
actual fun getSqlDriver(dbArgs: DbArgs): SqlDriver? {
1111
val driver: SqlDriver = NativeSqliteDriver(Database.Schema, "test.db")
1212
return driver
1313
}

SharedCode/src/jvmMain/kotlin/com/jarroyo/sharedcode/source/disk/SQLDriver.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ actual class DbArgs(
1111
actual fun getSqlDriver(dbArgs: DbArgs): SqlDriver? {
1212
// By default JdbcSqliteDriver create database in Memory. If you want to create a dataBase on your path add something
1313
// similar to:
14-
// jdbc:sqlite:/Users/javierarroyo/Projects/Pruebas/KotlinMultiplatform/First/database/database.db
15-
val driver: SqlDriver = JdbcSqliteDriver("jdbc:sqlite:/Users/javierarroyo/Projects/Pruebas/KotlinMultiplatform/First/database/database.db")
14+
// jdbc:sqlite:/Users/javierarroyo/Projects/Pruebas/KotlinMultiplatform/First/JavaFxApp/database/database.db
15+
val driver: SqlDriver = JdbcSqliteDriver("jdbc:sqlite:/Users/javierarroyo/Projects/Pruebas/KotlinMultiplatform/First/JavaFxApp/database/database.db")
1616
try {
1717
Database.Schema.create(driver)
1818
} catch (e: Exception) {}

backend/src/main/resources/index.html

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@
1010
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
1111
crossorigin="anonymous">
1212
</head>
13-
<body>
13+
<body >
1414
<div id="content"></div>
1515
<script src="/frontend/JsApp.bundle.js"></script>
16+
17+
<div id="searchDiv">
18+
<p> Enter location: </p>
19+
<input type="text" id="locationTextArea"></input>
20+
<button id="buttonGetWeather" type="button">Get Weather</button>
21+
</div>
22+
<p id="tempMaxLabel"></p>
23+
<p id="tempMinLabel"></p>
24+
<p id="descriptionLabel"></p>
1625
</body>
1726
</html>

build.gradle

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
31
buildscript {
42
ext.kotlin_version = '1.3.41'
53
repositories {
@@ -16,8 +14,7 @@ buildscript {
1614
}
1715
dependencies {
1816
classpath "org.jetbrains.kotlin:kotlin-frontend-plugin:0.0.45"
19-
20-
classpath 'com.android.tools.build:gradle:3.4.0' // 3.4.0(for Android) or 3.5.0-beta01(for iOS)
17+
classpath 'com.android.tools.build:gradle:3.5.0' // 3.4.0(for Android) or 3.5.0-beta01(for iOS)
2118
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2219
classpath "com.github.jengelman.gradle.plugins:shadow:5.0.0"
2320
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

settings.gradle

-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
//pluginManagement {
2-
// resolutionStrategy {
3-
// eachPlugin {
4-
// if (requested.id.id == "kotlin-multiplatform") {
5-
// useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
6-
// }
7-
// if (requested.id.id == "kotlinx-serialization") {
8-
// useModule("org.jetbrains.kotlin:kotlin-serialization:${requested.version}")
9-
// }
10-
// }
11-
// }
12-
//}
13-
141
include ':app'
152
include ':SharedCode'
163
include ":JavaFxApp"

0 commit comments

Comments
 (0)