Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Whats new in Liferay Mobile SDK 2.0 for Android

Whats new in Liferay Mobile SDK 2.0 for Android

Liferay Mobile SDK has been enabling developers to create native apps backed by Liferay Portal’s power. We’ve been using it in production since 2013 and have noticed many improvement points. We also listened to the community and added new features that will make app development even faster. The new Liferay Mobile SDK for Android brings a lot of new features that boosts apps development. Things from automatic JSON parsing and RxJava compatibility to better code generation are ones of the improvements in this new major release.

Silvio Santos

November 15, 2016
Tweet

More Decks by Silvio Santos

Other Decks in Programming

Transcript

  1. What’s New in Liferay Mobile SDK 2.0 for Android Silvio

    Santos, Mobile Lead Engineer DEVCON | MODCONF 2016
  2. BUILD REQUEST JSONObject command = new JSONObject();
 String method =

    "/dlapp/add-folder";
 JSONObject params = new JSONObject();
 
 params.put("repositoryId", repositoryId);
 params.put("parentFolderId", parentFolderId);
 params.put("name", name);
 params.put("description", description);
 
 command.put(method, params);
  3. DefaultHttpClient client = new DefaultHttpClient();
 
 AuthScope authScope = new

    AuthScope(
 AuthScope.ANY_HOST, AuthScope.ANY_PORT);
 
 Credentials credentials = new UsernamePasswordCredentials(
 username, password);
 
 client.getCredentialsProvider().setCredentials(
 authScope, credentials); CONFIGURE HTTP CLIENT
  4. EXECUTE REQUEST HttpPost post = new HttpPost(url);
 post.setEntity(new StringEntity(command.toString()));
 


    HttpResponse httpResponse = client.execute(post);
 
 HttpEntity entity = httpResponse.getEntity();
 String response = EntityUtils.toString(entity); …handle exceptions
  5. 2.0

  6. 1. @NNOTATION BASED API 2. DEFAULT PARAMETERS 3. POJO AUTO

    PARSING 4. REQUEST CANCELATION 5. BETTER CONFIGURATION API 6. RxJAVA INTEGRATION
  7. PARAMETERS @Path("/add-folder")
 Call<JsonObject> addFolder(
 @Param(name = "repositoryId") long repositoryId,
 @Param(name

    = "parentFolderId") long parentId,
 @Param(name = "name") String name, @Param(name = “description”) String description);
  8. PARAMETERS @Path("/add-folder")
 Call<JsonObject> addFolder(
 @Param(name = "repositoryId") long repositoryId,
 @Param(name

    = "parentFolderId") long parentId,
 @Param(name = "name") String name, @Param(name = “description”) String description);
  9. PARAMETERS @Path("/add-folder")
 Call<JsonObject> addFolder(
 @Param(name = "repositoryId") long repositoryId,
 @Param(name

    = "parentFolderId") long parentId,
 @Param(name = "name") String name, @Param(name = “description”) String description);
  10. DEFAULT PARAMETERS @Path("/add-folder")
 @Params({
 @Param(name = "description", value = "")


    })
 Call<JsonObject> addFolder(
 @Param(name = "repositoryId") long repositoryId,
 @Param(name = "parentFolderId") long parentId,
 @Param(name = "name") String name);
  11. DEFAULT PARAMETERS @Path("/add-folder")
 @Params({
 @Param(name = "description", value = "")


    })
 Call<JsonObject> addFolder(
 @Param(name = "repositoryId") long repositoryId,
 @Param(name = “parentFolderId") long parentId,
 @Param(name = "name") String name);
  12. POJO AUTO PARSING public class Site {
 
 boolean active;


    long groupId;
 String name;
 String descriptiveName;
 
 }
  13. CANCEL REQUESTS Call<List<Site>> call = service.getUserSites(); call.async(new Callback<List<Site>>() { public

    void onFailure(Exception exception) {
 }
 public void onSuccess(List<Site> sites) {
 } }); Call.cancel(call)
  14. CANCEL REQUESTS Call<List<Site>> call = service.getUserSites(); call.async(new Callback<List<Site>>() { public

    void onFailure(Exception exception) {
 }
 public void onSuccess(List<Site> sites) {
 } }); Call.cancel(call)
  15. CONFIGURING REQUESTS Config config = new Config.Builder( “http://localhost:8080”) 
 .auth(new

    BasicAuthentication("login", "pwd"))
 .header("headerKey", "headerValue")
 .timeout(10000)
 .build();
 
 Config.global(config);
  16. CONFIGURING REQUESTS Config config = new Config.Builder( “http://localhost:8080”) 
 .auth(new

    BasicAuthentication("login", "pwd"))
 .header("headerKey", "headerValue")
 .timeout(10000)
 .build();
 
 Config.global(config);
  17. CONFIGURING REQUESTS Config config = new Config.Builder( “http://localhost:8080”) 
 .auth(new

    BasicAuthentication("login", "pwd"))
 .header("headerKey", "headerValue")
 .timeout(10000)
 .build();
 
 Config.global(config);
  18. CONFIGURING REQUESTS Config config = new Config.Builder( “http://localhost:8080”) 
 .auth(new

    BasicAuthentication("login", "pwd"))
 .header("headerKey", "headerValue")
 .timeout(10000)
 .build();
 
 Config.global(config);
  19. CONFIGURING REQUESTS Config config = Config.global()
 .newBuilder()
 .header("key", "value")
 .build();


    
 Call<JsonArray> call = service.getUserSites();
 JsonArray sites = call.execute(config);
  20. CONFIGURING REQUESTS Config config = Config.global()
 .newBuilder()
 .header("key", "value")
 .build();


    
 Call<JsonArray> call = service.getUserSites();
 JsonArray sites = call.execute(config);
  21. BATCH REQUESTS 
 Call<User> call1 = service.getUserByEmailAddress(
 20116, "[email protected]");
 


    Call<User> call2 = service.getUserByEmailAddress(
 20116, "[email protected]");
 
 Response response = Batch.execute(call1, call2);
  22. RxJAVA INTEGRATION 
 getUserSites()
 .subscribe(sites -> {
 //new data event,

    do something
 },
 throwable -> {
 //on error
 });