use of com.foobnix.pdf.info.wrapper.AppBookmark in project LibreraReader by foobnix.
the class DragingDialogs method addBookmarks.
public static void addBookmarks(final FrameLayout anchor, final DocumentController controller, final Runnable onRefeshUI) {
final List<AppBookmark> objects = new ArrayList<AppBookmark>();
final BookmarksAdapter bookmarksAdapter = new BookmarksAdapter(anchor.getContext(), objects, true);
final View.OnClickListener onAdd = new View.OnClickListener() {
@Override
public void onClick(final View v) {
ListBoxHelper.showAddDialog(controller, objects, bookmarksAdapter, "");
}
};
final OnItemClickListener onItem = new OnItemClickListener() {
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
final AppBookmark appBookmark = objects.get(position);
int page = PageUrl.realToFake(appBookmark.getPage());
if (page != controller.getCurentPageFirst1()) {
final Integer offsetY = Integer.valueOf((int) controller.getOffsetY());
LOG.d("onItemClick: Bookmark", offsetY);
controller.getLinkHistory().clear();
controller.getLinkHistory().add(offsetY);
}
controller.onGoToPage(page);
onRefeshUI.run();
}
};
final OnItemLongClickListener onBooksLong = new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position, final long id) {
ListBoxHelper.showEditDeleteDialog(objects.get(position), controller, bookmarksAdapter, objects);
return true;
}
};
new DragingPopup(R.string.bookmarks, anchor, 300, 400) {
@Override
public View getContentView(final LayoutInflater inflater) {
View a = inflater.inflate(R.layout.dialog_bookmarks, null, false);
final ListView contentList = (ListView) a.findViewById(R.id.contentList);
contentList.setDivider(new ColorDrawable(Color.TRANSPARENT));
contentList.setVerticalScrollBarEnabled(false);
contentList.setAdapter(bookmarksAdapter);
contentList.setOnItemClickListener(onItem);
contentList.setOnItemLongClickListener(onBooksLong);
a.findViewById(R.id.addBookmark).setOnClickListener(onAdd);
final View.OnClickListener onAddPAge = new View.OnClickListener() {
@Override
public void onClick(final View v) {
int page = PageUrl.fakeToReal(controller.getCurentPageFirst1());
for (AppBookmark all : objects) {
if (all.getPage() == page) {
Toast.makeText(controller.getActivity(), R.string.bookmark_for_this_page_already_exists, Toast.LENGTH_LONG).show();
return;
}
}
final AppBookmark bookmark = new AppBookmark(controller.getCurrentBook().getPath(), controller.getString(R.string.fast_bookmark), page, controller.getTitle());
AppSharedPreferences.get().addBookMark(bookmark);
objects.clear();
objects.addAll(AppSharedPreferences.get().getBookmarksByBook(controller.getCurrentBook()));
bookmarksAdapter.notifyDataSetChanged();
closeDialog();
String TEXT = controller.getString(R.string.fast_bookmark) + " " + TxtUtils.LONG_DASH + " " + controller.getString(R.string.page) + " " + page + "";
Toast.makeText(controller.getActivity(), TEXT, Toast.LENGTH_SHORT).show();
}
};
a.findViewById(R.id.addPageBookmark).setOnClickListener(onAddPAge);
objects.clear();
objects.addAll(AppSharedPreferences.get().getBookmarksByBook(controller.getCurrentBook()));
bookmarksAdapter.notifyDataSetChanged();
return a;
}
}.show("addBookmarks", false, true);
}
use of com.foobnix.pdf.info.wrapper.AppBookmark in project LibreraReader by foobnix.
the class AppSharedPreferences method getBookmarksByBook.
public List<AppBookmark> getBookmarksByBook(File book) {
List<AppBookmark> filter = new ArrayList<AppBookmark>();
if (book == null) {
return filter;
}
for (AppBookmark current : getBookmarks()) {
if (current != null && current.getPath() != null && book.getPath() != null && current.getPath().equals(book.getPath())) {
filter.add(current);
}
}
Collections.sort(filter, COMPARE_BY_PAGE);
return filter;
}
use of com.foobnix.pdf.info.wrapper.AppBookmark in project LibreraReader by foobnix.
the class AppSharedPreferences method getBookmarks.
public List<AppBookmark> getBookmarks() {
if (!bookmarks.isEmpty()) {
return bookmarks;
}
for (String key : bookmarkPreferences.getAll().keySet()) {
if (key.startsWith(BOOKMARK_)) {
String bookString = bookmarkPreferences.getString(key, null);
AppBookmark encode = AppBookmark.encode(bookString);
if (encode != null) {
bookmarks.add(encode);
}
}
}
Collections.sort(bookmarks, BY_DATE);
return bookmarks;
}
use of com.foobnix.pdf.info.wrapper.AppBookmark in project LibreraReader by foobnix.
the class AppSharedPreferences method getBookmarksMap.
public Map<String, List<AppBookmark>> getBookmarksMap() {
Map<String, List<AppBookmark>> map = new HashMap<String, List<AppBookmark>>();
List<AppBookmark> bookmarks = new ArrayList<AppBookmark>();
for (String key : bookmarkPreferences.getAll().keySet()) {
if (key.startsWith(BOOKMARK_)) {
String bookString = bookmarkPreferences.getString(key, null);
AppBookmark encode = AppBookmark.encode(bookString);
if (encode != null) {
bookmarks.add(encode);
String path = encode.getPath();
List<AppBookmark> list = map.get(path);
if (list == null) {
list = new ArrayList<AppBookmark>();
}
list.add(encode);
map.put(path, list);
}
}
}
Collections.sort(bookmarks, BY_DATE);
return map;
}
use of com.foobnix.pdf.info.wrapper.AppBookmark in project LibreraReader by foobnix.
the class ExtUtils method getAllExportString.
public static String getAllExportString(final Activity a, AppSharedPreferences viewerPreferences) {
final StringBuilder out = new StringBuilder();
Map<String, List<AppBookmark>> bookmarks = viewerPreferences.getBookmarksMap();
out.append(a.getString(R.string.bookmarks) + "\n");
out.append("\n");
for (String path : bookmarks.keySet()) {
List<AppBookmark> list = bookmarks.get(path);
Collections.sort(list, AppSharedPreferences.COMPARE_BY_PAGE);
File file = new File(path);
if (file.isFile()) {
path = file.getName();
}
out.append(path + "\n");
out.append("\n");
for (AppBookmark item : list) {
out.append(String.format("%s. %s \n", item.getPage(), item.getText()));
}
out.append("\n");
}
return out.toString();
}
Aggregations