Search in sources :

Example 1 with SyncedFolderProvider

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);
        }
    }
}
Also used : Context(android.content.Context) SyncedFolder(com.owncloud.android.datamodel.SyncedFolder) SyncedFolderProvider(com.owncloud.android.datamodel.SyncedFolderProvider) ContentResolver(android.content.ContentResolver)

Example 2 with SyncedFolderProvider

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);
        }
    }
}
Also used : Context(android.content.Context) HashMap(java.util.HashMap) SyncedFolder(com.owncloud.android.datamodel.SyncedFolder) ArrayList(java.util.ArrayList) SyncedFolderProvider(com.owncloud.android.datamodel.SyncedFolderProvider) Pair(android.support.v4.util.Pair)

Example 3 with SyncedFolderProvider

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);
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) BottomNavigationView(android.support.design.widget.BottomNavigationView) MediaGridItemDecoration(com.owncloud.android.ui.decoration.MediaGridItemDecoration) SyncedFolderProvider(com.owncloud.android.datamodel.SyncedFolderProvider) SyncedFolderAdapter(com.owncloud.android.ui.adapter.SyncedFolderAdapter)

Example 4 with SyncedFolderProvider

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();
        }
    }
}
Also used : SyncedFolder(com.owncloud.android.datamodel.SyncedFolder) SyncedFolderProvider(com.owncloud.android.datamodel.SyncedFolderProvider)

Example 5 with SyncedFolderProvider

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;
    }
}
Also used : Context(android.content.Context) Account(android.accounts.Account) FilesystemDataProvider(com.owncloud.android.datamodel.FilesystemDataProvider) PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat) ArrayList(java.util.ArrayList) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) SyncedFolderProvider(com.owncloud.android.datamodel.SyncedFolderProvider) SyncedFolder(com.owncloud.android.datamodel.SyncedFolder) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) UploadsStorageManager(com.owncloud.android.datamodel.UploadsStorageManager) AccountManager(android.accounts.AccountManager) File(java.io.File) NonNull(android.support.annotation.NonNull)

Aggregations

SyncedFolderProvider (com.owncloud.android.datamodel.SyncedFolderProvider)8 Context (android.content.Context)6 SyncedFolder (com.owncloud.android.datamodel.SyncedFolder)6 ContentResolver (android.content.ContentResolver)3 ArrayList (java.util.ArrayList)3 Account (android.accounts.Account)2 NonNull (android.support.annotation.NonNull)2 PersistableBundleCompat (com.evernote.android.job.util.support.PersistableBundleCompat)2 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)2 FilesystemDataProvider (com.owncloud.android.datamodel.FilesystemDataProvider)2 File (java.io.File)2 AccountManager (android.accounts.AccountManager)1 SuppressLint (android.annotation.SuppressLint)1 Resources (android.content.res.Resources)1 PowerManager (android.os.PowerManager)1 BottomNavigationView (android.support.design.widget.BottomNavigationView)1 ExifInterface (android.support.media.ExifInterface)1 Pair (android.support.v4.util.Pair)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)1