• Stars
    star
    119
  • Rank 297,930 (Top 6 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An elegant looking and easy to use informative library with LiveData integration for Android.

LiveSmashBar

Download API License

LiveSmashBar allows you a great alternative for native snackbar & toast in Android. It allows a great extent of customisation & flexibility in terms of usage & behaviour.

Also it has support for LiveData which can be beneficial for displaying repetitive messages just be single initialization.

Library has been designed & developed purely in Kotlin. ❤️

Alt text

Spread Your ❤️:

GitHub followers Twitter Follow

Samples

You can check the Demo Project developed in kotlin for better understanding of concepts & usage.

Get it on Google Play

Download

This library is available in maven & jcenter which can also be imported from source as a module.

maven

<dependency>
    <groupId>com.yuvraj.livesmashbar</groupId>
    <artifactId>smashbar</artifactId>
    <version>1.0.0</version>
    <type>pom</type>
</dependency>

gradle

dependencies {
    // other dependencies here
    implementation 'com.yuvraj.livesmashbar:smashbar:1.0.0'
}

Get Started

Basic

Alt text

Shows a simple LiveSmashBar with description & duration.

LiveSmashBar.Builder(this)
            .description(getString(R.string.description))
            .descriptionColor(ContextCompat.getColor(this, R.color.white))
            .gravity(GravityView.BOTTOM)
            .duration(3000)
            .show();

Also you can show both title & description along with duration in milliseconds. Duration is set to indefinite which means it won't dismiss until & unless specified for.Also you can use predefined parameters i.e DURATION_SHORT = 1000, DURATION_LONG = 2500 for specifying duration for LiveSmashBar.

LiveSmashBar.Builder(this)
            .title(getString(R.string.title))
            .titleColor(ContextCompat.getColor(this, R.color.white))
            .description(getString(R.string.description))
            .descriptionColor(ContextCompat.getColor(this, R.color.white))
            .gravity(GravityView.BOTTOM)
            .duration(DURATION_SHORT)
            .show();

Gravity

Gravity_top

You can show LiveSmashBar at both Bottom ae well as Top of the screen by specifying GravityView.BOTTOM / GravityView.TOP.

GravityView.BOTTOM :

LiveSmashBar.Builder(this)
            .title(getString(R.string.title))
            .description(getString(R.string.description))
            .gravity(GravityView.BOTTOM)
            .duration(DURATION_SHORT)
            .show();

GravityView.TOP :

LiveSmashBar.Builder(this)
            .title(getString(R.string.title))
            .description(getString(R.string.description))
            .gravity(GravityView.TOP)
            .duration(DURATION_SHORT)
            .show();

LiveData Support

LiveData

LiveSmashBar allows support for LiveData , which can be used for showing similar group of messages with single initialization thereby avoiding code redundancy. This can be achieved by simply creating a LiveSmashBar instance & passing the livedata object as parameter. So when ever you post anything to livedata, your LiveSmashBar will receive that call back and will display the same to the end user. Following is a sample demostrating the use of livedata,

val liveData: MutableLiveData<Unit> = MutableLiveData()

LiveSmashBar.Builder(this)
            .showIcon()
            .icon(R.mipmap.ic_launcher)
            .title(getString(R.string.flutter_title)) 
            .description(getString(R.string.flutter_info)) 
            .gravity(GravityView.BOTTOM)
            .liveDataCallback(this, liveData)

Icon

Gravity_top

You can add icons to make details displayed on LiveSmashBar more meaningful & intuitive.

LiveSmashBar.Builder(this)
            .icon(R.mipmap.ic_launcher)
            .title(getString(R.string.title))
            .titleColor(ContextCompat.getColor(this, R.color.white))
            .description(getString(R.string.description))
            .descriptionColor(ContextCompat.getColor(this, R.color.white))
            .gravity(GravityView.BOTTOM)
            .duration(DURATION_SHORT)
            .show();

Also you can apply animation to icons, with the following snippet,

LiveSmashBar.Builder(this)
            .icon(R.mipmap.ic_launcher)
            .iconAnimation(AnimIconBuilder(this).pulse())
            .title(getString(R.string.description))
            .titleColor(ContextCompat.getColor(this, R.color.white))
            .gravity(GravityView.TOP)
            .duration(3000)
            .show()

Primary Button

Primary_Action

Similar to Snackbar, a message can be accompanied by an action button which can be used to perform some functionality. Below example listens for action button click to dismiss LiveSmashBar displayed to user.

LiveSmashBar.Builder(this)
            .icon(R.mipmap.ic_launcher)
            .title(getString(R.string.title)) 
            .description(getString(R.string.description)) 
            .primaryActionText("DONE") 
            .primaryActionEventListener(object : OnEventTapListener {
                      override fun onActionTapped(bar: LiveSmashBar) {
                                bar.dismiss()
                       }
             })
            .show();

Dialog Style

Dialog_Style

LiveSmashBar can also be used to display a dialog view with a message & action buttons. By defalut the view type set is BarStyle.DEFAULT_MESSAGE which shows basic message with action button. For displaying dialog style LiveSmashBar use the following snippet,

LiveSmashBar.Builder(this)
            .icon(R.mipmap.ic_launcher)
            .title(getString(R.string.title)) 
            .description(getString(R.string.description)) 
            .backgroundColor(ContextCompat.getColor(this, R.color.orange))
            .setBarStyle(BarStyle.DIALOG)
            .positiveActionText("DONE")
            .positiveActionTextColor(ContextCompat.getColor(this, R.color.white))
            .positiveActionEventListener(object : OnEventTapListener {
                     override fun onActionTapped(bar: LiveSmashBar) {
                             bar.dismiss()
                     }
            })
            .negativeActionText("CLOSE")
            .negativeActionTextColor(ContextCompat.getColor(this, R.color.white))
            .negativeActionEventListener(object : OnEventTapListener {
                     override fun onActionTapped(bar: LiveSmashBar) {
                             bar.dismiss()
                     }
            })
            .show();

Overlay

Dialog_Style

LiveSmashBar allows to show modal overlay messages that dims the background & highlights the message to user. It blocks the UI if function overlayBlockable() is called thereby blocking user taps on the underlying content. You can dismiss the overlay by calling function dismissOnTapOutside() for dismissing the overlay.

LiveSmashBar.Builder(this)
            .showIcon()
            .icon(R.mipmap.ic_launcher)
            .title(getString(R.string.flutter_title))
            .description(getString(R.string.flutter_info))
            .gravity(GravityView.TOP)
            .dismissOnTapOutside()
            .showOverlay()
            .overlayBlockable()
            .backgroundColor(ContextCompat.getColor(this, R.color.white))
            .show();            

Event Listeners

You can subscribe to events like when the LiveSmashBar is showing, or dismissing. You can also subscribe to when the LiveSmashBar is being shown or dismissed to perform animations on other views if needed.

You can also subscribe to tap events inside or outside the bar.

Show Event

You can subscribe to events on OnEventShowListener as follows,

LiveSmashBar.Builder(this) 
        .title("Hello World!")
        .description("You can listen to events when the LiveSmashBar is shown")
        .barShowListener(object : LiveSmashBar.OnEventShowListener {
            override fun onShowing(bar: LiveSmashBar) {
                Log.d(TAG, "LiveSmashBar is showing")
            }

            override fun onShown(bar: LiveSmashBar) {
                Log.d(TAG, "LiveSmashBar is shown")
            }
        })
        .show()

Dismiss

You can listen to events on OnEventDismissListener for dismissing events. You can also specifically get to know the reason behind the bar dismiss action - TIMEOUT, MANUAL, TAP_OUTSIDE and SWIPE.

LiveSmashBar.Builder(this) 
        .title("Hello World!") 
        .description("You can listen to events when the LiveSmashBar is dismissed")
        .barDismissListener(object : LiveSmashBar.OnEventDismissListener {
            override fun onDismissing(bar: LiveSmashBar, isSwiped: Boolean) {
                Log.d(TAG, "LiveSmashBar is dismissing with $isSwiped")
            }

            override fun onDismissed(bar: LiveSmashBar, event: LiveSmashBar.DismissEvent) {
                Log.d(TAG, "LiveSmashBar is dismissed with event $event")
            }
        }) 
        .show()

Taps

You can listen to tap events inside or outside of the LiveSmashBar.

LiveSmashBar.Builder(this) 
        .title("Hello World!")
        .description("You can listen to tap events inside or outside the LiveSmashBar.")
        .listenBarTaps(object : LiveSmashBar.OnEventListener {
            override fun onTap(bar: LiveSmashBar) {
                Log.d(TAG, "Bar tapped")
            }
        })
        .listenOutsideTaps(object : LiveSmashBar.OnTapListener {
            override fun onTap(bar: LiveSmashBar) {
                Log.d(TAG, "Outside tapped")
            }
        })
        .show()

About Me

Yuvraj Pandey

I am a passionate Mobility Engineer which likes to push himself on various fronts of technologies.

For more exciting updates follow me,

                                    

License


Copyright 2018 Yuvraj Pandey 

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.

More Repositories

1

react-native-stories-view

A simple and fully customizable React Native component that implements a status/stories feature similar to Whatsapp & Instagram ⭐✨🌟
TypeScript
411
star
2

WhatsApp-Clone

WhatsApp Clone provides an in-depth view of implementation on how to create a full-stack, mobile, hybrid web application from scratch using React Native, ReactJs, Typescript, NodeJs, ExpressJs, MongoDB, Socket.io, Heroku & Firebase Deployment. 🔥🔥
JavaScript
381
star
3

SwiftNotes

Creating notes was never so smooth, just check out this demo developed in XCode 9 & Swift 4.
Swift
33
star
4

Fluttereo

This repository explores various fundamentals of Flutter from scratch developed in Dart with Android Studio & Visual Code 🔥.
Dart
26
star
5

EStoreline

EStoreLine is an eCommerce platform that provides an in-depth view of implementation on how to create a Full Stack Web application from scratch using Reactjs, Html5, CSS3, Bootstrap4, React-Redux, NodeJs, ExpressJs, MySQL.
JavaScript
9
star
6

React-Food-App

React-Food-App is a sample UI Design-Kit implementation build in React Native for both Android & iOS platform's.
JavaScript
7
star
7

react-native-picker-calendar-view

A simple and fully customizable React Native library that can be used as a Date picker or a simple Calendar view 📅
TypeScript
6
star
8

SwiftSocial

A deep dive into Social login integration including Facebook, Google & Firebase Authentication in SWIFT for IOS.
Swift
5
star
9

MVPCodeDemo

Java
4
star
10

ArchComponents

The repository covers the concepts regarding ViewModel, LiveData, LifeCycle along with Retrofit & RxJava in a Kotlin
Kotlin
4
star
11

recipe-rest-apis

Python
2
star
12

AndroidFundamentals

Kotlin
2
star
13

MovieCreator

MovieCreator demonstrates simple implementation of MERN (MongoDb | ExpressJs | ReactJs | NodeJs) Stack for complete end-to-end web app development ⚡️ 🔥
JavaScript
2
star
14

CircularSearchAnimation

Kotlin
2
star
15

Reactify

A sample repository exploring the basics of React Native 🔥🔥🔥
Objective-C
1
star