Skip to content

liaohuqiu/android-ActionQueue

Repository files navigation

Android Gems

ActionQueue allows you run action one by one.

Import

Repositories:

allprojects {
    repositories {
        mavenCentral()
        maven {
            url "https://oss.sonatype.org/content/repositories/snapshots"
        }
        jcenter()
    }
}

Add to dependencies:

compile 'in.srain.cube:action-queue:1.0.1'

Usage

  • create actions

    String[] messageList = new String[]{
            "message 1",
            "message 2",
            "message 3",
    };
    for (int i = 0; i < messageList.length; i++) {
        String message = messageList[i];
        PopDialogAction action = new PopDialogAction(message);
        mActionQueue.add(action);
    }
  • process action

    class PopDialogAction extends ActionQueue.Action<String> {
    
        public PopDialogAction(String badge) {
            super(badge);
        }
    
        @Override
        public void onAction() {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            Dialog dialog = builder.setMessage(getBadge()).show();
            // notify action is done, and next aciton will be executed
            dialog.setOnDismissListener(mOnDismissListener);
        }
    }
  • notify when action is done

    DialogInterface.OnDismissListener mOnDismissListener = new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            mActionQueue.notifyActionDoneThenTryToPopNext();
        }
    };
  • LICENSE: MIT

About

ActionQueue allows you run action one by one.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published