A collection of useful Kotlin extension for Android

Overview

karamba

A collection of useful Kotlin extension for Android

karamba

Install

Add to gradle in allprojects

maven { url 'https://jitpack.io' }

then add this

compile 'com.github.matteocrippa:karamba:1.2.0'

Usage

Karamba provides you a list of different and useful extensions for your project, here the list organized by the type extended.

General

  • support(apiVersion), lambda that allow you to run code only if current SDK is up to specified one
  • supportKitkat(), lambda that checks if kitkat is supported and run the code
  • supportLollipop(), lambda that checks if lollipop is supported and run the code

Bitmap

  • base64(), produces a base64 representation of the current bitmap
  • resize(height, width), resize the current bitmap to new format

Boolean

  • toggle(), handle the bool as a toogle changing the value to opposite one, then the new value is returned (not yet possible to change this)
  • random(), returns a random boolean value, then the new value is returned (not yet possible to change this)

Date

  • convertTo(format), converts current date to a custom format provided as argument (eg. dd-MM-yy HH:mm)
  • toCalendar(), converts current date to Calendar
  • isFuture(), returns true if date is in the future
  • isPast(), returns true if date is in the past
  • isToday(), returns if current date is today
  • isTomorrow(), returns if current date is tomorrow
  • isYesterday(), returns if current date is yesterday
  • today(), returns today's date
  • tomorrow(), returns tomorrow's date
  • yesterday(), returns yesterday's date
  • hour(), returns current date hour as number
  • minute(), returns current date minutes as number
  • second(), returns current date seconds as number
  • month(), returns current date month as number
  • monthName(), returns current date month as long name
  • year(), returns current date year as number
  • day(), returns current date day as number
  • dayOfWeek(), returns current date day of the week as number
  • dayOfWeekName(), returns current date weekday as string
  • dayOfYear(), returns current date day of year as number

Double

  • localCurrency(currency), converts current double to the currency format passed as argument (eg. EUR)
  • celsiusToFahrenheit(), converts current double to fahrenheit
  • fahrenheitToCelsius(), converts current double to celsius

Drawable

  • toBitmap(), converts the current drawable in Bitmap

Int

  • readableDistanceFromMeters(), converts an int amount of meters in a readable meter, kilometers distance
  • commaSeparatedId(), converts an array of int, in a string of comma separated items
  • random(), provides a random number in the range provided (eg. (0..10).random())

String

  • isValidEmail(), returns if current string is a valid email
  • isUrl(), returns if current string is a valid url
  • isNumeric(), returns if current string contains a number
  • isPhoneNumber(), returns if current string contains a phone number
  • random(lenght), returns a random string of provided length
  • toBitmap(), convert current base64 string into Bitmap
  • ellipsize(chars), ellipsizes the current string, truncating at defined amount of characters
  • toDate(format), converts current string in a Date object using the provided format
  • plainText(), removes all html formatting from current string
  • toCamelCase(), camel case the current string current string

View

  • toBitmap(), converts current view into Bitmap

Credits

Icon is taken by free emojii set by Vincent Le Moign

You might also like...
An Easy-to-use Kotlin based Customizable Modules Collection with Material Layouts by BlackBeared.
An Easy-to-use Kotlin based Customizable Modules Collection with Material Layouts by BlackBeared.

Fusion By BlackBeared An Easy-to-use Kotlin based Customizable Library with Material Layouts by @blackbeared. Features Custom Floating Action Buttons

A collection of hand-crafted extensions for your Kotlin projects.

Splitties Splitties is a collection of small Kotlin multiplatform libraries (with Android as first target). These libraries are intended to reduce the

A curated collection of splendid gradients made in Kotlin
A curated collection of splendid gradients made in Kotlin

