Search in sources :

Example 6 with Tag

use of com.quran.labs.androidquran.dao.Tag in project quran_android by quran.

the class TagBookmarkPresenter method onRefreshedData.

void onRefreshedData(Pair<List<Tag>, List<Long>> data) {
    List<Tag> tags1 = data.first;
    int numberOfTags = tags1.size();
    if (numberOfTags == 0 || tags1.get(numberOfTags - 1).getId() != -1) {
        tags1.add(new Tag(-1, ""));
    }
    List<Long> bookmarkTags = data.second;
    checkedTags.clear();
    for (int i = 0, tagsSize = tags1.size(); i < tagsSize; i++) {
        Tag tag = tags1.get(i);
        if (bookmarkTags.contains(tag.getId())) {
            checkedTags.add(tag.getId());
        }
    }
    madeChanges = false;
    TagBookmarkPresenter.this.tags = tags1;
    shouldRefreshTags = false;
    if (dialog != null) {
        dialog.setData(TagBookmarkPresenter.this.tags, checkedTags);
    }
}
Also used : Tag(com.quran.labs.androidquran.dao.Tag)

Example 7 with Tag

use of com.quran.labs.androidquran.dao.Tag in project quran_android by quran.

the class QuranListAdapter method bindRow.

private void bindRow(HeaderHolder vh, int position) {
    ViewHolder holder = (ViewHolder) vh;
    final QuranRow item = elements[position];
    bindHeader(vh, position);
    holder.number.setText(QuranUtils.getLocalizedNumber(context, item.sura));
    holder.metadata.setVisibility(View.VISIBLE);
    holder.metadata.setText(item.metadata);
    holder.tags.setVisibility(View.GONE);
    if (item.juzType != null) {
        holder.image.setImageDrawable(new JuzView(context, item.juzType, item.juzOverlayText));
        holder.image.setVisibility(View.VISIBLE);
        holder.number.setVisibility(View.GONE);
    } else if (item.imageResource == null) {
        holder.number.setVisibility(View.VISIBLE);
        holder.image.setVisibility(View.GONE);
    } else {
        holder.image.setImageResource(item.imageResource);
        if (item.imageFilterColor == null) {
            holder.image.setColorFilter(null);
        } else {
            holder.image.setColorFilter(item.imageFilterColor, PorterDuff.Mode.SRC_ATOP);
        }
        holder.image.setVisibility(View.VISIBLE);
        holder.number.setVisibility(View.GONE);
        List<Tag> tags = new ArrayList<>();
        Bookmark bookmark = item.bookmark;
        if (bookmark != null && !bookmark.tags.isEmpty() && showTags) {
            for (int i = 0, bookmarkTags = bookmark.tags.size(); i < bookmarkTags; i++) {
                Long tagId = bookmark.tags.get(i);
                Tag tag = tagMap.get(tagId);
                if (tag != null) {
                    tags.add(tag);
                }
            }
        }
        if (tags.isEmpty()) {
            holder.tags.setVisibility(View.GONE);
        } else {
            holder.tags.setTags(tags);
            holder.tags.setVisibility(View.VISIBLE);
        }
    }
}
Also used : JuzView(com.quran.labs.androidquran.widgets.JuzView) Bookmark(com.quran.labs.androidquran.dao.Bookmark) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.quran.labs.androidquran.dao.Tag)

Example 8 with Tag

use of com.quran.labs.androidquran.dao.Tag in project quran_android by quran.

the class BookmarkPresenter method predictQuranListAfterDeletion.

private BookmarkResult predictQuranListAfterDeletion(List<QuranRow> remove) {
    if (cachedData != null) {
        List<QuranRow> placeholder = new ArrayList<>(cachedData.getRows().size() - remove.size());
        List<QuranRow> rows = cachedData.getRows();
        List<Long> removedTags = new ArrayList<>();
        for (int i = 0, rowsSize = rows.size(); i < rowsSize; i++) {
            QuranRow row = rows.get(i);
            if (!remove.contains(row)) {
                placeholder.add(row);
            }
        }
        for (int i = 0, removedSize = remove.size(); i < removedSize; i++) {
            QuranRow row = remove.get(i);
            if (row.isHeader() && row.tagId > 0) {
                removedTags.add(row.tagId);
            }
        }
        Map<Long, Tag> tagMap;
        if (removedTags.isEmpty()) {
            tagMap = cachedData.getTagMap();
        } else {
            tagMap = new HashMap<>(cachedData.getTagMap());
            for (int i = 0, removedTagsSize = removedTags.size(); i < removedTagsSize; i++) {
                Long tagId = removedTags.get(i);
                tagMap.remove(tagId);
            }
        }
        return new BookmarkResult(placeholder, tagMap);
    }
    return null;
}
Also used : BookmarkResult(com.quran.labs.androidquran.model.bookmark.BookmarkResult) QuranRow(com.quran.labs.androidquran.ui.helpers.QuranRow) ArrayList(java.util.ArrayList) Tag(com.quran.labs.androidquran.dao.Tag) SuppressLint(android.annotation.SuppressLint)

