Search in sources :

Example 1 with OwnCloudVersion

use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.

the class FileUploader method onStartCommand.

/**
     * Entry point to add one or several files to the queue of uploads.
     *
     * New uploads are added calling to startService(), resulting in a call to
     * this method. This ensures the service will keep on working although the
     * caller activity goes away.
     */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);
    boolean retry = intent.getBooleanExtra(KEY_RETRY, false);
    AbstractList<String> requestedUploads = new Vector<String>();
    if (!intent.hasExtra(KEY_ACCOUNT)) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return Service.START_NOT_STICKY;
    }
    Account account = intent.getParcelableExtra(KEY_ACCOUNT);
    if (!AccountUtils.exists(account, getApplicationContext())) {
        return Service.START_NOT_STICKY;
    }
    OwnCloudVersion ocv = AccountUtils.getServerVersion(account);
    boolean chunked = ocv.isChunkedUploadSupported();
    if (!retry) {
        if (!(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) {
            Log_OC.e(TAG, "Not enough information provided in intent");
            return Service.START_NOT_STICKY;
        }
        String[] localPaths = null, remotePaths = null, mimeTypes = null;
        OCFile[] files = null;
        if (intent.hasExtra(KEY_FILE)) {
            Parcelable[] files_temp = intent.getParcelableArrayExtra(KEY_FILE);
            files = new OCFile[files_temp.length];
            System.arraycopy(files_temp, 0, files, 0, files_temp.length);
        } else {
            localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE);
            remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE);
            mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
        }
        boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
        int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
        boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
        int createdBy = intent.getIntExtra(KEY_CREATED_BY, UploadFileOperation.CREATED_BY_USER);
        if (intent.hasExtra(KEY_FILE) && files == null) {
            Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
            return Service.START_NOT_STICKY;
        } else if (!intent.hasExtra(KEY_FILE)) {
            if (localPaths == null) {
                Log_OC.e(TAG, "Incorrect array for local paths provided in upload intent");
                return Service.START_NOT_STICKY;
            }
            if (remotePaths == null) {
                Log_OC.e(TAG, "Incorrect array for remote paths provided in upload intent");
                return Service.START_NOT_STICKY;
            }
            if (localPaths.length != remotePaths.length) {
                Log_OC.e(TAG, "Different number of remote paths and local paths!");
                return Service.START_NOT_STICKY;
            }
            files = new OCFile[localPaths.length];
            for (int i = 0; i < localPaths.length; i++) {
                files[i] = UploadFileOperation.obtainNewOCFileToUpload(remotePaths[i], localPaths[i], ((mimeTypes != null) ? mimeTypes[i] : null));
                if (files[i] == null) {
                    Log_OC.e(TAG, "obtainNewOCFileToUpload() returned null for remotePaths[i]:" + remotePaths[i] + " and localPaths[i]:" + localPaths[i]);
                    return Service.START_NOT_STICKY;
                }
            }
        }
        // at this point variable "OCFile[] files" is loaded correctly.
        String uploadKey = null;
        UploadFileOperation newUpload = null;
        try {
            for (int i = 0; i < files.length; i++) {
                OCUpload ocUpload = new OCUpload(files[i], account);
                ocUpload.setFileSize(files[i].getFileLength());
                ocUpload.setForceOverwrite(forceOverwrite);
                ocUpload.setCreateRemoteFolder(isCreateRemoteFolder);
                ocUpload.setCreatedBy(createdBy);
                ocUpload.setLocalAction(localAction);
                /*ocUpload.setUseWifiOnly(isUseWifiOnly);
                    ocUpload.setWhileChargingOnly(isWhileChargingOnly);*/
                ocUpload.setUploadStatus(UploadStatus.UPLOAD_IN_PROGRESS);
                newUpload = new UploadFileOperation(account, files[i], ocUpload, chunked, forceOverwrite, localAction, this);
                newUpload.setCreatedBy(createdBy);
                if (isCreateRemoteFolder) {
                    newUpload.setRemoteFolderToBeCreated();
                }
                newUpload.addDatatransferProgressListener(this);
                newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
                newUpload.addRenameUploadListener(this);
                Pair<String, String> putResult = mPendingUploads.putIfAbsent(account.name, files[i].getRemotePath(), newUpload);
                if (putResult != null) {
                    uploadKey = putResult.first;
                    requestedUploads.add(uploadKey);
                    // Save upload in database
                    long id = mUploadsStorageManager.storeUpload(ocUpload);
                    newUpload.setOCUploadId(id);
                }
            }
        } catch (IllegalArgumentException e) {
            Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
            return START_NOT_STICKY;
        } catch (IllegalStateException e) {
            Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
            return START_NOT_STICKY;
        } catch (Exception e) {
            Log_OC.e(TAG, "Unexpected exception while processing upload intent", e);
            return START_NOT_STICKY;
        }
    // *** TODO REWRITE: block inserted to request A retry; too many code copied, no control exception ***/
    } else {
        if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_RETRY_UPLOAD)) {
            Log_OC.e(TAG, "Not enough information provided in intent: no KEY_RETRY_UPLOAD_KEY");
            return START_NOT_STICKY;
        }
        OCUpload upload = intent.getParcelableExtra(KEY_RETRY_UPLOAD);
        UploadFileOperation newUpload = new UploadFileOperation(account, null, upload, chunked, // TODO should be read from DB?
        upload.isForceOverwrite(), // TODO should be read from DB?
        upload.getLocalAction(), this);
        newUpload.addDatatransferProgressListener(this);
        newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
        newUpload.addRenameUploadListener(this);
        Pair<String, String> putResult = mPendingUploads.putIfAbsent(account.name, upload.getRemotePath(), newUpload);
        if (putResult != null) {
            String uploadKey = putResult.first;
            requestedUploads.add(uploadKey);
            // Update upload in database
            upload.setUploadStatus(UploadStatus.UPLOAD_IN_PROGRESS);
            mUploadsStorageManager.updateUpload(upload);
        }
    }
    if (requestedUploads.size() > 0) {
        Message msg = mServiceHandler.obtainMessage();
        msg.arg1 = startId;
        msg.obj = requestedUploads;
        mServiceHandler.sendMessage(msg);
        sendBroadcastUploadsAdded();
    }
    return Service.START_NOT_STICKY;
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) Message(android.os.Message) Parcelable(android.os.Parcelable) UploadFileOperation(com.owncloud.android.operations.UploadFileOperation) OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) Vector(java.util.Vector) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion)

