Card 77 (Add photo details to Trovebox Collect)

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
This commit is contained in:
Eugene Popovich 2014-02-10 10:58:04 +02:00
parent 9fed259c19
commit 40f2023352
13 changed files with 115 additions and 15 deletions

View file

@ -143,6 +143,12 @@ public class AlbumsFragment extends CommonRefreshableFragmentWithImageWorker imp
.loadImage(photo.getUrl(thumbSize.toString()), image);
}
}, new Runnable() {
@Override
public void run() {
mImageWorker.loadImage(null, image);
}
}, loadingControl);
} else
{

View file

@ -157,7 +157,8 @@ public class FacebookFragment extends CommonStyledDialogFragment
new PostPhotoTask(photo).execute();
}
};
PhotoUtils.validateUrlForSizeExistAsyncAndRun(photo, thumbSize, runnable, loadingControl);
PhotoUtils.validateUrlForSizeExistAsyncAndRun(photo, thumbSize, runnable, null,
loadingControl);
}
private void performFacebookLogout()

View file

@ -230,6 +230,12 @@ public class SelectAlbumsActivity
.loadImage(photo.getUrl(thumbSize.toString()), vh.cover);
}
}, new Runnable() {
@Override
public void run() {
mImageWorker.loadImage(null, vh.cover);
}
}, SelectAlbumsUiFragment.this);
} else
{

View file

@ -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>

View file

@ -431,6 +431,12 @@ public abstract class GalleryFragment extends CommonRefreshableFragmentWithImage
photo, photo.getUrl(thumbSize.toString()));
mImageWorker.loadImage(fo, imageView);
}
}, new Runnable() {
@Override
public void run() {
mImageWorker.loadImage(null, imageView);
}
}, loadingControl);
}
};

View file

@ -501,7 +501,15 @@ public class PhotoDetailsFragment extends CommonFragmentWithImageWorker implemen
GuiUtils.noAlertError(TAG, ex);
}
}
}, loadingControl);
},
new Runnable() {
@Override
public void run() {
mImageWorker.loadImage(null, imageView);
}
},
loadingControl);
loadingControl.stopLoading();
@ -601,6 +609,12 @@ public class PhotoDetailsFragment extends CommonFragmentWithImageWorker implemen
String url = photo.getUrl(thumbSize.toString());
mImageWorker2.loadImage(url, imageView);
}
}, new Runnable() {
@Override
public void run() {
mImageWorker2.loadImage(null, imageView);
}
}, null);
return view;
}

View file

@ -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;
@ -149,6 +151,42 @@ public class Photo implements Parcelable {
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.
@ -247,6 +285,8 @@ public class Photo implements Parcelable {
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());
@ -283,6 +323,8 @@ public class Photo implements Parcelable {
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());

View file

@ -54,10 +54,13 @@ 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.");
@ -65,6 +68,9 @@ public class PhotoUtils {
} 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();
}
}
@ -154,7 +160,7 @@ public class PhotoUtils {
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);
@ -204,6 +210,7 @@ public class PhotoUtils {
private static class RetrieveThumbUrlTask extends SimpleAsyncTaskEx {
private Photo mPhoto;
private Photo mPhoto2;
private ReturnSizes photoSize;
private RunnableWithParameter<Photo> runnable;
@ -218,9 +225,7 @@ public class PhotoUtils {
@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);
@ -230,7 +235,13 @@ public class PhotoUtils {
@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);
}
}
}

View file

@ -67,13 +67,15 @@ public interface ITroveboxApi {
*
* @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;

View file

@ -79,15 +79,20 @@ public class TroveboxApi extends ApiBase implements ITroveboxApi {
}
@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());
}

View file

@ -270,6 +270,8 @@ public abstract class AbstractUploaderService extends Service implements PhotoUp
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 {

View file

@ -58,7 +58,8 @@ public class GalleryActivityTest extends
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()

View file

@ -47,7 +47,8 @@ public class PhotoDetailsActivityTest extends
getApiMock().getPhoto(
(String) EasyMock.anyObject(),
(ReturnSizes) EasyMock.anyObject()
(ReturnSizes) EasyMock.anyObject(),
(String) EasyMock.anyObject(), (String) EasyMock.anyObject()
);
PowerMock
.expectLastCall()