Handy library to send & receive command with payload between subscribers for Android.

Related tags

Utility Commander
Overview

Release

Commander

Handy library to send & receive command with payload between subscribers for Android.

Features

  • Subscription based
  • No dependency on Framework
  • Lightweight

Documentation

Installation


Step 1. Add the JitPack repository to your build file

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.rommansabbir:Commander:Tag'
}

Version available

Latest Releases
1.0.0

Initialize

CommanderManager.initialize()

Note: You can initialize Commander from anywhere in application scope. But it's recommanded to initialize Commander from your application class.


Calling CommanderManager.initialize() several time from anywhere will be ignored if the instance is already initialized.


How To Access

CommanderManager.getInstance()

which return an instace of Commander.

Note: Before accessing Commander you must initialize Commander properly or else it will throw NotInitializedException exception.


Available methods

  • register(subscriptionId: String, commandListener: Listener)
  • unregister(subscriptionId: String): Boolean
  • broadcastCommand(command: Command)
  • receiveCommand(command: Command) [Commander.Listener]

Usages

How to register/unregister?

To register to Commander, you must initialize the Commander.Listener to get broadcasted command from other susbcribers.

Example:

private val listener = object : Commander.Listener {
    override fun receiveCommand(command: Command) {
        println(command.toString())
    }
}

//Register as a subscriber.
CommanderManager.getInstance().register(SubscriptionId, listener)

Note: SubscriptionId must be an unique identifier. If you try to register with an duplicate SubscriptionId, it will throw an DuplicateSubscriptionID exception.


SubscriptionId is the public unique identifer to communicate/send command between subscribers.


How to Broadcast a command using Commander?

Get the instance through CommanderManager.getInstance()

(), Class1.SubscriptionId ) ) ">
CommanderManager.getInstance().broadcastCommand(
        Command(
            "Init Command",
            mutableListOf
   
    (),
            Class1.SubscriptionId
        )
    )

   

Note: If you try to send command to a not registered subscriber , then it will throw NoSubscriberFound exception.


What is command?. Command is a simple data class that take action, payload and subscriptionId as the params & pass the same instance to the respective subscriber. SubscriberId is the main key point to identify to whom the command will be sent.


How to receive command?

Register as a subscriber and the command will be passed to the Commander.Listener's onReceived() callback method.

private val listener = object : Commander.Listener {
    override fun receiveCommand(command: Command) {
        //Broadcasted command would be received here if the `SubscriptionId` matched properly.
    }
}

For detail implementation, check the demo application. Happy Coding...


Contact me

Portfolio | LinkedIn | Twitter | Facebook

License


Apache Version 2.0

Copyright (C) 2021 Romman Sabbir

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...
UPnP/DLNA library for Java and Android

Cling EOL: This project is no longer actively maintained, code may be outdated. If you are interested in maintaining and developing this project, comm

:iphone: [Android Library] Get device information in a super easy way.
:iphone: [Android Library] Get device information in a super easy way.

EasyDeviceInfo Android library to get device information in a super easy way. The library is built for simplicity and approachability. It not only eli

Android library for viewing, editing and sharing in app databases.
Android library for viewing, editing and sharing in app databases.

DbInspector DbInspector provides a simple way to view the contents of the in-app database for debugging purposes. There is no need to pull the databas

Android Market In-app Billing Library

Update In-app Billing v2 API is deprecated and will be shut down in January 2015. This library was developed for v2 a long time ago. If your app is st

An Android library allowing images to exhibit a parallax effect that reacts to the device's tilt
An Android library allowing images to exhibit a parallax effect that reacts to the device's tilt

Motion An Android library allowing images to exhibit a parallax effect. By replacing static pictures and backgrounds with a fluid images that reacts t

Android library to easily serialize and cache your objects to disk using key/value pairs.

Deprecated This project is no longer maintained. No new issues or pull requests will be accepted. You can still use the source or fork the project to

Form Validator Library for Android

Android-Validator Form Validator Library for Android [](https://flattr.com/submit/auto?user_id=throrin19&url=https://github.com/throrin19/Android-Vali

Very easy to use wrapper library for Android SharePreferences

Treasure English document Treasure是一个Android平台上基于SharePreferences的偏好存储库,只需要定义接口,无需编写实现,默认支持Serializable和Parcelable。运行时0反射,不仅使用方便而且性能和原生写法几乎无差别。 使用方法 1

Error handling library for Android and Java

ErrorHandler Error handling library for Android and Java Encapsulate error handling logic into objects that adhere to configurable defaults. Then pass

Releases(1.4.0)
Owner
Romman Sabbir
Software Engineer (Android) | Backend Developer | Tech Lover | Music Producer
Romman Sabbir
A command line tool for NFT stuff

MartaKli is a command line tool to help you generate your NFT pfp project. Current features: Generate batch of images using different layers and corre

Martabak Cult 2 Oct 4, 2022
KDoctor - A command-line tool that helps to set up the environment for Kotlin Multiplatform Mobile app development

KDoctor is a command-line tool that helps to set up the environment for Kotlin Multiplatform Mobile app development.

Kotlin 331 Dec 29, 2022
Small command-line utility to safely merge multiple WhatsApp backups (msgstore.db) into one.

whatsapp-database-merger A small command-line utility that can be used to merge multiple WhatsApp databases (msgstore.db) into one. A few notes: input

Mattia Iavarone 31 Dec 27, 2022
A command line utility to help you investigate the sensitive data associated with Macie findings.

Macie Finding Data Reveal This project contains a command line utility to help you investigate the sensitive data associated with Macie findings.

AWS Samples 8 Nov 16, 2022
Command framework built around Kord, built to be robust and scalable, following Kord's convention and design patterns.

Command framework built around Kord, built to be robust and scalable, following Kord's convention and design patterns.

ZeroTwo Bot 4 Jun 15, 2022
🐫🐍🍢🅿 Multiplatform Kotlin library to convert strings between various case formats including Camel Case, Snake Case, Pascal Case and Kebab Case

KaseChange Multiplatform Kotlin library to convert strings between various case formats Supported Case Formats SCREAMING_SNAKE_CASE snake_case PascalC

PearX Team 67 Dec 30, 2022
Android library which makes it easy to handle the different obstacles while calling an API (Web Service) in Android App.

API Calling Flow API Calling Flow is a Android library which can help you to simplify handling different conditions while calling an API (Web Service)

Rohit Surwase 19 Nov 9, 2021
Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Shahid Iqbal 4 Nov 29, 2022
A robust native library loader for Android.

ReLinker A robust native library loader for Android. More information can be found in our blog post Min SDK: 9 JavaDoc Overview The Android PackageMan

Keepsafe 2.9k Dec 27, 2022
Joda-Time library with Android specialization

joda-time-android This library is a version of Joda-Time built with Android in mind. Why Joda-Time? Android has built-in date and time handling - why

Daniel Lew 2.6k Dec 9, 2022