use of com.foobnix.ui2.adapter.FileMetaAdapter in project LibreraReader by foobnix.
the class BrowseFragment2 method onCreateView.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_browse2, container, false);
Bundle arguments = getArguments();
pathContainer = view.findViewById(R.id.pathContainer);
View onCloseActionPaner = view.findViewById(R.id.onCloseActionPaner);
onClose = view.findViewById(R.id.onClose);
starIcon = (ImageView) view.findViewById(R.id.starIcon);
onSort = (ImageView) view.findViewById(R.id.onSort);
onSort.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
AppState.get().sortByReverse = !AppState.get().sortByReverse;
onSort.setImageResource(AppState.get().sortByReverse ? R.drawable.glyphicons_410_sort_by_attributes_alt : R.drawable.glyphicons_409_sort_by_attributes);
populate();
return true;
}
});
onSort.setImageResource(AppState.get().sortByReverse ? R.drawable.glyphicons_410_sort_by_attributes_alt : R.drawable.glyphicons_409_sort_by_attributes);
onAction = view.findViewById(R.id.onAction);
editPath = (EditText) view.findViewById(R.id.editPath);
fragmentType = TYPE_DEFAULT;
if (arguments != null) {
fragmentType = arguments.getInt(EXTRA_TYPE, TYPE_DEFAULT);
fragmentText = arguments.getString(EXTRA_TEXT);
editPath.setText(fragmentText);
}
onClose.setOnClickListener(onCloseButtonActoin);
onAction.setOnClickListener(onSelectAction);
if (TYPE_DEFAULT == fragmentType) {
editPath.setVisibility(View.GONE);
onCloseActionPaner.setVisibility(View.GONE);
}
if (TYPE_SELECT_FOLDER == fragmentType) {
editPath.setVisibility(View.VISIBLE);
editPath.setEnabled(false);
onCloseActionPaner.setVisibility(View.VISIBLE);
}
if (TYPE_SELECT_FILE == fragmentType) {
editPath.setVisibility(View.VISIBLE);
editPath.setEnabled(false);
onCloseActionPaner.setVisibility(View.VISIBLE);
}
if (TYPE_CREATE_FILE == fragmentType) {
editPath.setVisibility(View.VISIBLE);
editPath.setEnabled(true);
onCloseActionPaner.setVisibility(View.VISIBLE);
}
View onBack = view.findViewById(R.id.onBack);
recyclerView = (FastScrollRecyclerView) view.findViewById(R.id.recyclerView);
paths = (LinearLayout) view.findViewById(R.id.paths);
scroller = (HorizontalScrollView) view.findViewById(R.id.scroller);
final View onHome = view.findViewById(R.id.onHome);
onListGrid = (ImageView) view.findViewById(R.id.onListGrid);
onListGrid.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
popupMenu(onListGrid);
}
});
searchAdapter = new FileMetaAdapter();
bindAdapter(searchAdapter);
bindAuthorsSeriesAdapter(searchAdapter);
onGridList();
onHome.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
List<String> extFolders = new ArrayList<String>();
extFolders = ExtUtils.getExternalStorageDirectories(getActivity());
String sdPath = ExtUtils.getSDPath();
if (TxtUtils.isNotEmpty(sdPath) && !extFolders.contains(sdPath)) {
extFolders.add(sdPath);
}
MyPopupMenu menu = new MyPopupMenu(getActivity(), onHome);
menu.getMenu().add(R.string.internal_storage).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setDirPath(Environment.getExternalStorageDirectory().getPath());
return false;
}
}).setIcon(R.drawable.glyphicons_146_folder_sd1);
for (final String info : extFolders) {
String name;
if (ExtUtils.isExteralSD(info)) {
name = ExtUtils.getExtSDDisplayName(getContext(), info);
} else {
name = new File(info).getName();
}
menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setDirPath(info);
return false;
}
}).setIcon(R.drawable.glyphicons_146_folder_sd1);
}
menu.getMenu().add("Librera").setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setDirPath(AppState.get().downlodsPath);
return false;
}
}).setIcon(R.drawable.glyphicons_591_folder_heart);
if (Build.VERSION.SDK_INT >= 21 && getActivity() instanceof MainTabs2) {
List<String> safs = StringDB.asList(AppState.get().pathSAF);
for (final String saf : safs) {
String fileName = DocumentsContract.getTreeDocumentId(Uri.parse(saf));
menu.getMenu().add(fileName).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setDirPath(saf);
return false;
}
}).setOnMenuItemLongClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().pathSAF = StringDB.delete(AppState.get().pathSAF, saf);
return false;
}
}).setIcon(R.drawable.glyphicons_146_folder_plus);
}
}
// stars
List<FileMeta> starFolders = AppDB.get().getStarsFolder();
List<String> names = new ArrayList<String>();
for (FileMeta f : starFolders) {
names.add(f.getPath());
}
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
for (final String info : names) {
String name;
if (ExtUtils.isExteralSD(info)) {
name = ExtUtils.getExtSDDisplayName(getContext(), info);
} else {
name = new File(info).getName();
}
menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setDirPath(info);
return false;
}
}).setIcon(R.drawable.glyphicons_591_folder_star);
}
if (Build.VERSION.SDK_INT >= 21 && getActivity() instanceof MainTabs2) {
menu.getMenu().add(R.string.add_resource).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(//
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | //
Intent.FLAG_GRANT_PREFIX_URI_PERMISSION | //
Intent.FLAG_GRANT_READ_URI_PERMISSION | //
Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getActivity().startActivityForResult(intent, MainTabs2.REQUEST_CODE_ADD_RESOURCE);
return true;
}
}).setIcon(R.drawable.glyphicons_146_add_folder_plus);
}
menu.show();
}
});
onBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onBackAction();
}
});
searchAdapter.setOnItemClickListener(new ResultResponse<FileMeta>() {
@Override
public boolean onResultRecive(FileMeta result) {
if (result.getCusType() != null && result.getCusType() == FileMetaAdapter.DISPLAY_TYPE_DIRECTORY) {
setDirPath(result.getPath());
if (fragmentType == TYPE_SELECT_FOLDER) {
editPath.setText(fragmentText);
}
} else {
if (fragmentType == TYPE_DEFAULT) {
DefaultListeners.getOnItemClickListener(getActivity()).onResultRecive(result);
} else if (fragmentType == TYPE_SELECT_FILE) {
editPath.setText(ExtUtils.getFileName(result.getPath()));
}
}
return false;
}
});
searchAdapter.setOnItemLongClickListener(new ResultResponse<FileMeta>() {
@Override
public boolean onResultRecive(FileMeta result) {
if (result.getCusType() != null && result.getCusType() == FileMetaAdapter.DISPLAY_TYPE_DIRECTORY) {
// setDirPath(result.getPath());
} else {
DefaultListeners.getOnItemLongClickListener(getActivity(), searchAdapter).onResultRecive(result);
}
return false;
}
});
onSort.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
List<String> names = //
Arrays.asList(//
getActivity().getString(R.string.by_file_name), //
getActivity().getString(R.string.by_date), //
getActivity().getString(R.string.by_size), //
getActivity().getString(R.string.by_title), //
getActivity().getString(R.string.by_number_in_serie), //
getActivity().getString(R.string.by_number_of_pages), //
getActivity().getString(R.string.by_extension));
//
final List<Integer> ids = //
Arrays.asList(//
AppState.BR_SORT_BY_PATH, //
AppState.BR_SORT_BY_DATE, //
AppState.BR_SORT_BY_SIZE, //
AppState.BR_SORT_BY_TITLE, //
AppState.BR_SORT_BY_NUMBER, //
AppState.BR_SORT_BY_PAGES, //
AppState.BR_SORT_BY_EXT);
//
MyPopupMenu menu = new MyPopupMenu(getActivity(), v);
for (int i = 0; i < names.size(); i++) {
String name = names.get(i);
final int j = i;
menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().sortByBrowse = ids.get(j);
populate();
return false;
}
});
}
menu.show();
}
});
populate();
onTintChanged();
return view;
}
Aggregations