Search in sources :

Example 1 with FileDownloaderBinder

use of com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder in project android by owncloud.

the class FileMenuFilter method anyFileSynchronizing.

private boolean anyFileSynchronizing() {
    boolean synchronizing = false;
    if (mComponentsGetter != null && !mFiles.isEmpty() && mAccount != null) {
        OperationsServiceBinder opsBinder = mComponentsGetter.getOperationsServiceBinder();
        FileUploaderBinder uploaderBinder = mComponentsGetter.getFileUploaderBinder();
        FileDownloaderBinder downloaderBinder = mComponentsGetter.getFileDownloaderBinder();
        synchronizing = (// comparing local and remote
        anyFileSynchronizing(opsBinder) || anyFileDownloading(downloaderBinder) || anyFileUploading(uploaderBinder));
    }
    return synchronizing;
}
Also used : OperationsServiceBinder(com.owncloud.android.services.OperationsService.OperationsServiceBinder) FileUploaderBinder(com.owncloud.android.files.services.FileUploader.FileUploaderBinder) FileDownloaderBinder(com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder)

Example 2 with FileDownloaderBinder

use of com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder in project android by owncloud.

the class FileOperationsHelper method cancelTransference.

/**
     * Cancel the transference in downloads (files/folders) and file uploads
     * @param file OCFile
     */
public void cancelTransference(OCFile file) {
    Account account = mFileActivity.getAccount();
    if (file.isFolder()) {
        OperationsService.OperationsServiceBinder opsBinder = mFileActivity.getOperationsServiceBinder();
        if (opsBinder != null) {
            opsBinder.cancel(account, file);
        }
    }
    // for both files and folders
    FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder();
    if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) {
        downloaderBinder.cancel(account, file);
    }
    FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
    if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) {
        uploaderBinder.cancel(account, file);
    }
}
Also used : Account(android.accounts.Account) FileDownloaderBinder(com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder) FileUploaderBinder(com.owncloud.android.files.services.FileUploader.FileUploaderBinder) OperationsService(com.owncloud.android.services.OperationsService)

Example 3 with FileDownloaderBinder

use of com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder in project android by owncloud.

