A collection of hand-crafted extensions for your Kotlin projects.
APACHE-2.0 License
Bot releases are hidden (Show)
Compiled with Kotlin 1.5.21 and kotlinx.coroutines 1.5.1-native-mt.
Finally! Splitties 3.0.0 is there, and it's ready to keep iterating.
The last 2.x version, the 2.1.1 dates back from 2018-11-25, close to 3 years ago.
Why did it take so long to have version 3.0.0?
Let's say making a multi-modules, multiplatform library isn't full of easy and straightforward steps.
A blog post (my first!) will be published later to share that experience from start to now.
Feel free to click follow on blog.louiscad.com, or on Twitter to know when the story is published.
I'll also share a roadmap for Splitties there, which I hope will get you excited for your future endeavors.
Let's get into the actual content of this release:
In case you missed it, Splitties now has a website, happily powered by Material for MKDocs. The address is splitties.louiscad.com.
The main page shows a better overview of what Splitties is about, and its content. It should be helpful for newcomers.
The setup info for each module is now upfront in their respective doc pages, be it on the website, or on GitHub, and they have been updated to recommend using the dependency notations from refreshVersions, which will also help you update Splitties, along with other libraries, and all that in less time.
Full disclosure: I am working on refreshVersions myself, in close collaboration with its author, Jean-Michel Fayard. I use it, and I totally recommend it for all Gradle projects. Splitties is using it of course.
The hasFlag
, withFlag
, and minusFlag
extensions for unsigned integers (UByte
, UShort
, UInt
, and ULong
) are no longer annotated with the @ExperimentalUnsignedTypes
annotation.
There's a new DataStorePreferences
class for the Android side, which you can use as a substitute of the Preferences
class. If you were already using SuspendPrefsAccessor
, that's all you need to change.
This AndroidX DataStore backed implementation should remove the risks of your app and their users being affected by the potential performance issues of Android platform's SharedPreferences
.
Be sure to check out the updated docs!
Published by LouisCAD about 3 years ago
Compiled with Kotlin 1.5.21 and kotlinx.coroutines 1.5.1-native-mt.
The AppCtxInitializer
class is now public, so you can put it in the list of dependencies of your own AndroidX App Startup Initializer in case it relies on appCtx
to be initialized.
In 3.0.0-rc02, changes in styledColorSL
made it break when the theme attribute was pointing to a color resource that had no selector (i.e. a non inlined plain color code like #00bbff
). This has now been fixed, and the code also got simpler.
Published by LouisCAD about 3 years ago
Compiled with Kotlin 1.5.21 and kotlinx.coroutines 1.5.1-native-mt.
By resolving a subtle issue that could break IDE preview, the version 3.0.0-alpha07 of Splitties also broke the styledColor
function and some other in come cases. If you had a color theme attribute and had a theme that was setting its value, pointing to another color resource, you'd be in luck. However, if the color value was set inline, right into the theme, it'd crash (as you can see in this issue). This release fixes this kind of problem for all the
affected functions:
styledColor
styledColorSL
styledDimen
styledDimenPxSize
styledDimenPxOffset
styledBool
styledInt
styledTxt
styledStr
Published by LouisCAD about 3 years ago
Compiled with Kotlin 1.5.21 and kotlinx.coroutines 1.5.1-native-mt.
This release removes previously deprecated code.
Make sure you don't have transitive dependencies that relied on deprecated code from a previous release of Splitties! If that's the case, you'll see the host app crash at runtime.
The "Init provider" split has been removed and is no longer published starting with this release.
You can find if you are using it by searching for its maven coordinates:
com.louiscad.splitties:splitties-initprovider
(the "Find in Path" IDE option can help you locate it).
If you used it, you'll need to move to AndroidX App Startup.
All the other previously deprecated symbols at hidden level have been removed.
This completes the deprecation cycle for the upcoming Splitties 3.0.0 release.
Published by LouisCAD about 3 years ago
Compiled with Kotlin 1.5.21 and kotlinx.coroutines 1.5.1-native-mt.
This release is advancing deprecation cycles further before the upcoming 3.0.0 release.
All previously deprecated symbols were either removed, or hidden:
Published by LouisCAD about 3 years ago
Compiled with Kotlin 1.5.21 and kotlinx.coroutines 1.5.1-native-mt.
This release is advancing deprecation cycles before the upcoming 3.0.0 release.
All previously deprecated symbols were either removed, or moved one step closer to it:
Published by LouisCAD about 3 years ago
Compiled with Kotlin 1.5.21 and kotlinx.coroutines 1.5.1-native-mt.
Fix iOS/multiplatform publication (see issue #280).
Published by LouisCAD over 3 years ago
Compiled with Kotlin 1.5.21 and kotlinx.coroutines 1.5.1-native-mt.
Other transitive dependencies have also been upgraded to the latest stable version.
It includes upgrades to various AndroidX libraries, Material Design Components 1.4.0, and Stetho 1.6.0.
This release is advancing deprecation cycles before the upcoming, long awaited 3.0.0 release.
The SendChannel.offerCatching
has been deprecated in favor of trySend
from kotlinx.coroutines 1.5+
The deprecation level of awaitCancellation()
has been raised from warning to error. Use the one from kotlinx.coroutines instead.
Dispatchers.MainAndroid
deprecation level has been raised from warning to error. Using Dispatchers.Main
is fine performance wise since kotlinx.coroutines 1.3.3.
The PotentialFutureAndroidXLifecycleKtxApi
annotation deprecation level was also raised to error.
The following symbols that were previously deprecated at error level are now hidden and will be removed in the next release:
Lifecycle.coroutineScope
Lifecycle.job
LifecycleOwner.lifecycleScope
MainDispatcherPerformanceIssueWorkaround
Raise the deprecation level of the implicit key delegates from warning to error.
Raise the deprecation level of Context.withStyledAttributes
to error.
Raise the deprecation level of ActionBar.showHomeAsUp
to error.
Published by LouisCAD over 3 years ago
Compiled with Kotlin 1.4.32 and kotlinx.coroutines 1.4.3-native-mt.
This is the first release of Splitties that is published on MavenCentral!
The maven coordinates are the same.
Also, there's now a documentation website on splitties.louiscad.com, check it out!
Add "calls in place exactly once" contracts for the lambdas of all the alertDialog
functions.
Add "calls in place exactly once" contracts for the lambdas of all the alertDialog
functions.
Fix rare crash that could happen when waiting for a button click if multiple ones were clicked simultaneously.
Now, only the first one to be considered clicked by the system will trigger, and the second one will be ignored.
Add "calls in place exactly once" contracts for the lambdas of all the materialAlertDialog
functions.
Replace the initializing ContentProvider
with AndroidX App Startup.
Deprecate awaitCancellation()
in favor of the one now included right into kotlinx.coroutines.
Introduce the whileStarted(Lifecyle)
extension function for Flow
to have a flow emit values only while the passed Lifecycle
is started.
Replace the initializing ContentProvider
with AndroidX App Startup.
Published by LouisCAD about 4 years ago
Compiled with Kotlin 1.4.10 and kotlinx.coroutines 1.3.9-native-mt.
This release has multiplatform splits compatible with iOS, macOS and watchOS projects that use Kotlin/Native 1.4.0 and 1.4.10.
Feedback is appreciated (Twitter, Kotlin's Slack, GitHub issues…).
watchOS support has been added to the following splits:
All CPU architectures are supported (arm32, arm64 & X86 for simulator).
Deprecated the transaction
and inTransaction
extension functions in favor of withTransaction
(Room KTX) and runInTransaction
(Room runtime) itself.
Now requires to opt-in to @ObsoleteContentProviderHack
.
This split will be deprecated once App Startup from AndroidX goes stable.
Deprecated symbols now have error level. Next release will remove them.
LifecycleOwner.coroutineScope
that was at error deprecation level. Use LifecycleOwner.lifecycleScope
from AndroidX instead.Using this API now requires to opt-in to @UnreliableToastApi
so the developers acknowledge
the gotchas of android.widget.Toast
or use something else (like snackbars, banners or dialogs).
Add the following read/write extensions properties for View
:
startPadding
endPadding
leftPadding
rightPadding
The onClick
parameter changed from a crossinline
lambda to a View.OnClickListener
now
that Kotlin 1.4 brings SAM conversion for Kotlin functions taking SAM Java interfaces.
Usage should not change. Note that there is now an implicit it
parameter of type View
that
might break existing code if an outer it
was used in the onClick
lambda.
All lambdas in AndroidStyles
now have a contract. That allows you to initialize val
s declared in the outer scope.
AppCompatStyles
now have a contract. That allows you to initialize val
s declared in the outer scope.Add the missing AppCompat version of ToggleButton
.
MaterialComponentsStyles
now have a contract. That allows you to initialize val
s declared in the outer scope.Add the following missing Material Components counterparts of Android widgets:
CheckBox
, RadioButton
, TextView
, AutoCompleteTextView
.
Published by LouisCAD about 4 years ago
Compiled with Kotlin 1.3.72 and kotlinx.coroutines 1.3.8.
This release introduces 2 new splits:
Add isCancellable
parameter (defaults to true
, as when unspecified) to alertDialog
builders.
viewModels { … }
for FragmentActivity
and Fragment
activityViewModels { … }
for Fragment
This split no longer depends on the androidx.lifecycle:lifecycle-extensions
artifact that has been deprecated in AndroidX Lifecycle 2.2.0 and is no longer published in later versions.
AndroidX Lifecycle KTX artifacts caught up with features that this split originally provided, so we've deprecated that overlap:
activityScope()
for Activity
-> viewModels()
activityScope()
for Fragment
-> activityViewModels()
fragmentScope()
for Fragment
-> viewModels()
Also, we provided variants of these that took a lambda. Since AndroidX doesn't provide such a facility, they have been kept, but the old naming has been deprecated to match the AndroidX naming.
Note that these changes provide a ReplaceWith clause for easy migration.
Important: Next alpha release will move the deprecation level to error, and the alpha release after will remove them completely. (So it's best to not skip this update if you were using these extensions.)
forEachReversedWithIndex
extension for List
now has an allowSafeModifications
parameter.
When set to true
(default is false
), you can mutate the list as long as it doesn't prevent the
next iteration from happening (or that you perform a non local return to stop iterating altogether).
As usual, unsafe operations while iterating a list can result in a ConcurrentModificationException
or in an IndexOutOfBoundsException
to be thrown.
The dip
and dp
functions now return the type of their argument (Int
or Float
).
You'll need to migrate usages of the previous dp
function, so they pass a Float
. Use "Find in Path" in the IDE to find them before fixing. If you often passed the same value to dp
, the "Replace in Path" IDE option can save you even more time.
Lifecycle.isStartedFlow()
Lifecycle.isStartedFlow(timeout: Duration)
Lifecycle.isResumedFlow()
Lifecycle.isResumedFlow(timeout: Duration)
Lifecycle.stateFlow(): Flow<Lifecycle.State>
The following extension functions for Lifecycle
have been promoted to @ExperimentalSplittiesApi
(from @PotentialFutureAndroidXLifecycleKtxApi
):
createScope
createJob
awaitResumed
awaitStarted
awaitCreated
awaitState
Dispatchers.MainAndroid
is no longer needed and has been deprecated since the performance issue that affected Dispatchers.Main
has been fixed since kotlinx.coroutines 1.3.3
.
The following extension properties have been deprecated because they are now provided by AndroidX Lifecycle Runtime KTX:
Lifecycle.coroutineScope
LifecycleOwner.lifecycleScope
Lifecycle.job
has also been deprecated even though there's no as-concise replacement because it doesn't satisfy a common use case.
Now supports macOS, iOS and JS.
TextView
s in the list items are at least one line tall, even if the text is empty.New ensureAllPermissions
function available in top-level and as extension for FragmentActivity
and Fragment
to request multiple permissions in a row and ensure you have them all granted.
NSUserDefaults
, but supports custom implementation too, just like on Android).preferences
property to PrefDelegate
s.key
property to PrefDelegate
s.valueFlow()
function to PrefDelegate
s to get current value and changes of a pref field.availableAtDirectBoot
parameter has been renamed to androidAvailableAtDirectBoot
.XxxPref
classes (e.g. BoolPref
, StringPref
, etc.) are no longer inner classes but are now part of the PrefDelegate
sealed class hierarchy.resolveThemeAttribute
extension function for Context
. This is the replacement for withStyledAttributes
.withStyledAttributes
must be replaced by new resolveThemeAttribute
that also has an implementation that is working reliably in IDE Preview. It will be removed in a future release.snack
, longSnack
and snackForever
extension functions now work with any View
instead of just CoordinatorLayout
.biometricManager
from API 29.roleManager
from API 29.configActionBar
extension function for AppCompatActivity
.homeAsUp
extension read/write property for ActionBar
.ActionBar.showTitle
now supports reading current value.ActionBar.showHome
now supports reading current value.ActionBar.useLogo
now supports reading current value.ActionBar.showCustomView
now supports reading current value.ActionBar.showHomeAsUp
has been deprecated and must be replaced by homeAsUp
. It will be removed in a future release.performClick
twice without a UI thread dispatch) when using View.awaitOneClick()
, View.awaitOneLongClick()
or FloatingActionButton.showAndAwaitOneClickThenHide()
.UiPreView
is now included by default, the extra "Views DSL IDE Preview" module is no longer needed. If you never use it in your production code, R8 should remove it from your release app. This has been done to simplify setup.isInPreview
extension properties for Ui
and View
allow you to condition content to show based on whether it's the actual app or the IDE preview. Note that it statically evaluates to false
in release builds (unlike View.isInEditmode
), so the compiler will remove any code placed in the branch of an if (isInPreview)
condition, and will allow R8 to remove any code that was only used in IDE preview.ViewGroup.add
extension functions that take either a beforeChild
or an afterChild
parameter. You must use the parameter name to call one of these overloads. It comes handy in ViewGroup
s where the order of the child View
s matters (e.g. FrameLayout
and LinearLayout
).space
to create an android.widget.Space
from a Ui
, a View
or a Context
reference. Thanks to @Miha-x64 for the contribution!UiPreView
now shows known error cases in the preview itself with a red warning triangle icon.above
, below
, before
and after
for ConstraintLayout.LayoutParams
.Add slider
, rangeSlider
and shapeableImageView
extensions for View
, Ui
and Context
. They can instantiate the new widgets from the version 1.2.0 of the material-components-android library.
This module has been deprecated. It will no longer published in future releases.
Its content has been moved to the main "Views DSL" split.
Published by LouisCAD over 5 years ago
Published by LouisCAD over 5 years ago
Compiled with Kotlin 1.3.31.
This release introduces 3 new splits:
The most important change though, is how simpler integrating Splitties in your Android projects has become starting from this release, thanks to the new grouping artifacts.
See their content and their maven coordinates in the dedicated part of the README.
There is also new features and changes in existing splits, as detailed below.
The alert
functions have been deprecated in favor of a more accurate naming: alertDialog
.
These alertDialog
functions are now usable on Context
(vs previously only on Activity
), and they have optional parameters to specify the title, the message and even an icon (using a resource id or a Drawable
.
Also, the title
and the message
properties are now nullable, in respect to their accepted value.
The show
and showAsync
extension functions allow you to show a DialogFragment
without fearing the infamous IllegalStateException
if the state has already been saved, because it will wait for the lifecycle to be in the RESUMED state before showing the DialogFragment
.
These 2 extension functions are defined for FragmentManager
, FragmentActivity
and Fragment
.
show
is a suspending function that resumes after the lifecycle was resumed and the DialogFragment
was shown.
showAsync
is when you are outside of a coroutine but it is marked as experimental because it has "async" in its name while not returning a Deferred
. Feel free to suggest a better name in the issues or in the #splitties
channel of Kotlin's Slack.
New suspending inline extensions functions for Lifecycle
have been added for convenience:
awaitResumed
, awaitStarted
& awaitCreated
.
They can replace code like awaitState(Lifecycle.State.RESUMED)
for improved readability.
A new IconTwoLinesCheckBoxListItem
class has been added. What it does is self-explanatory.
Also, all the list items are now fully xml friendly.
The colorSL
and appColorSL
extension functions no longer return the nullable version of ColorStateList
.
All the ConstraintLayout.LayoutParams
extension functions now have overloads that allow specifying the margin.
For example, the following code:
centerHorizontally()
horizontalMargin = dip(16)
can now be written on one line: centerHorizontally(margin = dip(16))
.
That improves readability as the word "horizontal" is no longer repeated, and it is still explicit.
Two set-only extensions properties have been added for MaterialButton
:
iconResource
and iconTintAndTextColor
.
Published by LouisCAD over 5 years ago
Compiled with Kotlin 1.3.21.
wrapContent
and matchParent
extensions for ViewGroup
now apply for View
too.wrapInScrollView
and wrapInHorizontalScrollView
extension functions for View
.Bit Flags
and Collections
splits.LifecycleOwner.coroutineScope
to lifecycleScope
. This change is binary compatible.wrapInRecyclerView
lambda inline. This change is not binary compatible.Intents
split that would cause compilation to fail when used.Published by LouisCAD over 5 years ago
This release introduces a new split: Views Coroutines.
radioGroup { ... }
functions in Views DSL.ConstraintLayout
barriers, guidelines and groups.styledView
function for use when making an API for xml styles usage in Kotlin. See an example in AppCompatStyles.materialCardView { ... }
functions in Views DSL Material.navigationView { ... }
functions in Views DSL Material.EditText
inputType typesafe with the set only type
extension property and the InputType
inline class.CoroutineContext
and CoroutineScope
as constructor parameters for Ui
subclasses.lParams
functions from Views DSL and variants. Also added to the roomDb
function from Arch Room as well as the verticalListLayoutParams
and horizontalListLayoutParams
functions from Views DSL RecyclerView.UByte
, UShort
, UInt
and ULong
).button
function from Views DSL, MaterialButton
is now automatically used in place of AppCompatButton
if you also use Views DSL Material.mainHandler
async by default to avoid vSync delays. It is used for Dispatchers.MainAndroid
, so it will result in speed improvements when using Lifecycle Coroutines. If you really need sync behavior, you can use the new mainHandlerSync
top level property instead.Dispatchers.MainAndroid
of type MainCoroutineDispatcher
so the immediate
property is available.awaitState
function from Lifecycle Coroutines safe to use off the main thread, and document it.validate()
from the lParams { ... }
function for ConstraintLayout
.view
from Views DSL is now an internal API.ViewFactory
and related symbols are now an internal API.WallpaperManager
,WifiManager
, WifiP2pManager
, UsbManager
, DevicePolicyManager
, FingerprintManager
,ShortcutManager
and WifiAwareManager
.compileDebugKotlin
gradle task is enough to update the preview. This is faster than a full build.viewFactory
from Views DSL internal API compatible with IDE Preview.illegal
top level function from Exceptions has been deprecated in favor of error
from Kotlin stdlib.This release has the following new artifact:
"com.louiscad.splitties:splitties-views-coroutines:3.0.0-alpha03"
Published by LouisCAD almost 6 years ago
This release introduces a new split: Lifecycle Coroutines.
This release has the following new artifact:
"com.louiscad.splitties:splitties-lifecycle-coroutines:3.0.0-alpha02"
Published by LouisCAD almost 6 years ago
This release is compiled with Kotlin 1.3.11.
It is a breaking release (more details in the changes section), and the API is subject to changes as it is back to an alpha stage.
APIs that are likely to change have an experimental annotation that triggers a warning (which can be removed by opt-in), to prevent you from using them unintentionally.
All the old support library artifacts have been replaced by AndroidX ones.
If your project has not migrated to AndroidX yet, please follow the quick steps below.
Theoretically, migrating a project to AndroidX is easy: you just select "Migrate to AndroidX" from the "Refactor" menu. Unfortunately, in addition to being unacceptably slow, it didn't work properly for Splitties (except for a past attempt which had to be abandoned for API stability reasons). Our experience was waiting minutes with an unresponsive IDE, then giving up with no other choice than force closing Android Studio, and finally getting a broken project, with some dangling fully qualified references (instead of proper import replacement). We reverted and looked for an alternative that would work properly, and perform faster.
The solution has been a Kotlin script that is a white box, and runs in a matter of seconds. You can use it for your project too, so you can migrate to AndroidX quickly, and in a fun
way.
It is available here, and depends on this csv file.
Note that this script doesn't migrate the dependencies, because we changed the way we define dependencies (using constants defined in buildSrc
), and it would have been harder to handle all the edge cases, and doing it by hand with Replace in Path from IDE was quick enough for us. If you prefer to have it, you are free to contribute and reach out in the issues or elsewhere.
To use it in your project, follow these simple steps:
gradle.properties
file: android.useAndroidX=true
and android.enableJetifier=true
. That will ensure you can still use libraries still relying on the old support libraries.expectedNumberOfModules
property defined in the AndroidX-migrator.gradle.kts
file to match the number of modules that your project has.kotlinc
1.3+ available (see easy installation in official docs here).kotlinc -script AndroidX-migrator.gradle.kts
and wait for completion.Now, you pass the Context
only once to the AndroidStyles
or AppCompatStyles
constructor, and you no longer have to pass it to the subsequent functions call. It is advised to obviously cache this instance to reduce boilerplate and avoid overhead. This is a breaking change.
The design support library no longer exists in AndroidX. It is replaced by several AndroidX artifacts and the Google Material Components library.
Consequently, the package names no longer reference "design" but "coordinatorlayout" and "material" instead.
As you can see below, the design support library dependent artifacts have been replaced. Note that Views DSL Material has a transitive dependency to Views DSL CoordinatorLayout, so you don't need to add an explicit dependency for the latter if you already use the former.
This release has the following new artifacts:
"com.louiscad.splitties:splitties-views-material:3.0.0-alpha01"
"com.louiscad.splitties:splitties-views-dsl-coordinatorlayout:3.0.0-alpha01"
"com.louiscad.splitties:splitties-views-dsl-material:3.0.0-alpha01"
This release removes these two artifacts:
"com.louiscad.splitties:splitties-views-design-styles:2.1.1"
"com.louiscad.splitties:splitties-views-dsl-design-styles:2.1.1"
Published by LouisCAD almost 6 years ago
This release is compiled with Kotlin 1.3.10.
withExtras
extension function for Activity
. Any attempt to mutateIllegalStateException
to be thrown, because this should beputExtras
instead. You can see more info in the updated KDoc of these functions.withExtras
extension function for Intent
(previously only available for Activity
).putExtras
extension function for Activity
(previously only available for Intent
).Published by LouisCAD almost 6 years ago
This release targets Android SDK 28, and splits depending on support libraries use version 28.0.0.
ConfigChangesHandlingCollapsingToolbarLayout
from View DSL Design to be compatible with design support library version 28.0.0.Published by LouisCAD almost 6 years ago
This release targets Android SDK 27, and splits depending on support libraries use version 27.1.1.
onCreate
and onOpen
functions in Arch Room are now crossinline
.LifecycleObserver
class is now marked as experimental.