Search in sources :

Example 1 with RichObject

use of com.owncloud.android.lib.resources.activities.models.RichObject in project android by nextcloud.

the class ActivitiesListActivity method onActivityClicked.

@Override
public void onActivityClicked(RichObject richObject) {
    String path = FileUtils.PATH_SEPARATOR + richObject.getPath();
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
            swipeListRefreshLayout.setVisibility(View.GONE);
            setLoadingMessage();
        }
    });
    updateTask = new AsyncTask<String, Object, OCFile>() {

        @Override
        protected OCFile doInBackground(String... path) {
            OCFile ocFile = null;
            // always update file as it could be an old state saved in database
            ReadRemoteFileOperation operation = new ReadRemoteFileOperation(path[0]);
            RemoteOperationResult resultRemoteFileOp = operation.execute(ownCloudClient);
            if (resultRemoteFileOp.isSuccess()) {
                OCFile temp = FileStorageUtils.fillOCFile((RemoteFile) resultRemoteFileOp.getData().get(0));
                ocFile = getStorageManager().saveFileWithParent(temp, getBaseContext());
                if (ocFile.isFolder()) {
                    // perform folder synchronization
                    RemoteOperation synchFolderOp = new RefreshFolderOperation(ocFile, System.currentTimeMillis(), false, getFileOperationsHelper().isSharedSupported(), true, getStorageManager(), getAccount(), getApplicationContext());
                    synchFolderOp.execute(ownCloudClient);
                }
            }
            return ocFile;
        }

        @Override
        protected void onPostExecute(OCFile ocFile) {
            if (!isCancelled()) {
                if (ocFile == null) {
                    Toast.makeText(getBaseContext(), R.string.file_not_found, Toast.LENGTH_LONG).show();
                    swipeEmptyListRefreshLayout.setVisibility(View.GONE);
                    swipeListRefreshLayout.setVisibility(View.VISIBLE);
                    dismissLoadingDialog();
                } else {
                    Intent showDetailsIntent;
                    if (PreviewImageFragment.canBePreviewed(ocFile)) {
                        showDetailsIntent = new Intent(getBaseContext(), PreviewImageActivity.class);
                    } else {
                        showDetailsIntent = new Intent(getBaseContext(), FileDisplayActivity.class);
                    }
                    showDetailsIntent.putExtra(EXTRA_FILE, ocFile);
                    showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
                    startActivity(showDetailsIntent);
                }
            }
        }
    };
    updateTask.execute(path);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) RefreshFolderOperation(com.owncloud.android.operations.RefreshFolderOperation) ReadRemoteFileOperation(com.owncloud.android.lib.resources.files.ReadRemoteFileOperation) RichObject(com.owncloud.android.lib.resources.activities.models.RichObject) Intent(android.content.Intent) BindString(butterknife.BindString) RemoteFile(com.owncloud.android.lib.resources.files.RemoteFile)

Aggregations

Intent (android.content.Intent)1 BindString (butterknife.BindString)1 OCFile (com.owncloud.android.datamodel.OCFile)1 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 RichObject (com.owncloud.android.lib.resources.activities.models.RichObject)1 ReadRemoteFileOperation (com.owncloud.android.lib.resources.files.ReadRemoteFileOperation)1 RemoteFile (com.owncloud.android.lib.resources.files.RemoteFile)1 RefreshFolderOperation (com.owncloud.android.operations.RefreshFolderOperation)1