Search in sources :

Example 1 with DividerItemDecoration

use of com.amaze.filemanager.ui.views.DividerItemDecoration in project AmazeFileManager by TeamAmaze.

the class MainFragment method reloadListElements.

public void reloadListElements(boolean back, boolean results, boolean grid) {
    if (isAdded()) {
        boolean isOtg = CURRENT_PATH.equals(OTGUtil.PREFIX_OTG + "/"), isOnTheCloud = CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_BOX + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_DROPBOX + "/");
        if (getBoolean(PREFERENCE_SHOW_GOBACK_BUTTON) && !CURRENT_PATH.equals("/") && (openMode == OpenMode.FILE || openMode == OpenMode.ROOT) && !isOtg && !isOnTheCloud && (LIST_ELEMENTS.size() == 0 || !LIST_ELEMENTS.get(0).size.equals(getString(R.string.goback)))) {
            LIST_ELEMENTS.add(0, getBackElement());
        }
        if (LIST_ELEMENTS.size() == 0 && !results) {
            nofilesview.setVisibility(View.VISIBLE);
            listView.setVisibility(View.GONE);
            mSwipeRefreshLayout.setEnabled(false);
        } else {
            mSwipeRefreshLayout.setEnabled(true);
            nofilesview.setVisibility(View.GONE);
            listView.setVisibility(View.VISIBLE);
        }
        if (grid && IS_LIST)
            switchToGrid();
        else if (!grid && !IS_LIST)
            switchToList();
        if (adapter == null) {
            adapter = new RecyclerAdapter(getMainActivity(), ma, utilsProvider, sharedPref, listView, LIST_ELEMENTS, ma.getActivity());
        } else {
            adapter.setItems(listView, new ArrayList<>(LIST_ELEMENTS));
        }
        stopAnims = true;
        if (openMode != OpenMode.CUSTOM) {
            dataUtils.addHistoryFile(CURRENT_PATH);
        }
        listView.setAdapter(adapter);
        if (!addheader) {
            listView.removeItemDecoration(dividerItemDecoration);
            addheader = true;
        }
        if (addheader && IS_LIST) {
            dividerItemDecoration = new DividerItemDecoration(getActivity(), true, getBoolean(PREFERENCE_SHOW_DIVIDERS));
            listView.addItemDecoration(dividerItemDecoration);
            addheader = false;
        }
        if (!results) {
            this.results = false;
        }
        if (back && scrolls.containsKey(CURRENT_PATH)) {
            Bundle b = scrolls.get(CURRENT_PATH);
            int index = b.getInt("index"), top = b.getInt("top");
            if (IS_LIST) {
                mLayoutManager.scrollToPositionWithOffset(index, top);
            } else {
                mLayoutManagerGrid.scrollToPositionWithOffset(index, top);
            }
        }
        getMainActivity().updatePaths(no);
        listView.stopScroll();
        fastScroller.setRecyclerView(listView, IS_LIST ? 1 : columns);
        mToolbarContainer.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
            fastScroller.updateHandlePosition(verticalOffset, 112);
        });
        fastScroller.registerOnTouchListener(() -> {
            if (stopAnims && adapter != null) {
                stopAnimation();
                stopAnims = false;
            }
        });
        startFileObserver();
    } else {
        // list loading cancelled
        // TODO: Add support for cancelling list loading
        loadlist(home, true, OpenMode.FILE);
    }
}
Also used : RecyclerAdapter(com.amaze.filemanager.adapters.RecyclerAdapter) Bundle(android.os.Bundle) DividerItemDecoration(com.amaze.filemanager.ui.views.DividerItemDecoration)

Example 2 with DividerItemDecoration

use of com.amaze.filemanager.ui.views.DividerItemDecoration in project AmazeFileManager by TeamAmaze.

