Search in sources :

Example 6 with ReadingListPage

use of org.wikipedia.readinglist.database.ReadingListPage in project apps-android-wikipedia by wikimedia.

the class ReadingListItemView method updateThumbnails.

private void updateThumbnails() {
    if (readingList == null) {
        return;
    }
    clearThumbnails();
    List<String> thumbUrls = new ArrayList<>();
    for (ReadingListPage page : readingList.pages()) {
        if (!TextUtils.isEmpty(page.thumbUrl())) {
            thumbUrls.add(page.thumbUrl());
        }
        if (thumbUrls.size() > imageViews.size()) {
            break;
        }
    }
    for (int i = thumbUrls.size(); i < imageViews.size() && i < readingList.pages().size(); i++) {
        thumbUrls.add("");
    }
    for (int i = 0; i < thumbUrls.size() && i < imageViews.size(); ++i) {
        loadThumbnail(imageViews.get(i), thumbUrls.get(i));
    }
}
Also used : ArrayList(java.util.ArrayList) ReadingListPage(org.wikipedia.readinglist.database.ReadingListPage)

Example 7 with ReadingListPage

use of org.wikipedia.readinglist.database.ReadingListPage in project apps-android-wikipedia by wikimedia.

the class ReadingListsFragment method showDeleteListUndoSnackbar.

private void showDeleteListUndoSnackbar(final ReadingList readingList) {
    Snackbar snackbar = FeedbackUtil.makeSnackbar(getActivity(), String.format(getString(R.string.reading_list_deleted), readingList.title()), FeedbackUtil.LENGTH_DEFAULT);
    snackbar.setAction(R.string.reading_list_item_delete_undo, v -> {
        ReadingList newList = ReadingListDbHelper.instance().createList(readingList.title(), readingList.description());
        List<ReadingListPage> newPages = new ArrayList<>();
        for (ReadingListPage page : readingList.pages()) {
            newPages.add(new ReadingListPage(ReadingListPage.toPageTitle(page)));
        }
        ReadingListDbHelper.instance().addPagesToList(newList, newPages, true);
        updateLists();
    });
    snackbar.show();
}
Also used : ArrayList(java.util.ArrayList) ReadingList(org.wikipedia.readinglist.database.ReadingList) ReadingListPage(org.wikipedia.readinglist.database.ReadingListPage) Snackbar(android.support.design.widget.Snackbar)

Example 8 with ReadingListPage

use of org.wikipedia.readinglist.database.ReadingListPage in project apps-android-wikipedia by wikimedia.

the class ReadingListSyncAdapter method manualSyncWithDeletePages.

public static void manualSyncWithDeletePages(@NonNull ReadingList list, @NonNull List<ReadingListPage> pages) {
    if (list.remoteId() <= 0) {
        return;
    }
    Set<String> ids = new HashSet<>();
    for (ReadingListPage page : pages) {
        if (page.remoteId() > 0) {
            ids.add(Long.toString(list.remoteId()) + ":" + Long.toString(page.remoteId()));
        }
    }
    if (!ids.isEmpty()) {
        Prefs.addReadingListPagesDeletedIds(ids);
        manualSync();
    }
}
Also used : ReadingListPage(org.wikipedia.readinglist.database.ReadingListPage) HashSet(java.util.HashSet)

Example 9 with ReadingListPage

use of org.wikipedia.readinglist.database.ReadingListPage in project apps-android-wikipedia by wikimedia.

the class ReadingListSyncAdapter method deletePageByTitle.

private void deletePageByTitle(@NonNull ReadingList listForPage, @NonNull PageTitle title) {
    ReadingListPage localPage = null;
    for (ReadingListPage page : listForPage.pages()) {
        if (ReadingListPage.toPageTitle(page).equals(title)) {
            localPage = page;
            break;
        }
    }
    if (localPage == null) {
        localPage = ReadingListDbHelper.instance().getPageByTitle(listForPage, title);
        if (localPage == null) {
            return;
        }
    }
    L.d("Deleting local page " + localPage.title());
    ReadingListDbHelper.instance().markPagesForDeletion(listForPage, Collections.singletonList(localPage), false);
}
Also used : ReadingListPage(org.wikipedia.readinglist.database.ReadingListPage)

Example 10 with ReadingListPage

use of org.wikipedia.readinglist.database.ReadingListPage in project apps-android-wikipedia by wikimedia.

the class FeaturedArticleCardView method footer.

private void footer(@NonNull FeaturedArticleCard card) {
    PageTitle title = new PageTitle(card.articleTitle(), card.wikiSite());
    CallbackTask.execute(() -> ReadingListDbHelper.instance().findPageInAnyList(title), new CallbackTask.DefaultCallback<ReadingListPage>() {

        @Override
        public void success(ReadingListPage page) {
            boolean pageInList = page != null;
            int actionIcon = pageInList ? R.drawable.ic_bookmark_white_24dp : R.drawable.ic_bookmark_border_black_24dp;
            int actionText = pageInList ? R.string.view_featured_article_footer_saved_button_label : R.string.view_featured_article_footer_save_button_label;
            footerView.actionIcon(actionIcon).actionText(actionText).onActionListener(pageInList ? new CardBookmarkMenuListener() : new CardAddToListListener()).onShareListener(new CardShareListener());
            footerView.actionIconColor(ResourceUtil.getThemedAttributeId(getContext(), pageInList ? R.attr.colorAccent : R.attr.secondary_text_color));
            footerView.actionTextColor(ResourceUtil.getThemedAttributeId(getContext(), pageInList ? R.attr.colorAccent : R.attr.secondary_text_color));
        }
    });
}
Also used : CallbackTask(org.wikipedia.concurrency.CallbackTask) PageTitle(org.wikipedia.page.PageTitle) ReadingListPage(org.wikipedia.readinglist.database.ReadingListPage)

Aggregations

ReadingListPage (org.wikipedia.readinglist.database.ReadingListPage)18 ArrayList (java.util.ArrayList)8 PageTitle (org.wikipedia.page.PageTitle)5 ReadingList (org.wikipedia.readinglist.database.ReadingList)3 Snackbar (android.support.design.widget.Snackbar)2 IOException (java.io.IOException)2 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 OnClick (butterknife.OnClick)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 CallbackTask (org.wikipedia.concurrency.CallbackTask)1 WikiSite (org.wikipedia.dataclient.WikiSite)1 ReadingListsEnableDialogEvent (org.wikipedia.events.ReadingListsEnableDialogEvent)1 ReadingListsEnabledStatusEvent (org.wikipedia.events.ReadingListsEnabledStatusEvent)1 ReadingListsMergeLocalDialogEvent (org.wikipedia.events.ReadingListsMergeLocalDialogEvent)1 ReadingListsNoLongerSyncedEvent (org.wikipedia.events.ReadingListsNoLongerSyncedEvent)1 ReadingListBookmarkMenu (org.wikipedia.readinglist.ReadingListBookmarkMenu)1 RemoteReadingList (org.wikipedia.readinglist.sync.SyncedReadingLists.RemoteReadingList)1