Skip to content

Commit

Permalink
build: enable strict api mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tynn committed Nov 7, 2021
1 parent b2dd63a commit 3abe911
Show file tree
Hide file tree
Showing 42 changed files with 315 additions and 330 deletions.
18 changes: 0 additions & 18 deletions android.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,4 @@ android {
minSdkVersion 19
targetSdkVersion 30
}

compileOptions {
sourceCompatibility '1.8'
targetCompatibility '1.8'
}
}

pluginManager.withPlugin('org.jetbrains.kotlin.android') {
android {
kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs += [
'-Xno-call-assertions',
'-Xno-param-assertions',
'-Xno-receiver-assertions',
]
}
}
}
20 changes: 10 additions & 10 deletions astring/src/main/kotlin/xyz/tynn/astring/AString.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,40 @@ import kotlin.reflect.KProperty
/**
* Invokes the `AString` with [Fragment.requireContext]
*/
operator fun AString.invoke(
public operator fun AString.invoke(
fragment: Fragment,
) = invoke(fragment.requireContext())
): CharSequence? = invoke(fragment.requireContext())

/**
* Invokes the `AString` with [View.getContext]
*/
operator fun AString.invoke(
public operator fun AString.invoke(
view: View,
) = invoke(view.context)
): CharSequence? = invoke(view.context)

/**
* Delegates a `CharSequence?` property within a [Context] to the `AString`
*/
@JvmSynthetic
operator fun AString.getValue(
public operator fun AString.getValue(
thisRef: Context,
property: KProperty<*>,
) = invoke(thisRef)
): CharSequence? = invoke(thisRef)

/**
* Delegates a `CharSequence?` property within a [Fragment] to the `AString`
*/
@JvmSynthetic
operator fun AString.getValue(
public operator fun AString.getValue(
thisRef: Fragment,
property: KProperty<*>,
) = invoke(thisRef.requireContext())
): CharSequence? = invoke(thisRef.requireContext())

/**
* Delegates a `CharSequence?` property within a [View] to the `AString`
*/
@JvmSynthetic
operator fun AString.getValue(
public operator fun AString.getValue(
thisRef: View,
property: KProperty<*>,
) = invoke(thisRef.context)
): CharSequence? = invoke(thisRef.context)
42 changes: 21 additions & 21 deletions astring/src/main/kotlin/xyz/tynn/astring/AStringFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import androidx.annotation.PluralsRes
import androidx.annotation.StringRes

@JvmField
val nullAsAString: AString = NullValueWrapper.I
public val nullAsAString: AString = NullValueWrapper.I

/**
* Creates an `AString` from a `CharSequence?`
*
* Returns [nullAsAString] for null
*/
@JvmName("createFromCharSequence")
fun CharSequence?.asAString() = if (this == null)
NullValueWrapper.I
public fun CharSequence?.asAString(): AString = if (this == null)
nullAsAString
else CharSequenceWrapper(this)

