Android Express Events Library

Overview

Eventex, Android Express Events

Android library to send/post data to Fragments, Layouts, Activity. No need to create interfaces and pass listeners to multiple classes. There is also no need to subscribe/unsubscribe for events!

Try It Now

Make sure Java 8 (1.8) support is enabled in the gradle file

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

Add EventEx to the project gradle file (Androidx based projects)

implementation 'dev.uchitel:eventex:2.1.0'

Or for Android Support Library projects

implementation 'dev.uchitel:eventex-support:2.0.0'

Simple

To post message

new UIEvent("button.ok.click").post(view); // yes, this is it

To receive message. In any class that extends Fragment, ViewGroup, or Activity

public class CustomFragment extends Fragment implements UIEventListener {
//  .....
    @Override
    public boolean onMessage(@NonNull UIEvent uiEvent) {
        switch (uiEvent.what) {
            case "button.ok.click":
                Log.d(uiEvent.toString());
                return true; // to stop message propagation
        }
        return false;   // to let other objects to process message
    }
}

No need to setOnItemClickListener in the RecyclerView.Adapter! Much less boilerplate code compare to classic solution Communicate with other fragments! Class CustomFragment extends Android class Fragment. It will also work well if the class extends Activity, ViewGroup, or any layout derived from ViewGroup (LinearLayout, FrameLayout, etc..)

Features

  • Delivers messages between UI components of an Activity.
  • Supports synchronous and asynchronous communication.
  • No need to subscribe/unsubscribe to receive messages.
  • Can deliver any data type.
  • Completely decouples components.
  • No reflection and no ProGuard rules.
  • Tiny code size.

More Details

Message can be sent synchronously

new UIEvent(12345).send(viewGroup);

Message can carry additional integer, string value, and anything that can fit into Bundle:

new UIEvent(12345)
    .setText("some text to pass with message")
    .setNumber(9876) // some integer to pass with message
    .putAll(bundle)
    .post(viewGroup);

Next code will properly receive this message:

public class FragmentReceiver extends FrameLayout implements UIEventListener {
//  .....
    @Override
    public boolean onMessage(@NonNull UIEvent uiEvent) {
        switch (uiEvent.code) {
            case 12345:
                Log.d("FragmentReceiver", "text="+uiEvent.getText());
                Log.d("FragmentReceiver", "number="+uiEvent.getNumber());
                return true; // to stop message propagation
        }
        return false;   // to let other components to process the message
    }
}

Class UIEvent isn't 'final' and can be extended to carry any data. See sample CustomUIEvent.

Message can use integer ID, string ID, or both for more complex control scenarios:

new UIEvent(12345, "button.ok.click"))
    .post(view);

The 'onMessage' for the above code:

public class FragmentReceiver extends Activity implements UIEventListener {
//  .....
    @Override
    public boolean onMessage(@NonNull UIEvent uiEvent) {
        switch (uiEvent.code) {
            case 12345:
                if(uiEvent.what.equals("button.ok.click")){
                    // ...
                    return true; // to stop message propagation
                }
        }
        return false;   // to let other components to process the message
    }
}

When writing android library make sure to use 'namespace' to prevent collisions. Sending message inside library can look like:

new UIEvent("button.ok.click")
    .setNamespace("lib_name.company_name.com")
    .post(view);

Namespace "lib_name.company_name.com" is going to prevent ID collisions when the library is distributed to third party developers.

And to receive this message inside library module

public class FragmentReceiver extends Fragment implements UIEventListener {
//  .....
    @Override
    public boolean onMessage(@NonNull UIEvent uiEvent) {
        // return false if this is not library message
        if (!uiEvent.getNamespace().equals("libname.company.com")) return false;

        switch (uiEvent.what){
            case "button.ok.click":
                Log.d(uiEvent.getText());
                return true; // to stop message propagation
        }
        return false;   // to let other objects to process message
    }
}

Requirements

  • Android 4.1.0(API 16) or above.
  • Java 8

R8 / ProGuard

No special requirements for R8 or ProGuard

Do you think it might be useful? Help devs to find it.

Alternative libraries

License

Copyright 2019 Alexander Uchitel

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.
You might also like...
The library that removes all boilerplate code allowing you to display lists with few lines of code.

