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);
;
}
});
}
}
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;
}
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);
}
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();
}
}
}
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;
}
Aggregations