diff --git a/app/build.gradle b/app/build.gradle index 044b623..7fdf6fd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,16 +20,22 @@ android { buildTypes { release { - minifyEnabled false + minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } + debug { + debuggable true + //minifyEnabled true + proguardFiles 'proguard-rules.pro' + } } compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } kotlinOptions { - jvmTarget = '11' + jvmTarget = '17' } buildFeatures { compose true @@ -39,6 +45,7 @@ android { dependencies { implementation project(":core") + implementation libs.scala3.library.x implementation libs.androidx.core.ktx implementation libs.androidx.lifecycle.runtime.ktx implementation libs.androidx.activity.compose diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 481bb43..f977030 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,21 +1,4 @@ -# 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 \ No newline at end of file +-dontwarn java.net.http.HttpClient$Builder +-dontwarn java.net.http.HttpClient$Redirect +-dontwarn java.net.http.HttpClient +-dontwarn java.net.http.HttpRequest \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f09a918..72c754c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,8 @@ + + - Greeting( - name = "Android with Scala: ${Foo.bar()}", - modifier = Modifier.padding(innerPadding) - ) - } + Form() } } } } @Composable -fun Greeting(name: String, modifier: Modifier = Modifier) { - Text( - text = "Hello $name!", - modifier = modifier - ) +fun Form() { + var org by remember { mutableStateOf("indoorvivants") } + var repo by remember { mutableStateOf("sn-bindgen") } + var error by remember { mutableStateOf("") } + var proj: Optional by remember { mutableStateOf(Optional.empty()) } + val exc = Executors.newSingleThreadExecutor() + + + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background + ) { + Column( + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text(text = error) + Text("Organisation") + OutlinedTextField(value = org, onValueChange = { org = it }) + Text("Repository") + OutlinedTextField(value = repo, onValueChange = { repo = it }) + Button(onClick = { + exc.execute({ + try { + Foo.getProjectInfo(org, repo).fold({ println(it) }, { + proj = Optional.of(it) + }) + } catch (e: Exception) { + println(e.message) + println(e.printStackTrace()) + } + }) + }) { Text("Look up on Scaladex") } + ProjectDescription(proj) + + + } + } +} + +@Composable +fun ProjectDescription(desc: Optional) { + if (desc.isEmpty) Column { } + else { + var proj = desc.get() + Column { + Text(proj.description()) + Text("Stars: " + proj.stars().toString()) + } + } } -@Preview(showBackground = true) @Composable -fun GreetingPreview() { - ScalaCoreModuleTheme { - Greeting("Android") +fun Submit(onClick: () -> Unit) { + Button(onClick = onClick) { + Text("Look up") } } \ No newline at end of file diff --git a/app/src/main/java/java/net/http/HttpTimeoutException.java b/app/src/main/java/java/net/http/HttpTimeoutException.java new file mode 100644 index 0000000..f19824a --- /dev/null +++ b/app/src/main/java/java/net/http/HttpTimeoutException.java @@ -0,0 +1,9 @@ +package java.net.http; + +import java.io.IOException; + +public class HttpTimeoutException extends IOException { + HttpTimeoutException(String message) { + super(message); + } +} diff --git a/core/.scalafmt.conf b/core/.scalafmt.conf new file mode 100644 index 0000000..0444b4c --- /dev/null +++ b/core/.scalafmt.conf @@ -0,0 +1,7 @@ +version = "3.9.2" +runner.dialect = scala3 +rewrite.scala3.insertEndMarkerMinLines = 10 +rewrite.scala3.removeOptionalBraces = true +rewrite.scala3.convertToNewSyntax = true +align.preset = more + diff --git a/core/build.gradle b/core/build.gradle index 62a5f43..068de83 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -2,8 +2,12 @@ plugins { id 'scala' } + dependencies { - implementation 'org.scala-lang:scala3-library_3:3.6.3' + implementation libs.scala3.library.x + implementation 'com.softwaremill.sttp.client4:okhttp-backend_3:dev' + implementation 'com.softwaremill.sttp.client4:upickle_3:dev' + implementation 'com.lihaoyi:upickle_3:4.1.0' testImplementation 'org.scalatest:scalatest_3:3.2.19' testImplementation 'junit:junit:4.13.1' } diff --git a/core/proguard-rules.pro b/core/proguard-rules.pro index 481bb43..f977030 100644 --- a/core/proguard-rules.pro +++ b/core/proguard-rules.pro @@ -1,21 +1,4 @@ -# 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 \ No newline at end of file +-dontwarn java.net.http.HttpClient$Builder +-dontwarn java.net.http.HttpClient$Redirect +-dontwarn java.net.http.HttpClient +-dontwarn java.net.http.HttpRequest \ No newline at end of file diff --git a/core/src/main/scala/com/example/core/Foo.scala b/core/src/main/scala/com/example/core/Foo.scala index 9550a4b..20b7dc4 100644 --- a/core/src/main/scala/com/example/core/Foo.scala +++ b/core/src/main/scala/com/example/core/Foo.scala @@ -1,5 +1,32 @@ package com.example.core +import sttp.client4.upicklejson.default.asJson + +import scala.util.Try + +case class Description( + description: String, + stars: Int, + topic: List[String] = List.empty +) derives upickle.default.ReadWriter + object Foo: + import sttp.client4.okhttp.OkHttpSyncBackend + + val backend = OkHttpSyncBackend() + import sttp.client4.* + import sttp.client4.upicklejson.* + + val x = Seq(Option(25), Option(-30), Option(100)).find(_.isDefined).flatten + + val bar: Int = (1 to 11).toList.sum - val bar: Int = 42 + def getProjectInfo(org: String, repo: String): Either[String, Description] = + basicRequest + .get(uri"https://index.scala-lang.org/api/v1/projects/$org/$repo") + .response(asJson[Description]) + .send(backend) + .body + .left + .map(_.toString) +end Foo diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 12fdf5c..ceae04a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,6 +10,8 @@ activityCompose = "1.10.0" composeBom = "2024.04.01" appcompat = "1.7.0" material = "1.12.0" +#scala3Library_x = "3.7.0-RC1-bin-SNAPSHOT" +scala3Library_x = "3.6.3" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } @@ -28,6 +30,7 @@ androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit androidx-material3 = { group = "androidx.compose.material3", name = "material3" } androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } material = { group = "com.google.android.material", name = "material", version.ref = "material" } +scala3-library_x = { module = "org.scala-lang:scala3-library_3", version.ref = "scala3Library_x" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" } diff --git a/settings.gradle b/settings.gradle index 5649e6c..717dedc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -9,6 +9,7 @@ pluginManagement { } mavenCentral() gradlePluginPortal() + } } dependencyResolutionManagement { @@ -16,6 +17,7 @@ dependencyResolutionManagement { repositories { google() mavenCentral() + mavenLocal() } }