Skip to content

Commit

Permalink
Kotlin 1.7 + Deprecation cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
romainbsl committed Jun 21, 2022
1 parent 84f1d61 commit 9d5ed2c
Show file tree
Hide file tree
Showing 17 changed files with 1,987 additions and 328 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ plugins {

allprojects {
group = "org.kodein.di"
version = "7.12.0"
version = "7.13.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,104 +43,48 @@ class LazyContextDIPropertyDelegateProvider(private val getContext: () -> Contex
override operator fun provideDelegate(thisRef: Any?, property: KProperty<*>?) = lazy { closestDI(thisRef, getContext()) }
}

@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI()", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun di(): DIPropertyDelegateProvider<Context> = closestDI()

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*
* To be used on Android's `Context` classes, such as `Activity` or `Service`.
*/
fun closestDI(): DIPropertyDelegateProvider<Context> = ContextDIPropertyDelegateProvider()

@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI(context)", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun di(context: Context): DIPropertyDelegateProvider<Any?> = closestDI(context)

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*
* @param context The Android context to use to walk up the context hierarchy.
*/
fun closestDI(context: Context): LazyContextDIPropertyDelegateProvider = LazyContextDIPropertyDelegateProvider { context }

@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI(getContext)", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun di(getContext: () -> Context): DIPropertyDelegateProvider<Any?> = closestDI(getContext)

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*
* @param getContext A function that returns the Android context to use to walk up the context hierarchy.
*/
fun closestDI(getContext: () -> Context): DIPropertyDelegateProvider<Any?> = LazyContextDIPropertyDelegateProvider(getContext)

@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI()", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun Fragment.di(): DIPropertyDelegateProvider<Any?> = closestDI()

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*/
fun Fragment.closestDI(): DIPropertyDelegateProvider<Any?> = closestDI { activity }

@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI()", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun Dialog.di(): DIPropertyDelegateProvider<Any?> = closestDI()

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*/
fun Dialog.closestDI(): DIPropertyDelegateProvider<Any?> = closestDI { context }

@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI()", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun View.di() = org.kodein.di.android.closestDI()

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*/
fun View.closestDI(): DIPropertyDelegateProvider<Any?> = closestDI { context }

@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI()", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun AbstractThreadedSyncAdapter.di(): DIPropertyDelegateProvider<Any?> = closestDI()

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*/
fun AbstractThreadedSyncAdapter.closestDI(): DIPropertyDelegateProvider<Any?> = closestDI { context }

@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI()", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun Loader<*>.di(): DIPropertyDelegateProvider<Context> = org.kodein.di.android.closestDI()

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*/
fun Loader<*>.closestDI(): DIPropertyDelegateProvider<Any?> = closestDI { context }
fun Loader<*>.closestDI(): DIPropertyDelegateProvider<Any?> = closestDI { context }
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,19 @@ import android.app.Application
import android.arch.lifecycle.AndroidViewModel
import android.support.v4.app.Fragment
import android.support.v4.content.Loader
import org.kodein.di.*
import org.kodein.di.android.closestDI
import org.kodein.di.android.di


@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI()", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun Fragment.di() = closestDI()

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*/
fun Fragment.closestDI() = closestDI { requireActivity() }

@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI()", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun Loader<*>.di() = closestDI()

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*/
fun Loader<*>.closestDI() = closestDI { context }

@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI()", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun AndroidViewModel.di() = closestDI()

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,19 @@ import android.app.Application
import androidx.fragment.app.Fragment
import androidx.lifecycle.AndroidViewModel
import androidx.loader.content.Loader
import org.kodein.di.*
import org.kodein.di.android.closestDI
import org.kodein.di.android.di


@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI()", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun Fragment.di() = closestDI()

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*/
fun Fragment.closestDI() = closestDI { requireActivity() }

@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI()", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun Loader<*>.di() = closestDI()

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*/
fun Loader<*>.closestDI() = closestDI { context }

@Deprecated(
message = "di() function leads to import conflicts. please replace with closestDI().",
replaceWith = ReplaceWith("closestDI()", "org.kodein.di.android"),
level = DeprecationLevel.ERROR
)
fun AndroidViewModel.di() = closestDI()

/**
* Returns the closest DI (or the app DI, if no closest DI could be found).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,5 @@ public fun androidContextDI(): DI {
return remember { di }
}

// Deprecated since 7.7.0
@Deprecated(
message = "Renamed to androidContextDI",
replaceWith = ReplaceWith("androidContextDI()"),
level = DeprecationLevel.ERROR
)
@Composable
public fun contextDI(): DI = androidContextDI()

/**
* Attaches a [DI] container to the underlying [Composable] tree, using the [DI] container attached to the current [Context] (see [contextDI]).
*
* @param content underlying [Composable] tree that will be able to consume the [LocalDI] container
*/
// Deprecated since 7.7.0
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated(
message = "This is not necessary anymore as the DI container is automatically used if no local DI is defined",
level = DeprecationLevel.ERROR
)
@Composable
public fun withDI(content: @Composable () -> Unit) = CompositionLocalProvider(LocalDI provides androidContextDI()) { content() }

@Composable
internal actual fun diFromAppContext(): DI = androidContextDI()
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ public inline fun <reified T : Any> rememberInstance(tag: Any? = null): LazyDele
public inline fun <reified T : Any> rememberNamedInstance(): LazyDelegate<T> =
rememberDI { named.instance() }

// Deprecated since 7.7.0
@Deprecated(
message = "Renamed rememberInstance",
replaceWith = ReplaceWith("rememberInstance(tag)"),
level = DeprecationLevel.ERROR
)
@Composable
public inline fun <reified T : Any> instance(tag: Any? = null): LazyDelegate<T> =
rememberInstance(tag = tag)

/**
* Retrieves and keeps a reference on an instance of [T] for the given type and tag,
* curried from a factory that takes an argument [A].
Expand Down Expand Up @@ -111,16 +101,6 @@ public inline fun <reified A : Any, reified T : Any> rememberInstance(tag: Any?
public inline fun <reified A : Any, reified T : Any> rememberNamedInstance(arg: A): LazyDelegate<T> =
rememberDI { named.instance(arg = arg) }

// Deprecated since 7.7.0
@Deprecated(
message = "Renamed rememberInstance",
replaceWith = ReplaceWith("rememberInstance(tag, arg)"),
level = DeprecationLevel.ERROR
)
@Composable
public inline fun <reified A : Any, reified T : Any> instance(tag: Any? = null, arg: A): LazyDelegate<T> =
rememberInstance(tag = tag, arg = arg)

/**
* Retrieves and keeps of [T] for the given type and tag,
* curried from a factory that takes an argument [A].
Expand Down Expand Up @@ -162,15 +142,6 @@ public inline fun <reified A : Any, reified T : Any> rememberNamedInstance(noinl
public inline fun <reified A : Any, reified T : Any> rememberFactory(tag: Any? = null): LazyDelegate<(A) -> T> =
rememberDI { factory(tag = tag) }

// Deprecated since 7.7.0
@Deprecated(
message = "Renamed rememberFactory",
replaceWith = ReplaceWith("rememberFactory(tag)"),
level = DeprecationLevel.ERROR)
@Composable
public inline fun <reified A : Any, reified T : Any> factory(tag: Any? = null): LazyDelegate<(A) -> T> =
rememberFactory(tag = tag)

/**
* Retrieves and keeps a reference on a provider of `T` for the given type and tag.
*
Expand All @@ -186,16 +157,6 @@ public inline fun <reified A : Any, reified T : Any> factory(tag: Any? = null):
public inline fun <reified T : Any> rememberProvider(tag: Any? = null): LazyDelegate<() -> T> =
rememberDI { provider(tag = tag) }

// Deprecated since 7.7.0
@Deprecated(
message = "Renamed rememberProvider",
replaceWith = ReplaceWith("rememberProvider(tag)"),
level = DeprecationLevel.ERROR
)
@Composable
public inline fun <reified T : Any> provider(tag: Any? = null): LazyDelegate<() -> T> =
rememberProvider(tag = tag)

/**
* Retrieves and keeps a reference on a provider of [T] for the given type and tag, curried from a factory that takes an argument [A].
*
Expand All @@ -213,16 +174,6 @@ public inline fun <reified T : Any> provider(tag: Any? = null): LazyDelegate<()
public inline fun <reified A : Any, reified T : Any> rememberProvider(tag: Any? = null, arg: A): LazyDelegate<() -> T> =
rememberDI { provider(tag = tag, arg = arg) }

// Deprecated since 7.7.0
@Deprecated(
message = "Renamed rememberProvider",
replaceWith = ReplaceWith("rememberProvider(tag, arg)"),
level = DeprecationLevel.ERROR
)
@Composable
public inline fun <reified A : Any, reified T : Any> provider(tag: Any? = null, arg: A): LazyDelegate<() -> T> =
rememberProvider(tag = tag, arg = arg)

/**
* Retrieves and keeps a reference on a provider of [T] for the given type and tag, curried from a factory that takes an argument [A].
*
Expand All @@ -242,16 +193,3 @@ public inline fun <reified A : Any, reified T : Any> rememberProvider(
noinline fArg: () -> A,
): LazyDelegate<() -> T> =
rememberDI { provider(tag = tag, fArg = fArg) }

// Deprecated since 7.7.0
@Deprecated(
message = "Renamed rememberProvider",
replaceWith = ReplaceWith("rememberProvider(tag, fArg)"),
level = DeprecationLevel.ERROR
)
@Composable
public inline fun <reified A : Any, reified T : Any> provider(
tag: Any? = null,
noinline fArg: () -> A,
): LazyDelegate<() -> T> =
rememberProvider(tag = tag, fArg = fArg)
Loading

0 comments on commit 9d5ed2c

Please sign in to comment.