Search in sources :

Example 1 with QuranRow

use of com.quran.labs.androidquran.ui.helpers.QuranRow in project quran_android by quran.

the class BookmarksFragment method handleTagEdit.

private void handleTagEdit(QuranActivity activity, List<QuranRow> selected) {
    if (selected.size() == 1) {
        QuranRow row = selected.get(0);
        activity.editTag(row.tagId, row.text);
    }
}
Also used : QuranRow(com.quran.labs.androidquran.ui.helpers.QuranRow)

Example 2 with QuranRow

use of com.quran.labs.androidquran.ui.helpers.QuranRow in project quran_android by quran.

the class BookmarksFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.quran_list, container, false);
    final Context context = getActivity();
    recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    bookmarksAdapter = new QuranListAdapter(context, recyclerView, new QuranRow[0], true);
    bookmarksAdapter.setQuranTouchListener(this);
    recyclerView.setAdapter(bookmarksAdapter);
    return view;
}
Also used : Context(android.content.Context) QuranRow(com.quran.labs.androidquran.ui.helpers.QuranRow) QuranListAdapter(com.quran.labs.androidquran.ui.helpers.QuranListAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Nullable(android.support.annotation.Nullable)

Example 3 with QuranRow

use of com.quran.labs.androidquran.ui.helpers.QuranRow in project quran_android by quran.

the class BookmarkPresenter method getSortedRows.

private List<QuranRow> getSortedRows(List<Bookmark> bookmarks) {
    List<QuranRow> rows = new ArrayList<>(bookmarks.size());
    List<Bookmark> ayahBookmarks = new ArrayList<>();
    // add the page bookmarks directly, save ayah bookmarks for later
    for (int i = 0, bookmarksSize = bookmarks.size(); i < bookmarksSize; i++) {
        Bookmark bookmark = bookmarks.get(i);
        if (bookmark.isPageBookmark()) {
            rows.add(quranRowFactory.fromBookmark(appContext, bookmark));
        } else {
            ayahBookmarks.add(bookmark);
        }
    }
    // add page bookmarks header if needed
    if (rows.size() > 0) {
        rows.add(0, quranRowFactory.fromPageBookmarksHeader(appContext));
    }
    // add ayah bookmarks if any
    if (ayahBookmarks.size() > 0) {
        rows.add(quranRowFactory.fromAyahBookmarksHeader(appContext));
        for (int i = 0, ayahBookmarksSize = ayahBookmarks.size(); i < ayahBookmarksSize; i++) {
            rows.add(quranRowFactory.fromBookmark(appContext, ayahBookmarks.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) SuppressLint(android.annotation.SuppressLint)

Example 4 with QuranRow

use of com.quran.labs.androidquran.ui.helpers.QuranRow 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 5 with QuranRow

use of com.quran.labs.androidquran.ui.helpers.QuranRow 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)

Aggregations

QuranRow (com.quran.labs.androidquran.ui.helpers.QuranRow)9 SuppressLint (android.annotation.SuppressLint)5 Bookmark (com.quran.labs.androidquran.dao.Bookmark)3 Tag (com.quran.labs.androidquran.dao.Tag)3 ArrayList (java.util.ArrayList)3 Activity (android.app.Activity)2 QuranActivity (com.quran.labs.androidquran.ui.QuranActivity)2 Context (android.content.Context)1 Resources (android.content.res.Resources)1 Nullable (android.support.annotation.Nullable)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 RecentPage (com.quran.labs.androidquran.dao.RecentPage)1 BookmarkResult (com.quran.labs.androidquran.model.bookmark.BookmarkResult)1 QuranListAdapter (com.quran.labs.androidquran.ui.helpers.QuranListAdapter)1 List (java.util.List)1