the class FileListListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    OCFile file = null;
    LayoutInflater inflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (mFiles != null && mFiles.size() > position) {
        file = mFiles.get(position);
    }
    // Find out which layout should be displayed
    ViewType viewType;
    if (parent instanceof GridView) {
        if (file != null && file.isImage()) {
            viewType = ViewType.GRID_IMAGE;
        } else {
            viewType = ViewType.GRID_ITEM;
        }
    } else {
        viewType = ViewType.LIST_ITEM;
    }
    // create view only if differs, otherwise reuse
    if (convertView == null || convertView.getTag() != viewType) {
        switch(viewType) {
            case GRID_IMAGE:
                view = inflator.inflate(R.layout.grid_image, parent, false);
                view.setTag(ViewType.GRID_IMAGE);
                break;
            case GRID_ITEM:
                view = inflator.inflate(R.layout.grid_item, parent, false);
                view.setTag(ViewType.GRID_ITEM);
                break;
            case LIST_ITEM:
                view = inflator.inflate(R.layout.list_item, parent, false);
                view.setTag(ViewType.LIST_ITEM);
                break;
        }
    }
    if (file != null) {
        ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);
        fileIcon.setTag(file.getFileId());
        TextView fileName;
        String name = file.getFileName();
        LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.ListItemLayout);
        linearLayout.setContentDescription("LinearLayout-" + name);
        switch(viewType) {
            case LIST_ITEM:
                TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
                TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator);
                TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
                lastModV.setVisibility(View.VISIBLE);
                lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.getModificationTimestamp()));
                fileSizeSeparatorV.setVisibility(View.VISIBLE);
                fileSizeV.setVisibility(View.VISIBLE);
                fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength(), mContext));
            case GRID_ITEM:
                // filename
                fileName = (TextView) view.findViewById(R.id.Filename);
                name = file.getFileName();
                fileName.setText(name);
            case GRID_IMAGE:
                // sharedIcon
                ImageView sharedIconV = (ImageView) view.findViewById(R.id.sharedIcon);
                if (file.isSharedViaLink()) {
                    sharedIconV.setImageResource(R.drawable.shared_via_link);
                    sharedIconV.setVisibility(View.VISIBLE);
                    sharedIconV.bringToFront();
                } else if (file.isSharedWithSharee() || file.isSharedWithMe()) {
                    sharedIconV.setImageResource(R.drawable.shared_via_users);
                    sharedIconV.setVisibility(View.VISIBLE);
                    sharedIconV.bringToFront();
                } else {
                    sharedIconV.setVisibility(View.GONE);
                }
                // local state
                ImageView localStateView = (ImageView) view.findViewById(R.id.localFileIndicator);
                localStateView.bringToFront();
                FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
                FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
                OperationsServiceBinder opsBinder = mTransferServiceGetter.getOperationsServiceBinder();
                // default first
                localStateView.setVisibility(View.INVISIBLE);
                if (//synchronizing
                opsBinder != null && opsBinder.isSynchronizing(mAccount, file)) {
                    localStateView.setImageResource(R.drawable.ic_synchronizing);
                    localStateView.setVisibility(View.VISIBLE);
                } else if (// downloading
                downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
                    localStateView.setImageResource(R.drawable.ic_synchronizing);
                    localStateView.setVisibility(View.VISIBLE);
                } else if (//uploading
                uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
                    localStateView.setImageResource(R.drawable.ic_synchronizing);
                    localStateView.setVisibility(View.VISIBLE);
                } else if (file.getEtagInConflict() != null) {
                    // conflict
                    localStateView.setImageResource(R.drawable.ic_synchronizing_error);
                    localStateView.setVisibility(View.VISIBLE);
                } else if (file.isDown()) {
                    localStateView.setImageResource(R.drawable.ic_synced);
                    localStateView.setVisibility(View.VISIBLE);
                }
                break;
        }
        // For all Views
        ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
        checkBoxV.setVisibility(View.GONE);
        view.setBackgroundColor(Color.WHITE);
        AbsListView parentList = (AbsListView) parent;
        if (parentList.getChoiceMode() != AbsListView.CHOICE_MODE_NONE && parentList.getCheckedItemCount() > 0) {
            if (parentList.isItemChecked(position)) {
                view.setBackgroundColor(mContext.getResources().getColor(R.color.selected_item_background));
                checkBoxV.setImageResource(R.drawable.ic_checkbox_marked);
            } else {
                view.setBackgroundColor(Color.WHITE);
                checkBoxV.setImageResource(R.drawable.ic_checkbox_blank_outline);
            }
            checkBoxV.setVisibility(View.VISIBLE);
        }
        // because android reuses views in listview
        if (file.getAvailableOfflineStatus() == OCFile.AvailableOfflineStatus.NOT_AVAILABLE_OFFLINE) {
            view.findViewById(R.id.favoriteIcon).setVisibility(View.GONE);
        } else {
            view.findViewById(R.id.favoriteIcon).setVisibility(View.VISIBLE);
        }
        // No Folder
        if (!file.isFolder()) {
            if (file.isImage() && file.getRemoteId() != null) {
                // Thumbnail in Cache?
                Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(String.valueOf(file.getRemoteId()));
                if (thumbnail != null && !file.needsUpdateThumbnail()) {
                    fileIcon.setImageBitmap(thumbnail);
                } else {
                    // generate new Thumbnail
                    if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, fileIcon)) {
                        final ThumbnailsCacheManager.ThumbnailGenerationTask task = new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon, mStorageManager, mAccount);
                        if (thumbnail == null) {
                            thumbnail = ThumbnailsCacheManager.mDefaultImg;
                        }
                        final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable = new ThumbnailsCacheManager.AsyncThumbnailDrawable(mContext.getResources(), thumbnail, task);
                        fileIcon.setImageDrawable(asyncDrawable);
                        task.execute(file);
                    }
                }
                if (file.getMimetype().equalsIgnoreCase("image/png")) {
                    fileIcon.setBackgroundColor(mContext.getResources().getColor(R.color.background_color));
                }
            } else {
                fileIcon.setImageResource(MimetypeIconUtil.getFileTypeIconId(file.getMimetype(), file.getFileName()));
            }
        } else {
            // Folder
            fileIcon.setImageResource(MimetypeIconUtil.getFolderTypeIconId(file.isSharedWithMe() || file.isSharedWithSharee(), file.isSharedViaLink()));
        }
    }
    return view;
}
Also used : OperationsServiceBinder(com.owncloud.android.services.OperationsService.OperationsServiceBinder) FileDownloaderBinder(com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder) AbsListView(android.widget.AbsListView) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) OCFile(com.owncloud.android.datamodel.OCFile) Bitmap(android.graphics.Bitmap) ThumbnailsCacheManager(com.owncloud.android.datamodel.ThumbnailsCacheManager) LayoutInflater(android.view.LayoutInflater) FileUploaderBinder(com.owncloud.android.files.services.FileUploader.FileUploaderBinder) TextView(android.widget.TextView) GridView(android.widget.GridView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 4 with FileDownloaderBinder

use of com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder in project android by owncloud.

the class FileDetailFragment method setButtonsForTransferring.

/**
     * Enables or disables buttons for a file being downloaded
     */
private void setButtonsForTransferring() {
    if (!isEmpty()) {
        // show the progress bar for the transfer
        getView().findViewById(R.id.fdProgressBlock).setVisibility(View.VISIBLE);
        TextView progressText = (TextView) getView().findViewById(R.id.fdProgressText);
        progressText.setVisibility(View.VISIBLE);
        FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
        FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
        //if (getFile().isDownloading()) {
        if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile())) {
            progressText.setText(R.string.downloader_download_in_progress_ticker);
        } else {
            if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, getFile())) {
                progressText.setText(R.string.uploader_upload_in_progress_ticker);
            }
        }
    }
}
Also used : FileDownloaderBinder(com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder) FileUploaderBinder(com.owncloud.android.files.services.FileUploader.FileUploaderBinder) TextView(android.widget.TextView)