Gradients A curated collection of splendid gradients made in Kotlin (port of https://webgradients.com for Android). Only linear gradients included for

KaMP Kit by Touchlab is a collection of code and tools designed to get your mobile team started quickly with Kotlin Multiplatform.
KaMP Kit by Touchlab is a collection of code and tools designed to get your mobile team started quickly with Kotlin Multiplatform.

KaMP Kit Welcome to the KaMP Kit! About Goal The goal of the KaMP Kit is to facilitate your evaluation of Kotlin Multiplatform (aka KMP). It is a coll

An awesome collaborative collection of Kotlin Multiplatform libraries

Awesome Kotlin Multiplatform Awesome Projects Updated 33 November 21, 2021 Contents Guides Dependency Injection Database NoSQL SQL Extension Reactive

Write a Ghidra Extension without using Java or Eclipse!

Ghidra Extension in Kotlin using IntelliJ IDEA Write a Ghidra Extension without using Java or Eclipse! Setup Hit Use this template at the top of the r

A Burp extension to find stuff ¯\_(ツ)_/¯
A Burp extension to find stuff ¯\_(ツ)_/¯

FindStuffer FindStuffer, a Burp extension to find stuff, both for Community and Pro versions. You can use FindStuffer to aggregate as many text querie

Jackson extension for Mojang's NBT format

Jackson NBT Data Format Implements Mojang's NBT format in jackson. Usage Using this format works just like regular jackson, but with the ObjectMapper

A collection of small utility functions to make it easier to deal with some otherwise nullable APIs on Android.

requireKTX requireKTX is a collection of small utility functions to make it easier to deal with some otherwise nullable APIs on Android, using the sam

Comments
  • [Request Feature] Separate features into modules.

    [Request Feature] Separate features into modules.

    Kotlin extensions is huge, I think author should separate extensions by modules.

    For examples:

    • core module, include generic class type helpers: 'com.github.matteocrippa:karamba-core:1.2.0'
    • image module, include bitmap, drawable, images helpers: 'com.github.matteocrippa:karamba-image:1.2.0'
    • localization module, include currency, locale, country,... helpers: 'com.github.matteocrippa:karamba-localization:1.2.0'
    • dialogs module, include alert, toast, bottomsheet helpers: 'com.github.matteocrippa:karamba-dialogs:1.2.0'

    ... Core android (ktx) already do that, reference modules of material-dialogs: https://github.com/afollestad/material-dialogs

    opened by dphans 0
Owner
Matteo Crippa
👨🏻‍💻 Senior Software Engineer
Matteo Crippa
A library provides some useful kotlin extension functions

ktext ?? A library provides some useful kotlin extension functions. Including in your project Gradle Add below codes to your root build.gradle file (n

热心市民苏苏仔 76 Oct 26, 2022
Extension functions over Android's callback-based APIs which allows writing them in a sequential way within coroutines or observe multiple callbacks through kotlin flow.

callback-ktx A lightweight Android library that wraps Android's callback-based APIs into suspending extension functions which allow writing them in a

Sagar Viradiya 171 Oct 31, 2022
Andorid app which provides a bunch of useful Linux commands.

Linux Command Library for Android The app currently has 3203 manual pages, 1351 one-line scripts and a bunch of general terminal tips. It works 100% o

Simon Schubert 276 Dec 31, 2022
WolfxPaper - A Paper fork designed for Wolfx Survial, may useful for some Semi-Vanilla Server

WolfxPaper A Paper fork designed for Wolfx Survial, may useful for some "Semi-Va

TenkyuChimata 1 Jan 19, 2022
A library with many useful and easy-to-use features

This library was made as a replacement for qLib and in the future cubed. These 2 plugins are hard to get you hands on and one of them has many outdated methods so this is a more modern version of those things

Max 1 May 6, 2022
Gits-android-extensions - A collection of Kotlin extensions to simplify Android development

gits-android-extensions A collection of Kotlin extensions to simplify Android de

GITS Indonesia 3 Feb 3, 2022
An extension of EditText with pin style written in Kotlin

pin-edittext An extension of EditText with pin style Usage Include PinCodeEditText in your layout XML <com.oakkub.android.PinEditText android:layo

Metas Kerdwat 15 May 28, 2021
A set of extension properties on Int, Long, Double, and Duration, that makes it easier to work with Kotlin Duration

Kotlin Duration Extensions Gradle Groovy repositories { mavenCentral() } implementation 'com.eygraber:kotlin-duration-extensions:1.0.1' Kotlin rep

Eliezer Graber 8 Nov 8, 2022
Most used extension methods for Kotlin

Extensify Most used extension methods for Kotlin Download Step 1. Add the JitPack repository to your build file allprojects { repositories {

Mobven 36 Aug 25, 2022
A kotlin library of extension functions that add smalltalk style methods to objects.

KtTalk A kotlin library of extension functions that add smalltalk style methods to objects. Motivation Smalltalk is a pure OO language in which everyt

null 11 Oct 16, 2021