Search in sources :

Example 1 with SyncedFolder

use of com.owncloud.android.datamodel.SyncedFolder 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 SyncedFolder

use of com.owncloud.android.datamodel.SyncedFolder 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 SyncedFolder

use of com.owncloud.android.datamodel.SyncedFolder 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 4 with SyncedFolder

use of com.owncloud.android.datamodel.SyncedFolder in project android by nextcloud.

the class SyncedFoldersActivity method mergeFolderData.

/**
 * merges two lists of {@link SyncedFolder} and {@link MediaFolder} items into one of SyncedFolderItems.
 *
 * @param syncedFolders the synced folders
 * @param mediaFolders  the media folders
 * @return the merged list of SyncedFolderItems
 */
@NonNull
private List<SyncedFolderDisplayItem> mergeFolderData(List<SyncedFolder> syncedFolders, @NonNull List<MediaFolder> mediaFolders) {
    Map<String, SyncedFolder> syncedFoldersMap = createSyncedFoldersMap(syncedFolders);
    List<SyncedFolderDisplayItem> result = new ArrayList<>();
    for (MediaFolder mediaFolder : mediaFolders) {
        if (syncedFoldersMap.containsKey(mediaFolder.absolutePath + "-" + mediaFolder.type)) {
            SyncedFolder syncedFolder = syncedFoldersMap.get(mediaFolder.absolutePath + "-" + mediaFolder.type);
            syncedFoldersMap.remove(mediaFolder.absolutePath + "-" + mediaFolder.type);
            if (MediaFolderType.CUSTOM == syncedFolder.getType()) {
                result.add(createSyncedFolderWithoutMediaFolder(syncedFolder));
            } else {
                result.add(createSyncedFolder(syncedFolder, mediaFolder));
            }
        } else {
            result.add(createSyncedFolderFromMediaFolder(mediaFolder));
        }
    }
    for (SyncedFolder syncedFolder : syncedFoldersMap.values()) {
        result.add(createSyncedFolderWithoutMediaFolder(syncedFolder));
    }
    return result;
}
Also used : SyncedFolder(com.owncloud.android.datamodel.SyncedFolder) ArrayList(java.util.ArrayList) SyncedFolderDisplayItem(com.owncloud.android.datamodel.SyncedFolderDisplayItem) MediaFolder(com.owncloud.android.datamodel.MediaFolder) NonNull(android.support.annotation.NonNull)

Example 5 with SyncedFolder

use of com.owncloud.android.datamodel.SyncedFolder in project android by nextcloud.

the class SyncedFoldersActivity method load.

/**
 * loads all media/synced folders, adds them to the recycler view adapter and shows the list.
 *
 * @param perFolderMediaItemLimit the amount of media items to be loaded/shown per media folder
 */
private void load(final int perFolderMediaItemLimit, boolean force) {
    if (mAdapter.getItemCount() > 0 && !force) {
        return;
    }
    setListShown(false);
    final List<MediaFolder> mediaFolders = MediaProvider.getImageFolders(getContentResolver(), perFolderMediaItemLimit, SyncedFoldersActivity.this);
    mediaFolders.addAll(MediaProvider.getVideoFolders(getContentResolver(), perFolderMediaItemLimit, SyncedFoldersActivity.this));
    List<SyncedFolder> syncedFolderArrayList = mSyncedFolderProvider.getSyncedFolders();
    List<SyncedFolder> currentAccountSyncedFoldersList = new ArrayList<>();
    Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(SyncedFoldersActivity.this);
    for (SyncedFolder syncedFolder : syncedFolderArrayList) {
        if (currentAccount != null && syncedFolder.getAccount().equals(currentAccount.name)) {
            currentAccountSyncedFoldersList.add(syncedFolder);
        }
    }
    List<SyncedFolderDisplayItem> syncFolderItems = sortSyncedFolderItems(mergeFolderData(currentAccountSyncedFoldersList, mediaFolders));
    mAdapter.setSyncFolderItems(syncFolderItems);
    mAdapter.notifyDataSetChanged();
    setListShown(true);
}
Also used : Account(android.accounts.Account) SyncedFolder(com.owncloud.android.datamodel.SyncedFolder) ArrayList(java.util.ArrayList) SyncedFolderDisplayItem(com.owncloud.android.datamodel.SyncedFolderDisplayItem) MediaFolder(com.owncloud.android.datamodel.MediaFolder)

Aggregations

SyncedFolder (com.owncloud.android.datamodel.SyncedFolder)8 SyncedFolderProvider (com.owncloud.android.datamodel.SyncedFolderProvider)6 Context (android.content.Context)5 ArrayList (java.util.ArrayList)5 Account (android.accounts.Account)3 ContentResolver (android.content.ContentResolver)3 NonNull (android.support.annotation.NonNull)3 MediaFolder (com.owncloud.android.datamodel.MediaFolder)3 PersistableBundleCompat (com.evernote.android.job.util.support.PersistableBundleCompat)2 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)2 FilesystemDataProvider (com.owncloud.android.datamodel.FilesystemDataProvider)2 SyncedFolderDisplayItem (com.owncloud.android.datamodel.SyncedFolderDisplayItem)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 ExifInterface (android.support.media.ExifInterface)1 Pair (android.support.v4.util.Pair)1 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)1