Skip to content

Commit

Permalink
Enable explicit API mode, add explicit visibility and typing to comply
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmb13 committed Dec 12, 2020
1 parent e737487 commit edc3ebc
Show file tree
Hide file tree
Showing 26 changed files with 63 additions and 51 deletions.
11 changes: 10 additions & 1 deletion kite/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,13 @@ dependencies {
testImplementation deps.test.junit
testImplementation deps.test.mockito_core
testImplementation deps.test.truth
}
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
freeCompilerArgs += [
'-progressive',
'-Xexplicit-api=strict',
]
}
}
47 changes: 25 additions & 22 deletions kite/src/main/kotlin/com/cioccarellia/kite/Kite.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import android.util.TypedValue
import android.view.animation.Animation
import android.view.animation.Interpolator
import androidx.annotation.RestrictTo
import androidx.annotation.StringRes
import com.cioccarellia.kite.resparser.KiteCustomResParser
import com.cioccarellia.kite.resparser.KiteResParser
import com.cioccarellia.kite.resparser.compat.KiteColorStateLists
import com.cioccarellia.kite.resparser.compat.KiteColors
import com.cioccarellia.kite.resparser.compat.KiteDrawables
Expand All @@ -35,11 +38,11 @@ import com.cioccarellia.kite.resparser.custom.KiteInterpolators
import com.cioccarellia.kite.resparser.resources.*
import java.io.InputStream

