GitXplorerGitXplorer
k

alertdialog

public
1 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
d4e4d68d95cb5744038b72e321d971dcf95269eb

Update README.md

kkhoben committed 3 years ago
Unverified
483371d877e1617f5f3dbf83567fbd11fddaefcc

Merge branch 'dev'

kkhoben committed 3 years ago
Unverified
edbaf335de83fd826eb37c838ad78f62e08fd985

Update alert events

kkhoben committed 3 years ago
Unverified
d1d05a38ea08fe45fb4f93d2f60528e18e589566

Update to 3.0.0

kkhoben committed 3 years ago
Unverified
6c1044f77dd6e9928394ae7bbeeb47db81ef84b6

Update to 2.0.0-alpha04

kkhoben committed 3 years ago
Unverified
ac977375051bdd117f4293942029c72b262db65e

Update to 2.0.0-alpha03

kkhoben committed 3 years ago

README

The README file for this repository.

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>'
    }