Giter VIP home page Giter VIP logo

kota's Introduction

kota

Kotlin DSL and extension functions for minimalist Android development.

Deprecated

anko and android-ktx do exactly the same thing, and are still maintained.

Showcase

Layouts

Generate Android layouts and controls with Kotlin DSL, no XML required.

verticalLayout {
    val name = editText { hint = "What's on your mind?" }
    button {
        text = "Post"
        setOnClickListener { toast(name.text) }
    }
}

Layouts demo

Collections

SparseArray are considered more memory-efficient Map for Android. SparseArraysKt provides familiar APIs to make SparseArray Kotlin-friendly.

// create new mutable sparse array
val array = sparseArrayOf(Pair(12, "Little"), Pair(34, "Piggy"))

// obtain non-null element with get operator
val element = array[12]

// iterate it
array.forEachIndexed { i, element ->
    // do some shit
}

Dialogs

DialogsKt lets you create and show alerts and dialogs, often in one line.

// show a confirmation alert
alert("Are you sure?", "You have to be completely sure.", NoButton, YesButton {
    // do some shit
})

// choice alert with custom buttons
choiceAlert("Pick one", items, { dialog, index ->
    // index is selected
}, NeutralButton("Reset") {
    // neutral button is clicked
})

// progress dialog
indeterminateProgressDialog("Loading", "Please wait...")

Resources

ResourcesKt have consistent APIs in Activity, Fragment, and support Fragment. Easily obtain any resources with the same syntax across your app.

// obtain array in Activity, Fragment, or support Fragment.
val array = getStringArray(R.array.some_array)

// checks device configurations
val myScreenSize = screenSize
val mAtLeastLarge = isScreenSizeAtLeast(SCREENLAYOUT_SIZE_LARGE)
val myKeyboard = hasKeyboard

// dp and sp conversion
val margin = 16.dp
val textSize = 18.sp

Text

TextsKt is focused on text spanning and string utilities.

// create new spannable
val spannable = "I'm a little piggy".toSpannable()

// add some spans to it
spannable.span(Regex("I'm"), ForegroundColorSpan(Color.RED))
spannable.spanRange(5, 6, RelativeSizeSpan(18.sp))
spannable.spanAll(BackgroundColorSpan(Color.YELLOW))

// TextUtils.java
val isEmpty = spannable.isEmpty

Others

// display a toast
toast("I'm a little piggy")

// or snackbar
snackbar(R.string.are_you_sure, android.R.string.yes, { view ->
    // do some shit
})

// one-line fragment editor
fragmentManager.replace(R.id.container, myFragment)

// logging with component name as tag
debug("Little piggy just died")

// I hate Uri
val path = uri.getActualPath(context)

Download

Each package below include core module.

repositories {
    google()
    jcenter()
}

dependencies {
    // core module
    compile 'com.hendraanggrian:kota:0.22'
    
    // kota implementation on support fragment
    compile 'com.hendraanggrian:kota-support-v4:0.22'
    
    // individual v7 package
    compile 'com.hendraanggrian:kota-appcompat-v7:0.22'
    compile 'com.hendraanggrian:kota-cardview-v7:0.22'
    compile 'com.hendraanggrian:kota-gridlayout-v7:0.22'
    compile 'com.hendraanggrian:kota-preference-v7:0.22'
    compile 'com.hendraanggrian:kota-recyclerview-v7:0.22'
    
    // material design DSL
    compile 'com.hendraanggrian:kota-design:0.22'
}

License

Copyright 2017 Hendra Anggrian

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.