Search in sources :

Example 6 with FileSortOrder

use of com.owncloud.android.utils.FileSortOrder in project android by nextcloud.

the class LocalFileListAdapter method swapDirectory.

/**
 * Change the adapted directory for a new one
 *
 * @param directory New file to adapt. Can be NULL, meaning "no content to adapt".
 */
public void swapDirectory(final File directory) {
    localFileListFragmentInterface.setLoading(true);
    final Handler uiHandler = new Handler(Looper.getMainLooper());
    Executors.newSingleThreadExecutor().execute(() -> {
        List<File> fileList;
        if (directory == null) {
            fileList = new ArrayList<>();
        } else {
            if (mLocalFolderPicker) {
                fileList = getFolders(directory);
            } else {
                fileList = getFiles(directory);
            }
        }
        if (!fileList.isEmpty()) {
            FileSortOrder sortOrder = preferences.getSortOrderByType(FileSortOrder.Type.localFileListView);
            fileList = sortOrder.sortLocalFiles(fileList);
            // Fetch preferences for showing hidden files
            boolean showHiddenFiles = preferences.isShowHiddenFilesEnabled();
            if (!showHiddenFiles) {
                fileList = filterHiddenFiles(fileList);
            }
        }
        final List<File> newFiles = fileList;
        uiHandler.post(() -> {
            mFiles = newFiles;
            mFilesAll = new ArrayList<>();
            mFilesAll.addAll(mFiles);
            notifyDataSetChanged();
            localFileListFragmentInterface.setLoading(false);
        });
    });
}
Also used : Handler(android.os.Handler) FileSortOrder(com.owncloud.android.utils.FileSortOrder) File(java.io.File)

Example 7 with FileSortOrder

use of com.owncloud.android.utils.FileSortOrder in project android by nextcloud.

the class OCFileListAdapter method setData.

public void setData(List<Object> objects, SearchType searchType, FileDataStorageManager storageManager, @Nullable OCFile folder, boolean clear) {
    if (storageManager != null && mStorageManager == null) {
        mStorageManager = storageManager;
        showShareAvatar = mStorageManager.getCapability(user.getAccountName()).getVersion().isShareesOnDavSupported();
    }
    if (mStorageManager == null) {
        mStorageManager = new FileDataStorageManager(user, activity.getContentResolver());
    }
    if (clear) {
        mFiles.clear();
        resetLastTimestamp();
        preferences.setPhotoSearchTimestamp(0);
        VirtualFolderType type;
        switch(searchType) {
            case FAVORITE_SEARCH:
                type = VirtualFolderType.FAVORITE;
                break;
            case GALLERY_SEARCH:
                type = VirtualFolderType.GALLERY;
                break;
            default:
                type = VirtualFolderType.NONE;
                break;
        }
        if (type != VirtualFolderType.GALLERY) {
            mStorageManager.deleteVirtuals(type);
        }
    }
    // early exit
    if (objects.size() > 0 && mStorageManager != null) {
        if (searchType == SearchType.SHARED_FILTER) {
            parseShares(objects);
        } else {
            if (searchType != SearchType.GALLERY_SEARCH) {
                parseVirtuals(objects, searchType);
            }
        }
    }
    if (searchType != SearchType.GALLERY_SEARCH && searchType != SearchType.RECENTLY_MODIFIED_SEARCH) {
        FileSortOrder sortOrder = preferences.getSortOrderByFolder(folder);
        mFiles = sortOrder.sortCloudFiles(mFiles);
    } else {
        mFiles = FileStorageUtils.sortOcFolderDescDateModifiedWithoutFavoritesFirst(mFiles);
    }
    mFilesAll.clear();
    mFilesAll.addAll(mFiles);
    new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
}
Also used : FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) Handler(android.os.Handler) FileSortOrder(com.owncloud.android.utils.FileSortOrder) VirtualFolderType(com.owncloud.android.datamodel.VirtualFolderType)

Example 8 with FileSortOrder

use of com.owncloud.android.utils.FileSortOrder in project android by nextcloud.

the class OCFileListAdapter method setFavoriteAttributeForItemID.

public void setFavoriteAttributeForItemID(String fileId, boolean favorite, boolean removeFromList) {
    for (OCFile file : mFiles) {
        if (file.getRemoteId().equals(fileId)) {
            file.setFavorite(favorite);
            if (removeFromList) {
                mFiles.remove(file);
            }
            break;
        }
    }
    for (OCFile file : mFilesAll) {
        if (file.getRemoteId().equals(fileId)) {
            file.setFavorite(favorite);
            mStorageManager.saveFile(file);
            if (removeFromList) {
                mFiles.remove(file);
            }
            break;
        }
    }
    FileSortOrder sortOrder = preferences.getSortOrderByFolder(currentDirectory);
    mFiles = sortOrder.sortCloudFiles(mFiles);
    new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) Handler(android.os.Handler) FileSortOrder(com.owncloud.android.utils.FileSortOrder)

Example 9 with FileSortOrder

use of com.owncloud.android.utils.FileSortOrder in project android by nextcloud.

the class SortingOrderDialogFragment method setupActiveOrderSelection.

/**
 * tints the icon reflecting the actual sorting choice in the apps primary color.
 */
private void setupActiveOrderSelection() {
    final int color = ThemeColorUtils.primaryColor(null, true, true, getContext());
    for (View view : mTaggedViews) {
        if (!((FileSortOrder) view.getTag()).name.equals(mCurrentSortOrderName)) {
            continue;
        }
        if (view instanceof ImageButton) {
            ThemeButtonUtils.colorImageButton((ImageButton) view, color);
        }
        if (view instanceof TextView) {
            ((TextView) view).setTextColor(color);
            ((TextView) view).setTypeface(Typeface.DEFAULT_BOLD);
        }
    }
}
Also used : ImageButton(android.widget.ImageButton) TextView(android.widget.TextView) FileSortOrder(com.owncloud.android.utils.FileSortOrder) TextView(android.widget.TextView) View(android.view.View)

Aggregations

FileSortOrder (com.owncloud.android.utils.FileSortOrder)9 Handler (android.os.Handler)4 OCFile (com.owncloud.android.datamodel.OCFile)2 View (android.view.View)1 Button (android.widget.Button)1 ImageButton (android.widget.ImageButton)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 ActionBar (androidx.appcompat.app.ActionBar)1 MaterialButton (com.google.android.material.button.MaterialButton)1 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)1 VirtualFolderType (com.owncloud.android.datamodel.VirtualFolderType)1 LocalFileListAdapter (com.owncloud.android.ui.adapter.LocalFileListAdapter)1 UploaderAdapter (com.owncloud.android.ui.adapter.UploaderAdapter)1 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1