Example 5 with FileDownloaderBinder

use of com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder in project android by owncloud.

the class FileDetailFragment method updateFileDetails.

/**
     * Updates the view with all relevant details about that file.
     *
     * @param forcedTransferring Flag signaling if the file should be considered as downloading or uploading,
     *                     although {@link FileDownloaderBinder#isDownloading(Account, OCFile)}  and
     *                     {@link FileUploaderBinder#isUploading(Account, OCFile)} return false.
     * @param refresh      If 'true', try to refresh the whole file from the database
     */
private void updateFileDetails(boolean forcedTransferring, boolean refresh) {
    if (readyToShow()) {
        FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
        if (refresh && storageManager != null) {
            setFile(storageManager.getFileByPath(getFile().getRemotePath()));
        }
        OCFile file = getFile();
        // set file details
        setFilename(file.getFileName());
        setFiletype(file);
        setFilesize(file.getFileLength());
        setTimeModified(file.getModificationTimestamp());
        // configure UI for depending upon local state of the file
        FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
        FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
        if (forcedTransferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file))) {
            setButtonsForTransferring();
        } else if (file.isDown()) {
            setButtonsForDown();
        } else {
            // TODO load default preview image; when the local file is removed, the preview
            // remains there
            setButtonsForRemote();
        }
    }
    getView().invalidate();
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileDownloaderBinder(com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder) FileUploaderBinder(com.owncloud.android.files.services.FileUploader.FileUploaderBinder) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Aggregations

FileDownloaderBinder (com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder)5 FileUploaderBinder (com.owncloud.android.files.services.FileUploader.FileUploaderBinder)5 TextView (android.widget.TextView)2 OCFile (com.owncloud.android.datamodel.OCFile)2 OperationsServiceBinder (com.owncloud.android.services.OperationsService.OperationsServiceBinder)2 Account (android.accounts.Account)1 Bitmap (android.graphics.Bitmap)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)1 ThumbnailsCacheManager (com.owncloud.android.datamodel.ThumbnailsCacheManager)1 OperationsService (com.owncloud.android.services.OperationsService)1