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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations