Iris


Source link: https://github.com/RoRoche/Iris

Iris

Convenient wrapper library to perform network queries using Retrofit and Android Priority Job Queue (Job Manager)

STILL IN DEVELOPMENT

Dependency

In the top-level build.gradle file:

buildscript {

  dependencies {

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
  
}
 
}

In the project build.gradle file:

apply plugin: 'com.neenbedankt.android-apt'  repositories {

  maven {

url 'https://dl.bintray.com/guddy/maven/'
  
}
 
}
  dependencies {

  compile 'fr.guddy.iris:iris:0.0.7'
  apt 'fr.guddy.iris:compiler:0.0.7' 
}

How to use the Iris compiler

  • Create a retrofit interface as usual
public interface ApiService {

  @GET("users/{
user
}
/repos")
  Call<List<RepoDTO>> listRepos(@NonNull @Path("user") final String user);
 
}

Supported annotations are @DELETE, @GET, @HEADER, @HTTP, @PATCH, @POST, @PUT.

  • The annotation processor will generate the following query class:
public abstract class AbstractQueryListRepos extends AbstractQuery<List<RepoDTO>> {

public final String user;
 private transient List<RepoDTO> mResult;
 protected AbstractQueryListRepos(final Params params, final String user) {

  super(params);

  this.user = user;

}

 public List<RepoDTO> getResult() {

  return mResult;

}

 @Override
protected void execute() throws Throwable {

  mResponse = getApiService().listRepos(user).execute();

  mResult = mResponse.body();

}

 @Override
protected void onQueryDidFinish() {

}

 protected abstract ApiService getApiService();

 public static final class EventQueryListReposDidFinish extends AbstractEventQueryDidFinish<AbstractQueryListRepos> {

  public EventQueryListReposDidFinish(final AbstractQueryListRepos query) {

 super(query);

  
}

}
 
}
  • The annotation processor will generate the following query class:
public class ApiServiceQueryFactory extends AbstractQueryFactory {

public ApiServiceQueryFactory(final JobManager pJobManager, final MerlinsBeard pMerlinsBeard) {

  super(pJobManager, pMerlinsBeard);

}

 public boolean startAbstractQueryListRepos(final AbstractQueryListRepos pQuery) {

  return startQuery(pQuery);

}
 
}
  • now just subclass AbstractQueryListRepos as follows to provide the ApiService instance and deal with query ending:
public class QueryListRepos extends AbstractQueryListRepos {

public QueryListRepos(@NonNull final String pUser) {

super(new Params(1), pUser);

  
}

@Override
  protected ApiService getApiService() {

return IrisApplication.getInstance()

  .getApplicationComponent()

  .apiService();

  
}

@Override
  protected void onQueryDidFinish() {

IrisApplication.getInstance()

  .getApplicationComponent()

  .eventBus()

  .post(new EventQueryListReposDidFinish(this));

  
}
 
}
  • start the query using the factory and test if it's return true or false:
if(queryFactory.startAbstractQueryListRepos(new QueryListRepos("RoRoche"))) {

// query started 
}
 else {

// no network and not a persistent query 
}

How to use Iris standalone (i.e., without its compiler)

  • Subclass AbstractQuery
public class QueryGetRepos extends AbstractQuery<List<RepoDTO>> {

public final String user;

public QueryGetRepos(@NonNull final String pUser) {

super(new Params(1));

user = pUser;
  
}

@Override
  protected void execute() throws Throwable {

// TODO perform network query thanks to retrofit
  
}

@Override
  protected void onQueryDidFinish() {

// TODO deal with results
  
}
 
}
  • Subclass AbstractEventQueryDidFinish
public static final class EventQueryGetReposDidFinish extends AbstractEventQueryDidFinish<QueryGetRepos> {

  public EventQueryGetReposDidFinish(final QueryGetRepos pQuery) {

super(pQuery);

  
}
 
}
  • Subclass AbstractQueryFactory :
public class QueryFactory extends AbstractQueryFactory {

  public QueryFactory(final JobManager pJobManager, final MerlinsBeard pMerlinsBeard) {

super(pJobManager, pMerlinsBeard);

  
}

public boolean startQueryListRepos(@NonNull final String pUser) {

return startQuery(new QueryListRepos(pUser));

  
}
 
}

Benefits

  • processing the retrofit interface, the compiler generates all of the boilerplate code
  • developer can focus on the specific job to do when the HTTP request is finished (for example: save data to local storage, by overriding the execute method)
  • the "Iris" library can be used without its compiler
  • it improves the network layer with a normalized structure
  • it's DI ready (cf. sample app using Dagger2)
  • it's Event-buses ready (cf. sample app using greenrobot's EventBus)

Logo credits

Nature graphic by Freepik from Flaticon is licensed under CC BY 3.0. Made with Logo Maker

Resources

This library provides a means to access the content on the Web easily from AndroidWear.

Bash script to simplify adb command usage.

This is a helpful bash utility for working with multiple devices at the same time.

Wrapper for Android Preferences which provides a fluid syntax.

Example:

Prefs.with(context).save(key, value);

Library that allows you to customize the font of a PagerTitleStrip.

This library provides a circular button that looks like the new button shown in the Google+ app for Android.

Drawable animation inspired by Tinder.

Interpolation methods:

  • LinearInterpolator
  • BounceInterpolator
  • CycleInterpolator

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes