Skip to content

Commit

Permalink
Card 77 (Add photo details to Trovebox Collect)
Browse files Browse the repository at this point in the history
Trovebox-Android-App:

- AlbumsFragment.AlbumsAdapter: added missing newly added runnable
parameter to the PhotoUtils.validateUrlForSizeExistAsyncAndRun call in
the getView method
- FacebookFragment: added missing newly added runnable parameter to the
PhotoUtils.validateUrlForSizeExistAsyncAndRun call in the postPhoto
method
- SelectAlbumsActivity.SelectAlbumsUiFragment.AlbumsAdapter: added
missing newly added runnable parameter to the
PhotoUtils.validateUrlForSizeExistAsyncAndRun call in the getView method

Trovebox-Android-Common:

- GalleryFragment.GalleryAdapterExt: added missing newly added runnable
parameter to the PhotoUtils.validateUrlForSizeExistAsyncAndRun call in
the init method
- PhotoDetailsFragment.PhotoDetailsPagerAdapter: added missing newly
added runnable parameter to the
PhotoUtils.validateUrlForSizeExistAsyncAndRun call in the
instantiateItem method
- PhotoDetailsFragment.ThumbnailsAdapter: added missing newly added
runnable parameter to the PhotoUtils.validateUrlForSizeExistAsyncAndRun
call in the getView method
- Photo: added mHost, mToken fields, their getters and setters and
support to parcelable implementation
- PhotoUtils: added additional parameter to the
validateUrlForSizeExistAsyncAndRun method declaration
- PhotoUtils: added missing newly added parameters to the getPhoto API
call in the getThePhotoWithReturnSize method
- PhotoUtils.RetrieveThumbUrlTask: added mPhoto2 field and moved mPhoto
field modification from doInBackground to the onSuccessPostExecute to
avoid concurent modification
- ITroveboxApi: modified getPhoto declaration: added new token and host
parameters
- TroveboxApi: added host and token parameters support to the getPhoto
API method implementation
- AbstractUploaderService: added setting of host and token information
to the Photo object onsuccessful upload in the handleIntent method

Trovebox-Android-Test:
- GalleryActivityTest: added missing parameters to the getPhoto call in
the testLoadImages method
- PhotoDetailsActivityTest: added missing parameters to the getPhoto
call in the testPreconditions method
  • Loading branch information
httpdispatch committed Feb 10, 2014
1 parent 9fed259 commit 40f2023
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 15 deletions.
6 changes: 6 additions & 0 deletions app/src/com/trovebox/android/app/AlbumsFragment.java
Expand Up @@ -143,6 +143,12 @@ public void run(Photo photo) {
.loadImage(photo.getUrl(thumbSize.toString()), image);

}
}, new Runnable() {

@Override
public void run() {
mImageWorker.loadImage(null, image);
}
}, loadingControl);
} else
{
Expand Down
3 changes: 2 additions & 1 deletion app/src/com/trovebox/android/app/FacebookFragment.java
Expand Up @@ -157,7 +157,8 @@ public void run(Photo photo) {
new PostPhotoTask(photo).execute();
}
};
PhotoUtils.validateUrlForSizeExistAsyncAndRun(photo, thumbSize, runnable, loadingControl);
PhotoUtils.validateUrlForSizeExistAsyncAndRun(photo, thumbSize, runnable, null,
loadingControl);
}

private void performFacebookLogout()
Expand Down
6 changes: 6 additions & 0 deletions app/src/com/trovebox/android/app/SelectAlbumsActivity.java
Expand Up @@ -230,6 +230,12 @@ public void run(Photo photo) {
.loadImage(photo.getUrl(thumbSize.toString()), vh.cover);

}
}, new Runnable() {

@Override
public void run() {
mImageWorker.loadImage(null, vh.cover);
}
}, SelectAlbumsUiFragment.this);
} else
{
Expand Down
3 changes: 3 additions & 0 deletions common/res/values-pt/strings.xml
Expand Up @@ -25,6 +25,9 @@
<string name="sync_show_all">Mostre todas</string>
<string name="sync_uploaded">ENVIADA!</string>

<!-- Photo details -->
<string name="details_title_and_date_header">%1$s tirada em %2$s</string>

<!-- Notifications -->
<string name="notification_uploading_photo">Enviando %1$s</string>
<string name="notification_upload_failed_title">Falha no envio</string>
Expand Down
Expand Up @@ -431,6 +431,12 @@ public void run(Photo photo) {
photo, photo.getUrl(thumbSize.toString()));
mImageWorker.loadImage(fo, imageView);
}
}, new Runnable() {

@Override
public void run() {
mImageWorker.loadImage(null, imageView);
}
}, loadingControl);
}
};
Expand Down
Expand Up @@ -501,7 +501,15 @@ public void run(Photo photo) {
GuiUtils.noAlertError(TAG, ex);
}
}
}, loadingControl);
},
new Runnable() {

@Override
public void run() {
mImageWorker.loadImage(null, imageView);
}
},
loadingControl);

loadingControl.stopLoading();

Expand Down Expand Up @@ -601,6 +609,12 @@ public void run(Photo photo) {
String url = photo.getUrl(thumbSize.toString());
mImageWorker2.loadImage(url, imageView);
}
}, new Runnable() {

@Override
public void run() {
mImageWorker2.loadImage(null, imageView);
}
}, null);
return view;
}
Expand Down
42 changes: 42 additions & 0 deletions common/src/com/trovebox/android/common/model/Photo.java
Expand Up @@ -35,6 +35,8 @@ public class Photo implements Parcelable {
protected String mId;
protected final List<String> mTags;
protected String mAppId;
protected String mHost;
protected String mToken;
protected final Map<String, String> mUrls;
protected String mTitle;
protected String mDescription;
Expand Down Expand Up @@ -149,6 +151,42 @@ public String getAppId() {
return mAppId;
}

/**
* Returns the host of the server on which this Photo is located.
*
* @return host
*/
public String getHost() {
return mHost;
}

/**
* Set the host of the server on which the Photo is located
*
* @param host
*/
public void setHost(String host) {
mHost = host;
}

/**
* Returns the access token of the photo.
*
* @return token
*/
public String getToken() {
return mToken;
}

/**
* Set the access token of the photo
*
* @param token
*/
public void setToken(String token) {
mToken = token;
}

/**
* Get URL for a specific size. Examples are: 50x50xCR and 640x960 . CR
* stands for cropped.
Expand Down Expand Up @@ -247,6 +285,8 @@ public void writeToParcel(Parcel out, int flags) {
out.writeString(mTitle);
out.writeString(mDescription);
out.writeString(mAppId);
out.writeString(mHost);
out.writeString(mToken);
out.writeStringList(mTags);
out.writeInt(mPermission);
out.writeLong(mDateTaken.getTime());
Expand Down Expand Up @@ -283,6 +323,8 @@ private Photo(Parcel in) {
mTitle = in.readString();
mDescription = in.readString();
mAppId = in.readString();
mHost = in.readString();
mToken = in.readString();
in.readStringList(mTags);
mPermission = in.readInt();
mDateTaken = new Date(in.readLong());
Expand Down
23 changes: 17 additions & 6 deletions common/src/com/trovebox/android/common/model/utils/PhotoUtils.java
Expand Up @@ -54,17 +54,23 @@ public class PhotoUtils {
* @param photo the photo to check
* @param photoSize the required photo size
* @param runnable the runnable which will run with the validated photo
* @param preSizeRetrievalRunnable runnable to run before the retrieval task
* started
* @param loadingControl the loading control to display loading indicator
*/
public static void validateUrlForSizeExistAsyncAndRun(Photo photo, ReturnSizes photoSize,
RunnableWithParameter<Photo> runnable, LoadingControl loadingControl) {
RunnableWithParameter<Photo> runnable, Runnable preSizeRetrievalRunnable,
LoadingControl loadingControl) {
String size = photoSize.toString();
if (photo.getUrl(size) != null) {
CommonUtils.debug(TAG, "Url for the size " + size + " exists. Running action.");
runnable.run(photo);
} else {
CommonUtils.debug(TAG, "Url for the size " + size
+ " doesn't exist. Running size retrieval task.");
if (preSizeRetrievalRunnable != null) {
preSizeRetrievalRunnable.run();
}
new RetrieveThumbUrlTask(photo, photoSize, runnable, loadingControl).execute();
}
}
Expand Down Expand Up @@ -154,7 +160,7 @@ public static Photo getThePhotoWithReturnSize(Photo photo, ReturnSizes photoSize
TrackerUtils.trackBackgroundEvent("getThePhotoWithReturnSize", TAG);
long start = System.currentTimeMillis();
PhotoResponse response = CommonConfigurationUtils.getApi().getPhoto(photo.getId(),
photoSize);
photoSize, photo.getToken(), photo.getHost());
photo = response.getPhoto();
TrackerUtils.trackDataLoadTiming(System.currentTimeMillis() - start,
"getThePhotoWithReturnSize", TAG);
Expand Down Expand Up @@ -204,6 +210,7 @@ public static String getShareUrl(Photo photo, boolean appendToken) {

private static class RetrieveThumbUrlTask extends SimpleAsyncTaskEx {
private Photo mPhoto;
private Photo mPhoto2;
private ReturnSizes photoSize;
private RunnableWithParameter<Photo> runnable;

Expand All @@ -218,9 +225,7 @@ public RetrieveThumbUrlTask(Photo photo, ReturnSizes photoSize,
@Override
protected Boolean doInBackground(Void... params) {
try {
Photo mPhoto2 = getThePhotoWithReturnSize(mPhoto, photoSize);
String size = photoSize.toString();
mPhoto.putUrl(size, mPhoto2.getUrl(size));
mPhoto2 = getThePhotoWithReturnSize(mPhoto, photoSize);
return true;
} catch (Exception e) {
GuiUtils.error(TAG, R.string.errorCouldNotGetPhoto, e);
Expand All @@ -230,7 +235,13 @@ protected Boolean doInBackground(Void... params) {

@Override
protected void onSuccessPostExecute() {
runnable.run(mPhoto);
try {
String size = photoSize.toString();
mPhoto.putUrl(size, mPhoto2.getUrl(size));
runnable.run(mPhoto);
} catch (Exception ex) {
GuiUtils.error(TAG, R.string.errorCouldNotGetPhoto, ex);
}
}

}
Expand Down
4 changes: 3 additions & 1 deletion common/src/com/trovebox/android/common/net/ITroveboxApi.java
Expand Up @@ -67,13 +67,15 @@ AlbumResponse getAlbum(String albumId) throws ClientProtocolException,
*
* @param photoId id of the photo
* @param returnSize which sizes should be returned
* @param token access token for the photo if required
* @param host alternate host
* @return the photo
* @throws IOException
* @throws ClientProtocolException
* @throws JSONException
* @throws IllegalStateException
*/
PhotoResponse getPhoto(String photoId, ReturnSizes returnSize)
PhotoResponse getPhoto(String photoId, ReturnSizes returnSize, String token, String host)
throws ClientProtocolException, IOException, IllegalStateException,
JSONException;

Expand Down
13 changes: 9 additions & 4 deletions common/src/com/trovebox/android/common/net/TroveboxApi.java
Expand Up @@ -79,15 +79,20 @@ public AlbumResponse getAlbum(String albumId) throws ClientProtocolException, IO
}

@Override
public PhotoResponse getPhoto(String photoId, ReturnSizes returnSize)
public PhotoResponse getPhoto(String photoId, ReturnSizes returnSize, String token, String host)
throws ClientProtocolException, IOException, IllegalStateException,
JSONException {
ApiRequest request = new ApiRequest(ApiRequest.GET, "/photo/" + photoId
+ "/view.json");
StringBuilder path = new StringBuilder("/photo/" + photoId);

if (!TextUtils.isEmpty(token)) {
path.append("/token-" + token);
}
path.append("/view.json");
ApiRequest request = new ApiRequest(ApiRequest.GET, path.toString());
if (returnSize != null) {
request.addParameter("returnSizes", returnSize.toString());
}
ApiResponse response = execute(request);
ApiResponse response = TextUtils.isEmpty(host) ? execute(request) : execute(request, host);
return new PhotoResponse(RequestType.PHOTO, response.getJSONObject());
}

Expand Down
Expand Up @@ -270,6 +270,8 @@ public boolean isCancelled() {
if (uploadResponse.isSuccess()) {
Log.i(TAG, "Upload to Trovebox completed for: " + photoUpload.getPhotoUri());
photo = uploadResponse.getPhoto();
photo.setHost(photoUpload.getHost());
photo.setToken(photoUpload.getToken());
TrackerUtils.trackDataLoadTiming(System.currentTimeMillis() - start,
"photoUpload", TAG);
} else {
Expand Down
3 changes: 2 additions & 1 deletion test/src/com/trovebox/android/test/GalleryActivityTest.java
Expand Up @@ -58,7 +58,8 @@ public void testLoadsImages() throws ClientProtocolException,
R.raw.json_photos_get))).times(2);
getApiMock().getPhoto(
(String) EasyMock.anyObject(),
(ReturnSizes) EasyMock.anyObject()
(ReturnSizes) EasyMock.anyObject(),
(String) EasyMock.anyObject(), (String) EasyMock.anyObject()
);
PowerMock
.expectLastCall()
Expand Down
Expand Up @@ -47,7 +47,8 @@ public void testPreconditions() throws JSONException,

getApiMock().getPhoto(
(String) EasyMock.anyObject(),
(ReturnSizes) EasyMock.anyObject()
(ReturnSizes) EasyMock.anyObject(),
(String) EasyMock.anyObject(), (String) EasyMock.anyObject()
);
PowerMock
.expectLastCall()
Expand Down

0 comments on commit 40f2023

Please sign in to comment.