Example 2 with OwnCloudVersion

use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.

the class AccountUtils method hasSearchUsersSupport.

public static boolean hasSearchUsersSupport(Account account) {
    OwnCloudVersion serverVersion = null;
    if (account != null) {
        AccountManager accountMgr = AccountManager.get(MainApp.getAppContext());
        String serverVersionStr = accountMgr.getUserData(account, Constants.KEY_OC_VERSION);
        if (serverVersionStr != null) {
            serverVersion = new OwnCloudVersion(serverVersionStr);
        }
    }
    return (serverVersion != null ? serverVersion.isSearchUsersSupported() : false);
}
Also used : AccountManager(android.accounts.AccountManager) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion)

Example 3 with OwnCloudVersion

use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.

the class EditShareFragment method refreshUiFromState.

/**
     * Updates the UI with the current permissions in the edited {@OCShare}
     *
     * @param editShareView     Root view in the fragment.
     */
private void refreshUiFromState(View editShareView) {
    if (editShareView != null) {
        setPermissionsListening(editShareView, false);
        int sharePermissions = mShare.getPermissions();
        boolean isFederated = ShareType.FEDERATED.equals(mShare.getShareType());
        OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mAccount);
        boolean isNotReshareableFederatedSupported = (serverVersion != null && serverVersion.isNotReshareableFederatedSupported());
        CompoundButton compound;
        compound = (CompoundButton) editShareView.findViewById(R.id.canShareSwitch);
        if (isFederated && !isNotReshareableFederatedSupported) {
            compound.setVisibility(View.INVISIBLE);
        }
        compound.setChecked((sharePermissions & OCShare.SHARE_PERMISSION_FLAG) > 0);
        compound = (CompoundButton) editShareView.findViewById(R.id.canEditSwitch);
        int anyUpdatePermission = OCShare.CREATE_PERMISSION_FLAG | OCShare.UPDATE_PERMISSION_FLAG | OCShare.DELETE_PERMISSION_FLAG;
        boolean canEdit = (sharePermissions & anyUpdatePermission) > 0;
        compound.setChecked(canEdit);
        boolean areEditOptionsAvailable = !isFederated || isNotReshareableFederatedSupported;
        if (mFile.isFolder() && areEditOptionsAvailable) {
            /// TODO change areEditOptionsAvailable in order to delete !isFederated
            // from checking when iOS is ready
            compound = (CompoundButton) editShareView.findViewById(R.id.canEditCreateCheckBox);
            compound.setChecked((sharePermissions & OCShare.CREATE_PERMISSION_FLAG) > 0);
            compound.setVisibility((canEdit) ? View.VISIBLE : View.GONE);
            compound = (CompoundButton) editShareView.findViewById(R.id.canEditChangeCheckBox);
            compound.setChecked((sharePermissions & OCShare.UPDATE_PERMISSION_FLAG) > 0);
            compound.setVisibility((canEdit) ? View.VISIBLE : View.GONE);
            compound = (CompoundButton) editShareView.findViewById(R.id.canEditDeleteCheckBox);
            compound.setChecked((sharePermissions & OCShare.DELETE_PERMISSION_FLAG) > 0);
            compound.setVisibility((canEdit) ? View.VISIBLE : View.GONE);
        }
        setPermissionsListening(editShareView, true);
    }
}
Also used : OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion) CompoundButton(android.widget.CompoundButton)

