use of com.amaze.filemanager.adapters.RecyclerAdapter 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);
}
}
use of com.amaze.filemanager.adapters.RecyclerAdapter in project AmazeFileManager by TeamAmaze.
the class FileHandler method handleMessage.
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
MainFragment main = mainFragment.get();
String path = (String) msg.obj;
switch(msg.what) {
case CustomFileObserver.GOBACK:
main.goBack();
break;
case CustomFileObserver.NEW_ITEM:
HybridFile fileCreated = new HybridFile(main.openMode, main.getCurrentPath() + "/" + path);
main.getElementsList().add(fileCreated.generateLayoutElement(useThumbs));
break;
case CustomFileObserver.DELETED_ITEM:
for (int i = 0; i < main.getElementsList().size(); i++) {
File currentFile = new File(main.getElementsList().get(i).desc);
if (currentFile.getName().equals(path)) {
main.getElementsList().remove(i);
break;
}
}
break;
default:
// Pass along other messages from the UI
super.handleMessage(msg);
return;
}
if (listView.getVisibility() == View.VISIBLE) {
if (main.getElementsList().size() == 0) {
// no item left in list, recreate views
main.reloadListElements(true, main.results, !main.IS_LIST);
} else {
// we already have some elements in list view, invalidate the adapter
((RecyclerAdapter) listView.getAdapter()).setItems(listView, main.getElementsList());
}
} else {
// there was no list view, means the directory was empty
main.loadlist(main.getCurrentPath(), true, main.openMode);
}
main.computeScroll();
}
Aggregations