Thread Decorated View

Decorates a View to execute those methods with a custom Thread specification implementation

License

License

GroupId

GroupId

me.panavtec
ArtifactId

ArtifactId

threaddecoratedview-common
Last Version

Last Version

1.5.3
Release Date

Release Date

Type

Type

jar
Description

Description

Thread Decorated View
Decorates a View to execute those methods with a custom Thread specification implementation
Project URL

Project URL

https://github.com/PaNaVTEC/ViewThreadDecorator
Source Code Management

Source Code Management

https://github.com/PaNaVTEC/ViewThreadDecorator

Download threaddecoratedview-common

How to add to project

<!-- https://jarcasting.com/artifacts/me.panavtec/threaddecoratedview-common/ -->
<dependency>
    <groupId>me.panavtec</groupId>
    <artifactId>threaddecoratedview-common</artifactId>
    <version>1.5.3</version>
</dependency>
// https://jarcasting.com/artifacts/me.panavtec/threaddecoratedview-common/
implementation 'me.panavtec:threaddecoratedview-common:1.5.3'
// https://jarcasting.com/artifacts/me.panavtec/threaddecoratedview-common/
implementation ("me.panavtec:threaddecoratedview-common:1.5.3")
'me.panavtec:threaddecoratedview-common:jar:1.5.3'
<dependency org="me.panavtec" name="threaddecoratedview-common" rev="1.5.3">
  <artifact name="threaddecoratedview-common" type="jar" />
</dependency>
@Grapes(
@Grab(group='me.panavtec', module='threaddecoratedview-common', version='1.5.3')
)
libraryDependencies += "me.panavtec" % "threaddecoratedview-common" % "1.5.3"
[me.panavtec/threaddecoratedview-common "1.5.3"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

ViewThreadDecorator

This project attempts to make a common way to decorate a View interface from your MV* implementation to avoid suffer about threading problems. It's just a code generator that decorates an interface in order to post results in the Ui Thread, but you can use it in other ways. Here is a full explanation:

Further information: http://panavtec.me/say-goodbye-to-all-main-thread-problems-in-mvp/

Importing to your project

Add this dependency to your build.gradle file:

dependencies {
    compile 'me.panavtec:threaddecoratedview-common:1.5.2'
    apt/provided 'me.panavtec:threaddecoratedview-compiler:1.5.2'
}

Basic usage

Annotate your view interface contract with @ThreadDecoratedView:

@ThreadDecoratedView public interface MainView {
  void initUi();
}

Implement your custom ThreadSpec, here is a sample: Annotate your view interface contract with @ThreadDecoratedView:

public class MainThreadSpec implements ThreadSpec {
  Handler handler = new Handler();
  @Override public void execute(Runnable action) {
    handler.post(action);
  }
}

Where you need the decorated view, inject it with:

this.mainView = ViewInjector.inject(mainViewImplementation, mainThreadSpec);

If you need some methods of your interface to run without the decorator, just annotate those methods with @NotDecorated:

@ThreadDecoratedView public interface MainView {
  @NotDecorated void initUi();
  void refreshAList();
}

When you need to detach the view from the presenter, you can set your view to null if you handle nulls or you can use an included NullObjectPattern (an implemented view with empty methods) in this way:

this.mainView = ViewInjector.nullObjectPatternView(mainView);

Versions

Version
1.5.3
1.5.2
1.5.1
1.5
1.1.1
1.1
1.0.1
1.0.0