Search in sources :

Example 41 with OCFile

use of com.owncloud.android.datamodel.OCFile in project android by owncloud.

the class PreviewImageActivity method onPageSelected.

/**
     * This method will be invoked when a new page becomes selected. Animation is not necessarily
     * complete.
     * 
     *  @param  position        Position index of the new selected page
     */
@Override
public void onPageSelected(int position) {
    Log_OC.d(TAG, "onPageSelected " + position);
    if (getOperationsServiceBinder() != null) {
        mSavedPosition = position;
        mHasSavedPosition = true;
        OCFile currentFile = mPreviewImagePagerAdapter.getFileAt(position);
        getSupportActionBar().setTitle(currentFile.getFileName());
        setDrawerIndicatorEnabled(false);
        if (!mPreviewImagePagerAdapter.pendingErrorAt(position)) {
            getFileOperationsHelper().syncFile(currentFile);
        }
        // Call to reset image zoom to initial state
        ((PreviewImagePagerAdapter) mViewPager.getAdapter()).resetZoom();
    } else {
        // too soon! ; selection of page (first image) was faster than binding of FileOperationsService;
        // wait a bit!
        final int fPosition = position;
        getHandler().post(new Runnable() {

            @Override
            public void run() {
                onPageSelected(fPosition);
                ;
            }
        });
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) SuppressLint(android.annotation.SuppressLint)

Example 42 with OCFile

use of com.owncloud.android.datamodel.OCFile in project android by owncloud.

the class PreviewImagePagerAdapter method getItem.

public Fragment getItem(int i) {
    OCFile file = mImageFiles.get(i);
    Fragment fragment;
    if (file.isDown()) {
        fragment = PreviewImageFragment.newInstance(file, mAccount, mObsoletePositions.contains(i));
    } else if (mDownloadErrors.contains(i)) {
        fragment = FileDownloadFragment.newInstance(file, mAccount, true);
        ((FileDownloadFragment) fragment).setError(true);
        mDownloadErrors.remove(i);
    } else {
        fragment = FileDownloadFragment.newInstance(file, mAccount, mObsoletePositions.contains(i));
    }
    mObsoletePositions.remove(i);
    return fragment;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) Fragment(android.support.v4.app.Fragment) FileFragment(com.owncloud.android.ui.fragment.FileFragment)

Example 43 with OCFile

use of com.owncloud.android.datamodel.OCFile in project android by owncloud.

the class PreviewAudioFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    Log_OC.v(TAG, "onStart");
    OCFile file = getFile();
    if (file != null && file.isDown()) {
        bindMediaService();
    }
    mProgressController.startListeningProgressFor(getFile(), mAccount);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile)

Example 44 with OCFile

use of com.owncloud.android.datamodel.OCFile in project android by owncloud.

the class PreviewImageActivity method onAccountSet.

@Override
protected void onAccountSet(boolean stateWasRecovered) {
    super.onAccountSet(stateWasRecovered);
    if (getAccount() != null) {
        OCFile file = getFile();
        /// Validate handled file  (first image to preview)
        if (file == null) {
            throw new IllegalStateException("Instanced with a NULL OCFile");
        }
        if (!file.isImage()) {
            throw new IllegalArgumentException("Non-image file passed as argument");
        }
        // Update file according to DB file, if it is possible
        if (file.getFileId() > FileDataStorageManager.ROOT_PARENT_ID)
            file = getStorageManager().getFileById(file.getFileId());
        if (file != null) {
            /// Refresh the activity according to the Account and OCFile set
            // reset after getting it fresh from storageManager
            setFile(file);
            getSupportActionBar().setTitle(getFile().getFileName());
            initViewPager();
        } else {
            // handled file not in the current Account
            finish();
        }
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile)

Example 45 with OCFile

use of com.owncloud.android.datamodel.OCFile in project android by owncloud.

the class FileDownloader method onStartCommand.

/**
     * Entry point to add one or several files to the queue of downloads.
     *
     * New downloads 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);
    if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE)) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return START_NOT_STICKY;
    } else {
        final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
        final OCFile file = intent.getParcelableExtra(EXTRA_FILE);
        AbstractList<String> requestedDownloads = new Vector<String>();
        try {
            DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
            newDownload.addDatatransferProgressListener(this);
            newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
            Pair<String, String> putResult = mPendingDownloads.putIfAbsent(account.name, file.getRemotePath(), newDownload);
            if (putResult != null) {
                String downloadKey = putResult.first;
                requestedDownloads.add(downloadKey);
                sendBroadcastNewDownload(newDownload, putResult.second);
            }
        // else, file already in the queue of downloads; don't repeat the request
        } catch (IllegalArgumentException e) {
            Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
            return START_NOT_STICKY;
        }
        if (requestedDownloads.size() > 0) {
            Message msg = mServiceHandler.obtainMessage();
            msg.arg1 = startId;
            msg.obj = requestedDownloads;
            mServiceHandler.sendMessage(msg);
        }
    }
    return START_NOT_STICKY;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) DownloadFileOperation(com.owncloud.android.operations.DownloadFileOperation) Message(android.os.Message) Vector(java.util.Vector)

Aggregations

OCFile (com.owncloud.android.datamodel.OCFile)84 File (java.io.File)14 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)9 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)8 Intent (android.content.Intent)7 Account (android.accounts.Account)6 OCFileListFragment (com.owncloud.android.ui.fragment.OCFileListFragment)6 FileFragment (com.owncloud.android.ui.fragment.FileFragment)5 Vector (java.util.Vector)5 Bundle (android.os.Bundle)4 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)4 RemoteFile (com.owncloud.android.lib.resources.files.RemoteFile)4 SuppressLint (android.annotation.SuppressLint)3 Bitmap (android.graphics.Bitmap)3 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 ThumbnailsCacheManager (com.owncloud.android.datamodel.ThumbnailsCacheManager)3 TransferProgressController (com.owncloud.android.ui.controller.TransferProgressController)3 SharedPreferences (android.content.SharedPreferences)2