From 84e8d299f8104d3b55a4808481416d6a49736c1a Mon Sep 17 00:00:00 2001 From: Yekkanti Kishore Kumar Date: Mon, 11 Feb 2013 17:32:37 +0530 Subject: [PATCH] [#1239] kavitha|yekkanti Refactored code --- .../main/java/com/rapidftr/service/ChildService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/RapidFTR-Android/src/main/java/com/rapidftr/service/ChildService.java b/RapidFTR-Android/src/main/java/com/rapidftr/service/ChildService.java index 5195e6e3..f486e2a4 100644 --- a/RapidFTR-Android/src/main/java/com/rapidftr/service/ChildService.java +++ b/RapidFTR-Android/src/main/java/com/rapidftr/service/ChildService.java @@ -180,7 +180,14 @@ public Child apply(Map content) { public void setPhoto(Child child) throws IOException, JSONException { PhotoCaptureHelper photoCaptureHelper = new PhotoCaptureHelper(context); - JSONArray photoKeys = new JSONArray(child.optString("photo_keys")); + JSONArray photoKeys = child.optJSONArray("photo_keys"); + if(photoKeys != null){ + getPhotoFromServerIfNeeded(child, photoCaptureHelper, photoKeys); + } + + } + + private void getPhotoFromServerIfNeeded(Child child, PhotoCaptureHelper photoCaptureHelper, JSONArray photoKeys) throws JSONException, IOException { for(int i = 0; i < photoKeys.length(); i++){ String photoKey = photoKeys.get(i).toString(); try { @@ -192,7 +199,6 @@ public void setPhoto(Child child) throws IOException, JSONException { getPhotoFromServer(child, photoCaptureHelper, photoKey); } } - } public void getPhotoFromServer(Child child, PhotoCaptureHelper photoCaptureHelper, String fileName) throws IOException {