the class MainFragment method onActivityCreated.

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setHasOptionsMenu(false);
    // getMainActivity() = (MainActivity) getActivity();
    initNoFileLayout();
    getSortModes();
    this.setRetainInstance(false);
    HybridFile f = new HybridFile(OpenMode.UNKNOWN, CURRENT_PATH);
    f.generateMode(getActivity());
    getMainActivity().getAppbar().getBottomBar().setClickListener();
    if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT) && !IS_LIST) {
        listView.setBackgroundColor(Utils.getColor(getContext(), R.color.grid_background_light));
    } else {
        listView.setBackgroundDrawable(null);
    }
    listView.setHasFixedSize(true);
    columns = Integer.parseInt(sharedPref.getString(PREFERENCE_GRID_COLUMNS, "-1"));
    if (IS_LIST) {
        mLayoutManager = new LinearLayoutManager(getContext());
        listView.setLayoutManager(mLayoutManager);
    } else {
        if (columns == -1 || columns == 0)
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), 3);
        else
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), columns);
        setGridLayoutSpanSizeLookup(mLayoutManagerGrid);
        listView.setLayoutManager(mLayoutManagerGrid);
    }
    // use a linear layout manager
    // View footerView = getActivity().getLayoutInflater().inflate(R.layout.divider, null);// TODO: 23/5/2017 use or delete
    dividerItemDecoration = new DividerItemDecoration(getActivity(), false, getBoolean(PREFERENCE_SHOW_DIVIDERS));
    listView.addItemDecoration(dividerItemDecoration);
    mSwipeRefreshLayout.setColorSchemeColors(accentColor);
    DefaultItemAnimator animator = new DefaultItemAnimator();
    listView.setItemAnimator(animator);
    mToolbarContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            if ((columns == 0 || columns == -1)) {
                int screen_width = listView.getWidth();
                int dptopx = Utils.dpToPx(getContext(), 115);
                columns = screen_width / dptopx;
                if (columns == 0 || columns == -1)
                    columns = 3;
                if (!IS_LIST)
                    mLayoutManagerGrid.setSpanCount(columns);
            }
            if (savedInstanceState != null && !IS_LIST)
                onSavedInstanceState(savedInstanceState);
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
                mToolbarContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                mToolbarContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }
    });
    if (savedInstanceState == null) {
        loadlist(CURRENT_PATH, false, openMode);
    } else {
        if (IS_LIST)
            onSavedInstanceState(savedInstanceState);
    }
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) GridLayoutManager(android.support.v7.widget.GridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(com.amaze.filemanager.ui.views.DividerItemDecoration) ViewTreeObserver(android.view.ViewTreeObserver) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 3 with DividerItemDecoration

use of com.amaze.filemanager.ui.views.DividerItemDecoration in project AmazeFileManager by TeamAmaze.

the class CompressedExplorerFragment method createViews.

private void createViews(ArrayList<CompressedObjectParcelable> items, String dir) {
    if (compressedExplorerAdapter == null) {
        compressedExplorerAdapter = new CompressedExplorerAdapter(getActivity(), utilsProvider, items, this, decompressor);
        listView.setAdapter(compressedExplorerAdapter);
    } else {
        compressedExplorerAdapter.generateZip(items);
    }
    folder = 0;
    file = 0;
    for (CompressedObjectParcelable item : items) {
        if (item.type == CompressedObjectParcelable.TYPE_GOBACK)
            continue;
        if (item.directory)
            folder++;
        else
            file++;
    }
    stopAnims = true;
    if (!addheader) {
        listView.removeItemDecoration(dividerItemDecoration);
        // listView.removeItemDecoration(headersDecor);
        addheader = true;
    } else {
        dividerItemDecoration = new DividerItemDecoration(getActivity(), true, showDividers);
        listView.addItemDecoration(dividerItemDecoration);
        // headersDecor = new StickyRecyclerHeadersDecoration(compressedExplorerAdapter);
        // listView.addItemDecoration(headersDecor);
        addheader = false;
    }
    final FastScroller fastScroller = (FastScroller) rootView.findViewById(R.id.fastscroll);
    fastScroller.setRecyclerView(listView, 1);
    fastScroller.setPressedHandleColor(mainActivity.getColorPreference().getColor(ColorUsage.ACCENT));
    ((AppBarLayout) mToolbarContainer).addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
        fastScroller.updateHandlePosition(verticalOffset, 112);
    });
    listView.stopScroll();
    relativeDirectory = dir;
    updateBottomBar();
    swipeRefreshLayout.setRefreshing(false);
}
Also used : CompressedObjectParcelable(com.amaze.filemanager.adapters.data.CompressedObjectParcelable) FastScroller(com.amaze.filemanager.ui.views.FastScroller) AppBarLayout(android.support.design.widget.AppBarLayout) DividerItemDecoration(com.amaze.filemanager.ui.views.DividerItemDecoration) CompressedExplorerAdapter(com.amaze.filemanager.adapters.CompressedExplorerAdapter)

Aggregations

DividerItemDecoration (com.amaze.filemanager.ui.views.DividerItemDecoration)3 Bundle (android.os.Bundle)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 ViewTreeObserver (android.view.ViewTreeObserver)1 CompressedExplorerAdapter (com.amaze.filemanager.adapters.CompressedExplorerAdapter)1 RecyclerAdapter (com.amaze.filemanager.adapters.RecyclerAdapter)1 CompressedObjectParcelable (com.amaze.filemanager.adapters.data.CompressedObjectParcelable)1 HybridFile (com.amaze.filemanager.filesystem.HybridFile)1 FastScroller (com.amaze.filemanager.ui.views.FastScroller)1