use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.
the class FileMetaAdapter method getItemViewType.
@Override
public int getItemViewType(int position) {
FileMeta item = getItem(position);
if (item == null) {
return DISPLAY_TYPE_FILE;
}
Integer cusType = item.getCusType();
if (cusType == null) {
return DISPLAY_TYPE_FILE;
}
return cusType;
}
use of com.foobnix.dao2.FileMeta 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;
}
use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.
the class ImageExtractor method getStreamInner.
public synchronized InputStream getStreamInner(final String imageUri) throws IOException {
LOG.d("TEST", "url: " + imageUri);
if (imageUri.startsWith(Safe.TXT_SAFE_RUN)) {
LOG.d("MUPDF!", Safe.TXT_SAFE_RUN, "begin", imageUri);
// }
return baseImage.getStream("assets://opds/web.png", null);
}
if (imageUri.startsWith("https")) {
Request request = //
new Request.Builder().header("User-Agent", OPDS.USER_AGENT).url(//
imageUri).build();
LOG.d("https!!!", imageUri);
return OPDS.client.newCall(request).execute().body().byteStream();
}
if (imageUri.startsWith("data:")) {
String uri = imageUri;
// uri = uri.replace("data:image/png;base64,", "");
// uri = uri.replace("data:image/jpeg;base64,", "");
// uri = uri.replace("data:image/jpg;base64,", "");
// uri = uri.replace("data:image/gif;base64,", "");
uri = uri.substring(uri.indexOf(",") + 1);
LOG.d("Load image data ", uri);
return new ByteArrayInputStream(Base64.decode(uri, Base64.DEFAULT));
}
if (!imageUri.startsWith("{")) {
return baseImage.getStream(imageUri, null);
}
if (sp.contains("" + imageUri.hashCode())) {
LOG.d("Error FILE", imageUri);
return messageFile("#crash", "");
}
final PageUrl pageUrl = PageUrl.fromString(imageUri);
String path = pageUrl.getPath();
if (ExtUtils.isExteralSD(path)) {
if (ExtUtils.isImagePath(path)) {
return c.getContentResolver().openInputStream(Uri.parse(path));
}
return messageFile("", "");
}
File file = new File(path);
try {
if (ExtUtils.isImageFile(file)) {
FileMeta fileMeta = AppDB.get().getOrCreate(path);
FileMetaCore.get().upadteBasicMeta(fileMeta, new File(path));
AppDB.get().update(fileMeta);
return BaseExtractor.decodeImage(path, IMG.getImageSize());
}
if (path.endsWith("json")) {
FileMeta fileMeta = AppDB.get().getOrCreate(path);
FileMetaCore.get().upadteBasicMeta(fileMeta, new File(path));
AppDB.get().update(fileMeta);
return messageFile("#json", "");
}
if (!file.isFile()) {
return messageFile("#no file", "");
}
sp.edit().putBoolean("" + imageUri.hashCode(), true).commit();
int page = pageUrl.getPage();
if (pageUrl.getHeight() == 0) {
pageUrl.setHeight((int) (pageUrl.getWidth() * 1.5));
}
if (page == COVER_PAGE || page == COVER_PAGE_WITH_EFFECT) {
try {
MagicHelper.isNeedBC = false;
Bitmap proccessCoverPage = proccessCoverPage(pageUrl);
return generalCoverWithEffect(pageUrl, proccessCoverPage);
} finally {
MagicHelper.isNeedBC = true;
}
} else if (page == COVER_PAGE_NO_EFFECT) {
ByteArrayInputStream bitmapToStream = bitmapToStream(proccessCoverPage(pageUrl));
return bitmapToStream;
} else {
if (pageUrl.isDouble()) {
LOG.d("isDouble", pageUrl.getHeight(), pageUrl.getWidth());
if (AppState.get().isDoubleCoverAlone) {
pageUrl.setPage(pageUrl.getPage() - 1);
}
Bitmap bitmap1 = proccessOtherPage(pageUrl, null);
pageUrl.setPage(pageUrl.getPage() + 1);
Bitmap bitmap2 = null;
if (pageUrl.getPage() < pageCount) {
bitmap2 = proccessOtherPage(pageUrl, null);
} else {
bitmap2 = Bitmap.createBitmap(bitmap1);
Canvas canvas = new Canvas(bitmap2);
canvas.drawColor(Color.WHITE);
}
int maxH = Math.max(bitmap1.getHeight(), bitmap2.getHeight());
Bitmap bitmap = Bitmap.createBitmap(bitmap1.getWidth() + bitmap2.getWidth(), maxH, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(MagicHelper.getBgColor());
if (AppState.get().isCutRTL) {
canvas.drawBitmap(bitmap2, 0, (maxH - bitmap2.getHeight()) / 2, null);
canvas.drawBitmap(bitmap1, bitmap2.getWidth(), (maxH - bitmap1.getHeight()) / 2, null);
} else {
canvas.drawBitmap(bitmap1, 0, (maxH - bitmap1.getHeight()) / 2, null);
canvas.drawBitmap(bitmap2, bitmap1.getWidth(), (maxH - bitmap2.getHeight()) / 2, null);
}
bitmap1.recycle();
bitmap2.recycle();
return bitmapToStreamRAW(bitmap);
}
return bitmapToStreamRAW(proccessOtherPage(pageUrl, null));
}
} catch (MuPdfPasswordException e) {
return messageFile("#password", file.getName());
} catch (final Exception e) {
LOG.e(e);
return messageFile("#error", "");
} catch (OutOfMemoryError e2) {
AppState.get().pagesInMemory = 1;
return messageFile("#error", "");
} finally {
sp.edit().remove("" + imageUri.hashCode()).commit();
}
}
use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.
the class TTSNotification method show.
public static void show(String bookPath, int page) {
bookPath1 = bookPath;
page1 = page;
try {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, DEFAULT);
FileMeta fileMeta = AppDB.get().getOrCreate(bookPath);
Intent intent = new Intent(context, HorizontalViewActivity.class.getSimpleName().equals(AppState.get().lastMode) ? HorizontalViewActivity.class : VerticalViewActivity.class);
intent.setAction(ACTION_TTS);
intent.setData(Uri.fromFile(new File(bookPath)));
if (page > 0) {
intent.putExtra("page", page - 1);
}
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent stop = PendingIntent.getService(context, 0, new Intent(TTS_STOP, null, context, TTSService.class), PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent read = PendingIntent.getService(context, 0, new Intent(TTS_READ, null, context, TTSService.class), PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent next = PendingIntent.getService(context, 0, new Intent(TTS_NEXT, null, context, TTSService.class), PendingIntent.FLAG_UPDATE_CURRENT);
//
builder.setContentIntent(contentIntent).setSmallIcon(//
R.drawable.glyphicons_185_volume_up).setLargeIcon(//
getBookImage(bookPath)).setTicker(//
context.getString(R.string.app_name)).setWhen(//
System.currentTimeMillis()).setOngoing(//
AppState.get().notificationOngoing).addAction(R.drawable.glyphicons_175_pause, context.getString(R.string.to_stop), //
stop).addAction(R.drawable.glyphicons_174_play, context.getString(R.string.to_read), //
read).addAction(R.drawable.glyphicons_177_forward, context.getString(R.string.next), //
next).setContentTitle(//
TxtUtils.getFileMetaBookName(fileMeta)).setContentText(// /
context.getString(R.string.page) + " " + page);
//
Notification n = builder.build();
nm.notify(NOT_ID, n);
} catch (Exception e) {
LOG.e(e);
return;
}
}
use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.
the class AppDB method getAllRecentWithProgress.
public List<FileMeta> getAllRecentWithProgress() {
List<FileMeta> list = fileMetaDao.queryBuilder().where(FileMetaDao.Properties.IsRecent.eq(1)).orderDesc(FileMetaDao.Properties.IsRecentTime).list();
for (FileMeta meta : list) {
BookSettings bs = SettingsManager.getTempBookSettings(meta.getPath());
try {
float isRecentProgress = (float) (bs.currentPage.viewIndex + 1) / bs.getPages();
if (isRecentProgress > 1) {
isRecentProgress = 1;
}
if (isRecentProgress < 0) {
isRecentProgress = 0;
}
meta.setIsRecentProgress(isRecentProgress);
} catch (Exception e) {
LOG.d(e);
meta.setIsRecentProgress(1f);
}
}
return removeNotExist(list);
}
Aggregations