Example 4 with OwnCloudVersion

use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.

the class OCFileListFragment method updateLayout.

private void updateLayout() {
    if (!isShowingJustFolders()) {
        int filesCount = 0, foldersCount = 0;
        int count = mAdapter.getCount();
        OCFile file;
        for (int i = 0; i < count; i++) {
            file = (OCFile) mAdapter.getItem(i);
            if (file.isFolder()) {
                foldersCount++;
            } else {
                if (!file.isHidden()) {
                    filesCount++;
                }
            }
        }
        // set footer text
        setFooterText(generateFooterText(filesCount, foldersCount));
        // decide grid vs list view
        OwnCloudVersion version = AccountUtils.getServerVersion(((FileActivity) mContainerActivity).getAccount());
        if (version != null && version.supportsRemoteThumbnails() && isGridViewPreferred(mFile)) {
            switchToGridView();
        } else {
            switchToListView();
        }
    }
    invalidateActionMode();
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion)

Example 5 with OwnCloudVersion

use of com.owncloud.android.lib.resources.status.OwnCloudVersion in project android by owncloud.

the class AccountUtils method getServerVersion.

/**
     * Access the version of the OC server corresponding to an account SAVED IN THE ACCOUNTMANAGER
     *
     * @param   account     ownCloud account
     * @return              Version of the OC server corresponding to account, according to the data saved
     *                      in the system AccountManager
     */
public static OwnCloudVersion getServerVersion(Account account) {
    OwnCloudVersion serverVersion = null;
    if (account != null) {
        AccountManager accountMgr = AccountManager.get(MainApp.getAppContext());
        String serverVersionStr = accountMgr.getUserData(account, Constants.KEY_OC_VERSION);
        if (serverVersionStr != null) {
            serverVersion = new OwnCloudVersion(serverVersionStr);
        }
    }
    return serverVersion;
}
Also used : AccountManager(android.accounts.AccountManager) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion)

Aggregations

OwnCloudVersion (com.owncloud.android.lib.resources.status.OwnCloudVersion)9 AccountManager (android.accounts.AccountManager)3 OCFile (com.owncloud.android.datamodel.OCFile)2 Account (android.accounts.Account)1 Message (android.os.Message)1 Parcelable (android.os.Parcelable)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 OnTouchListener (android.view.View.OnTouchListener)1 WebView (android.webkit.WebView)1 CompoundButton (android.widget.CompoundButton)1 TextView (android.widget.TextView)1 OCUpload (com.owncloud.android.db.OCUpload)1 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)1 OwnCloudCredentials (com.owncloud.android.lib.common.OwnCloudCredentials)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 UploadFileOperation (com.owncloud.android.operations.UploadFileOperation)1 Vector (java.util.Vector)1