use of com.trovebox.android.common.model.Photo in project mobile-android by photo.
the class TwitterFragment method init.
void init(View view, Bundle savedInstanceState) {
try {
new ShowCurrentlyLoggedInUserTask(view).execute();
messageEt = (EditText) view.findViewById(R.id.message);
if (savedInstanceState != null) {
messageEt.setText(savedInstanceState.getString(TWEET));
textModified = savedInstanceState.getBoolean(TEXT_MODIFIED);
photo = savedInstanceState.getParcelable(PHOTO);
} else {
String message = getDefaultTweetMessage(photo);
messageEt.setText(message);
}
messageEt.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
textModified = true;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
Button logOutButton = (Button) view.findViewById(R.id.logoutBtn);
logOutButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TrackerUtils.trackButtonClickEvent("logoutBtn", TwitterFragment.this);
performTwitterLogout();
}
});
sendButton = (Button) view.findViewById(R.id.sendBtn);
sendButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TrackerUtils.trackButtonClickEvent("sendBtn", TwitterFragment.this);
if (GuiUtils.checkLoggedInAndOnline()) {
postTweet();
}
}
});
if (!textModified) {
sendButton.setEnabled(false);
PhotoUtils.validateShareTokenExistsAsyncAndRunAsync(photo, new RunnableWithParameter<Photo>() {
@Override
public void run(Photo parameter) {
sendButton.setEnabled(true);
String message = getDefaultTweetMessage(photo, true);
messageEt.setText(message);
}
}, new Runnable() {
@Override
public void run() {
sendButton.setEnabled(false);
}
}, new TweetLoadingControl(view));
}
} catch (Exception ex) {
GuiUtils.error(TAG, R.string.errorCouldNotInitTwitterFragment, ex, getActivity());
dismissAllowingStateLoss();
}
}
use of com.trovebox.android.common.model.Photo in project mobile-android by photo.
the class FacebookFragment method init.
void init(View view) {
try {
new ShowCurrentlyLoggedInUserTask(view).execute();
messageEt = (EditText) view.findViewById(R.id.message);
messageEt.setText(null);
Button logOutButton = (Button) view.findViewById(R.id.logoutBtn);
logOutButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TrackerUtils.trackButtonClickEvent("logoutBtn", FacebookFragment.this);
performFacebookLogout();
}
});
sendButton = (Button) view.findViewById(R.id.sendBtn);
sendButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TrackerUtils.trackButtonClickEvent("sendBtn", FacebookFragment.this);
if (GuiUtils.checkLoggedInAndOnline()) {
postPhoto();
}
}
});
{
sendButton.setEnabled(false);
PhotoUtils.validateShareTokenExistsAsyncAndRunAsync(photo, new RunnableWithParameter<Photo>() {
@Override
public void run(Photo parameter) {
sendButton.setEnabled(true);
}
}, new Runnable() {
@Override
public void run() {
sendButton.setEnabled(false);
}
}, new FBLoadingControl(view));
}
} catch (Exception ex) {
GuiUtils.error(TAG, R.string.errorCouldNotInitFacebookFragment, ex, getActivity());
dismissAllowingStateLoss();
}
}
use of com.trovebox.android.common.model.Photo in project mobile-android by photo.
the class PhotoDetailsFragment method initFromIntent.
public int initFromIntent(Intent intent) {
int position = -1;
if (intent.hasExtra(EXTRA_PHOTO)) {
Photo photo = intent.getParcelableExtra(EXTRA_PHOTO);
ArrayList<Photo> photos = new ArrayList<Photo>();
photos.add(photo);
thumbnailsAdapter = new ThumbnailsAdapter(photos);
position = 0;
} else if (intent.hasExtra(EXTRA_PHOTOS)) {
ArrayList<Photo> photos = intent.getParcelableArrayListExtra(EXTRA_PHOTOS);
thumbnailsAdapter = new ThumbnailsAdapter(photos);
position = 0;
} else if (intent.hasExtra(EXTRA_ADAPTER_PHOTOS)) {
PhotosEndlessAdapter.ParametersHolder parameters = (ParametersHolder) intent.getParcelableExtra(EXTRA_ADAPTER_PHOTOS);
position = parameters.getPosition();
thumbnailsAdapter = new ThumbnailsAdapter(parameters);
}
return position;
}
use of com.trovebox.android.common.model.Photo in project mobile-android by photo.
the class PhotoDetailsActivityTest method testPreconditions.
public void testPreconditions() throws JSONException, ClientProtocolException, IllegalStateException, IOException {
// Setup mock calls and their responses
PowerMock.reset(getApiMock());
getApiMock().getPhoto((String) EasyMock.anyObject(), (ReturnSizes) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject());
PowerMock.expectLastCall().andReturn(new PhotoResponse(RequestType.UNKNOWN, JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_photo_get))).times(2);
PowerMock.replayAll();
Intent intent = new Intent();
Photo photo = Photo.fromJson(JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_photo));
intent.putExtra(PhotoDetailsUiFragment.EXTRA_PHOTO, photo);
setActivityIntent(intent);
activity = this.getActivity();
Fragment fragment = activity.getSupportFragmentManager().findFragmentById(android.R.id.content);
Assert.assertNotNull(fragment);
Assert.assertTrue(fragment instanceof PhotoDetailsUiFragment);
}
use of com.trovebox.android.common.model.Photo in project mobile-android by photo.
the class AbstractUploaderService method handleIntent.
private void handleIntent(Intent intent) {
if (!GuiUtils.checkLoggedInAndOnline(true)) {
return;
}
UploadsProviderAccessor uploads = new UploadsProviderAccessor(this);
List<PhotoUpload> pendingUploads;
synchronized (mIdsToSkip) {
mIdsToSkip.clear();
pendingUploads = uploads.getPendingUploads();
}
boolean hasSuccessfulUploads = false;
NotificationCompat.Builder successNotification = getStandardSuccessNotification();
NotificationCompat.Builder errorNotification = getStandardErrorNotification();
int uploadedCount = 0;
int skippedCount = 0;
int successNotificationId = requestCounter++;
int errorNotificationId = requestCounter++;
ArrayList<Photo> uploadedPhotos = new ArrayList<Photo>();
List<PhotoUploadDetails> uploadDetails = new ArrayList<PhotoUploadDetails>();
ArrayList<PhotoUpload> errorUploads = new ArrayList<PhotoUpload>();
List<PhotoUploadDetails> errorDetails = new ArrayList<PhotoUploadDetails>();
for (final PhotoUpload photoUpload : pendingUploads) {
if (!GuiUtils.checkLoggedInAndOnline(true)) {
return;
}
Log.i(TAG, "Starting upload to Trovebox: " + photoUpload.getPhotoUri());
if (isUploadRemoved(photoUpload)) {
CommonUtils.info(TAG, "Upload skipped, because it was canceled externally");
continue;
}
String filePath = ImageUtils.getRealPathFromURI(this, photoUpload.getPhotoUri());
if (filePath == null || !(new File(filePath).exists())) {
uploads.delete(photoUpload.getId());
// TODO: Maybe set error, and set as "do not try again"
CommonUtils.info(TAG, "Upload canceled, because file does not exist anymore.");
UploaderServiceUtils.sendPhotoUploadRemovedBroadcast(photoUpload);
continue;
}
boolean wifiOnlyUpload = CommonConfigurationUtils.isWiFiOnlyUploadActive();
if (wifiOnlyUpload && !CommonUtils.isWiFiActive()) {
CommonUtils.info(TAG, "Upload canceled because WiFi is not active anymore");
break;
}
File file = new File(filePath);
stopErrorNotification(file);
try {
boolean skipped = false;
Photo photo = null;
if (mCheckPhotoExistingOnServer) {
String hash = SHA1Utils.computeSha1ForFile(filePath);
PhotosResponse photos = mApi.getPhotos(hash);
if (!photos.isSuccess()) {
uploads.setError(photoUpload.getId(), photos.getAlertMessage());
photoUpload.setError(photos.getAlertMessage());
addErrorDetailsAndUpdateErrorNotification(errorNotification, errorNotificationId, errorUploads, errorDetails, photoUpload, file);
if (!isUploadRemoved(photoUpload)) {
UploaderServiceUtils.sendPhotoUploadUpdatedBroadcast(photoUpload);
}
continue;
}
if (photos.getPhotos().size() > 0) {
CommonUtils.debug(TAG, "The photo " + filePath + " with hash " + hash + " already found on the server. Skip uploading");
skipped = true;
photo = photos.getPhotos().get(0);
}
}
if (isUploadRemoved(photoUpload)) {
CommonUtils.info(TAG, "Upload skipped, because it was canceled externally");
continue;
}
if (photo == null) {
long start = System.currentTimeMillis();
final Notification notification = CommonUtils.isIceCreamSandwichOrHigher() ? null : showUploadNotification(file);
final NotificationCompat.Builder builder = CommonUtils.isIceCreamSandwichOrHigher() ? getStandardUploadNotification(file) : null;
UploadMetaData metaData = photoUpload.getMetaData();
if (!isUploadRemoved(photoUpload)) {
UploaderServiceUtils.sendPhotoUploadUpdatedBroadcast(photoUpload, 0);
}
UploadResponse uploadResponse = mApi.uploadPhoto(file, metaData, photoUpload.getToken(), photoUpload.getHost(), new ProgressListener() {
private int mLastProgress = -1;
private boolean mCancelled;
@Override
public void transferred(long transferedBytes, long totalBytes) {
int newProgress = (int) (transferedBytes * 100 / totalBytes);
if (mLastProgress < newProgress) {
mLastProgress = newProgress;
if (mCancelled || isUploadRemoved(photoUpload)) {
if (!mCancelled) {
CommonUtils.info(TAG, "Upload interrupted, because it was canceled externally");
mCancelled = true;
// stopUploadNotification();
}
}
// else
{
if (!mCancelled) {
UploaderServiceUtils.sendPhotoUploadUpdatedBroadcast(photoUpload, mLastProgress);
}
if (builder != null) {
updateUploadNotification(builder, mLastProgress, 100);
} else {
updateUploadNotification(notification, mLastProgress, 100);
}
}
}
}
@Override
public boolean isCancelled() {
// is detached.
return false;
}
});
// }
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 {
uploads.setError(photoUpload.getId(), uploadResponse.getAlertMessage());
photoUpload.setError(uploadResponse.getAlertMessage());
addErrorDetailsAndUpdateErrorNotification(errorNotification, errorNotificationId, errorUploads, errorDetails, photoUpload, file);
stopUploadNotification();
if (!isUploadRemoved(photoUpload)) {
UploaderServiceUtils.sendPhotoUploadUpdatedBroadcast(photoUpload);
}
continue;
}
}
adjustRemainingUploadingLimit(-1);
hasSuccessfulUploads = true;
long uploaded = uploads.setUploaded(photoUpload.getId());
photoUpload.setUploaded(uploaded);
if (!isUploadRemoved(photoUpload)) {
UploaderServiceUtils.sendPhotoUploadUpdatedBroadcast(photoUpload);
}
if (skipped) {
skippedCount++;
} else {
uploadedCount++;
}
uploadedPhotos.add(photo);
uploadDetails.add(new PhotoUploadDetails(photoUpload, skipped, file));
updateSuccessNotification(successNotification, uploadedCount, skippedCount, uploadedPhotos, uploadDetails, successNotificationId);
shareIfRequested(photoUpload, photo, true);
if (!skipped) {
TrackerUtils.trackServiceEvent("photo_upload", TAG);
if (!isUploadRemoved(photoUpload)) {
UploaderServiceUtils.sendPhotoUploadedBroadcast();
}
mUploadCounters.increment(photoUpload.getToken(), photoUpload.getUserName(), photoUpload.getHost());
} else {
TrackerUtils.trackServiceEvent("photo_upload_skip", TAG);
}
} catch (Exception e) {
CommonUtils.error(TAG, e);
uploads.setError(photoUpload.getId(), e.getClass().getSimpleName() + ": " + e.getLocalizedMessage());
photoUpload.setError(e.getClass().getSimpleName() + ": " + e.getLocalizedMessage());
addErrorDetailsAndUpdateErrorNotification(errorNotification, errorNotificationId, errorUploads, errorDetails, photoUpload, file);
if (!isUploadRemoved(photoUpload)) {
UploaderServiceUtils.sendPhotoUploadUpdatedBroadcast(photoUpload);
}
}
stopUploadNotification();
}
mUploadCounters.notifyServer(mApi);
// update limit information only in case we had successful uploads
if (hasSuccessfulUploads) {
runAfterSuccessfullUploads();
}
}
Aggregations