Search in sources :

Example 1 with MediaFolder

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

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

Example 3 with MediaFolder

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

the class MainApp method splitOutAutoUploadEntries.

private static void splitOutAutoUploadEntries() {
    Context context = getAppContext();
    if (!PreferenceManager.getAutoUploadSplitEntries(context)) {
        // magic to split out existing synced folders in two when needed
        // otherwise, we migrate them to their proper type (image or video)
        Log_OC.i(TAG, "Migrate synced_folders records for image/video split");
        ContentResolver contentResolver = context.getContentResolver();
        SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
        final List<MediaFolder> imageMediaFolders = MediaProvider.getImageFolders(contentResolver, 1, null);
        final List<MediaFolder> videoMediaFolders = MediaProvider.getVideoFolders(contentResolver, 1, null);
        ArrayList<Long> idsToDelete = new ArrayList<>();
        List<SyncedFolder> syncedFolders = syncedFolderProvider.getSyncedFolders();
        long primaryKey;
        SyncedFolder newSyncedFolder;
        for (SyncedFolder syncedFolder : syncedFolders) {
            idsToDelete.add(syncedFolder.getId());
            Log_OC.i(TAG, "Migration check for synced_folders record: " + syncedFolder.getId() + " - " + syncedFolder.getLocalPath());
            for (int i = 0; i < imageMediaFolders.size(); i++) {
                if (imageMediaFolders.get(i).absolutePath.equals(syncedFolder.getLocalPath())) {
                    newSyncedFolder = (SyncedFolder) syncedFolder.clone();
                    newSyncedFolder.setType(MediaFolderType.IMAGE);
                    primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
                    Log_OC.i(TAG, "Migrated image synced_folders record: " + primaryKey + " - " + newSyncedFolder.getLocalPath());
                    break;
                }
            }
            for (int j = 0; j < videoMediaFolders.size(); j++) {
                if (videoMediaFolders.get(j).absolutePath.equals(syncedFolder.getLocalPath())) {
                    newSyncedFolder = (SyncedFolder) syncedFolder.clone();
                    newSyncedFolder.setType(MediaFolderType.VIDEO);
                    primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
                    Log_OC.i(TAG, "Migrated video synced_folders record: " + primaryKey + " - " + newSyncedFolder.getLocalPath());
                    break;
                }
            }
        }
        for (long id : idsToDelete) {
            Log_OC.i(TAG, "Removing legacy synced_folders record: " + id);
            syncedFolderProvider.deleteSyncedFolder(id);
        }
        PreferenceManager.setAutoUploadSplitEntries(context, true);
    }
}
Also used : Context(android.content.Context) SyncedFolder(com.owncloud.android.datamodel.SyncedFolder) ArrayList(java.util.ArrayList) SyncedFolderProvider(com.owncloud.android.datamodel.SyncedFolderProvider) MediaFolder(com.owncloud.android.datamodel.MediaFolder) StoragePoint(com.owncloud.android.datastorage.StoragePoint) SuppressLint(android.annotation.SuppressLint) ContentResolver(android.content.ContentResolver)

Aggregations

MediaFolder (com.owncloud.android.datamodel.MediaFolder)3 SyncedFolder (com.owncloud.android.datamodel.SyncedFolder)3 ArrayList (java.util.ArrayList)3 SyncedFolderDisplayItem (com.owncloud.android.datamodel.SyncedFolderDisplayItem)2 Account (android.accounts.Account)1 SuppressLint (android.annotation.SuppressLint)1 ContentResolver (android.content.ContentResolver)1 Context (android.content.Context)1 NonNull (android.support.annotation.NonNull)1 SyncedFolderProvider (com.owncloud.android.datamodel.SyncedFolderProvider)1 StoragePoint (com.owncloud.android.datastorage.StoragePoint)1