/**
Expand All @@ -28,11 +28,11 @@ else CharSequenceWrapper(this)
* Returns [nullAsAString] for 0
*/
@JvmName("createFromQuantityStringResource")
fun QuantityStringResource(
public fun QuantityStringResource(
@PluralsRes resId: Int,
quantity: Int,
) = if (resId == 0)
NullValueWrapper.I
): AString = if (resId == 0)
nullAsAString
else QuantityStringResourceDelegate(
resId,
quantity,
Expand All @@ -45,12 +45,12 @@ else QuantityStringResourceDelegate(
* Returns [nullAsAString] for 0
*/
@JvmName("createFromQuantityStringResource")
fun QuantityStringResource(
public fun QuantityStringResource(
@PluralsRes resId: Int,
quantity: Int,
vararg formatArgs: Any?,
) = if (resId == 0)
NullValueWrapper.I
): AString = if (resId == 0)
nullAsAString
else QuantityStringResourceDelegate(
resId,
quantity,
Expand All @@ -63,11 +63,11 @@ else QuantityStringResourceDelegate(
* Returns [nullAsAString] for 0
*/
@JvmName("createFromQuantityTextResource")
fun QuantityTextResource(
public fun QuantityTextResource(
@PluralsRes resId: Int,
quantity: Int,
) = if (resId == 0)
NullValueWrapper.I
): AString = if (resId == 0)
nullAsAString
else QuantityTextResourceDelegate(
resId,
quantity,
Expand All @@ -79,10 +79,10 @@ else QuantityTextResourceDelegate(
* Returns [nullAsAString] for 0
*/
@JvmName("createFromStringResource")
fun StringResource(
public fun StringResource(
@StringRes resId: Int,
) = if (resId == 0)
NullValueWrapper.I
): AString = if (resId == 0)
nullAsAString
else StringResourceDelegate(
resId,
null,
Expand All @@ -94,11 +94,11 @@ else StringResourceDelegate(
* Returns [nullAsAString] for 0
*/
@JvmName("createFromStringResource")
fun StringResource(
public fun StringResource(
@StringRes resId: Int,
vararg formatArgs: Any?,
) = if (resId == 0)
NullValueWrapper.I
): AString = if (resId == 0)
nullAsAString
else StringResourceDelegate(
resId,
formatArgs,
Expand All @@ -110,10 +110,10 @@ else StringResourceDelegate(
* Returns [nullAsAString] for 0
*/
@JvmName("createFromTextResource")
fun TextResource(
public fun TextResource(
@StringRes resId: Int,
) = if (resId == 0)
NullValueWrapper.I
): AString = if (resId == 0)
nullAsAString
else TextResourceDelegate(
resId,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

package xyz.tynn.astring;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static xyz.tynn.astring.NullValueWrapper.I;

import org.junit.Test;

public class AStringFactoryTest {

@Test
Expand Down
6 changes: 3 additions & 3 deletions astring/src/test/java/xyz/tynn/astring/AStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

package xyz.tynn.astring;

import static xyz.tynn.astring.testing.mockk.MockKt.init;
import static xyz.tynn.astring.testing.mockk.MockKt.verify;

import android.view.View;

import androidx.fragment.app.Fragment;
Expand All @@ -12,9 +15,6 @@

import io.mockk.impl.annotations.MockK;

import static xyz.tynn.astring.testing.mockk.MockKt.init;
import static xyz.tynn.astring.testing.mockk.MockKt.verify;

public class AStringTest {

@MockK
Expand Down
2 changes: 1 addition & 1 deletion astring/src/test/kotlin/xyz/tynn/astring/AStringKtTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import io.mockk.spyk
import io.mockk.verify
import kotlin.test.Test

class AStringKtTest {
internal class AStringKtTest {

val aString = mockk<AString>(relaxed = true)
val aContext = mockk<Context>()
Expand Down
17 changes: 1 addition & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,7 @@ subprojects {
pluginManager.withPlugin('com.android.library') {
apply plugin: 'org.jetbrains.kotlin.android'
apply from: "$rootDir/android.gradle"

android {
libraryVariants.all {
it.generateBuildConfigProvider.configure {
enabled = false
}
}
}

tasks.withType(GenerateModuleMetadata).configureEach {
enabled = false
}

dependencies {
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib'
}
apply from: "$rootDir/library.gradle"
}

pluginManager.withPlugin('com.android.application') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ package xyz.tynn.astring.example.base

import xyz.tynn.astring.*

val aString = "AString".asAString()
val accessibilityPaneTitle = "accessibility pane title".asAString()
val action1 = StringResource(R.string.astring_action, 1)
val action2 = StringResource(R.string.astring_action, 2)
val action3 = StringResource(R.string.astring_action, 3)
val append = StringResource(R.string.astring_append)
val appendRange = StringResource(R.string.astring_append_range, 123)
val contentDescription = "content description".asAString()
val dialog = StringResource(R.string.astring_dialog)
val error = StringResource(R.string.astring_error)
val errorIcon = StringResource(R.string.astring_error_with_icon)
val hint = QuantityStringResource(R.plurals.astring_text_hint, 0)
val message = StringResource(R.string.astring_message)
val stateDescription = "state description".asAString()
val text = TextResource(R.string.astring_text)
val textType = QuantityTextResource(R.plurals.astring_text_type, 5)
val title = StringResource(R.string.astring_title)
val tooltipText = QuantityStringResource(R.plurals.astring_tooltip_text, 2, 2)
public val aString: AString = "AString".asAString()
public val accessibilityPaneTitle: AString = "accessibility pane title".asAString()
public val action1: AString = StringResource(R.string.astring_action, 1)
public val action2: AString = StringResource(R.string.astring_action, 2)
public val action3: AString = StringResource(R.string.astring_action, 3)
public val append: AString = StringResource(R.string.astring_append)
public val appendRange: AString = StringResource(R.string.astring_append_range, 123)
public val contentDescription: AString = "content description".asAString()
public val dialog: AString = StringResource(R.string.astring_dialog)
public val error: AString = StringResource(R.string.astring_error)
public val errorIcon: AString = StringResource(R.string.astring_error_with_icon)
public val hint: AString = QuantityStringResource(R.plurals.astring_text_hint, 0)
public val message: AString = StringResource(R.string.astring_message)
public val stateDescription: AString = "state description".asAString()
public val text: AString = TextResource(R.string.astring_text)
public val textType: AString = QuantityTextResource(R.plurals.astring_text_type, 5)
public val title: AString = StringResource(R.string.astring_title)
public val tooltipText: AString = QuantityStringResource(R.plurals.astring_tooltip_text, 2, 2)
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,6 @@

package xyz.tynn.astring.example.java;

import android.app.AlertDialog.Builder;
import android.content.DialogInterface.OnClickListener;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;

import xyz.tynn.astring.appcompat.AStringAlertDialog;
import xyz.tynn.astring.appcompat.AStringAlertDialogBuilder;
import xyz.tynn.astring.core.AStringToast;
import xyz.tynn.astring.example.base.AStringsKt;
import xyz.tynn.astring.example.base.R;
import xyz.tynn.astring.example.base.databinding.ActivityMainBinding;
import xyz.tynn.astring.material.AStringSnackbar;

import static android.content.DialogInterface.BUTTON_NEGATIVE;
import static android.widget.TextView.BufferType.SPANNABLE;
import static android.widget.Toast.LENGTH_SHORT;
Expand Down Expand Up @@ -60,6 +36,30 @@
import static xyz.tynn.astring.material.AStringSnackbar.make;
import static xyz.tynn.astring.material.AStringSnackbar.setAction;

import android.app.AlertDialog.Builder;
import android.content.DialogInterface.OnClickListener;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;

import xyz.tynn.astring.appcompat.AStringAlertDialog;
import xyz.tynn.astring.appcompat.AStringAlertDialogBuilder;
import xyz.tynn.astring.core.AStringToast;
import xyz.tynn.astring.example.base.AStringsKt;
import xyz.tynn.astring.example.base.R;
import xyz.tynn.astring.example.base.databinding.ActivityMainBinding;
import xyz.tynn.astring.material.AStringSnackbar;

public class MainActivity extends AppCompatActivity {

private CharSequence tag = null;
Expand Down
Loading

0 comments on commit 3abe911

Please sign in to comment.