Skip to content

Commit 9d6f26d

Browse files
committed
Java interop
1 parent 425243f commit 9d6f26d

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.2.50'
4+
ext.kotlin_version = '1.2.60'
55
ext.supportVersion = '27.1.1'
66
ext.compileSdkVersion = 27
77
ext.targetSdkVersion = 27
@@ -11,7 +11,7 @@ buildscript {
1111
jcenter()
1212
}
1313
dependencies {
14-
classpath 'com.android.tools.build:gradle:3.1.3'
14+
classpath 'com.android.tools.build:gradle:3.1.4'
1515
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1616
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
1717
// NOTE: Do not place your application dependencies here; they belong

omegatypes/src/main/java/com/omega_r/libs/omegatypes/Image.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,39 @@ import android.view.View
1212
import android.widget.ImageView
1313
import java.io.Serializable
1414

15-
interface Image : Serializable {
15+
open class Image : Serializable {
1616

17-
fun getDrawable(context: Context): Drawable?
17+
open fun getDrawable(context: Context): Drawable? = null
1818

1919
companion object {
2020

21+
@JvmStatic
22+
fun empty() = Image()
23+
24+
@JvmStatic
2125
fun from(@DrawableRes stringRes: Int): Image = ResourceImage(stringRes)
2226

27+
@JvmStatic
2328
fun from(drawable: Drawable): Image = DrawableImage(drawable)
2429

30+
@JvmStatic
2531
fun from(bitmap: Bitmap): Image = BitmapImage(bitmap)
2632
}
2733

28-
class ResourceImage(@DrawableRes private val resId: Int) : Image {
34+
class ResourceImage(@DrawableRes private val resId: Int) : Image() {
2935

3036
override fun getDrawable(context: Context): Drawable? =
3137
ContextCompat.getDrawable(context, resId)
3238

3339
}
3440

35-
class DrawableImage(private val drawable: Drawable) : Image {
41+
class DrawableImage(private val drawable: Drawable) : Image() {
3642

3743
override fun getDrawable(context: Context): Drawable = drawable
3844

3945
}
4046

41-
class BitmapImage(private val bitmap: Bitmap) : Image {
47+
class BitmapImage(private val bitmap: Bitmap) : Image() {
4248

4349
override fun getDrawable(context: Context): Drawable =
4450
BitmapDrawable(context.resources, bitmap)

omegatypes/src/main/java/com/omega_r/libs/omegatypes/Text.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,30 @@ import android.widget.TextView
99
import android.widget.Toast
1010
import java.io.Serializable
1111

12-
interface Text : Serializable {
12+
open class Text private constructor() : Serializable {
1313

14-
fun isEmpty(): Boolean
15-
fun getString(resources: Resources): String?
14+
open fun isEmpty(): Boolean = true
15+
open fun getString(resources: Resources): String? = null
1616

1717
companion object {
18+
@JvmStatic
19+
fun empty(): Text = Text()
1820

21+
@JvmStatic
1922
fun from(string: String): Text = StringText(string)
2023

24+
@JvmStatic
2125
fun from(@StringRes stringRes: Int): Text = ResourceText(stringRes)
2226

27+
@JvmStatic
2328
fun from(@StringRes stringRes: Int, vararg formatArgs: Any): Text =
2429
FormatResourceText(stringRes, *formatArgs)
2530

31+
@JvmStatic
2632
fun from(throwable: Throwable): Text = StringText(throwable.message)
2733
}
2834

29-
class StringText constructor(private val string: String?) : Text {
35+
private class StringText internal constructor(private val string: String?) : Text() {
3036

3137
override fun isEmpty(): Boolean = string.isNullOrEmpty()
3238

@@ -35,7 +41,7 @@ interface Text : Serializable {
3541
}
3642
}
3743

38-
class ResourceText internal constructor(@StringRes private val stringRes: Int) : Text {
44+
private class ResourceText internal constructor(@StringRes private val stringRes: Int) : Text() {
3945

4046
override fun isEmpty(): Boolean = stringRes <= 0
4147

@@ -45,8 +51,8 @@ interface Text : Serializable {
4551

4652
}
4753

48-
class FormatResourceText internal constructor(@StringRes private val stringRes: Int,
49-
private vararg val formatArgs: Any) : Text {
54+
private class FormatResourceText internal constructor(@StringRes private val stringRes: Int,
55+
private vararg val formatArgs: Any) : Text() {
5056

5157
override fun isEmpty(): Boolean = stringRes <= 0
5258

0 commit comments

Comments
 (0)