Ejemplo n.º 1
0
    @Override
    protected Boolean doInBackground(Integer... params) {
      mSura = params[0];
      mAyah = params[1];
      mPage = params[2];

      BookmarksDBAdapter adapter = null;
      Activity activity = getActivity();
      if (activity != null && activity instanceof BookmarkHandler) {
        adapter = ((BookmarkHandler) activity).getBookmarksAdapter();
      }

      if (adapter == null) {
        return null;
      }

      boolean bookmarked = adapter.getBookmarkId(mSura, mAyah, mPage) >= 0;
      return bookmarked;
    }
Ejemplo n.º 2
0
  private QuranRow[] getTags() {
    BookmarksDBAdapter adapter = null;
    Activity activity = getActivity();
    if (activity != null && activity instanceof BookmarkHandler) {
      adapter = ((BookmarkHandler) activity).getBookmarksAdapter();
    }

    if (adapter == null) {
      return null;
    }

    List<Tag> tags;
    switch (mCurrentSortCriteria) {
      case R.id.sort_date:
        tags = adapter.getTags(BookmarksDBAdapter.SORT_DATE_ADDED);
        break;
      case R.id.sort_alphabetical:
      default:
        tags = adapter.getTags(BookmarksDBAdapter.SORT_ALPHABETICAL);
        break;
    }
    List<Bookmark> bookmarks = adapter.getBookmarks(true);

    List<QuranRow> rows = new ArrayList<QuranRow>();

    List<Bookmark> unTagged = new ArrayList<Bookmark>();
    Map<Long, List<Bookmark>> tagMap = new HashMap<Long, List<Bookmark>>();

    for (Bookmark bookmark : bookmarks) {
      List<Tag> bookmarkTags = bookmark.mTags;
      if (bookmarkTags == null) {
        unTagged.add(bookmark);
      } else {
        for (Tag tag : bookmarkTags) {
          List<Bookmark> tagBookmarkList = tagMap.get(tag.mId);
          if (tagBookmarkList == null) {
            List<Bookmark> newList = new ArrayList<Bookmark>();
            newList.add(bookmark);
            tagMap.put(tag.mId, newList);
          } else {
            tagBookmarkList.add(bookmark);
          }
        }
      }
    }

    for (Tag tag : tags) {
      List<Bookmark> tagBookmarkList = tagMap.get(tag.mId);

      // add the tag header
      QuranRow bookmarkHeader = new QuranRow(tag.mName, null, QuranRow.BOOKMARK_HEADER, 0, 0, null);
      bookmarkHeader.tagId = tag.mId;

      rows.add(bookmarkHeader);

      // no bookmarks in this tag, so move on
      if (tagBookmarkList == null || tagBookmarkList.isEmpty()) {
        continue;
      }

      // and now the bookmarks
      for (Bookmark bookmark : tagBookmarkList) {
        QuranRow row = createRow(activity, tag.mId, bookmark);
        rows.add(row);
      }
    }

    if (unTagged.size() > 0) {
      QuranRow header =
          new QuranRow(
              activity.getString(R.string.not_tagged), "", QuranRow.BOOKMARK_HEADER, 0, 0, null);
      header.tagId = -1;

      rows.add(header);

      for (Bookmark bookmark : unTagged) {
        QuranRow row = createRow(activity, -1, bookmark);
        rows.add(row);
      }
    }

    return rows.toArray(new QuranRow[rows.size()]);
  }