Пример #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;
    }
  @Override
  protected long saveBookmark(Bookmark bookmark) {
    SQLiteStatement statement;
    if (bookmark.getId() == -1) {
      if (myInsertBookmarkStatement == null) {
        myInsertBookmarkStatement =
            myDatabase.compileStatement(
                "INSERT OR IGNORE INTO Bookmarks (book_id,bookmark_text,creation_time,modification_time,access_time,access_counter,model_id,paragraph,word,char,visible) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
      }
      statement = myInsertBookmarkStatement;
    } else {
      if (myUpdateBookmarkStatement == null) {
        myUpdateBookmarkStatement =
            myDatabase.compileStatement(
                "UPDATE Bookmarks SET book_id = ?, bookmark_text = ?, creation_time =?, modification_time = ?,access_time = ?, access_counter = ?, model_id = ?, paragraph = ?, word = ?, char = ?, visible = ? WHERE bookmark_id = ?");
      }
      statement = myUpdateBookmarkStatement;
    }

    statement.bindLong(1, bookmark.getBookId());
    statement.bindString(2, bookmark.getText());
    SQLiteUtil.bindDate(statement, 3, bookmark.getTime(Bookmark.CREATION));
    SQLiteUtil.bindDate(statement, 4, bookmark.getTime(Bookmark.MODIFICATION));
    SQLiteUtil.bindDate(statement, 5, bookmark.getTime(Bookmark.ACCESS));
    statement.bindLong(6, bookmark.getAccessCount());
    SQLiteUtil.bindString(statement, 7, bookmark.ModelId);
    statement.bindLong(8, bookmark.ParagraphIndex);
    statement.bindLong(9, bookmark.ElementIndex);
    statement.bindLong(10, bookmark.CharIndex);
    statement.bindLong(11, bookmark.IsVisible ? 1 : 0);

    if (statement == myInsertBookmarkStatement) {
      return statement.executeInsert();
    } else {
      final long id = bookmark.getId();
      statement.bindLong(12, id);
      statement.execute();
      return id;
    }
  }
Пример #3
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");
    }
  }
Пример #4
0
 BookmarkDescription(Bookmark b) {
   super(CancelActionType.returnTo, b.getText());
   Bookmark = b;
 }