VsRecyclerView The library that removes all boilerplate code allowing you to display lists with few lines of code. Gradle androidExtensions { expe

An efficient TabLayout library implemented with RecyclerView.
An efficient TabLayout library implemented with RecyclerView.

RecyclerTabLayout An efficient TabLayout library implemented with RecyclerView. Features Efficient when having many tabs Easy setup with ViewPager (sa

the library is a loop RecyclerView(expression), can show some effects when display
the library is a loop RecyclerView(expression), can show some effects when display

CircleRecyclerView the library is a loop RecyclerView, can show some effects when display screenshot CircularViewMode ScaleXViewMode & ScaleYViewMode

Elegant design and convenient to use RecyclerView adapter library based on Kotlin DSL.
Elegant design and convenient to use RecyclerView adapter library based on Kotlin DSL.

xAdapter: Kotlin DSL 风格的 Adapter 封装 1、简介 该项目是 KotlinDSL 风格的 Adapter 框架封装,用来简化 Adapter 调用,思想是采用工厂和构建者方式获取 Adapter 避免代码中定义大量的 Adapter 类。该项目在 BRVAH 的 Ada

Handy library to integrate pagination, which allow no data layout, refresh layout, recycler view in one view and easy way to bind pagination in app.
Handy library to integrate pagination, which allow no data layout, refresh layout, recycler view in one view and easy way to bind pagination in app.

Pagination View Handy library to integrate pagination, which allow no data layout, refresh layout, recycler view in one view and easy way to bind pagi

Organize your images in beautiful collage with this library!

CollageImageView This app is an example. how to create collages with RecyclerView. See an example, how it's working: device-2021-04-24-015545.mp4 Inst

Yet another adapter delegate library.
Yet another adapter delegate library.

Yet another adapter delegate library. repositories { ... maven { url 'https://jitpack.io' } } ... dependencies { implementation("com.git

A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.
A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.

UltimateRecyclerView Master branch: Dev branch: Project website:https://github.com/cymcsg/UltimateRecyclerView Description UltimateRecyclerView is a R

[UNMAINTAINED] Sticky Headers decorator for Android's RecyclerView
[UNMAINTAINED] Sticky Headers decorator for Android's RecyclerView

This project is no longer being maintained sticky-headers-recyclerview This decorator allows you to easily create section headers for RecyclerViews us

Releases(v2.1.0)
Owner
Alexander Uchitel
Alexander Uchitel
Android Library to provide swipe, click and other functionality to RecyclerView

RecyclerViewEnhanced Android Library to provide swipe, click and other functionality to RecyclerView Usage Add this to your build.gradle file dependen

Nikhil Panju 1k Dec 29, 2022
Dividers is a simple Android library to create easy separators for your RecyclerViews

Dividers Dividers is an Android library to easily create separators for your RecyclerViews. It supports a wide range of dividers from simple ones, tha

Karumi 490 Dec 28, 2022
Android library defining adapter classes of RecyclerView to manage multiple view types

RecyclerView-MultipleViewTypeAdapter RecyclerView adapter classes for managing multiple view types Release Note [Release Note] (https://github.com/yqr

Yoshihito Ikeda 414 Nov 21, 2022
Android pagination library (updated 01.05.2018)

NoPaginate Android pagination library, based on @MarkoMilos repository Paginate Loading Item Error Item Gradle implementation 'ru.alexbykov:nopaginate

Alexey Bykov 183 Nov 22, 2022
Android library for RecyclerView to manage order of items and multiple view types.

recyclerview-binder Android Library for RecyclerView to manage order of items and multiple view types. Features Insert any items to wherever you want

Satoru Fujiwara 185 Nov 15, 2022
Android Library to provide swipe, click and other functionality to RecyclerView

RecyclerViewEnhanced Android Library to provide swipe, click and other functionality to RecyclerView Usage Add this to your build.gradle file dependen

Nikhil Panju 1k Dec 29, 2022
Epoxy is an Android library for building complex screens in a RecyclerView

Epoxy Epoxy is an Android library for building complex screens in a RecyclerView. Models are automatically generated from custom views or databinding

Airbnb 8.1k Dec 29, 2022
A customizable and easy-to-use Timeline View library for Android

TimelineView A customizable and easy-to-use Timeline View library for Android Can be used as a standalone view or as a RecyclerView decorator Setup 1.

Riccardo Lattarulo 189 Dec 10, 2022
An android library for quick setup of RecyclerView

SmartRecyclerView for Android An android library to quickly setup RecyclerView(List) with SwipeRefreshLayout Support, written entirely in Kotlin. Supp

Kunal Pasricha 16 Oct 18, 2022
RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)

Advanced RecyclerView This RecyclerView extension library provides Google's Inbox app like swiping, Play Music app like drag-and-drop sorting and expa

Haruki Hasegawa 5.2k Dec 23, 2022