Migrate Library to Kotlin

This commit is contained in:
GuilhermeWerner 2021-06-12 11:25:00 -03:00
parent 8a3eb4809e
commit 85ca2b7701
12 changed files with 81 additions and 79 deletions

View file

@ -41,7 +41,9 @@ dependencies {
implementation "androidx.core:core-ktx:1.3.2" implementation "androidx.core:core-ktx:1.3.2"
implementation "androidx.appcompat:appcompat:1.2.0" implementation "androidx.appcompat:appcompat:1.2.0"
implementation "com.google.android.material:material:1.3.0" implementation "com.google.android.material:material:1.3.0"
testImplementation "junit:junit:4.+" testImplementation "junit:junit:4.+"
androidTestImplementation "androidx.test.ext:junit:1.1.2" androidTestImplementation "androidx.test.ext:junit:1.1.2"
androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0" androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0"
} }

View file

@ -1,5 +1,5 @@
buildscript { buildscript {
ext.kotlin_version = "1.3.72" ext.kotlin_version = "1.4.31"
repositories { repositories {
google() google()

View file

@ -1,6 +1,6 @@
plugins { plugins {
// Apply the scala Plugin to add support for Scala. // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
id "scala" id "org.jetbrains.kotlin.jvm"
// Apply the java-library plugin for API and implementation separation. // Apply the java-library plugin for API and implementation separation.
id "java-library" id "java-library"
@ -15,26 +15,21 @@ repositories {
} }
dependencies { dependencies {
// Use Scala 2.13 in our library project // Align versions of all Kotlin components
implementation "org.scala-lang:scala-library:2.13.3" implementation platform("org.jetbrains.kotlin:kotlin-bom")
// Use the Kotlin JDK 8 standard library.
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
// This dependency is used internally, and not exposed to consumers on their own compile classpath. // This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation "com.google.guava:guava:30.0-jre" implementation "com.google.guava:guava:30.0-jre"
// Use Scalatest for testing our library // Use the Kotlin test library.
testImplementation "junit:junit:4.13.1" testImplementation "org.jetbrains.kotlin:kotlin-test"
testImplementation "org.scalatest:scalatest_2.13:3.2.3"
testImplementation "org.scalatestplus:junit-4-13_2.13:3.2.2.0"
// Need scala-xml at test runtime // Use the Kotlin JUnit integration.
testRuntimeOnly "org.scala-lang.modules:scala-xml_2.13:1.2.0" testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
// This dependency is exported to consumers, that is to say found on their compile classpath. // This dependency is exported to consumers, that is to say found on their compile classpath.
api "org.apache.commons:commons-math3:3.6.1" api "org.apache.commons:commons-math3:3.6.1"
} }
tasks.named("jar") {
manifest {
attributes("Implementation-Title": "TribuFu", "Implementation-Version": project.version)
}
}

View file

@ -2,4 +2,4 @@
package com.tribufu.sdk package com.tribufu.sdk
class System {} interface IHandler {}

View file

@ -2,4 +2,4 @@
package com.tribufu.sdk package com.tribufu.sdk
class Handler {} interface ISystem {}

View file

@ -0,0 +1,13 @@
// Copyright (c) TribuFu. All Rights Reserved
package com.tribufu.sdk
class TribuFu {
// Used to load the 'TribuFu' library on application startup.
init {
System.loadLibrary("TribuFu_Jvm")
}
/** A native method that is implemented by the 'TribuFu' native library. */
external fun Hello(input: String ): String
}

View file

@ -0,0 +1,10 @@
// Copyright (c) TribuFu. All Rights Reserved
package com.tribufu.sdk.models
class Email {
var address = ""
var user_id = "1"
var confirmed = false
var primary = true
}

View file

@ -1,11 +1,12 @@
// Copyright (c) TribuFu. All Rights Reserved. // Copyright (c) TribuFu. All Rights Reserved
package com.tribufu.sdk.models package com.tribufu.sdk.models
class User { class User {
val id = "" var id = ""
val name = "" var name = ""
var display_name = "" var display_name = ""
var password_hash = ""
var role = Role.User var role = Role.User
var confirmed = false var confirmed = false
var two_factor_enabled = false var two_factor_enabled = false
@ -15,15 +16,15 @@ class User {
var parental_control = false var parental_control = false
var profile_url = "" var profile_url = ""
var public_birthday = false var public_birthday = false
var birthday = "" var Birthday = ""
var location = "" var location = ""
var timezone = "" var timezone = ""
var language = "" var language = ""
var currency = "" var currency = ""
var theme = Theme.Light var theme = Theme.Light
var ip_address = "" var ip_address = ""
val registration_ip_address = "" var registration_ip_address = ""
val Joined = "" var Joined = ""
var Updated = "" var Updated = ""
var failed_logins = 0 var failed_logins = 0
var about = "" var about = ""
@ -32,21 +33,33 @@ class User {
var avatar_url = "" var avatar_url = ""
var background_url = "" var background_url = ""
var status = Status.Offline var status = Status.Offline
var last_online = "" var LastOnline = ""
var last_activity = "" var LastActivity = ""
var last_post = "" var LastPost = ""
var warnings = 0 var warnings = 0
var last_warn = "" var LastWarn = ""
} }
object Role extends Enumeration { enum class Role {
val User, Bot, Helper, Tester, Developer, Moderator, Admin, Root = Value User,
Bot,
Helper,
Tester,
Developer,
Moderator,
Admin,
Root
} }
object Theme extends Enumeration { enum class Theme {
val Light, Dark = Value Light,
Dark
} }
object Status extends Enumeration { enum class Status {
val Offline, Away, Disturb, Online, Playing = Value Offline,
Away,
Disturb,
Online,
Playing
} }

View file

@ -1,17 +0,0 @@
// Copyright (c) TribuFu. All Rights Reserved.
package com.tribufu.sdk
class TribuFu {
Init()
// Used to load the 'TribuFu' library on application startup.
private def Init() {
System.loadLibrary("TribuFu_Jvm")
}
/**
* A native method that is implemented by the 'TribuFu' native library.
*/
@native def Hello(input: String): String
}

View file

@ -1,11 +0,0 @@
// Copyright (c) TribuFu. All Rights Reserved.
package com.tribufu.sdk.models
class Email() {
val address = ""
val added = ""
var updated = ""
var confirmed = false
var primary = true
}

View file

@ -0,0 +1,13 @@
// Copyright (c) TribuFu. All Rights Reserved
package com.tribufu.sdk
import kotlin.test.Test
import kotlin.test.assertTrue
class LibraryTest {
@Test fun testSomeLibraryMethod() {
//val library = TribuFu()
assertTrue(true, "someLibraryMethod should return 'true'")
}
}

View file

@ -1,16 +0,0 @@
// Copyright (c) TribuFu. All Rights Reserved.
package com.tribufu.sdk
import org.junit.runner.RunWith
import org.scalatest.funsuite.AnyFunSuite
import org.scalatestplus.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class TribuFuSuite extends AnyFunSuite {
test("Hello is always true") {
//def library = new TribuFu()
//assert(library.Hello("Scala") == "Scala")
assert(true)
}
}