use of com.owncloud.android.datamodel.SyncedFolderProvider in project android by nextcloud.
the class FilesSyncHelper method insertAllDBEntries.
public static void insertAllDBEntries(boolean skipCustom) {
final Context context = MainApp.getAppContext();
final ContentResolver contentResolver = context.getContentResolver();
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
if ((syncedFolder.isEnabled()) && ((MediaFolderType.CUSTOM != syncedFolder.getType()) || !skipCustom)) {
insertAllDBEntriesForSyncedFolder(syncedFolder);
}
}
}
use of com.owncloud.android.datamodel.SyncedFolderProvider in project android by nextcloud.
the class MainApp method cleanOldEntries.
private static void cleanOldEntries() {
// previous versions of application created broken entries in the SyncedFolderProvider
// database, and this cleans all that and leaves 1 (newest) entry per synced folder
Context context = getAppContext();
if (!PreferenceManager.getLegacyClean(context)) {
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver());
List<SyncedFolder> syncedFolderList = syncedFolderProvider.getSyncedFolders();
Map<Pair<String, String>, Long> syncedFolders = new HashMap<>();
ArrayList<Long> ids = new ArrayList<>();
for (SyncedFolder syncedFolder : syncedFolderList) {
Pair<String, String> checkPair = new Pair<>(syncedFolder.getAccount(), syncedFolder.getLocalPath());
if (syncedFolders.containsKey(checkPair)) {
if (syncedFolder.getId() > syncedFolders.get(checkPair)) {
syncedFolders.put(checkPair, syncedFolder.getId());
}
} else {
syncedFolders.put(checkPair, syncedFolder.getId());
}
}
ids.addAll(syncedFolders.values());
if (ids.size() > 0) {
syncedFolderProvider.deleteSyncedFoldersNotInList(mContext, ids);
} else {
PreferenceManager.setLegacyClean(context, true);
}
}
}
use of com.owncloud.android.datamodel.SyncedFolderProvider in project android by nextcloud.
the class SyncedFoldersActivity method setupContent.
/**
* sets up the UI elements and loads all media/synced folders.
*/
private void setupContent() {
mRecyclerView = findViewById(android.R.id.list);
mProgress = findViewById(android.R.id.progress);
mEmpty = findViewById(android.R.id.empty);
final int gridWidth = getResources().getInteger(R.integer.media_grid_width);
boolean lightVersion = getResources().getBoolean(R.bool.syncedFolder_light);
mAdapter = new SyncedFolderAdapter(this, gridWidth, this, lightVersion);
mSyncedFolderProvider = new SyncedFolderProvider(getContentResolver());
final GridLayoutManager lm = new GridLayoutManager(this, gridWidth);
mAdapter.setLayoutManager(lm);
int spacing = getResources().getDimensionPixelSize(R.dimen.media_grid_spacing);
mRecyclerView.addItemDecoration(new MediaGridItemDecoration(spacing));
mRecyclerView.setLayoutManager(lm);
mRecyclerView.setAdapter(mAdapter);
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);
if (getResources().getBoolean(R.bool.bottom_toolbar_enabled)) {
bottomNavigationView.setVisibility(View.VISIBLE);
DisplayUtils.setupBottomBar(bottomNavigationView, getResources(), this, -1);
}
load(gridWidth * 2, false);
}
use of com.owncloud.android.datamodel.SyncedFolderProvider in project android by nextcloud.
the class FilesSyncHelper method scheduleNJobs.
public static void scheduleNJobs(boolean force, Context context) {
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver());
boolean hasVideoFolders = false;
boolean hasImageFolders = false;
if (syncedFolderProvider.getSyncedFolders() != null) {
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
if (MediaFolderType.VIDEO == syncedFolder.getType()) {
hasVideoFolders = true;
} else if (MediaFolderType.IMAGE == syncedFolder.getType()) {
hasImageFolders = true;
}
}
}
if (hasImageFolders || hasVideoFolders) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
scheduleJobOnN(hasImageFolders, hasVideoFolders, force);
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
cancelJobOnN();
}
}
}
use of com.owncloud.android.datamodel.SyncedFolderProvider 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;
}
}
Aggregations