Skip to content

Commit

Permalink
refactor: implement annotations and interfaces in kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
tynn committed Oct 15, 2023
1 parent d914d94 commit 0307eee
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 83 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
[![API][api-shield]][api]
###### A context aware parcelable string abstraction for _Android_

public interface AString extends Parcelable {
@Nullable
CharSequence invoke(@NonNull Context context);
interface AString extends Parcelable {
fun invoke(context: Context): CharSequence?
}

The library is implemented with _Kotlin_ for _Java_, thus
Expand Down
4 changes: 4 additions & 0 deletions astring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ plugins {
android {
namespace group

kotlinOptions {
freeCompilerArgs += '-Xjvm-default=all'
}

testFixtures {
enable = true
}
Expand Down
38 changes: 0 additions & 38 deletions astring/src/main/java/xyz/tynn/astring/AString.java

This file was deleted.

25 changes: 25 additions & 0 deletions astring/src/main/kotlin/xyz/tynn/astring/AString.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,36 @@
package xyz.tynn.astring

import android.content.Context
import android.os.Parcelable
import android.text.Spannable
import android.view.View
import androidx.fragment.app.Fragment
import java.util.Objects.requireNonNull
import kotlin.reflect.KProperty

/**
* A [String] abstraction for *Android*.
*
* The purpose of this type is to provide context sensitive strings.
* This could be a plain [CharSequence] or a [Spannable],
* a string resource, a formatted quantity string or something completely different.
*
* **Note**: `AString` is almost always used from the main thread,
* therefore all implementations must be non-blocking.
*/
public interface AString : Parcelable {

/**
* Provides a context sensitive string
*
* @param context to access resources
* @return string value from context; might be null
*/
public operator fun invoke(context: Context): CharSequence?

override fun describeContents(): Int = 0
}

/**
* Invokes the [aString] with [Context]
*/
Expand Down
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,3 @@ subprojects {
nexusPublishing.repositories.sonatype {
nexusUrl.set uri('https://s01.oss.sonatype.org/service/local/')
}

tasks.named('wrapper') {
gradleVersion '8.3'
}
12 changes: 6 additions & 6 deletions compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ android {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}

kotlinOptions {
freeCompilerArgs += [
'-P', 'plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=' +
libs.versions.kotlin.get()
]
}
// kotlinOptions {
// freeCompilerArgs += [
// '-P', 'plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=' +
// libs.versions.kotlin.get()
// ]
// }

testOptions {
unitTests {
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
android = "8.1.1"
android = "8.1.2"
compose-compiler = "1.5.3"
kotlin = "1.9.10"

Expand All @@ -12,7 +12,7 @@ publish = "io.github.gradle-nexus.publish-plugin:1.3.0"

[libraries]
androidx-appcompat = "androidx.appcompat:appcompat:1.6.1"
androidx-compose-bom = "androidx.compose:compose-bom:2023.09.01"
androidx-compose-bom = "androidx.compose:compose-bom:2023.10.00"
androidx-compose-ui.module = "androidx.compose.ui:ui"
androidx-compose-ui-test.module = "androidx.compose.ui:ui-test-junit4"
androidx-core = "androidx.core:core:1.12.0"
Expand All @@ -21,7 +21,7 @@ androidx-databinding-common = { module = "androidx.databinding:databinding-commo
androidx-fragment = "androidx.fragment:fragment:1.6.1"
androidx-test-core = "androidx.test:core:1.5.0"
androidx-test-runner = "androidx.test:runner:1.5.2"
google-material = "com.google.android.material:material:1.9.0"
google-material = "com.google.android.material:material:1.10.0"
junit = "junit:junit:4.13.2"
kotlin-stdlib.module = "org.jetbrains.kotlin:kotlin-stdlib"
kotlin-test.module = "org.jetbrains.kotlin:kotlin-test-junit"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public fun Context.load(
requireNonNull(this, "context"),
)?.toString()

@Suppress("unused")
@Suppress("UnusedReceiverParameter")
public fun Context.wrap(
value: String?,
): AString = AString(value)

This file was deleted.

13 changes: 0 additions & 13 deletions widget/core/src/main/java/xyz/tynn/astring/core/ToastDuration.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2023 Christian Schmitz
// SPDX-License-Identifier: Apache-2.0

package xyz.tynn.astring.core

import android.content.DialogInterface.BUTTON_NEGATIVE
import android.content.DialogInterface.BUTTON_NEUTRAL
import android.content.DialogInterface.BUTTON_POSITIVE
import androidx.annotation.IntDef
import kotlin.annotation.AnnotationRetention.SOURCE

@Retention(SOURCE)
@IntDef(BUTTON_POSITIVE, BUTTON_NEGATIVE, BUTTON_NEUTRAL)
public annotation class DialogInterfaceButton
13 changes: 13 additions & 0 deletions widget/core/src/main/kotlin/xyz/tynn/astring/core/ToastDuration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2023 Christian Schmitz
// SPDX-License-Identifier: Apache-2.0

package xyz.tynn.astring.core

import android.widget.Toast.LENGTH_LONG
import android.widget.Toast.LENGTH_SHORT
import androidx.annotation.IntDef
import kotlin.annotation.AnnotationRetention.SOURCE

@Retention(SOURCE)
@IntDef(LENGTH_LONG, LENGTH_SHORT)
public annotation class ToastDuration

0 comments on commit 0307eee

Please sign in to comment.