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.
All the multiplatform splits (Kotlin 1.4.10)
- Bit Flags:
hasFlag
,withFlag
andminusFlag
extensions onLong
,Int
,Short
,Byte
, and their unsigned counterparts. - Collections:
forEach
forList
s withoutIterator
allocation. - Coroutines: General purpose extensions to kotlinx.coroutines.
- Main Thread: Properties and precondition checkers related to the main thread.
- Preferences: Property syntax for Android's
SharedPreferences
and macOS/iOS/watchOSNSUserDefaults
.
All the Android splits
- Activities: Start activities with minimal boilerplate.
- Alert Dialog: Create simple alert dialogs with simple code.
- Alert Dialog AppCompat: AppCompat version of Alert Dialog.
- Alert Dialog AppCompat Coroutines:
showAndAwait
extension functions for AppCompat AlertDialog. - Alert Dialog Material: Material Components extension of Alert Dialog AppCompat.
- App Context: Always have your application
Context
at hand withappCtx
. - Arch Lifecycle: Extensions to get
ViewModel
s, useLiveData
and observeLifecycle
s. - Arch Room: Room helpers to instantiate your DB and perform transactions in Kotlin.
- Bundle:
BundleSpec
to useBundle
with property syntax forIntent
extras and more. - Checked Lazy:
mainThreadLazy
that checks property access on main thread, andcheckedLazy
to make your own variant. - Dimensions: Android
dp
extensions forView
andContext
. Particularly handy when using Views DSL. - Exceptions:
unexpectedValue(…)
,unsupportedAction(…)
and similar functions that returnNothing
. - Fragments: Start activities from fragments and do transactions with minimal boilerplate.
- Fragment Args: Fragment arguments without ceremony thanks to delegated properties.
- Init Provider: Base class for
ContentProvider
s used for automatic initialization purposes. - Intents: Transform
companion object
s into powerful typesafe intent specs, and createPendingIntent
s the clean and easy way. - Lifecycle Coroutines: Coroutines integration with AndroidX
Lifecycle
. - Main Handler: Top-level
mainHandler
property to stop allocating multipleHandler
s for mainLooper
. - Material Colors: 2014 Material Design color palettes as color resources.
- Material Lists: List item Views implementing Material Design guidelines (perfect for usage in a
RecyclerView
). - Permissions: Request runtime permissions without polluting your codebase.
- Resources: Extensions to get resources like strings, colors or drawables easily, with support for themed attributes.
- Selectable Views: Selectable Views with
foreground
property before API 23. - Selectable Views AppCompat: Selectable Views for AppCompatTextView.
- Selectable Views ConstraintLayout: Selectable Views for ConstraintLayout.
- Snackbar: Grab a snack without ceremony with
snack(…)
andlongSnack(…)
. - Stetho init: Have Stetho for your debug builds, without writing any code!
- System Services: No more
context.getSystemService(NAME_OF_SERVICE) as NameOfManager
. - Toast: Show a toast by just calling
toast(yourText)
, and dodge API 25BadTokenException
. - Typesafe RecyclerView: Typesafe
ViewHolder
andItemViewHolder
for easy basic usage ofRecyclerView
. - Views: Extensions function and properties on
View
s. - Views AppCompat: AppCompat extension of Views. Includes helpers
for
ImageView
tinting,ActionBar
and tooltip. - Views CardView: CardView extension of Views. Provides a
contentPadding
property. - Views Coroutines: Android Views + Kotlin coroutines.
- Views Coroutines Material: Material Components + Kotlin coroutines.
- Views DSL: Create UIs with readable Kotlin code (IDE preview supported).
- Views DSL AppCompat: AppCompat extension of Views DSL.
- Views DSL ConstraintLayout: ConstraintLayout extension of Views DSL.
- Views DSL CoordinatorLayout: CoordinatorLayout extension of Views DSL.
- Views DSL Material: Material Components extension of Views DSL.
- Views DSL RecyclerView: RecyclerView extension of Views DSL.
- Views Material: Material Components extension of Views.
- Views RecyclerView: RecyclerView extension of Views.
Make sure you have jcenter()
in the repositories defined in your project's
(root) build.gradle
file (default for new Android Studio projects).
To make is easier to take advantage of the contents of Splitties for your Android projects, there are grouping artifacts that include most splits.
These 2 packs don't include AppCompat and are suitable for WearOS apps.
Includes the following modules:
- activities
- appctx
- bitflags
- bundle
- collections
- coroutines
- dimensions
- fragments
- fragmentargs
- intents
- lifecycle-coroutines
- mainhandler
- mainthread
- material-colors
- permissions
- preferences
- resources
- systemservices
- toast
- views
- views-coroutines
- views-recyclerview
- views-selectable
- views-selectable-constraintlayout
Gradle dependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-base:3.0.0-beta01")
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-beta01")
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-beta01")
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-beta01")
These 2 packs include the Android AppCompat pack, and the following modules:
- alertdialog-material
- material-lists
- snackbar
- views-cardview
- views-coroutines-material
- views-material
Gradle dependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-material-components:3.0.0-beta01")
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-beta01")
Add the version of the library to not repeat yourself if you use multiple
artifacts, and make sure their versions are in sync by adding an ext property
into your root project build.gradle
file:
allProjects {
ext {
splitties_version = "3.0.0-beta01"
}
}
Here are all the artifacts of this library. Just use the ones you need. (Click to expand)
implementation("com.louiscad.splitties:splitties-activities:$splitties_version")
implementation("com.louiscad.splitties:splitties-alertdialog:$splitties_version")
implementation("com.louiscad.splitties:splitties-alertdialog-appcompat:$splitties_version")
implementation("com.louiscad.splitties:splitties-alertdialog-appcompat-coroutines:$splitties_version")
implementation("com.louiscad.splitties:splitties-appctx:$splitties_version")
implementation("com.louiscad.splitties:splitties-arch-lifecycle:$splitties_version")
implementation("com.louiscad.splitties:splitties-arch-room:$splitties_version")
implementation("com.louiscad.splitties:splitties-bitflags:$splitties_version")
implementation("com.louiscad.splitties:splitties-bundle:$splitties_version")
implementation("com.louiscad.splitties:splitties-checkedlazy:$splitties_version")
implementation("com.louiscad.splitties:splitties-collections:$splitties_version")
implementation("com.louiscad.splitties:splitties-coroutines:$splitties_version")
implementation("com.louiscad.splitties:splitties-dimensions:$splitties_version")
implementation("com.louiscad.splitties:splitties-exceptions:$splitties_version")
implementation("com.louiscad.splitties:splitties-fragments:$splitties_version")
implementation("com.louiscad.splitties:splitties-fragmentargs:$splitties_version")
implementation("com.louiscad.splitties:splitties-initprovider:$splitties_version")
implementation("com.louiscad.splitties:splitties-intents:$splitties_version")
implementation("com.louiscad.splitties:splitties-lifecycle-coroutines:$splitties_version")
implementation("com.louiscad.splitties:splitties-mainhandler:$splitties_version")
implementation("com.louiscad.splitties:splitties-mainthread:$splitties_version")
implementation("com.louiscad.splitties:splitties-material-colors:$splitties_version")
implementation("com.louiscad.splitties:splitties-material-lists:$splitties_version")
implementation("com.louiscad.splitties:splitties-permissions:$splitties_version")
implementation("com.louiscad.splitties:splitties-preferences:$splitties_version")
implementation("com.louiscad.splitties:splitties-resources:$splitties_version")
implementation("com.louiscad.splitties:splitties-snackbar:$splitties_version")
debugImplementation("com.louiscad.splitties:splitties-stetho-init:$splitties_version")
implementation("com.louiscad.splitties:splitties-systemservices:$splitties_version")
implementation("com.louiscad.splitties:splitties-toast:$splitties_version")
implementation("com.louiscad.splitties:splitties-typesaferecyclerview:$splitties_version")
implementation("com.louiscad.splitties:splitties-views:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-appcompat:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-cardview:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-coroutines:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-coroutines-material:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-dsl:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-dsl-appcompat:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-dsl-constraintlayout:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-dsl-coordinatorlayout:$splitties_version")
debugImplementation("com.louiscad.splitties:splitties-views-dsl-ide-preview:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-dsl-material:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-dsl-recyclerview:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-material:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-recyclerview:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-selectable:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-selectable-appcompat:$splitties_version")
implementation("com.louiscad.splitties:splitties-views-selectable-constraintlayout:$splitties_version")
Let's say you need a new feature or a fix that did not make it to a release yet:
You can grab it in the latest dev version by adding the corresponding repository and
changing the library version to the dev version you need in your root project build.gradle
file:
allProjects {
repositories {
google()
jcenter() // Add dev versions repo below
maven(url = "https://dl.bintray.com/louiscad/splitties-dev")
}
ext {
splitties_version = '3.0.0-dev-107'
}
}
For maven and alternative build-systems, check the Bintray page.
Releases are announced on GitHub, you can subscribe by clicking on "Watch", then "Releases only".
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 build 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.