object Kite {
public object Kite {
/**
* Initialized Kite
* */
fun fly(context: Context) {
public fun fly(context: Context) {
this.context = context
}

Expand All @@ -51,124 +54,124 @@ object Kite {
* [Context.getString()] is used to resolve the id.
* There is also a vararg variant which accepts format arguments, and maps to the appropriate [Context.getString()] function.
* */
val string by lazy { KiteStrings() }
public val string: KiteResParser<Int, String> by lazy { KiteStrings() }

/**
* Fetches [String]s Plurals from resources, given the [String] id and the [Int] quantity.
* [Resources.getQuantityString()] is used to resolve the id.
* There is also a vararg variant which accepts format arguments, and maps to the appropriate [Resources.getQuantityString()] function.
* */
val plural by lazy { KitePlurals() }
public val plural: KiteCustomResParser<Int, String> by lazy { KitePlurals() }

/**
* Fetches [CharSequence] Texts from resources.
* [Context.getText()] is used to resolve the id.
* */
val text by lazy { KiteTexts() }
public val text: KiteResParser<Int, CharSequence> by lazy { KiteTexts() }

/**
* Fetches color [Int]s from resources.
* [ContextCompat.getColor()] is used to resolve the id.
* */
val color by lazy { KiteColors() }
public val color: KiteResParser<Int, Int> by lazy { KiteColors() }


/**
* Fetches [ColorStateList]s from resources.
* [ContextCompat.getColorStateList()] is used to resolve the id.
* */
val colorStateList by lazy { KiteColorStateLists() }
public val colorStateList: KiteResParser<Int, ColorStateList> by lazy { KiteColorStateLists() }

/**
* Fetches [Boolean]s from resources.
* [Resources.getBoolean()] is used to resolve the id.
* */
val bools by lazy { KiteBools() }
public val bools: KiteResParser<Int, Boolean> by lazy { KiteBools() }

/**
* Fetches ID [Int]s from resources, given the definition type and package.
* [Resources.getIdentifier()] is used to resolve the id.
* */
val identifier by lazy { KiteIdentifier() }
public val identifier: KiteCustomResParser<String, Int> by lazy { KiteIdentifier() }

/**
* Fetches [Drawable]s from resources.
* [ContextCompat.getDrawable()] is used to resolve the id.
* There is also a variant which accepts a [Resources.Theme?] arguments, and maps to the [Resources.getDrawable()] function.
* */
val drawable by lazy { KiteDrawables() }
public val drawable: KiteResParser<Int, Drawable> by lazy { KiteDrawables() }

/**
* Fetches [Animation]s from resources.
* [AnimationUtils.loadAnimation()] is used to resolve the id.
* */
val animation by lazy { KiteAnimations() }
public val animation: KiteResParser<Int, Animation> by lazy { KiteAnimations() }

/**
* Fetches [Interpolator]s from resources.
* [AnimationUtils.loadInterpolator()] is used to resolve the id.
* */
val interpolator by lazy { KiteInterpolators() }
public val interpolator: KiteResParser<Int, Interpolator> by lazy { KiteInterpolators() }

/**
* Fetches [IntArray]s from resources.
* [Resources.getIntArray()] is used to resolve the id.
* */
val intArray by lazy { KiteIntArrays() }
public val intArray: KiteResParser<Int, IntArray> by lazy { KiteIntArrays() }

/**
* Fetches String Arrays ([Array<String>]) from resources.
* [Resources.getStringArray()] is used to resolve the id.
* */
val stringArray by lazy { KiteStringArrays() }
public val stringArray: KiteResParser<Int, Array<out String>> by lazy { KiteStringArrays() }

/**
* Fetches [TypedArray]s from resources.
* [Resources.obtainTypedArray()] is used to resolve the id.
* */
val typedArray by lazy { KiteTypedArrays() }
public val typedArray: KiteResParser<Int, TypedArray> by lazy { KiteTypedArrays() }

/**
* Fetches Dimension [Float]s from resources.
* [Resources.getDimension()] is used to resolve the id.
* */
val dimension by lazy { KiteDimensions() }
public val dimension: KiteResParser<Int, Float> by lazy { KiteDimensions() }

/**
* Fetches [Int]s from resources.
* [Resources.getInteger()] is used to resolve the id.
* */
val integer by lazy { KiteIntegers() }
public val integer: KiteResParser<Int, Int> by lazy { KiteIntegers() }

/**
* Fetches fractions [Float]s from resources, given the value base and the parent value base.
* [Resources.getFraction()] is used to resolve the id.
* */
val fraction by lazy { KiteFraction() }
public val fraction: KiteCustomResParser<Int, Float> by lazy { KiteFraction() }

/**
* Fetches Layout [XmlResourceParser]s from resources.
* [Resources.getLayout()] is used to resolve the id.
* */
val layout by lazy { KiteLayouts() }
public val layout: KiteResParser<Int, XmlResourceParser> by lazy { KiteLayouts() }

/**
* Fetches [InputStream]s from resources.
* [Resources.openRawResource()] is used to resolve the id.
* There is also a parameterized variant which accepts a [TypedValue], which maps to the appropriate [Resources.openRawResource()] function.
* */
val raw by lazy { KiteRaws() }
public val raw: KiteResParser<Int, InputStream> by lazy { KiteRaws() }

/**
* Fetches Layout [XmlResourceParser]s from resources.
* [Resources.getXml()] is used to resolve the id.
* */
val xml by lazy { KiteXmls() }
public val xml: KiteResParser<Int, XmlResourceParser> by lazy { KiteXmls() }

/**
* Requires API 26 (O)
* Fetches Layout [Typeface]s from resources.
* [Resources.getFont()] is used to resolve the id.
* */
val font by lazy { KiteFonts() }
public val font: KiteResParser<Int, Typeface> by lazy { KiteFonts() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import com.cioccarellia.kite.resparser.KiteParser
/**
* @return kite [Context] reference
* */
fun getKiteContext() = Kite.context
public fun getKiteContext(): Context = Kite.context

/**
* Permanently changes the context used by kite
* @param [context] The context to be set as the new kite context
* */
fun changeKiteContext(context: Context) {
public fun changeKiteContext(context: Context) {
Kite.context = context
}

Expand All @@ -38,7 +38,7 @@ fun changeKiteContext(context: Context) {
* @param [context] The context to be set as the new kite context
* @return [T] KiteParser instance referencing the new context
* */
fun <T : KiteParser> T.changeContext(context: Context): T = apply {
public fun <T : KiteParser> T.changeContext(context: Context): T = apply {
Kite.context = context
}

Expand All @@ -49,7 +49,7 @@ fun <T : KiteParser> T.changeContext(context: Context): T = apply {
* @param [block] The lambda to be executed
* @return [T] KiteParser instance, referencing the same context it was passed with
* */
fun <T : KiteParser, R> T.runWith(context: Context, block: T.() -> R): R = run {
public fun <T : KiteParser, R> T.runWith(context: Context, block: T.() -> R): R = run {
val previousContext = getKiteContext()
changeContext(context).block().also { changeContext(previousContext) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ package com.cioccarellia.kite.resparser
/**
* [KiteParser] which has precisely 1 input and 1 output
* */
abstract class KiteCustomResParser<in R, out O> : KiteParser()
public abstract class KiteCustomResParser<in R, out O> : KiteParser()
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.cioccarellia.kite.Kite
/**
* Represents a Kite parser entity
* */
abstract class KiteParser {
public abstract class KiteParser {
internal var kiteContext: Context
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ package com.cioccarellia.kite.resparser
/**
* [KiteParser] which has precisely 1 input and 1 output
* */
abstract class KiteResParser<in R, out O> : KiteParser() {
abstract operator fun get(resource: R): O
public abstract class KiteResParser<in R, out O> : KiteParser() {
public abstract operator fun get(resource: R): O
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteColorStateLists Implementation
* */
class KiteColorStateLists : KiteResParser<@ColorRes Int, ColorStateList>() {
internal class KiteColorStateLists : KiteResParser<@ColorRes Int, ColorStateList>() {
override operator fun get(
@ColorRes @IntRange(from = 1) colorStateList: Int
): ColorStateList = ContextCompat.getColorStateList(kiteContext, colorStateList)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteColors Implementation
* */
class KiteColors : KiteResParser<@ColorRes Int, @ColorInt Int>() {
internal class KiteColors : KiteResParser<@ColorRes Int, @ColorInt Int>() {
@ColorInt
override operator fun get(
@ColorRes @IntRange(from = 1) color: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteDrawables Implementation
* */
class KiteDrawables : KiteResParser<@DrawableRes Int, Drawable>() {
internal class KiteDrawables : KiteResParser<@DrawableRes Int, Drawable>() {
override operator fun get(
@DrawableRes @IntRange(from = 1) drawable: Int
): Drawable = ContextCompat.getDrawable(kiteContext, drawable)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteStrings Implementation
* */
class KiteStrings : KiteResParser<@StringRes Int, String>() {
internal class KiteStrings : KiteResParser<@StringRes Int, String>() {
override operator fun get(
@StringRes @IntRange(from = 1) string: Int
): String = kiteContext.getString(string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteTexts Implementation
* */
class KiteTexts : KiteResParser<@StringRes Int, CharSequence>() {
internal class KiteTexts : KiteResParser<@StringRes Int, CharSequence>() {
override operator fun get(
@StringRes @IntRange(from = 1) text: Int
): CharSequence = kiteContext.getText(text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteAnimations Implementation
* */
class KiteAnimations : KiteResParser<@AnimRes Int, Animation>() {
internal class KiteAnimations : KiteResParser<@AnimRes Int, Animation>() {
override operator fun get(
@AnimRes @IntRange(from = 1) animation: Int
): Animation = AnimationUtils.loadAnimation(kiteContext, animation)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteInterpolators Implementation
* */
class KiteInterpolators : KiteResParser<@InterpolatorRes Int, Interpolator>() {
internal class KiteInterpolators : KiteResParser<@InterpolatorRes Int, Interpolator>() {
override operator fun get(
@InterpolatorRes @IntRange(from = 1) animation: Int
): Interpolator = AnimationUtils.loadInterpolator(kiteContext, animation)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteBools Implementation
* */
class KiteBools : KiteResParser<@BoolRes Int, Boolean>() {
internal class KiteBools : KiteResParser<@BoolRes Int, Boolean>() {
override operator fun get(
@BoolRes @IntRange(from = 1) boolean: Int
): Boolean = kiteContext.resources.getBoolean(boolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteDimens Implementation
* */
class KiteDimensions : KiteResParser<@DimenRes Int, Float>() {
internal class KiteDimensions : KiteResParser<@DimenRes Int, Float>() {
override operator fun get(
@DimenRes @IntRange(from = 1) dimension: Int
): Float = kiteContext.resources.getDimension(dimension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteFonts Implementation
* */
class KiteFonts : KiteResParser<@FontRes Int, Typeface>() {
internal class KiteFonts : KiteResParser<@FontRes Int, Typeface>() {
@RequiresApi(Build.VERSION_CODES.O)
override operator fun get(
@FontRes @IntRange(from = 1) font: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.cioccarellia.kite.resparser.KiteCustomResParser
/**
* KiteFraction Implementation
* */
class KiteFraction : KiteCustomResParser<@FractionRes Int, Float>() {
internal class KiteFraction : KiteCustomResParser<@FractionRes Int, Float>() {
operator fun get(
@FractionRes @IntRange(from = 1) fraction: Int,
@IntRange(from = 2) base: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.cioccarellia.kite.resparser.KiteCustomResParser
/**
* KiteIdentifier Implementation
* */
class KiteIdentifier : KiteCustomResParser<String, Int>() {
internal class KiteIdentifier : KiteCustomResParser<String, Int>() {
operator fun get(
name: String,
defType: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteIntArrays Implementation
* */
class KiteIntArrays : KiteResParser<@ArrayRes Int, IntArray>() {
internal class KiteIntArrays : KiteResParser<@ArrayRes Int, IntArray>() {
override operator fun get(
@ArrayRes @IntRange(from = 1) intArray: Int
): IntArray = kiteContext.resources.getIntArray(intArray)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteIntegers Implementation
* */
class KiteIntegers : KiteResParser<@IntegerRes Int, Int>() {
internal class KiteIntegers : KiteResParser<@IntegerRes Int, Int>() {
override operator fun get(
@IntegerRes @IntRange(from = 1) integer: Int
): Int = kiteContext.resources.getInteger(integer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.cioccarellia.kite.resparser.KiteResParser
/**
* KiteLayouts Implementation
* */
class KiteLayouts : KiteResParser<@LayoutRes Int, XmlResourceParser>() {
internal class KiteLayouts : KiteResParser<@LayoutRes Int, XmlResourceParser>() {
override operator fun get(
@LayoutRes @IntRange(from = 1) layout: Int
): XmlResourceParser = kiteContext.resources.getLayout(layout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.cioccarellia.kite.resparser.KiteCustomResParser
/**
* KitePlurals Implementation
* */
class KitePlurals : KiteCustomResParser<@PluralsRes Int, String>() {
internal class KitePlurals : KiteCustomResParser<@PluralsRes Int, String>() {
operator fun get(
@PluralsRes @IntRange(from = 1) plurals: Int,
quantity: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import java.io.InputStream
/**
* KiteRaws Implementation
* */
class KiteRaws : KiteResParser<@RawRes Int, InputStream>() {
internal class KiteRaws : KiteResParser<@RawRes Int, InputStream>() {
override operator fun get(
@RawRes @IntRange(from = 1) raw: Int
): InputStream = kiteContext.resources.openRawResource(raw)
Expand Down

0 comments on commit edc3ebc

Please sign in to comment.