GithubHelp home page GithubHelp logo

tonnyl / light Goto Github PK

View Code? Open in Web Editor NEW
547.0 12.0 37.0 471 KB

🍭 The usual Snackbar, but elegant

License: MIT License

Kotlin 100.00%
material-design material-components snackbar android ui-components kotlin kotlin-android kotlin-library

light's Introduction

Light

Build Status Download

The usual Snackbar, but elegant. Inspired by Toasty.

Screenshots

success Info warning
Success Info Warning
Error Normal Custom
Error Normal Custom

Download

Gradle

Add the code below to your root build.gradle file (NOT your module build.gradle file, check here for an example).

allprojects {
    repositories {
        jcenter()
    }
}

Add the code below to your module's build.gradle file:

dependencies {
	implementation 'io.github.tonnyl:light:latest_version'
}

Maven

<dependency>
  <groupId>io.github.tonnyl</groupId>
  <artifactId>light</artifactId>
  <version>latest_version</version>
  <type>pom</type>
</dependency>

Usage

Each method always returns a Snackbar object, so you can customize the Snackbar much more. DO NOT FORGET TO CALL THE show() METHOD!

  • To display a success Snackbar:
// Kotlin
import io.github.tonnyl.light.success

success(fab, "Success", Snackbar.LENGTH_SHORT)
	.setAction("Action", {
		Toast.makeText(this@MainActivity, "Hello, Light!", Toast.LENGTH_SHORT).show()
	})
	.show()
// Java
Light.success(fab, "Success", Snackbar.LENGTH_SHORT)
	.setAction("Action", v ->
		Toast.makeText(SettingsActivity.this, "Hello, Light!", Toast.LENGTH_SHORT).show())
	.show());
  • To display an info Snackbar:
// Kotlin
import io.github.tonnyl.light.info

info(fab, "Info", Snackbar.LENGTH_SHORT).show()
// Java
Light.info(fab, "Info", Snackbar.LENGTH_SHORT).show());
  • To display a warning Snackbar:
// Kotlin
import io.github.tonnyl.light.warning

warning(fab, "Warning", Snackbar.LENGTH_SHORT).show()
// Java
Light.warning(fab, "Warning", Snackbar.LENGTH_SHORT).show());
  • To display an error Snackbar:
// Kotlin
import io.github.tonnyl.light.error

error(fab, "Error", Snackbar.LENGTH_SHORT).show()
// Java
Light.error(fab, "Error", Snackbar.LENGTH_SHORT).show());
  • To display the usual Snackbar:
// Kotlin
import io.github.tonnyl.light.normal

normal(fab, "Normal", Snackbar.LENGTH_SHORT).show()
// Java
Light.normal(fab, "Normal", Snackbar.LENGTH_SHORT).show();
  • You can also create your own Snackbar in custom-designed style:
// Kotlin
import io.github.tonnyl.light.make

make(
	fab, // // The view to find a parent from.
	"Awesome Snackbar", // The message to show.
	Snackbar.LENGTH_INDEFINITE, // How long to display the message.
	R.drawable.ic_album_white_24dp, // The left icon of message to show.
	R.color.color_cyan, // The background color of Snackbar.
	android.R.color.white, // The color of text to show.
	R.drawable.ic_done_all_white_24dp,
	R.color.colorAccent) // The left icon of action text.
	.setAction("Done all", {
		// Do whatever you want to do.
		Toast.makeText(this@MainActivity, "Hello, Light!", Toast.LENGTH_SHORT).show()
	})
	.show()
// Java
Light.make(
	fab,
	"Awesome Snackbar",
	Snackbar.LENGTH_SHORT,
	R.drawable.ic_album_white_24dp,
	R.color.color_cyan,
	android.R.color.white,
	R.drawable.ic_done_all_white_24dp,
	R.color.colorAccent)
	.setAction("Done all", v ->
		Toast.makeText(SettingsActivity.this, "Hello, Light!", Toast.LENGTH_SHORT).show())
	.show());

Extra

You can pass formatted text to Light!

Pull Request

Have some new ideas or find a bug? Do not hesitate to open an issue and make a pull request.

License

Light is under an MIT license. See the LICENSE file for more info.

light's People

Contributors

hellohudi avatar jerryokafor avatar tonnyl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

light's Issues

Failed to resolve: io.github.tonnyl:light:1.1.0

This my dependencies code for Light:
implementation "io.github.tonnyl:light:${versions.light}"
and i am getting this error: Failed to resolve: io.github.tonnyl:light:1.1.0.
Looks the particular release is not available on jcenter().

Remove Kotlin as an implementation detail

Thank you for this nice library!

I was surprised to find Companion references in your README, leaking an implementation detail of your library (= using Kotlin).
But as same time you're using @JvmStatic so you're already generating functions like Light.success(...).

Why not updating the README to avoid using this ugly Companion notation in Java? ;)

Bonus: your Light.kt is only including static functions. My advise would be to remove 2 indentation levels by reformating Light.kt like this example:

@file:JvmName("Light")
package io.github.tonnyl.light

fun success(....) { ... }

Only bad point: seems not possible to have javadoc for this class :/

The library Light has max lines allowed?

Hi,

I have imported Light in my project to show, in special cases, long String alerts. The issue appears when the String has 3 lines or more, for example:

"Welcome"
System.lineSeparator()
"Name: Diego Gómez Pérez"
System.lineSeparator()
"You have agreed at 10:00 am"

With these Strings, Light shows:

"Welcome
Name: Diego Gómez ..."

I think that you have a maximum of allowed lines, could you please solve it in some way?

Thanks!

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.