use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.
the class BrowseFragment2 method setDirPath.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setDirPath(final String path, List<FileMeta> items) {
LOG.d("setDirPath", path);
if (searchAdapter == null) {
return;
}
if (!path.equals(prevPath)) {
int pos = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
rememberPos.put(prevPath, pos);
LOG.d("rememberPos", path, pos);
}
prevPath = path;
if (AppDB.get().isStarFolder(path)) {
starIcon.setImageResource(R.drawable.star_1);
} else {
starIcon.setImageResource(R.drawable.star_2);
}
TintUtil.setTintImageWithAlpha(starIcon, Color.WHITE);
starIcon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FileMeta fileMeta = AppDB.get().getOrCreate(path);
fileMeta.setCusType(FileMetaAdapter.DISPLAY_TYPE_DIRECTORY);
fileMeta.setPathTxt(ExtUtils.getFileName(path));
DefaultListeners.getOnStarClick(getActivity()).onResultRecive(fileMeta, null);
if (AppDB.get().isStarFolder(path)) {
starIcon.setImageResource(R.drawable.star_1);
} else {
starIcon.setImageResource(R.drawable.star_2);
}
}
});
AppState.get().dirLastPath = path;
searchAdapter.clearItems();
if (items == null) {
if (!ExtUtils.isExteralSD(path)) {
items = SearchCore.getFilesAndDirs(path, fragmentType == TYPE_DEFAULT);
} else {
items = new ArrayList<FileMeta>();
if (Build.VERSION.SDK_INT >= 21) {
Uri uri = Uri.parse(path);
ContentResolver contentResolver = getActivity().getContentResolver();
Uri childrenUri = null;
try {
childrenUri = ExtUtils.getChildUri(getContext(), uri);
if (childrenUri != null) {
LOG.d("newNode uri >> ", uri);
LOG.d("newNode childrenUri >> ", childrenUri);
Cursor childCursor = contentResolver.query(childrenUri, new String[] { //
Document.COLUMN_DISPLAY_NAME, //
Document.COLUMN_DOCUMENT_ID, //
Document.COLUMN_ICON, //
Document.COLUMN_LAST_MODIFIED, //
Document.COLUMN_MIME_TYPE, //
Document.COLUMN_SIZE, //
Document.COLUMN_SUMMARY }, //
null, null, //
null);
try {
while (childCursor.moveToNext()) {
String COLUMN_DISPLAY_NAME = childCursor.getString(0);
String COLUMN_DOCUMENT_ID = childCursor.getString(1);
String COLUMN_ICON = childCursor.getString(2);
String COLUMN_LAST_MODIFIED = childCursor.getString(3);
String COLUMN_MIME_TYPE = childCursor.getString(4);
String COLUMN_SIZE = childCursor.getString(5);
String COLUMN_SUMMARY = childCursor.getString(6);
LOG.d("found- child 2=", COLUMN_DISPLAY_NAME, COLUMN_DOCUMENT_ID, COLUMN_ICON);
FileMeta meta = new FileMeta();
meta.setAuthor(SearchFragment2.EMPTY_ID);
final Uri newNode = DocumentsContract.buildDocumentUriUsingTree(uri, COLUMN_DOCUMENT_ID);
meta.setPath(newNode.toString());
LOG.d("newNode", newNode);
if (Document.MIME_TYPE_DIR.equals(COLUMN_MIME_TYPE)) {
meta.setCusType(FileMetaAdapter.DISPLAY_TYPE_DIRECTORY);
meta.setPathTxt(COLUMN_DISPLAY_NAME);
meta.setTitle(COLUMN_DISPLAY_NAME);
} else {
try {
if (COLUMN_SIZE != null) {
long size = Long.parseLong(COLUMN_SIZE);
meta.setSize(size);
meta.setSizeTxt(ExtUtils.readableFileSize(size));
}
if (COLUMN_LAST_MODIFIED != null) {
meta.setDateTxt(ExtUtils.getDateFormat(Long.parseLong(COLUMN_LAST_MODIFIED)));
}
} catch (Exception e) {
LOG.e(e);
}
meta.setExt(ExtUtils.getFileExtension(COLUMN_DISPLAY_NAME));
if (BookType.FB2.is(COLUMN_DISPLAY_NAME)) {
meta.setTitle(TxtUtils.encode1251(COLUMN_DISPLAY_NAME));
} else {
meta.setTitle(COLUMN_DISPLAY_NAME);
}
}
items.add(meta);
}
} finally {
closeQuietly(childCursor);
}
}
} catch (Exception e) {
LOG.e(e);
Toast.makeText(getActivity(), R.string.incorrect_value, Toast.LENGTH_SHORT).show();
}
}
}
}
if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_PATH) {
Collections.sort(items, FileMetaComparators.BY_PATH);
} else if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_DATE) {
Collections.sort(items, FileMetaComparators.BY_DATE);
} else if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_SIZE) {
Collections.sort(items, FileMetaComparators.BY_SIZE);
} else if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_NUMBER) {
Collections.sort(items, FileMetaComparators.BR_BY_NUMBER1);
} else if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_PAGES) {
Collections.sort(items, FileMetaComparators.BR_BY_PAGES);
} else if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_TITLE) {
Collections.sort(items, FileMetaComparators.BR_BY_TITLE);
} else if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_EXT) {
Collections.sort(items, FileMetaComparators.BR_BY_EXT);
}
if (AppState.get().sortByReverse) {
Collections.reverse(items);
}
Collections.sort(items, FileMetaComparators.DIRS);
for (int i = 0; i < items.size(); i++) {
FileMeta m = items.get(i);
if (m.getCusType() == null) {
// directory
LOG.d("DISPALY_TYPE_LAYOUT_TITLE_FOLDERS", i);
FileMeta it = new FileMeta();
it.setCusType(FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_NONE);
items.add(i, it);
break;
}
}
searchAdapter.getItemsList().addAll(items);
recyclerView.setAdapter(searchAdapter);
paths.removeAllViews();
if (ExtUtils.isExteralSD(path)) {
String id = ExtUtils.getExtSDDisplayName(getContext(), path);
TextView slash = new TextView(getActivity());
slash.setText(id);
slash.setTextColor(getResources().getColor(R.color.white));
paths.addView(slash);
} else {
final String[] split = path.split("/");
if (split == null || split.length == 0) {
TextView slash = new TextView(getActivity());
slash.setText(" / ");
slash.setTextColor(getResources().getColor(R.color.white));
paths.addView(slash);
} else {
for (int i = 0; i < split.length; i++) {
final int index = i;
String part = split[i];
if (TxtUtils.isEmpty(part)) {
continue;
}
TextView slash = new TextView(getActivity());
slash.setText(" / ");
slash.setTextColor(getResources().getColor(R.color.white));
TextView item = new TextView(getActivity());
item.setText(part);
item.setGravity(Gravity.CENTER);
item.setTextColor(getResources().getColor(R.color.white));
item.setSingleLine();
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
item.setBackgroundResource(outValue.resourceId);
if (i == split.length - 1) {
item.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
}
item.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
StringBuilder builder = new StringBuilder();
for (int j = 0; j <= index; j++) {
builder.append("/");
builder.append(split[j]);
}
String itemPath = builder.toString();
setDirPath(itemPath);
}
});
paths.addView(slash);
paths.addView(item, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
}
TextView stub = new TextView(getActivity());
stub.setText(" ");
paths.addView(stub);
}
}
scroller.postDelayed(new Runnable() {
@Override
public void run() {
scroller.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}, 100);
}
use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.
the class OpdsFragment2 method onClickLink.
public void onClickLink(final Link link) {
LOG.d("onClickLink", link.type, link.href);
if (link.filePath != null) {
FileMeta meta = new FileMeta(link.filePath);
meta.setTitle(link.getDownloadName());
ExtUtils.openFile(getActivity(), meta);
} else if (link.isDisabled()) {
Toast.makeText(getActivity(), R.string.can_t_download, Toast.LENGTH_SHORT).show();
} else if (link.isWebLink()) {
Urls.open(getActivity(), link.href);
} else if (link.isOpdsLink()) {
if (url.equals("/")) {
urlRoot = link.href;
}
url = link.href;
stack.push(url);
LOG.d("URLAction", "ADD", url);
populate();
} else if (link.isImageLink()) {
} else {
LOG.d("Download >>", link.href);
if (isInProgress()) {
Toast.makeText(getContext(), R.string.please_wait, Toast.LENGTH_SHORT).show();
return;
}
AlertDialogs.showDialog(getActivity(), link.getDownloadName(), getActivity().getString(R.string.download), new Runnable() {
String bookPath;
@Override
public void run() {
new AsyncTask() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
protected Object doInBackground(Object... params) {
try {
OutputStream outStream = null;
String displayName = link.getDownloadName();
if (ExtUtils.isExteralSD(AppState.get().downlodsPath)) {
String mimeType = ExtUtils.getMimeType(displayName);
Uri uri = Uri.parse(AppState.get().downlodsPath);
Uri childrenUri = ExtUtils.getChildUri(getContext(), uri);
Uri createDocument = DocumentsContract.createDocument(getActivity().getContentResolver(), childrenUri, mimeType, displayName);
bookPath = createDocument.toString();
outStream = getActivity().getContentResolver().openOutputStream(createDocument);
} else {
File LIRBI_DOWNLOAD_DIR = new File(AppState.get().downlodsPath);
if (!LIRBI_DOWNLOAD_DIR.exists()) {
LIRBI_DOWNLOAD_DIR.mkdirs();
}
final File file = new File(LIRBI_DOWNLOAD_DIR, displayName);
file.delete();
outStream = new FileOutputStream(file);
bookPath = file.getPath();
}
okhttp3.Request request = //
new okhttp3.Request.Builder().cacheControl(new CacheControl.Builder().noCache().build()).url(//
link.href).build();
Response response = //
OPDS.client.newCall(//
request).execute();
BufferedSource source = response.body().source();
BufferedSink sink = Okio.buffer(Okio.sink(outStream));
sink.writeAll(response.body().source());
sink.close();
} catch (Exception e) {
LOG.e(e);
return false;
}
return true;
}
@Override
protected void onPreExecute() {
progressBar.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(Object result) {
progressBar.setVisibility(View.GONE);
if ((Boolean) result == false) {
Toast.makeText(getContext(), R.string.loading_error, Toast.LENGTH_LONG).show();
// Urls.openWevView(getActivity(), link.href, null);
} else {
link.filePath = bookPath;
if (!ExtUtils.isExteralSD(bookPath)) {
FileMeta meta = AppDB.get().getOrCreate(bookPath);
meta.setIsSearchBook(true);
AppDB.get().updateOrSave(meta);
IMG.loadCoverPageWithEffect(meta.getPath(), IMG.getImageSize());
}
TempHolder.listHash++;
}
clearEmpty();
}
}.execute();
}
});
}
}
use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.
the class SearchFragment2 method prepareDataInBackground.
@Override
public List<FileMeta> prepareDataInBackground() {
String txt = searchEditText.getText().toString().trim();
if (Arrays.asList(AppState.MODE_GRID, AppState.MODE_COVERS, AppState.MODE_LIST, AppState.MODE_LIST_COMPACT).contains(AppState.get().libraryMode)) {
if (!prevText.contains(txt)) {
prevText.push(txt);
}
if (TxtUtils.isEmpty(txt)) {
prevText.clear();
}
boolean isSearchOnlyEmpy = txt.contains(NO_SERIES);
if (isSearchOnlyEmpy) {
txt = txt.replace(NO_SERIES, "");
}
List<FileMeta> searchBy = AppDB.get().searchBy(txt, SORT_BY.getByID(AppState.get().sortBy), AppState.get().isSortAsc);
List<String> result = new ArrayList<String>();
boolean byGenre = txt.startsWith(SEARCH_IN.GENRE.getDotPrefix());
boolean byAuthor = txt.startsWith(SEARCH_IN.AUTHOR.getDotPrefix());
if (!txt.contains("::") && (byGenre || byAuthor)) {
if (isSearchOnlyEmpy) {
Iterator<FileMeta> iterator = searchBy.iterator();
while (iterator.hasNext()) {
if (TxtUtils.isNotEmpty(iterator.next().getSequence())) {
iterator.remove();
}
}
return searchBy;
}
boolean hasEmpySeries = false;
for (FileMeta it : searchBy) {
String sequence = it.getSequence();
TxtUtils.addFilteredGenreSeries(sequence, result, true);
if (!hasEmpySeries && TxtUtils.isEmpty(sequence)) {
hasEmpySeries = true;
}
}
Collections.sort(result, String.CASE_INSENSITIVE_ORDER);
Collections.reverse(result);
String genreName = txt.replace(byGenre ? "@genre " : "@author ", "");
for (String it : result) {
FileMeta fm = new FileMeta();
fm.setCusType(FileMetaAdapter.DISPALY_TYPE_SERIES);
fm.setSequence(it);
searchBy.add(0, fm);
}
if (hasEmpySeries && !result.isEmpty()) {
FileMeta fm = new FileMeta();
fm.setCusType(FileMetaAdapter.DISPALY_TYPE_SERIES);
fm.setSequence(genreName + NO_SERIES);
searchBy.add(result.size(), fm);
}
}
return searchBy;
} else {
return null;
}
}
use of com.foobnix.dao2.FileMeta 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.dao2.FileMeta in project LibreraReader by foobnix.
the class DefaultListeners method bindAdapter.
public static void bindAdapter(final Activity a, final FileMetaAdapter searchAdapter, final DocumentController dc, final Runnable onClick) {
searchAdapter.setOnItemClickListener(new ResultResponse<FileMeta>() {
@Override
public boolean onResultRecive(final FileMeta result) {
onClick.run();
dc.onCloseActivityFinal(new Runnable() {
@Override
public void run() {
ExtUtils.showDocumentWithoutDialog(a, new File(result.getPath()), -1);
}
});
return false;
}
});
searchAdapter.setOnItemLongClickListener(getOnItemLongClickListener(a, searchAdapter));
searchAdapter.setOnMenuClickListener(getOnMenuClick(a, searchAdapter));
searchAdapter.setOnStarClickListener(getOnStarClick(a));
}
Aggregations