Splitties is a collection of small Kotlin multiplatform libraries (with Android as first target).
These libraries are intended to reduce the amount of code you have to write, freeing code reading and writing
time, so you can focus more on what you want to build for your users (even if you're the only one), or
have more time to have fun
.
This project is named "Splitties" because it is split in small modules, distributed as independent libraries, so you can add only the ones you need to your project/module, helping reduce the size of the final binary that users devices will need to download and keep in the limited storage (BTW, everything is limited).
Some Android targeting modules have a content similar to what Anko offers. See a short comparison of Splitties with Anko here.
Each module has been designed to have a small footprint and be as efficient as possible.
Splitties is all about simplifying your code. Here are a few examples:
Kotlin:
startActivity(Intent(this, DemoActivity::class.java))
Kotlin with Splitties Activities:
start<DemoActivity>()
Kotlin:
Snackbar.make(root, R.string.refresh_successful, Snackbar.LENGTH_SHORT)
.show()
Kotlin with Splitties Snackbar:
root.snack(R.string.refresh_successful)
Racing coroutines: (raceOf(…)
comes from the Coroutines module)
suspend fun awaitUserChoice(ui: SomeUi, choices: List<Stuff>): Stuff? = raceOf({
ui.awaitSomeUserAction(choices)
}, {
ui.awaitDismissal()
null
}, {
ui.showSomethingInRealtimeUntilCancelled() // Returns Nothing, will run, but never "win".
})
Kotlin:
Snackbar.make(root, getString(R.string.deleted_x_items, deletedCount), Snackbar.LENGTH_LONG)
.setAction(android.R.string.cancel) {
deleteOperation.requestRollback()
}
.setActionTextColor(ContextCompat.getColor(this, R.color.fancy_color))
.show()
Kotlin with Splitties Snackbar:
root.longSnack(str(R.string.deleted_x_items, deletedCount)) {
action(android.R.string.cancel, textColor = color(R.color.fancy_color)) {
deleteOperation.requestRollback()
}
}
Context
at hand with appCtx
.context.getSystemService(NAME_OF_SERVICE) as NameOfManager
.snack(…)
and longSnack(…)
.toast(yourText)
, and dodge API 25
BadTokenException
.showAndAwait
extension functions for AppCompat AlertDialog.View
s.ImageView
tinting, ActionBar
and tooltip.contentPadding
property.dp
extensions for View
and Context
.
Particularly handy when using Views DSL.foreground
property before API 23.ViewHolder
and ItemViewHolder
for easy basic usage of RecyclerView
.RecyclerView
).companion object
s into powerful typesafe intent specs,
and create PendingIntent
s the clean and easy way.BundleSpec
to use Bundle
with property syntax for Intent
extras and more.Lifecycle
.mainHandler
property to stop allocating multiple
Handler
s for main Looper
.mainThreadLazy
that checks property access onSharedPreferences
/DataStore
and macOS/iOS/watchOS NSUserDefaults
.hasFlag
, withFlag
and minusFlag
extensions on Long
, Int
, Short
, Byte
, and their unsigned counterparts.forEach
for List
s without Iterator
allocation.unexpectedValue(…)
, unsupportedAction(…)
and similar
functions that return Nothing
.ViewModel
s, use LiveData
and
observe Lifecycle
s.Make sure you have mavenCentral()
in the repositories defined in your project's
(root) build.gradle
file (default for new Android Studio projects).
To make it easier to take advantage of the contents of Splitties for your Android projects, there are grouping artifacts that include most splits.
Adding with refreshVersions: Splitties.pack.androidBase
or Splitties.pack.androidBaseWithViewsDsl
.
These 2 packs don't include AppCompat and are suitable for WearOS apps.
Includes the following modules:
Gradle dependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-base:3.0.0")
There's also a version with Views DSL. It additionally includes the following modules:
Gradle dependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-base-with-views-dsl:3.0.0")
Adding with refreshVersions: Splitties.pack.appCompat
or Splitties.pack.appCompatWithViewsDsl
.
These 2 packs include the Android base pack, and the following modules:
Gradle dependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-appcompat:3.0.0")
There's also a version with Views DSL. It additionally includes the Views DSL version of the Android base pack and the following module:
Gradle dependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-appcompat-with-views-dsl:3.0.0")
Adding with refreshVersions: Splitties.pack.androidMdc
or Splitties.pack.androidMdcWithViewsDsl
.
These 2 packs include the Android AppCompat pack, and the following modules:
Gradle dependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-material-components:3.0.0")
There's also a version with Views DSL. It additionally includes the Views DSL version of the Android AppCompat pack and the following modules:
Gradle dependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-material-components-with-views-dsl:3.0.0")
Since you might use multiple artifacts, to not repeat yourself, we recommend you to put the version in a central place, so it's little effort to upgrade to newer versions.
The best way to do this is to use refreshVersions,
it has built-in dependency notations for Splitties
, and also many other popular and qualitative libraries,
like kotlinx, AndroidX, libraries from Square/CashApp and libraries from Google.
Most importantly, with it, running the refreshVersions
task will show you the available updates in a matter of seconds,
for all of your dependencies, right into the versions.properties
, in a way that makes upgrading effortless,
even with just the keyboard.
FYI, the current latest release of Splitties is the version 3.0.0
Let's say you need to try a new feature or a fix that did not make it to a release yet:
You can grab it in the snapshot version by adding the corresponding repository as shown below, and
changing the library version to the latest snapshot, 3.0.0-SNAPSHOT
:
allProjects {
repositories {
mavenCentral()
google() // Add sonatype snapshots repo below
maven(url = "https://oss.sonatype.org/content/repositories/snapshots")
}
}
Releases are announced on GitHub, you can subscribe by clicking on "Watch", then "Releases only".
However, if you use refreshVersions,
you'll also learn about updates when you run the refreshVersions
task right in the versions.properties
file.
If you want this library to have a new feature or an improvement in a new or in an existing module, please, open an issue or vote/comment a similar one first, so it can be discussed.
Documentation contributions are also welcome. For typos or other small improvements, feel free to submit a PR (pull request) directly. For more significant doc contributions, please open an issue first, so it can be discussed.
If you find a bug, please open an issue with all the important details. If you know a simple fix that is not API breaking and that does not have side effects that need to be considered, you may also directly submit a PR.
You can also join the discussion on Kotlin's Slack in the #splitties channel (you can get an invitation here).
A "split" is a module of the Splitties library that you can add as a dependency. It only includes the required transitive dependencies. This allows you to only add what you need in your app or library module, so the final apk/ipa/app is as small as possible and doesn't include stuff not used by your app.
Let's say you're building a Wear OS app using the Views DSL. Wear OS apps don't need AppCompat. Including it would be a waste of bandwidth and storage. The Views DSL core module relies on the Android SDK but not on AppCompat, so you don't bloat your wrist app with AppCompat by using Views DSL. However, if you are building a phone, tablet or computer Android app, there's a Views DSL AppCompat split with a few extensions for you to use.
Special thanks to Jovche Mitrejchevski for helping in taking decisions for this project.
Thanks to JetBrains and the contributors for Anko, which was a great source of inspiration, especially for Views DSL, and of course thanks for the excellent Kotlin programming language that makes this project possible.
Thanks to Doug Stevenson for his articles "Kotlin & Android: A Brass Tacks Experiment". It is fair to say that Views DSL has its root in this experiment.
This library is published under Apache License version 2.0 which you can see here.