use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class SynchronizeFolderOperation method mergeRemoteFolder.
/**
* Synchronizes the data retrieved from the server about the contents of the target folder
* with the current data in the local database.
*
* Grants that mFoldersToVisit is updated with fresh data after execution.
*
* @param folderAndFiles Remote folder and children files in folder
*/
private void mergeRemoteFolder(ArrayList<Object> folderAndFiles) throws OperationCancelledException {
Log_OC.d(TAG, "Synchronizing " + mAccount.name + mRemotePath);
FileDataStorageManager storageManager = getStorageManager();
// parse data from remote folder
OCFile updatedFolder = FileStorageUtils.createOCFileFrom((RemoteFile) folderAndFiles.get(0));
// NOTE: updates ETag with remote value; that's INTENDED
updatedFolder.copyLocalPropertiesFrom(mLocalFolder);
Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data ");
List<OCFile> updatedFiles = new Vector<>(folderAndFiles.size() - 1);
mFoldersToVisit = new Vector<>(folderAndFiles.size() - 1);
mFilesToSyncContents.clear();
if (mCancellationRequested.get()) {
throw new OperationCancelledException();
}
// get current data about local contents of the folder to synchronize
List<OCFile> localFiles = storageManager.getFolderContent(mLocalFolder);
Map<String, OCFile> localFilesMap = new HashMap<>(localFiles.size());
for (OCFile file : localFiles) {
localFilesMap.put(file.getRemotePath(), file);
}
// loop to synchronize every child
OCFile remoteFile, localFile, updatedLocalFile;
RemoteFile r;
int foldersToExpand = 0;
for (int i = 1; i < folderAndFiles.size(); i++) {
/// new OCFile instance with the data from the server
r = (RemoteFile) folderAndFiles.get(i);
remoteFile = FileStorageUtils.createOCFileFrom(r);
/// new OCFile instance to merge fresh data from server with local state
updatedLocalFile = FileStorageUtils.createOCFileFrom(r);
/// retrieve local data for the read file
localFile = localFilesMap.remove(remoteFile.getRemotePath());
/// add to updatedFile data about LOCAL STATE (not existing in server)
updatedLocalFile.setLastSyncDateForProperties(mCurrentSyncTime);
if (localFile != null) {
updatedLocalFile.copyLocalPropertiesFrom(localFile);
// remote eTag will not be set unless file CONTENTS are synchronized
updatedLocalFile.setEtag(localFile.getEtag());
if (!updatedLocalFile.isFolder() && remoteFile.isImage() && remoteFile.getModificationTimestamp() != localFile.getModificationTimestamp()) {
updatedLocalFile.setNeedsUpdateThumbnail(true);
}
} else {
updatedLocalFile.setParentId(mLocalFolder.getFileId());
// remote eTag will not be set unless file CONTENTS are synchronized
updatedLocalFile.setEtag("");
// new files need to check av-off status of parent folder!
if (updatedFolder.isAvailableOffline()) {
updatedLocalFile.setAvailableOfflineStatus(OCFile.AvailableOfflineStatus.AVAILABLE_OFFLINE_PARENT);
}
}
/// check and fix, if needed, local storage path
searchForLocalFileInDefaultPath(updatedLocalFile);
/// prepare content synchronizations
boolean serverUnchanged = addToSyncContents(updatedLocalFile, remoteFile);
if (updatedLocalFile.isFolder() && !serverUnchanged) {
foldersToExpand++;
}
updatedFiles.add(updatedLocalFile);
}
// save updated contents in local database
if (foldersToExpand == 0) {
updatedFolder.setTreeEtag(updatedFolder.getEtag());
// TODO - propagate up
}
storageManager.saveFolder(updatedFolder, updatedFiles, localFilesMap.values());
}
use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class MoveFileOperation method resumeObservation.
private void resumeObservation(String targetPath) {
OCFile updatedFile = new OCFile(targetPath);
updatedFile.setMimetype(mFile.getMimetype());
updatedFile.setFileId(mFile.getFileId());
updatedFile.setStoragePath(FileStorageUtils.getDefaultSavePathFor(getStorageManager().getAccount().name, updatedFile));
FileObserverService.observeFile(MainApp.getAppContext(), updatedFile, getStorageManager().getAccount(), true);
}
use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class ReceiveExternalFilesActivity method populateDirectoryList.
private void populateDirectoryList() {
setContentView(R.layout.uploader_layout);
setupToolbar();
ActionBar actionBar = getSupportActionBar();
ListView mListView = (ListView) findViewById(android.R.id.list);
String current_dir = mParents.peek();
if (current_dir.equals("")) {
actionBar.setTitle(getString(R.string.uploader_top_message));
} else {
actionBar.setTitle(current_dir);
}
boolean notRoot = (mParents.size() > 1);
actionBar.setDisplayHomeAsUpEnabled(notRoot);
actionBar.setHomeButtonEnabled(notRoot);
String full_path = generatePath(mParents);
Log_OC.d(TAG, "Populating view with content of : " + full_path);
mFile = getStorageManager().getFileByPath(full_path);
if (mFile != null) {
// TODO Enable when "On Device" is recovered ?
Vector<OCFile> files = getStorageManager().getFolderContent(mFile);
files = sortFileList(files);
ReceiveExternalFilesAdapter sa = new ReceiveExternalFilesAdapter(this, files, getStorageManager(), getAccount());
mListView.setAdapter(sa);
Button btnChooseFolder = (Button) findViewById(R.id.uploader_choose_folder);
btnChooseFolder.setOnClickListener(this);
Button btnNewFolder = (Button) findViewById(R.id.uploader_cancel);
btnNewFolder.setOnClickListener(this);
mListView.setOnItemClickListener(this);
}
}
use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class PreviewVideoActivity 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.isVideo()) {
throw new IllegalArgumentException("Non-video file passed as argument");
}
file = getStorageManager().getFileById(file.getFileId());
if (file != null) {
if (file.isDown()) {
mVideoPlayer.setVideoURI(file.getStorageUri());
} else {
// not working yet
String url;
try {
url = AccountUtils.constructFullURLForAccount(this, getAccount()) + file.getRemotePath();
mVideoPlayer.setVideoURI(Uri.parse(url));
} catch (AccountNotFoundException e) {
onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_no_account);
}
}
// create and prepare control panel for the user
mMediaController = new MediaController(this);
mMediaController.setMediaPlayer(mVideoPlayer);
mMediaController.setAnchorView(mVideoPlayer);
mVideoPlayer.setMediaController(mMediaController);
} else {
finish();
}
} else {
finish();
}
}
use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class FileStorageUtils method sortByName.
/**
* Sorts list by Name
* @param files files to sort
*/
public static Vector<OCFile> sortByName(Vector<OCFile> files) {
final Integer val;
if (mSortAscending) {
val = 1;
} else {
val = -1;
}
Collections.sort(files, new Comparator<OCFile>() {
public int compare(OCFile o1, OCFile o2) {
if (o1.isFolder() && o2.isFolder()) {
return val * new AlphanumComparator().compare(o1, o2);
} else if (o1.isFolder()) {
return -1;
} else if (o2.isFolder()) {
return 1;
}
return val * new AlphanumComparator().compare(o1, o2);
}
});
return files;
}
Aggregations