use of com.foobnix.ui2.adapter.FileMetaAdapter in project LibreraReader by foobnix.
the class RecentFragment2 method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_recent, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
panelRecent = view.findViewById(R.id.panelRecent);
onListGrid = (ImageView) view.findViewById(R.id.onListGrid);
onListGrid.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
popupMenu(onListGrid);
}
});
TxtUtils.underlineTextView((TextView) view.findViewById(R.id.clearAllRecent)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialogs.showDialog(getActivity(), getString(R.string.do_you_want_to_clear_everything_), getString(R.string.ok), new Runnable() {
@Override
public void run() {
clearAllRecent.run();
RecentUpates.updateAll(getActivity());
}
});
}
});
recentAdapter = new FileMetaAdapter();
recentAdapter.tempValue = FileMetaAdapter.TEMP_VALUE_FOLDER_PATH;
bindAdapter(recentAdapter);
bindAuthorsSeriesAdapter(recentAdapter);
recentAdapter.setOnDeleteClickListener(onDeleteRecentClick);
onGridList();
populate();
TintUtil.setBackgroundFillColor(panelRecent, TintUtil.color);
return view;
}
use of com.foobnix.ui2.adapter.FileMetaAdapter in project LibreraReader by foobnix.
the class FileMetaAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holderAll, final int position) {
final FileMeta fileMeta = getItem(position);
if (holderAll instanceof StarsTitleViewHolder) {
final StarsTitleViewHolder holder = (StarsTitleViewHolder) holderAll;
if (holder.clearAllFolders != null) {
TxtUtils.underlineTextView(holder.clearAllFolders).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clearAllStarredFolders.run();
}
});
}
if (holder.clearAllBooks != null) {
TxtUtils.underlineTextView(holder.clearAllBooks).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clearAllStarredBooks.run();
}
});
}
if (holder.onGridList != null) {
PopupHelper.updateGridOrListIcon(holder.onGridList, AppState.get().starsMode);
holder.onGridList.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onGridOrList.onResultRecive(holder.onGridList);
}
});
}
TintUtil.setBackgroundFillColor(holder.parent, TintUtil.color);
}
if (holderAll instanceof FileMetaViewHolder) {
final FileMetaViewHolder holder = (FileMetaViewHolder) holderAll;
if (!AppState.get().isShowImages && adapterType == ADAPTER_COVERS) {
adapterType = ADAPTER_GRID;
}
bindFileMetaView(holder, position);
IMG.getCoverPageWithEffect(holder.image, fileMeta.getPath(), IMG.getImageSize(), new SimpleImageLoadingListener() {
@Override
public void onLoadingCancelled(String imageUri, View view) {
super.onLoadingCancelled(imageUri, view);
}
@Override
public void onLoadingStarted(String imageUri, View view) {
super.onLoadingStarted(imageUri, view);
}
@Override
public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
if (position <= items.size() - 1) {
FileMeta it = AppDB.get().load(fileMeta.getPath());
if (it != null) {
items.set(position, it);
bindFileMetaView(holder, position);
}
}
}
});
holder.imageParent.setVisibility(AppState.get().isShowImages ? View.VISIBLE : View.GONE);
} else if (holderAll instanceof TagViewHolder) {
final TagViewHolder holder = (TagViewHolder) holderAll;
holder.title.setText(fileMeta.getPathTxt());
TintUtil.setTintImageWithAlpha(holder.image);
bindItemClickAndLongClickListeners(holder.parent, fileMeta);
} else if (holderAll instanceof DirectoryViewHolder) {
final DirectoryViewHolder holder = (DirectoryViewHolder) holderAll;
holder.title.setText(fileMeta.getPathTxt());
holder.path.setText(fileMeta.getPath());
TintUtil.setTintImageWithAlpha(holder.image, holder.image.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
bindItemClickAndLongClickListeners(holder.parent, fileMeta);
if (!AppState.get().isBorderAndShadow) {
holder.parent.setBackgroundColor(Color.TRANSPARENT);
}
if (AppDB.get().isStarFolder(fileMeta.getPath())) {
holder.starIcon.setImageResource(R.drawable.star_1);
} else {
holder.starIcon.setImageResource(R.drawable.star_2);
}
TintUtil.setTintImageWithAlpha(holder.starIcon, holder.starIcon.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
if (onStarClickListener != null) {
holder.starIcon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onStarClickListener.onResultRecive(fileMeta, FileMetaAdapter.this);
}
});
}
holder.starIcon.setVisibility(ExtUtils.isExteralSD(fileMeta.getPath()) ? View.GONE : View.VISIBLE);
if (adapterType == ADAPTER_GRID || adapterType == ADAPTER_COVERS) {
// holder.image.setVisibility(View.GONE);
holder.path.setVisibility(View.GONE);
} else {
// holder.image.setVisibility(View.VISIBLE);
if (tempValue == TEMP_VALUE_FOLDER_PATH) {
holder.path.setVisibility(View.VISIBLE);
} else {
holder.path.setVisibility(View.GONE);
}
}
} else if (holderAll instanceof StarsLayoutViewHolder) {
final StarsLayoutViewHolder holder = (StarsLayoutViewHolder) holderAll;
final FileMetaAdapter adapter = new FileMetaAdapter();
adapter.setOnItemClickListener(onItemClickListener);
adapter.setOnItemLongClickListener(onItemLongClickListener);
adapter.setOnMenuClickListener(onMenuClickListener);
adapter.setOnStarClickListener(onStarClickListener);
adapter.setOnAuthorClickListener(onAuthorClickListener);
adapter.setOnSeriesClickListener(onSeriesClickListener);
adapter.setAdapterType(FileMetaAdapter.ADAPTER_GRID);
adapter.tempValue = TEMP_VALUE_STAR_GRID_ITEM;
holder.recyclerView.setAdapter(adapter);
adapter.getItemsList().clear();
TintUtil.setBackgroundFillColor(holder.panelRecent, TintUtil.color);
TintUtil.setBackgroundFillColor(holder.panelStars, TintUtil.color);
List<FileMeta> allStars = AppDB.get().getStarsFiles();
final String STARRED = holder.starredName.getContext().getString(R.string.starred).toUpperCase(Locale.US) + " (" + allStars.size() + ")";
holder.recentName.setText(holder.starredName.getContext().getString(R.string.recent) + " (" + (getItemCount() - 1) + ")");
holder.starredNameIcon.setImageResource(R.drawable.star_1);
TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
TxtUtils.underlineTextView(holder.starredName);
holder.starredName.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
MyPopupMenu menu = new MyPopupMenu(v.getContext(), v);
menu.getMenu().add(STARRED).setIcon(R.drawable.star_1).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().recentTag = "";
holder.starredNameIcon.setImageResource(R.drawable.star_1);
TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
TxtUtils.underline(holder.starredName, STARRED);
adapter.getItemsList().clear();
List<FileMeta> allStars = AppDB.get().getStarsFiles();
adapter.getItemsList().addAll(allStars);
adapter.notifyDataSetChanged();
return false;
}
});
List<String> tags = AppDB.get().getAll(SEARCH_IN.TAGS);
Collections.sort(tags);
for (final String tag : tags) {
int count = AppDB.get().getAllWithTag(tag).size();
final String nameName = tag + " (" + count + ")";
menu.getMenu().add(nameName).setIcon(R.drawable.glyphicons_67_tags).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().recentTag = tag;
holder.starredNameIcon.setImageResource(R.drawable.glyphicons_67_tags);
TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
TxtUtils.underline(holder.starredName, nameName);
adapter.getItemsList().clear();
List<FileMeta> allTags = AppDB.get().searchBy("@tags " + tag, SORT_BY.FILE_NAME, false);
adapter.getItemsList().addAll(allTags);
adapter.notifyDataSetChanged();
return false;
}
});
}
menu.show();
}
});
if (TxtUtils.isEmpty(AppState.get().recentTag)) {
holder.starredNameIcon.setImageResource(R.drawable.star_1);
TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
TxtUtils.underline(holder.starredName, STARRED);
adapter.getItemsList().clear();
adapter.getItemsList().addAll(allStars);
adapter.notifyDataSetChanged();
} else {
holder.starredNameIcon.setImageResource(R.drawable.glyphicons_67_tags);
TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
adapter.getItemsList().clear();
List<FileMeta> allTags = AppDB.get().searchBy("@tags " + AppState.get().recentTag, SORT_BY.FILE_NAME, false);
adapter.getItemsList().addAll(allTags);
adapter.notifyDataSetChanged();
TxtUtils.underline(holder.starredName, AppState.get().recentTag + " (" + allTags.size() + ")");
}
} else if (holderAll instanceof AuthorViewHolder) {
AuthorViewHolder aHolder = (AuthorViewHolder) holderAll;
aHolder.onBindViewHolder(aHolder, fileMeta.getSequence());
aHolder.parent.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onSeriesClickListener != null) {
onSeriesClickListener.onResultRecive(fileMeta.getSequence());
}
}
});
}
}
use of com.foobnix.ui2.adapter.FileMetaAdapter in project LibreraReader by foobnix.
the class SearchFragment2 method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_search2, container, false);
NO_SERIES = " (" + getString(R.string.without_series) + ")";
handler = new Handler();
secondTopPanel = view.findViewById(R.id.secondTopPanel);
countBooks = (TextView) view.findViewById(R.id.countBooks);
onRefresh = view.findViewById(R.id.onRefresh);
onRefresh.setActivated(true);
cleanFilter = (ImageView) view.findViewById(R.id.cleanFilter);
sortBy = (TextView) view.findViewById(R.id.sortBy);
sortOrder = (ImageView) view.findViewById(R.id.sortOrder);
myAutoCompleteImage = (ImageView) view.findViewById(R.id.myAutoCompleteImage);
searchEditText = (AutoCompleteTextView) view.findViewById(R.id.filterLine);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
myAutoCompleteImage.setVisibility(View.GONE);
((FastScrollRecyclerView) recyclerView).setFastScrollStateChangeListener(new FastScrollStateChangeListener() {
@Override
public void onFastScrollStop() {
ImageLoader.getInstance().resume();
LOG.d("ImageLoader resume");
}
@Override
public void onFastScrollStart() {
LOG.d("ImageLoader pause");
ImageLoader.getInstance().pause();
}
});
searchEditText.addTextChangedListener(filterTextWatcher);
searchEditText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
EditTextHelper.enableKeyboardSearch(searchEditText, new Runnable() {
@Override
public void run() {
Keyboards.close(searchEditText);
Keyboards.hideNavigation(getActivity());
}
});
searchAdapter = new FileMetaAdapter();
authorsAdapter = new AuthorsAdapter2();
onGridlList = (ImageView) view.findViewById(R.id.onGridList);
onGridlList.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
popupMenu(onGridlList);
}
});
onRefresh.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!onRefresh.isActivated()) {
Toast.makeText(getActivity(), R.string.extracting_information_from_books, Toast.LENGTH_LONG).show();
return;
}
PrefDialogs.chooseFolderDialog(getActivity(), new Runnable() {
@Override
public void run() {
AppState.get().searchPaths = AppState.get().searchPaths.replace("//", "/");
}
}, new Runnable() {
@Override
public void run() {
recyclerView.scrollToPosition(0);
seachAll();
}
});
}
});
cleanFilter.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
searchEditText.setText("");
recyclerView.scrollToPosition(0);
searchAndOrderAsync();
}
});
sortBy.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sortByPopup(v);
}
});
sortOrder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().isSortAsc = !AppState.get().isSortAsc;
searchAndOrderAsync();
}
});
bindAdapter(searchAdapter);
searchAdapter.setOnAuthorClickListener(onAuthorClick);
searchAdapter.setOnSeriesClickListener(onSeriesClick);
authorsAdapter.setOnItemClickListener(onAuthorSeriesClick);
onGridList();
if (AppDB.get().getCount() == 0) {
seachAll();
} else {
checkForDeleteBooks();
searchAndOrderAsync();
}
initAutocomplition();
onTintChanged();
recyclerView.addOnScrollListener(new OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
}
});
myAutoCompleteImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showAutoCompleteDialog();
}
});
return view;
}
use of com.foobnix.ui2.adapter.FileMetaAdapter in project LibreraReader by foobnix.
the class StarsFragment2 method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_starred, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
panelRecent = view.findViewById(R.id.panelRecent);
recentAdapter = new FileMetaAdapter();
recentAdapter.tempValue = FileMetaAdapter.TEMP_VALUE_FOLDER_PATH;
bindAdapter(recentAdapter);
bindAuthorsSeriesAdapter(recentAdapter);
TxtUtils.underlineTextView((TextView) view.findViewById(R.id.clearAllRecent)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialogs.showDialog(getActivity(), getString(R.string.do_you_want_to_clear_everything_), getString(R.string.ok), new Runnable() {
@Override
public void run() {
for (FileMeta f : AppDB.get().getStarsFolder()) {
f.setIsStar(false);
AppDB.get().update(f);
}
for (FileMeta f : AppDB.get().getStarsFiles()) {
f.setIsStar(false);
AppDB.get().update(f);
}
populate();
RecentUpates.updateAll(getActivity());
}
});
}
});
onListGrid = (ImageView) view.findViewById(R.id.onListGrid);
onListGrid.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
popupMenu(onListGrid);
}
});
recentAdapter.setOnGridOrList(new ResultResponse<ImageView>() {
@Override
public boolean onResultRecive(ImageView result) {
popupMenu(result);
return false;
}
});
onGridList();
populate();
TintUtil.setBackgroundFillColor(panelRecent, TintUtil.color);
return view;
}
use of com.foobnix.ui2.adapter.FileMetaAdapter in project LibreraReader by foobnix.
the class UIFragment method onGridList.
public void onGridList(int mode, ImageView onGridlList, final FileMetaAdapter searchAdapter, AuthorsAdapter2 authorsAdapter) {
if (searchAdapter == null) {
return;
}
if (onGridlList != null) {
PopupHelper.updateGridOrListIcon(onGridlList, mode);
}
if (mode == AppState.MODE_LIST) {
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(mLayoutManager);
searchAdapter.setAdapterType(FileMetaAdapter.ADAPTER_LIST);
recyclerView.setAdapter(searchAdapter);
} else if (mode == AppState.MODE_COVERS || mode == AppState.MODE_GRID) {
final int num = Math.max(1, Dips.screenWidthDP() / AppState.get().coverBigSize);
GridLayoutManager mGridManager = new GridLayoutManager(getActivity(), num);
mGridManager.setSpanSizeLookup(new SpanSizeLookup() {
@Override
public int getSpanSize(int pos) {
int type = searchAdapter.getItemViewType(pos);
if (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_FOLDERS) {
return num;
}
if (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TAG) {
return 1;
}
if (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_NONE) {
return num;
}
if (type == FileMetaAdapter.DISPLAY_TYPE_DIRECTORY) {
if (num == 1) {
return 1;
} else if (num == 2) {
return 1;
} else if (num == 3) {
return 3;
}
return 2;
}
if (type == FileMetaAdapter.DISPALY_TYPE_SERIES) {
return num;
}
return (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_BOOKS) ? num : 1;
}
});
recyclerView.setLayoutManager(mGridManager);
searchAdapter.setAdapterType(mode == AppState.MODE_COVERS ? FileMetaAdapter.ADAPTER_COVERS : FileMetaAdapter.ADAPTER_GRID);
recyclerView.setAdapter(searchAdapter);
} else if (Arrays.asList(AppState.MODE_AUTHORS, AppState.MODE_SERIES, AppState.MODE_GENRE, AppState.MODE_TAGS).contains(mode)) {
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setAdapter(authorsAdapter);
} else if (mode == AppState.MODE_LIST_COMPACT) {
final int num = Math.max(2, Dips.screenWidthDP() / Dips.dpToPx(300));
GridLayoutManager mGridManager = new GridLayoutManager(getActivity(), num);
mGridManager.setSpanSizeLookup(new SpanSizeLookup() {
@Override
public int getSpanSize(int pos) {
int type = searchAdapter.getItemViewType(pos);
if (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_FOLDERS) {
return num;
}
if (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TAG) {
return 1;
}
if (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_NONE) {
return num;
}
return (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_BOOKS) ? num : 1;
}
});
recyclerView.setLayoutManager(mGridManager);
searchAdapter.setAdapterType(FileMetaAdapter.ADAPTER_LIST_COMPACT);
recyclerView.setAdapter(searchAdapter);
}
if (recyclerView instanceof FastScrollRecyclerView) {
((FastScrollRecyclerView) recyclerView).myConfiguration();
}
}
Aggregations