use of com.trovebox.android.common.model.Photo in project mobile-android by photo.
the class PhotoUtils method getAndRegisterOnPhotoUpdatedActionBroadcastReceiver.
/**
* Get and register the broadcast receiver for the photo updated event
*
* @param TAG
* @param handler
* @param activity
* @return
*/
public static BroadcastReceiver getAndRegisterOnPhotoUpdatedActionBroadcastReceiver(final String TAG, final PhotoUpdatedHandler handler, final Activity activity) {
BroadcastReceiver br = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
CommonUtils.debug(TAG, "Received photo updated broadcast message");
Photo photo = intent.getParcelableExtra(PHOTO_UPDATED);
handler.photoUpdated(photo);
} catch (Exception ex) {
GuiUtils.error(TAG, ex);
}
}
};
activity.registerReceiver(br, new IntentFilter(PHOTO_UPDATED_ACTION));
return br;
}
use of com.trovebox.android.common.model.Photo in project mobile-android by photo.
the class AlbumTest method testAlbumData.
public void testAlbumData(Album album) {
assertNotNull(album);
assertEquals("4", album.getId());
assertEquals("hello@openphoto.me", album.getOwner());
assertEquals("Beautiful Scenery", album.getName());
assertEquals(0, album.getVisible());
assertEquals(13, album.getCount());
Photo cover = album.getCover();
assertNotNull(cover);
assertEquals("bd", cover.getId());
}
use of com.trovebox.android.common.model.Photo in project mobile-android by photo.
the class TroveboxApiTest method testCreateTokenForPhoto.
public void testCreateTokenForPhoto() throws Exception {
File file = createTestFileForUpload();
boolean priv = true;
UploadMetaData settings = new UploadMetaData();
String title = "Android";
String description = "Nice picture of an android";
String tags = "test";
settings.setTitle(title);
settings.setDescription(description);
settings.setTags(tags);
settings.setPrivate(priv);
try {
String hash = SHA1Utils.computeSha1ForFile(file.getAbsolutePath());
PhotosResponse photos = mApi.getPhotos(hash);
assertTrue(photos.isSuccess());
boolean created = false;
Photo photo;
if (photos.getPhotos().size() > 0) {
photo = photos.getPhotos().get(0);
} else {
UploadResponse resp = mApi.uploadPhoto(file, settings, null);
assertTrue(resp.isSuccess());
assertNotNull(resp.getPhoto());
photo = resp.getPhoto();
created = true;
}
try {
assertNotNull(photo);
assertTrue(photo.getTags().size() >= 1);
// assertEquals("test", resp.getPhoto().getTags().get(0));
assertEquals(title, photo.getTitle());
assertEquals(description, photo.getDescription());
assertEquals(priv, photo.isPrivate());
TokenResponse tokenResponse = mApi.createTokenForPhoto(photo.getId());
assertEquals(tokenResponse.getCode(), 201);
Token token = tokenResponse.getToken();
assertNotNull(token);
assertEquals(token.getType(), "photo");
assertEquals(token.getData(), photo.getId());
assertNotNull(token.getId());
assertFalse(token.getId().isEmpty());
System.out.println(token.getDateExpires());
assertNotNull(token.getDateExpires());
} finally {
if (created) {
// remove uploaded photo
mApi.deletePhoto(photo.getId());
}
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception should not happen: " + e.getClass().getSimpleName() + " - " + e.getMessage());
}
file.delete();
}
use of com.trovebox.android.common.model.Photo in project mobile-android by photo.
the class TroveboxApiTest method testPhotoUploadAndDetailsEdit.
public void testPhotoUploadAndDetailsEdit() throws Exception {
File file = createTestFileForUpload();
UploadMetaData settings = new UploadMetaData();
String title = "Android";
String description = "Nice picture of an android";
String tags = "test";
boolean priv = false;
settings.setTitle(title);
settings.setDescription(description);
settings.setTags(tags);
settings.setPrivate(priv);
try {
UploadResponse resp = mApi.uploadPhoto(file, settings, null);
assertTrue(resp.isSuccess());
assertNotNull(resp.getPhoto());
try {
Photo photo = resp.getPhoto();
assertNotNull(photo);
assertTrue(photo.getTags().size() >= 1);
// assertEquals("test", resp.getPhoto().getTags().get(0));
assertEquals(title, photo.getTitle());
assertEquals(description, photo.getDescription());
assertFalse(photo.isPrivate());
title = "Android (Edited)";
description = "Nice picture of an android (Edited)";
tags = "edited";
Collection<String> tagsCollection = new ArrayList<String>();
tagsCollection.add("edited");
priv = true;
PhotoResponse photoResp = mApi.updatePhotoDetails(photo.getId(), title, description, tagsCollection, Photo.PERMISSION_PRIVATE);
photo = photoResp.getPhoto();
assertTrue(photoResp.isSuccess());
assertNotNull(photo);
assertTrue(photo.getTags().size() == 1);
assertEquals(tags, photo.getTags().get(0));
assertEquals(title, photo.getTitle());
assertEquals(description, photo.getDescription());
assertTrue(photo.isPrivate() == priv);
} finally {
// remove uploaded photo
mApi.deletePhoto(resp.getPhoto().getId());
}
} catch (Exception e) {
fail("Exception should not happen: " + e.getClass().getSimpleName() + " - " + e.getMessage());
}
file.delete();
}
use of com.trovebox.android.common.model.Photo in project mobile-android by photo.
the class PhotoTest method testFromJson.
public void testFromJson() {
Photo photo;
try {
JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_photo);
photo = Photo.fromJson(json);
} catch (JSONException e) {
throw new AssertionError("This exception should not be thrown!");
}
assertNotNull(photo);
assertEquals("4t", photo.getId());
assertNotNull(photo.getTags());
assertTrue(photo.isPrivate());
assertEquals(2, photo.getTags().size());
assertEquals("sunnyvale", photo.getTags().get(0));
assertEquals("tavin", photo.getTags().get(1));
assertEquals("Tavin riding the horsey at Murphy Park in Sunnyvale", photo.getTitle());
assertEquals("Nice description", photo.getDescription());
assertEquals("current.trovebox.com", photo.getAppId());
assertEquals("http://opmecurrent.s3.amazonaws.com/base/201108/1312348300-IMAG0015.jpg", photo.getUrl("base"));
assertEquals("http://opmecurrent.s3.amazonaws.com/original/201108/1312348300-IMAG0015.jpg", photo.getUrl("original"));
assertEquals("http://opmecurrent.s3.amazonaws.com/custom/201108/1312348300-IMAG0015_960x960.jpg", photo.getUrl("960x960"));
assertEquals("http://opmecurrent.s3.amazonaws.com/custom/201108/1312348300-IMAG0015_50x50xCR.jpg", photo.getUrl("50x50xCR"));
}
Aggregations