use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class FileDisplayActivity method openFile.
private void openFile(User user, String fileId) {
setUser(user);
if (fileId == null) {
dismissLoadingDialog();
DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file));
return;
}
FileDataStorageManager storageManager = getStorageManager();
if (storageManager == null) {
storageManager = new FileDataStorageManager(user, getContentResolver());
}
FetchRemoteFileTask fetchRemoteFileTask = new FetchRemoteFileTask(user, fileId, storageManager, this);
fetchRemoteFileTask.execute();
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class FolderPickerActivity method getCurrentFolder.
protected OCFile getCurrentFolder() {
OCFile currentFile = getFile();
OCFile finalFolder = null;
FileDataStorageManager storageManager = getStorageManager();
// If the file is null, take the root folder to avoid any error in functions depending on this one
if (currentFile != null) {
if (currentFile.isFolder()) {
finalFolder = currentFile;
} else if (currentFile.getRemotePath() != null) {
String parentPath = new File(currentFile.getRemotePath()).getParent();
finalFolder = storageManager.getFileByPath(parentPath);
}
} else {
finalFolder = storageManager.getFileByPath(OCFile.ROOT_PATH);
}
return finalFolder;
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class FileSyncAdapter method onPerformSync.
/**
* {@inheritDoc}
*/
@Override
public synchronized void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient providerClient, SyncResult syncResult) {
mCancellation = false;
mFailedResultsCounter = 0;
mLastFailedResult = null;
mConflictsFound = 0;
mFailsInFavouritesFound = 0;
mForgottenLocalFiles = new HashMap<String, String>();
mSyncResult = syncResult;
mSyncResult.fullSyncRequested = false;
// avoid too many automatic synchronizations
mSyncResult.delayUntil = (System.currentTimeMillis() / 1000) + 3 * 60 * 60;
this.setAccount(account);
this.setContentProviderClient(providerClient);
this.setStorageManager(new FileDataStorageManager(getUser(), providerClient));
try {
this.initClientForCurrentAccount();
} catch (IOException | AccountsException e) {
// / the account is unknown for the Synchronization Manager, unreachable this context,
// or can not be authenticated; don't try this again
mSyncResult.tooManyRetries = true;
notifyFailedSynchronization();
return;
}
Log_OC.d(TAG, "Synchronization of ownCloud account " + account.name + " starting");
// message to signal the start
sendLocalBroadcast(EVENT_FULL_SYNC_START, null, null);
// of the synchronization to the UI
/* When 'true' the process was requested by the user through the user interface;
when 'false', it was requested automatically by the system */
boolean mIsManualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
try {
updateOCVersion();
mCurrentSyncTime = System.currentTimeMillis();
if (!mCancellation) {
synchronizeFolder(getStorageManager().getFileByPath(OCFile.ROOT_PATH));
} else {
Log_OC.d(TAG, "Leaving synchronization before synchronizing the root folder " + "because cancellation request");
}
} finally {
if (mFailedResultsCounter > 0 && mIsManualSync) {
// / don't let the system synchronization manager retries MANUAL synchronizations
// (be careful: "MANUAL" currently includes the synchronization requested when
// a new account is created and when the user changes the current account)
mSyncResult.tooManyRetries = true;
// / notify the user about the failure of MANUAL synchronization
notifyFailedSynchronization();
}
if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {
notifyFailsInFavourites();
}
if (mForgottenLocalFiles.size() > 0) {
notifyForgottenLocalFiles();
}
// message to signal
sendLocalBroadcast(EVENT_FULL_SYNC_END, null, mLastFailedResult);
// the end to the UI
}
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by owncloud.
the class ErrorsWhileCopyingHandlerActivity method onCreate.
/**
* {@link}
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/// read extra parameters in intent
Intent intent = getIntent();
mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT);
mRemotePaths = intent.getStringArrayListExtra(EXTRA_REMOTE_PATHS);
mLocalPaths = intent.getStringArrayListExtra(EXTRA_LOCAL_PATHS);
mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());
mHandler = new Handler();
if (mCurrentDialog != null) {
mCurrentDialog.dismiss();
mCurrentDialog = null;
}
/// load generic layout
setContentView(R.layout.generic_explanation);
/// customize text message
TextView textView = (TextView) findViewById(R.id.message);
String appName = getString(R.string.app_name);
String message = String.format(getString(R.string.sync_foreign_files_forgotten_explanation), appName, appName, appName, appName, mAccount.name);
textView.setText(message);
textView.setMovementMethod(new ScrollingMovementMethod());
/// load the list of local and remote files that failed
ListView listView = (ListView) findViewById(R.id.list);
if (mLocalPaths != null && mLocalPaths.size() > 0) {
mAdapter = new ErrorsWhileCopyingListAdapter();
listView.setAdapter(mAdapter);
} else {
listView.setVisibility(View.GONE);
mAdapter = null;
}
/// customize buttons
Button cancelBtn = (Button) findViewById(R.id.cancel);
Button okBtn = (Button) findViewById(R.id.ok);
okBtn.setText(R.string.foreign_files_move);
cancelBtn.setOnClickListener(this);
okBtn.setOnClickListener(this);
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by owncloud.
the class FileObserverService method startObservation.
/**
* Read from the local database the list of files that must to be kept
* synchronized and starts observers to monitor local changes on them.
*
* Updates the list of currently observed files if called multiple times.
*/
private void startObservation() {
Log_OC.d(TAG, "Loading all available offline files from database to start watching them");
FileDataStorageManager fds = new FileDataStorageManager(// this is dangerous - handle with care
null, getContentResolver());
List<Pair<OCFile, String>> availableOfflineFiles = fds.getAvailableOfflineFilesFromEveryAccount();
OCFile file;
String accountName;
Account account;
for (Pair<OCFile, String> pair : availableOfflineFiles) {
file = pair.first;
accountName = pair.second;
account = new Account(accountName, MainApp.getAccountType());
if (!AccountUtils.exists(account, this)) {
continue;
}
addObservedFile(file, account);
}
// watch for instant uploads
updateInstantUploadsObservers();
// service does not stopSelf() ; that way it tries to be alive forever
}
Aggregations