Search in sources :

Example 1 with Photo

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();
    }
}
Also used : Photo(com.trovebox.android.common.model.Photo) View(android.view.View) TextView(android.widget.TextView) TwitterException(twitter4j.TwitterException) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) OnClickListener(android.view.View.OnClickListener)

Example 2 with Photo

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();
    }
}
Also used : Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) RunnableWithParameter(com.trovebox.android.common.util.RunnableWithParameter) Photo(com.trovebox.android.common.model.Photo) View(android.view.View) TextView(android.widget.TextView) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with Photo

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;
}
Also used : PhotosEndlessAdapter(com.trovebox.android.common.ui.adapter.PhotosEndlessAdapter) ParametersHolder(com.trovebox.android.common.ui.adapter.PhotosEndlessAdapter.ParametersHolder) ArrayList(java.util.ArrayList) Photo(com.trovebox.android.common.model.Photo) ParametersHolder(com.trovebox.android.common.ui.adapter.PhotosEndlessAdapter.ParametersHolder)

Example 4 with Photo

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);
}
Also used : PhotoResponse(com.trovebox.android.common.net.PhotoResponse) PhotoDetailsUiFragment(com.trovebox.android.app.PhotoDetailsActivity.PhotoDetailsUiFragment) Intent(android.content.Intent) Photo(com.trovebox.android.common.model.Photo) Fragment(android.support.v4.app.Fragment) PhotoDetailsUiFragment(com.trovebox.android.app.PhotoDetailsActivity.PhotoDetailsUiFragment)

Example 5 with Photo

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();
    }
}
Also used : ArrayList(java.util.ArrayList) Photo(com.trovebox.android.common.model.Photo) UploadMetaData(com.trovebox.android.common.net.UploadMetaData) PhotoUpload(com.trovebox.android.common.provider.PhotoUpload) Notification(android.app.Notification) UploadResponse(com.trovebox.android.common.net.UploadResponse) ProgressListener(com.trovebox.android.common.net.HttpEntityWithProgress.ProgressListener) NotificationCompat(android.support.v4.app.NotificationCompat) PhotosResponse(com.trovebox.android.common.net.PhotosResponse) UploadsProviderAccessor(com.trovebox.android.common.provider.UploadsProviderAccessor) File(java.io.File)

Aggregations

Photo (com.trovebox.android.common.model.Photo)17 Intent (android.content.Intent)5 IOException (java.io.IOException)5 JSONException (org.json.JSONException)5 ClientProtocolException (org.apache.http.client.ClientProtocolException)4 View (android.view.View)3 TextView (android.widget.TextView)3 UploadMetaData (com.trovebox.android.common.net.UploadMetaData)3 UploadResponse (com.trovebox.android.common.net.UploadResponse)3 RunnableWithParameter (com.trovebox.android.common.util.RunnableWithParameter)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 IntentFilter (android.content.IntentFilter)2 OnClickListener (android.view.View.OnClickListener)2 Button (android.widget.Button)2 PhotoResponse (com.trovebox.android.common.net.PhotoResponse)2 PhotosResponse (com.trovebox.android.common.net.PhotosResponse)2 Notification (android.app.Notification)1