Search in sources :

Example 1 with AppBookmark

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);
}
Also used : BookmarksAdapter(com.foobnix.pdf.info.presentation.BookmarksAdapter) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ArrayList(java.util.ArrayList) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) SuppressLint(android.annotation.SuppressLint) OnItemLongClickListener(android.widget.AdapterView.OnItemLongClickListener) AppBookmark(com.foobnix.pdf.info.wrapper.AppBookmark) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ColorDrawable(android.graphics.drawable.ColorDrawable) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView)

Example 2 with AppBookmark

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;
}
Also used : AppBookmark(com.foobnix.pdf.info.wrapper.AppBookmark) ArrayList(java.util.ArrayList)

Example 3 with AppBookmark

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;
}
Also used : AppBookmark(com.foobnix.pdf.info.wrapper.AppBookmark)

Example 4 with AppBookmark

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;
}
Also used : AppBookmark(com.foobnix.pdf.info.wrapper.AppBookmark) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with AppBookmark

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();
}
Also used : AppBookmark(com.foobnix.pdf.info.wrapper.AppBookmark) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

AppBookmark (com.foobnix.pdf.info.wrapper.AppBookmark)12 View (android.view.View)5 OnClickListener (android.view.View.OnClickListener)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 ArrayList (java.util.ArrayList)5 RecyclerView (android.support.v7.widget.RecyclerView)3 File (java.io.File)3 SuppressLint (android.annotation.SuppressLint)2 List (java.util.List)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 OnDismissListener (android.content.DialogInterface.OnDismissListener)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 CardView (android.support.v7.widget.CardView)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 LayoutInflater (android.view.LayoutInflater)1 AbsListView (android.widget.AbsListView)1