Example 9 with Tag

use of com.quran.labs.androidquran.dao.Tag in project quran_android by quran.

the class BookmarkPresenter method getBookmarkRows.

private List<QuranRow> getBookmarkRows(BookmarkData data, boolean groupByTags) {
    List<QuranRow> rows;
    List<Tag> tags = data.getTags();
    List<Bookmark> bookmarks = data.getBookmarks();
    if (groupByTags) {
        rows = getRowsSortedByTags(tags, bookmarks);
    } else {
        rows = getSortedRows(bookmarks);
    }
    List<RecentPage> recentPages = data.getRecentPages();
    int size = recentPages.size();
    if (size > 0) {
        if (!showRecents) {
            // only show the last bookmark if show recents is off
            size = 1;
        }
        rows.add(0, quranRowFactory.fromRecentPageHeader(appContext, size));
        for (int i = 0; i < size; i++) {
            int page = recentPages.get(i).getPage();
            if (page < Constants.PAGES_FIRST || page > totalPages) {
                page = 1;
            }
            rows.add(i + 1, quranRowFactory.fromCurrentPage(appContext, page));
        }
    }
    return rows;
}
Also used : Bookmark(com.quran.labs.androidquran.dao.Bookmark) QuranRow(com.quran.labs.androidquran.ui.helpers.QuranRow) RecentPage(com.quran.labs.androidquran.dao.RecentPage) Tag(com.quran.labs.androidquran.dao.Tag) SuppressLint(android.annotation.SuppressLint)

Example 10 with Tag

use of com.quran.labs.androidquran.dao.Tag in project quran_android by quran.

the class BookmarkPresenter method getRowsSortedByTags.

private List<QuranRow> getRowsSortedByTags(List<Tag> tags, List<Bookmark> bookmarks) {
    List<QuranRow> rows = new ArrayList<>();
    // sort by tags, alphabetical
    Map<Long, List<Bookmark>> tagsMapping = generateTagsMapping(tags, bookmarks);
    for (int i = 0, tagsSize = tags.size(); i < tagsSize; i++) {
        Tag tag = tags.get(i);
        rows.add(quranRowFactory.fromTag(tag));
        List<Bookmark> tagBookmarks = tagsMapping.get(tag.getId());
        for (int j = 0, tagBookmarksSize = tagBookmarks.size(); j < tagBookmarksSize; j++) {
            rows.add(quranRowFactory.fromBookmark(appContext, tagBookmarks.get(j), tag.getId()));
        }
    }
    // add untagged bookmarks
    List<Bookmark> untagged = tagsMapping.get(BOOKMARKS_WITHOUT_TAGS_ID);
    if (untagged.size() > 0) {
        rows.add(quranRowFactory.fromNotTaggedHeader(appContext));
        for (int i = 0, untaggedSize = untagged.size(); i < untaggedSize; i++) {
            rows.add(quranRowFactory.fromBookmark(appContext, untagged.get(i)));
        }
    }
    return rows;
}
Also used : Bookmark(com.quran.labs.androidquran.dao.Bookmark) QuranRow(com.quran.labs.androidquran.ui.helpers.QuranRow) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.quran.labs.androidquran.dao.Tag) SuppressLint(android.annotation.SuppressLint)

Aggregations

Tag (com.quran.labs.androidquran.dao.Tag)13 SuppressLint (android.annotation.SuppressLint)5 ArrayList (java.util.ArrayList)5 Bookmark (com.quran.labs.androidquran.dao.Bookmark)4 QuranRow (com.quran.labs.androidquran.ui.helpers.QuranRow)3 NonNull (android.support.annotation.NonNull)2 List (java.util.List)2 ContentValues (android.content.ContentValues)1 DialogInterface (android.content.DialogInterface)1 Cursor (android.database.Cursor)1 Bundle (android.os.Bundle)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 AlertDialog (android.support.v7.app.AlertDialog)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 EditText (android.widget.EditText)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 RecentPage (com.quran.labs.androidquran.dao.RecentPage)1