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());
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class ActivitiesListActivity method setupContent.
/**
* sets up the UI elements and loads all activity items.
*/
private void setupContent() {
emptyContentIcon.setImageResource(R.drawable.ic_activity_light_grey);
emptyContentProgressBar.getIndeterminateDrawable().setColorFilter(ThemeUtils.primaryAccentColor(), PorterDuff.Mode.SRC_IN);
setLoadingMessage();
FileDataStorageManager storageManager = new FileDataStorageManager(getAccount(), getContentResolver());
adapter = new ActivityListAdapter(this, this, storageManager);
recyclerView.setAdapter(adapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int visibleItemCount = recyclerView.getChildCount();
int totalItemCount = layoutManager.getItemCount();
int firstVisibleItemIndex = layoutManager.findFirstVisibleItemPosition();
// synchronize loading state when item count changes
if (!isLoadingActivities && (totalItemCount - visibleItemCount) <= (firstVisibleItemIndex + 5) && nextPageUrl != null && !nextPageUrl.isEmpty()) {
// Almost reached the end, continue to load new activities
fetchAndSetData(nextPageUrl);
}
}
});
if (getResources().getBoolean(R.bool.bottom_toolbar_enabled)) {
bottomNavigationView.setVisibility(View.VISIBLE);
DisplayUtils.setupBottomBar(bottomNavigationView, getResources(), this, -1);
}
fetchAndSetData(null);
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class PreferenceManager method getFolderPreference.
/**
* Get preference value for a folder.
* If folder is not set itself, it finds an ancestor that is set.
*
* @param context Context object.
* @param preferenceName Name of the preference to lookup.
* @param folder Folder.
* @param defaultValue Fallback value in case no ancestor is set.
* @return Preference value
*/
public static String getFolderPreference(Context context, String preferenceName, OCFile folder, String defaultValue) {
Account account = AccountUtils.getCurrentOwnCloudAccount(context);
if (account == null) {
return defaultValue;
}
ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
FileDataStorageManager storageManager = ((ComponentsGetter) context).getStorageManager();
if (storageManager == null) {
storageManager = new FileDataStorageManager(account, context.getContentResolver());
}
String value = dataProvider.getValue(account.name, getKeyFromFolder(preferenceName, folder));
while (folder != null && value.isEmpty()) {
folder = storageManager.getFileById(folder.getParentId());
value = dataProvider.getValue(account.name, getKeyFromFolder(preferenceName, folder));
}
return value.isEmpty() ? defaultValue : value;
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class AccountRemovalJob method onRunJob.
@NonNull
@Override
protected Result onRunJob(Params params) {
Context context = MainApp.getAppContext();
PersistableBundleCompat bundle = params.getExtras();
Account account = AccountUtils.getOwnCloudAccountByName(context, bundle.getString(ACCOUNT, ""));
AccountManager am = (AccountManager) context.getSystemService(ACCOUNT_SERVICE);
if (account != null && am != null) {
// disable contact backup job
ContactsPreferenceActivity.cancelContactBackupJobForAccount(context, account);
if (am != null) {
am.removeAccount(account, this, null);
}
FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver());
File tempDir = new File(FileStorageUtils.getTemporalPath(account.name));
File saveDir = new File(FileStorageUtils.getSavePath(account.name));
FileStorageUtils.deleteRecursively(tempDir, storageManager);
FileStorageUtils.deleteRecursively(saveDir, storageManager);
// delete all database entries
storageManager.deleteAllFiles();
// remove pending account removal
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
arbitraryDataProvider.deleteKeyForAccount(account.name, PENDING_FOR_REMOVAL);
// remove synced folders set for account
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver());
List<SyncedFolder> syncedFolders = syncedFolderProvider.getSyncedFolders();
List<Long> syncedFolderIds = new ArrayList<>();
for (SyncedFolder syncedFolder : syncedFolders) {
if (syncedFolder.getAccount().equals(account.name)) {
arbitraryDataProvider.deleteKeyForAccount(FilesSyncHelper.GLOBAL, FilesSyncHelper.SYNCEDFOLDERINITIATED + syncedFolder.getId());
syncedFolderIds.add(syncedFolder.getId());
}
}
syncedFolderProvider.deleteSyncFoldersForAccount(account);
UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver(), context);
uploadsStorageManager.removeAccountUploads(account);
FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(context.getContentResolver());
for (long syncedFolderId : syncedFolderIds) {
filesystemDataProvider.deleteAllEntriesForSyncedFolder(Long.toString(syncedFolderId));
}
// delete stored E2E keys
arbitraryDataProvider.deleteKeyForAccount(account.name, EncryptionUtils.PRIVATE_KEY);
arbitraryDataProvider.deleteKeyForAccount(account.name, EncryptionUtils.PUBLIC_KEY);
return Result.SUCCESS;
} else {
return Result.FAILURE;
}
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class OfflineSyncJob method onRunJob.
@NonNull
@Override
protected Result onRunJob(@NonNull Params params) {
final Context context = MainApp.getAppContext();
PowerManager.WakeLock wakeLock = null;
if (!PowerUtils.isPowerSaveMode(context) && Device.getNetworkType(context).equals(JobRequest.NetworkType.UNMETERED) && !ConnectivityUtils.isInternetWalled(context)) {
Set<Job> jobs = JobManager.instance().getAllJobsForTag(TAG);
for (Job job : jobs) {
if (!job.isFinished() && !job.equals(this)) {
return Result.SUCCESS;
}
}
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
wakeLock.acquire();
}
Cursor cursorOnKeptInSync = context.getContentResolver().query(ProviderMeta.ProviderTableMeta.CONTENT_URI, null, ProviderMeta.ProviderTableMeta.FILE_KEEP_IN_SYNC + " = ?", new String[] { String.valueOf(1) }, null);
if (cursorOnKeptInSync != null) {
if (cursorOnKeptInSync.moveToFirst()) {
String localPath = "";
String accountName = "";
Account account = null;
do {
localPath = cursorOnKeptInSync.getString(cursorOnKeptInSync.getColumnIndex(ProviderMeta.ProviderTableMeta.FILE_STORAGE_PATH));
accountName = cursorOnKeptInSync.getString(cursorOnKeptInSync.getColumnIndex(ProviderMeta.ProviderTableMeta.FILE_ACCOUNT_OWNER));
account = new Account(accountName, MainApp.getAccountType());
if (!AccountUtils.exists(account, context) || localPath == null || localPath.length() <= 0) {
continue;
}
offlineFileList.add(new OfflineFile(localPath, account));
} while (cursorOnKeptInSync.moveToNext());
}
cursorOnKeptInSync.close();
}
FileDataStorageManager storageManager;
for (OfflineFile offlineFile : offlineFileList) {
storageManager = new FileDataStorageManager(offlineFile.getAccount(), context.getContentResolver());
OCFile file = storageManager.getFileByLocalPath(offlineFile.getLocalPath());
SynchronizeFileOperation sfo = new SynchronizeFileOperation(file, null, offlineFile.getAccount(), true, context);
RemoteOperationResult result = sfo.execute(storageManager, context);
if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) {
Intent i = new Intent(context, ConflictsResolveActivity.class);
i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(ConflictsResolveActivity.EXTRA_FILE, file);
i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, offlineFile.getAccount());
context.startActivity(i);
}
}
if (wakeLock != null) {
wakeLock.release();
}
}
return Result.SUCCESS;
}
Aggregations