use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class EditShareFragment method refreshUiFromDB.
/**
* Get {@link OCShare} instance from DB and updates the UI.
*
* Depends on the parent Activity provides a {@link com.owncloud.android.datamodel.FileDataStorageManager}
* instance ready to use. If not ready, does nothing.
*
* @param editShareView Root view in the fragment.
*/
private void refreshUiFromDB(View editShareView) {
FileDataStorageManager storageManager = ((FileActivity) getActivity()).getStorageManager();
if (storageManager != null) {
// Get edited share
mShare = storageManager.getShareById(mShare.getId());
// Updates UI with new state
refreshUiFromState(editShareView);
}
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class ContactsBackupFragment method refreshBackupFolder.
private void refreshBackupFolder(final String backupFolderPath, final ContactsPreferenceActivity contactsPreferenceActivity) {
AsyncTask<String, Integer, Boolean> task = new AsyncTask<String, Integer, Boolean>() {
@Override
protected Boolean doInBackground(String... path) {
FileDataStorageManager storageManager = new FileDataStorageManager(account, contactsPreferenceActivity.getContentResolver());
OCFile folder = storageManager.getFileByPath(path[0]);
if (folder != null) {
RefreshFolderOperation operation = new RefreshFolderOperation(folder, System.currentTimeMillis(), false, false, false, storageManager, account, getContext());
RemoteOperationResult result = operation.execute(account, getContext());
return result.isSuccess();
} else {
return false;
}
}
@Override
protected void onPostExecute(Boolean result) {
if (result) {
OCFile backupFolder = contactsPreferenceActivity.getStorageManager().getFileByPath(backupFolderPath);
List<OCFile> backupFiles = contactsPreferenceActivity.getStorageManager().getFolderContent(backupFolder, false);
if (backupFiles == null || backupFiles.size() == 0) {
contactsDatePickerBtn.setVisibility(View.GONE);
} else {
contactsDatePickerBtn.setVisibility(View.VISIBLE);
}
}
}
};
task.execute(backupFolderPath);
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class ThemeUtils method getCapability.
private static OCCapability getCapability(Account acc) {
Account account;
Context context = MainApp.getAppContext();
if (context == null) {
return new OCCapability();
}
if (acc != null) {
account = acc;
} else {
account = AccountUtils.getCurrentOwnCloudAccount(context);
}
if (account != null) {
FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver());
return storageManager.getCapability(account.name);
} else {
return new OCCapability();
}
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class RemoveFileDialogFragment method onCancel.
/**
* Performs the removal of the local copy of the target file
*/
@Override
public void onCancel(String callerTag) {
ComponentsGetter cg = (ComponentsGetter) getActivity();
ArrayList<OCFile> list = new ArrayList<>();
list.add(mTargetFile);
cg.getFileOperationsHelper().removeFiles(list, true);
FileDataStorageManager storageManager = cg.getStorageManager();
boolean containsFavorite = false;
if (mTargetFile.isFolder()) {
List<OCFile> files = storageManager.getFolderContent(mTargetFile, false);
for (OCFile file : files) {
containsFavorite = file.isAvailableOffline() || containsFavorite;
if (containsFavorite) {
break;
}
}
}
// or is a folder and contains favorite
if (mTargetFile.isAvailableOffline() || containsFavorite) {
OCFile folder = null;
if (mTargetFile.isFolder()) {
folder = mTargetFile;
} else {
folder = storageManager.getFileById(mTargetFile.getParentId());
}
folder.setEtag("");
storageManager.saveFile(folder);
}
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class SynchronizeFolderOperation method synchronizeData.
/**
* Synchronizes the data retrieved from the server about the contents of the target folder
* with the current data in the local database.
*
* Grants that mChildren is updated with fresh data after execution.
*
* @param folderAndFiles Remote folder and children files in Folder
*/
private void synchronizeData(ArrayList<Object> folderAndFiles) throws OperationCancelledException {
FileDataStorageManager storageManager = getStorageManager();
// parse data from remote folder
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) folderAndFiles.get(0));
remoteFolder.setParentId(mLocalFolder.getParentId());
remoteFolder.setFileId(mLocalFolder.getFileId());
Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data ");
List<OCFile> updatedFiles = new Vector<>(folderAndFiles.size() - 1);
mFilesForDirectDownload.clear();
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, false);
Map<String, OCFile> localFilesMap = new HashMap<>(localFiles.size());
for (OCFile file : localFiles) {
localFilesMap.put(file.getRemotePath(), file);
}
// loop to synchronize every child
OCFile remoteFile = null;
OCFile localFile = null;
OCFile updatedFile = null;
RemoteFile r;
for (int i = 1; i < folderAndFiles.size(); i++) {
// / new OCFile instance with the data from the server
r = (RemoteFile) folderAndFiles.get(i);
remoteFile = FileStorageUtils.fillOCFile(r);
// / retrieve local data for the read file
// localFile = mStorageManager.getFileByPath(remoteFile.getRemotePath());
localFile = localFilesMap.remove(remoteFile.getRemotePath());
// / new OCFile instance to merge fresh data from server with local state
updatedFile = FileStorageUtils.fillOCFile(r);
updatedFile.setParentId(mLocalFolder.getFileId());
// / add to updatedFile data about LOCAL STATE (not existing in server)
updateLocalStateData(remoteFile, localFile, updatedFile);
// / check and fix, if needed, local storage path
searchForLocalFileInDefaultPath(updatedFile);
// / classify file to sync/download contents later
classifyFileForLaterSyncOrDownload(remoteFile, localFile);
updatedFiles.add(updatedFile);
}
// save updated contents in local database
storageManager.saveFolder(remoteFolder, updatedFiles, localFilesMap.values());
}
Aggregations