Execute asynchronous batch tasks with predefined or custom UI in Android.

Overview

AndroidBatchWorker

Execute asynchronous batch tasks with predefined or custom UI in Android.


Import

Add JitPack repository to your project level build.gradle file

...

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

Or, in newer android projects, if you need to the add repository in settings.gradle file...

...

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

Finally, add these two dependencies to your app/module level build.gradle file

...

dependencies {
    ...
    implementation 'com.github.buggysofts-com:AndroidBatchWorker:v1.0.2'
}

And you are done importing the library.


Sample codes

Here is a sample that uses Integer as input data type, and Double as the output data type. You can use any data type as input or output.

new BatchWorker<Integer, Double>(
    MainActivity.this,
    "Title",
    Arrays.asList(1, 2, 3, 4, 5),
    DialogMode.MODE_CLASSIC,
    new WorkerCallBack<Integer, Double>() {
        @UiThread
        @Override
        public void onShortPreWork() {
            // todo - perform any instantaneous task - eg. update/initialize ui
        }
    
        @WorkerThread
        @Override
        public void onLongPreWork(@NonNull List<Integer> dataList) {
            // todo - perform any long running task on the data
            // eg. initialize one or more property of each data item.
        }
    
        @Override
        public String longPreWorkDescriptor() {
            // todo - return anything you like, eg. "initializing", "connecting" etc.
            return "Pre-Processing...";
        }
    
        @WorkerThread
        @Override
        public Double performTask(@NonNull List<Integer> dataList, int activeDataIndex) {
            Integer activeData = dataList.get(activeDataIndex);
    
            // todo - perform actual task(may be long running) on each data item
            double lResult = getLongRunningProcessResult(activeData);
    
            // return a result
            return activeData*lResult;
        }
    
        @Override
        public String taskLabelDescriptor(@NonNull List<Integer> dataList, int activeDataIndex) {
            // todo - return any short details about the operation on the active data
            // e.g. it's name or any other details etc.
            return String.format("%s", dataList.get(activeDataIndex));
        }
    
        @Override
        public String taskProgressDescriptor(@NonNull List<Integer> dataList, int activeDataIndex) {
            // todo - return a text representation of the progress, for example...
            return String.format(
                "%s/%s",
                activeDataIndex+1,
                dataList.size()
            );
        }
    
        @WorkerThread
        @Override
        public void onLongPostWork(@NonNull List<Double> results) {
            // todo - perform any long running task on the result list
            // eg. finalize works, free used resources, anything.
        }
    
        @Override
        public String longPostWorkDescriptor() {
            // todo - return anything you like, eg. "Finalizing", "Clearing temporary resources" etc.
            return "Post-Processing...";
        }
    
        @UiThread
        @Override
        public void onShortPostWork(@NonNull List<Double> results, boolean completed) {
            // todo - perform any instantaneous task - eg. update/finalize ui
        }
    }
).start();

You can access the ui components of the dialog (if you are using built-in dialogs) using the following public getter methods.

  1. getDialogTitleView() The TextView acting as the title of the dialog.
  2. getSubjectDescriptionView() The TextView acting as the current subject descriptor. Current subject is the data item for which the task is currently running.
  3. getProgressDescriptionView() The TextView that is describing (by text) the progress of the total work.
  4. getProgressBar() The ProgressBar that is visualising the progress of the total work.
  5. getTasksCancellationButton() The Button for requesting cancellation of the remaining tasks.

Please see the image below if you are not sure about the ui components:

UI components



Please share & rate the library if you find it useful.

Happy coding!

You might also like...
Customtoast is a android library for show your toast message in a custom UI.

CUSTOM TOAST customtoast is a android library for show your toast message in a custom UI. To get a Git project into your build: Step 1. Add the JitPac

A simple time second selector seek bar custom made
A simple time second selector seek bar custom made

A simple time second selector seek bar custom made How to To get a Git project into your build: Step 1. Add the JitPack repository to your build file

A custom view for rating which easy to make and use, but function is excellent
A custom view for rating which easy to make and use, but function is excellent

QRatingView A custom view for rating which easy to make and use, but function is excellent Effect Picture Properties declare-styleable name="QRat

Ticker - A custom time picker library
Ticker - A custom time picker library

Ticker A simple spinner time picker library Adding dependencies: if your gradle

Show Custom TOAST
Show Custom TOAST

Show Custom TOAST

Custom plugin for private minecraft server

Custom Plugin Custom plugin for private minecraft server. Requirements Java 1.17 PaperMC 1.18 (Minecraft 1.18) Features Cancels Creeper griefing Build

A custom OTP view to enter a code usually used in authentication
A custom OTP view to enter a code usually used in authentication

A custom view to enter a code usually used in authentication. Different types of OTPViews. Easy to use and configure your own view and character of OTP using all the attributes.

Simple addon for BlueMap that allows using a custom skin server.
Simple addon for BlueMap that allows using a custom skin server.

BlueMap Custom Skin Server Description Simple addon for BlueMap that allows using a custom skin server. Config { "debug": false,

A simple textview with custom background to provide additional information.
A simple textview with custom background to provide additional information.

🧱 Tebel A simple textview with custom background to provide additional information. Install Gradle Add JitPack repository below to your module's buil

Releases(v1.0.2)
Owner
Nowrose Muhammad Ragib
Native Android Developer
Nowrose Muhammad Ragib
Ktor is an asynchronous framework for creating microservices, web applications and more.

ktor-sample Ktor is an asynchronous framework for creating microservices, web applications and more. Written in Kotlin from the ground up. Application

mohamed tamer 5 Jan 22, 2022
High performance and fully asynchronous pulsar client with Kotlin and Vert.x

pulsarkt High performance pulsar client with Kotlin and Vert.x Features Basic Producer/Consumer API Partitioned topics Batching Chunking Compression T

null 1 Nov 5, 2021
Webclient-kotlin-sample - An example of using the http web client to promote synchronous and asynchronous https calls

Web Client Consumer Kotlin Sample The project is an example of using the http we

null 1 May 1, 2022
Asynchronous Spring Initializr API wrapper for Kotlin/JVM

initializr-kt Asynchronous Spring Initializr API wrapper for Kotlin/JVM. This library provides the simplest DSL for initializing Spring Boot projects

Mikhail Titov 2 May 8, 2022
TakeNotes, taking care of your tasks and your health

Take Notes - Para tornar sua rotina mais Saudável TakeNotes, cuidando de suas tarefas e de sua saúde Sobre • Funcionalidades • Layout • Como executar

null 0 Dec 7, 2021
InterAcao: tasks shared between people in a condominium or the same community

Projeto Integrador - Generation Brasil ?? ?? Interação ?? ?? Sobre • Funcionalidades • Implementações futuras • Layout • Como executar • Tecnologias •

Ana Clara Fagundes 3 Aug 8, 2022
To-do-List - Creating a Reminders and Tasks app with Kotlin

To do List ?? App de Lembretes e Tarefas com Kotlin Telas do App Tecnologias Kot

Alini Rodrigues Ferreira 4 May 18, 2022
Taskify is a mobile application used to create and schedule tasks in your TODO list

Taskify is a mobile application used to create and schedule tasks in your TODO list. It is built upon the new Maaterial 3 UI components with the MVVM pattern and the latest Jetpack components.

Robert Muriithi 2 Jun 25, 2022
Android Custom View Accessibility

CustomFanController - Solution Code Creates a circular fan control dial that offers multiple selections marked by numeric indicators: 0 for off, 1 for

Atıl Samancıoğlu 7 Dec 28, 2022