Exemplo n.º 1
0
    public View getView(int position, View convertView, ViewGroup parent) {
      final View view =
          (convertView != null)
              ? convertView
              : LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.bookmark_item, parent, false);
      final ImageView imageView = (ImageView) view.findViewById(R.id.bookmark_item_icon);
      final TextView textView = (TextView) view.findViewById(R.id.bookmark_item_text);
      final TextView bookTitleView = (TextView) view.findViewById(R.id.bookmark_item_booktitle);

      final Bookmark bookmark = getItem(position);
      if (bookmark == null) {
        imageView.setVisibility(View.VISIBLE);
        imageView.setImageResource(R.drawable.ic_list_plus);
        textView.setText(ZLResource.resource("bookmarksView").getResource("new").getValue());
        bookTitleView.setVisibility(View.GONE);
      } else {
        imageView.setVisibility(View.GONE);
        textView.setText(bookmark.getText());
        if (myCurrentBook) {
          bookTitleView.setVisibility(View.GONE);
        } else {
          bookTitleView.setVisibility(View.VISIBLE);
          bookTitleView.setText(bookmark.getBookTitle());
        }
      }
      return view;
    }
Exemplo n.º 2
0
 @Override
 public void onPause() {
   for (Bookmark bookmark : AllBooksBookmarks) {
     bookmark.save();
   }
   super.onPause();
 }
Exemplo n.º 3
0
 private void gotoBookmark(Bookmark bookmark) {
   bookmark.markAsAccessed();
   myCollection.saveBookmark(bookmark);
   final Book book = myCollection.getBookById(bookmark.getBookId());
   if (book != null) {
     FBReader.openBookActivity(this, book, bookmark);
   } else {
     UIUtil.showErrorMessage(this, "cannotOpenBook");
   }
 }
Exemplo n.º 4
0
 private void gotoBookmark(Bookmark bookmark) {
   bookmark.onOpen();
   final FBReader fbreader = (FBReader) FBReader.Instance();
   final long bookId = bookmark.getBookId();
   if ((fbreader.Model == null) || (fbreader.Model.Book.getId() != bookId)) {
     final Book book = Book.getById(bookId);
     if (book != null) {
       finish();
       fbreader.openBook(book, bookmark);
     } else {
       Toast.makeText(
               this,
               ZLResource.resource("errorMessage").getResource("cannotOpenBook").getValue(),
               Toast.LENGTH_SHORT)
           .show();
     }
   } else {
     finish();
     fbreader.gotoBookmark(bookmark);
   }
 }
Exemplo n.º 5
0
  @Override
  protected void onNewIntent(Intent intent) {
    OrientationUtil.setOrientation(this, intent);

    if (!Intent.ACTION_SEARCH.equals(intent.getAction())) {
      return;
    }
    String pattern = intent.getStringExtra(SearchManager.QUERY);
    myBookmarkSearchPatternOption.setValue(pattern);

    final LinkedList<Bookmark> bookmarks = new LinkedList<Bookmark>();
    pattern = pattern.toLowerCase();
    for (Bookmark b : myAllBooksAdapter.bookmarks()) {
      if (MiscUtil.matchesIgnoreCase(b.getText(), pattern)) {
        bookmarks.add(b);
      }
    }
    if (!bookmarks.isEmpty()) {
      showSearchResultsTab(bookmarks);
    } else {
      UIUtil.showErrorMessage(this, "bookmarkNotFound");
    }
  }
Exemplo n.º 6
0
  @Override
  public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    Thread.setDefaultUncaughtExceptionHandler(
        new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));

    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);

    final TabHost host = getTabHost();
    LayoutInflater.from(this).inflate(R.layout.bookmarks, host.getTabContentView(), true);

    AllBooksBookmarks = Bookmark.bookmarks();
    Collections.sort(AllBooksBookmarks, new Bookmark.ByTimeComparator());
    final FBReader fbreader = (FBReader) FBReader.Instance();

    if (fbreader.Model != null) {
      final long bookId = fbreader.Model.Book.getId();
      for (Bookmark bookmark : AllBooksBookmarks) {
        if (bookmark.getBookId() == bookId) {
          myThisBookBookmarks.add(bookmark);
        }
      }

      myThisBookView = createTab("thisBook", R.id.this_book);
      new BookmarksAdapter(myThisBookView, myThisBookBookmarks, true);
    } else {
      findViewById(R.id.this_book).setVisibility(View.GONE);
    }

    myAllBooksView = createTab("allBooks", R.id.all_books);
    new BookmarksAdapter(myAllBooksView, AllBooksBookmarks, false);

    findViewById(R.id.search_results).setVisibility(View.GONE);
  }
Exemplo n.º 7
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   final int position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position;
   final ListView view = (ListView) getTabHost().getCurrentView();
   final Bookmark bookmark = ((BookmarksAdapter) view.getAdapter()).getItem(position);
   switch (item.getItemId()) {
     case OPEN_ITEM_ID:
       gotoBookmark(bookmark);
       return true;
     case EDIT_ITEM_ID:
       final Intent intent = new Intent(this, BookmarkEditActivity.class);
       startActivityForResult(intent, 1);
       // TODO: implement
       return true;
     case DELETE_ITEM_ID:
       bookmark.delete();
       myThisBookBookmarks.remove(bookmark);
       AllBooksBookmarks.remove(bookmark);
       mySearchResults.remove(bookmark);
       invalidateAllViews();
       return true;
   }
   return super.onContextItemSelected(item);
 }