Giter VIP home page Giter VIP logo

alertdialog's Introduction

AlertDialog - Customizable alert dialog with retained callback actions

Usage

Setup alert dialog config (optional)

Should be called once at Application.OnCreate() or smth:

Alert.defaultConfig {
   dialogStyle = R.style.MaterialAlertDialog_MaterialComponents
   headerLayoutResource = R.layout.dialog_header
   footerLayoutResource = R.layout.dialog_footer
   dialogIsCancellable = false
}

Create AlertDialog

private val SAMPLE_DIALOG_TAG = "SAMPLE_DIALOG_TAG"

...

alert { // build and show alert
    style(R.style.MaterialAlertDialog_MaterialComponents)
    header(R.layout.dialog_header)
    footer(R.layout.dialog_footer)
    title { 
        text("Hi")
        alignment(LayoutAlign.RIGHT)
    }
    message {
        text("How do you do?")
        alignment(LayoutAlign.RIGHT)
    }
    controlsAlignCenter(true) // make button layout centered
    buttonCallback(callbackTag = SAMPLE_DIALOG_TAG) { // enable callback
        positiveButton("Yes")
        neutralButton("Cancel")
        negativeButton("No")
    }
    customView(R.layout.activity_main) // set custom view
    cancellable(false)
}


Simple


With header


Full equipment

Listen alert dialog button click events:

// Implement AlertEventListener to catch button click events from alert dialog buttons
class MainActivity : AppCompatActivity(R.layout.activity_main), 
AlertEventListener {

    ...

    // from AlertEventListener
    override fun onAlertEvent(event: AlertEvent) {
       event.doIfMatches(SAMPLE_DIALOG_TAG) {
          when(event) {
             is AlertEvent.Negative -> {
                showToast("Negative via ${event.callbackTag}")
             }
             is AlertEvent.Neutral -> {
                showToast("Neutral via ${event.callbackTag}")
             }
             is AlertEvent.Positive -> {
                showToast("Positive via ${event.callbackTag}")
             }
          }
       }
    }
}

Installation

  1. Add the JitPack repository to your build file:

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
  2. Add the dependency

    Latest version isβ €

    dependencies {
        implementation 'com.github.khoben:alertdialog:<latest_version>'
    }

alertdialog's People

Contributors

khoben avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.