use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class ReadingListFragment method addSelectedPagesToList.
private void addSelectedPagesToList() {
List<ReadingListPage> selectedPages = getSelectedPages();
if (!selectedPages.isEmpty()) {
List<PageTitle> titles = new ArrayList<>();
for (ReadingListPage page : selectedPages) {
titles.add(ReadingListPage.toPageTitle(page));
}
bottomSheetPresenter.show(getChildFragmentManager(), AddToReadingListDialog.newInstance(titles, AddToReadingListDialog.InvokeSource.READING_LIST_ACTIVITY));
update();
}
}
use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class ReadingListDbHelper method addPagesToListIfNotExist.
public int addPagesToListIfNotExist(@NonNull ReadingList list, @NonNull List<PageTitle> titles) {
SQLiteDatabase db = getWritableDatabase();
db.beginTransaction();
int numAdded = 0;
try {
for (PageTitle title : titles) {
if (getPageByTitle(db, list, title) != null) {
continue;
}
addPageToList(db, list, title);
numAdded++;
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
if (numAdded > 0) {
SavedPageSyncService.enqueue();
ReadingListSyncAdapter.manualSync();
}
return numAdded;
}
use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class ReadingListPageTable method importOldLists.
// TODO: Remove in Dec 2018
private void importOldLists(@NonNull SQLiteDatabase db, @NonNull List<ReadingList> lists) {
try {
try (Cursor cursor = db.query(OldReadingListContract.TABLE, null, null, null, null, null, null)) {
while (cursor.moveToNext()) {
ReadingList list = ReadingListDbHelper.instance().createList(db, OldReadingListContract.Col.TITLE.val(cursor), OldReadingListContract.Col.DESCRIPTION.val(cursor));
lists.add(list);
}
}
boolean shouldShowLargeSplitMessage = false;
try (Cursor cursor = db.rawQuery("SELECT * FROM " + OldReadingListPageContract.TABLE_PAGE + " JOIN " + OldReadingListPageContract.TABLE_DISK + " ON (" + OldReadingListPageContract.Col.KEY.qualifiedName() + " = " + OldReadingListPageContract.Col.DISK_KEY.qualifiedName() + ")", null)) {
while (cursor.moveToNext()) {
Set<String> listKeys = OldReadingListPageContract.Col.LIST_KEYS.val(cursor);
String lang = OldReadingListPageContract.Col.LANG.val(cursor);
String site = OldReadingListPageContract.Col.SITE.val(cursor);
PageTitle title = new PageTitle(OldReadingListPageContract.Col.NAMESPACE.val(cursor).toLegacyString(), OldReadingListPageContract.Col.TITLE.val(cursor), lang == null ? new WikiSite(site) : new WikiSite(site, lang));
title.setThumbUrl(OldReadingListPageContract.Col.THUMBNAIL_URL.val(cursor));
title.setDescription(OldReadingListPageContract.Col.DESCRIPTION.val(cursor));
ReadingListPage page = new ReadingListPage(title);
page.atime(OldReadingListPageContract.Col.ATIME.val(cursor));
page.mtime(OldReadingListPageContract.Col.MTIME.val(cursor));
page.sizeBytes(OldReadingListPageContract.Col.LOGICAL_SIZE.val(cursor));
long diskStatus = OldReadingListPageContract.Col.DISK_STATUS.val(cursor);
if (diskStatus == OldReadingListPageContract.STATUS_DELETED) {
continue;
} else if (diskStatus == OldReadingListPageContract.STATUS_ONLINE) {
page.offline(false);
page.status(ReadingListPage.STATUS_QUEUE_FOR_SAVE);
} else if (diskStatus == OldReadingListPageContract.STATUS_UNSAVED) {
page.offline(false);
page.status(ReadingListPage.STATUS_SAVED);
} else if (diskStatus == OldReadingListPageContract.STATUS_OUTDATED) {
page.offline(true);
page.status(ReadingListPage.STATUS_QUEUE_FOR_SAVE);
} else if (diskStatus == OldReadingListPageContract.STATUS_SAVED) {
page.offline(true);
page.status(ReadingListPage.STATUS_SAVED);
}
ReadingList origList = null;
for (ReadingList list : lists) {
if (listKeys.contains(getListKey(list.dbTitle()))) {
origList = list;
break;
}
}
if (origList == null) {
continue;
}
int splitListIndex = 0;
ReadingList newList = origList;
while (newList.pages().size() >= SiteInfoClient.getMaxPagesPerReadingList()) {
shouldShowLargeSplitMessage = true;
newList = null;
String newListName = origList.dbTitle() + " (" + Integer.toString(++splitListIndex) + ")";
for (ReadingList list : lists) {
if (list.dbTitle().equals(newListName)) {
newList = list;
break;
}
}
if (newList == null) {
newList = ReadingListDbHelper.instance().createList(db, newListName, origList.description());
lists.add(newList);
}
}
newList.pages().add(page);
}
for (ReadingList list : lists) {
ReadingListDbHelper.instance().addPagesToList(db, list, list.pages());
}
}
if (shouldShowLargeSplitMessage) {
WikipediaApp.getInstance().getBus().post(new SplitLargeListsEvent());
}
db.execSQL("DROP TABLE IF EXISTS " + OldReadingListContract.TABLE);
db.execSQL("DROP TABLE IF EXISTS " + OldReadingListPageContract.TABLE_PAGE);
db.execSQL("DROP TABLE IF EXISTS " + OldReadingListPageContract.TABLE_DISK);
db.execSQL("DROP TABLE IF EXISTS " + OldReadingListPageContract.TABLE_HTTP);
} catch (Exception e) {
L.d("Error while importing old reading lists.");
e.printStackTrace();
}
}
use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class SavedPageSyncService method savePageFor.
private long savePageFor(@NonNull ReadingListPage page) throws IOException, InterruptedException {
PageTitle pageTitle = ReadingListPage.toPageTitle(page);
long totalSize = 0;
Call<PageLead> leadCall = reqPageLead(CacheControl.FORCE_NETWORK, OfflineCacheInterceptor.SAVE_HEADER_SAVE, pageTitle);
Call<PageRemaining> sectionsCall = reqPageSections(CacheControl.FORCE_NETWORK, OfflineCacheInterceptor.SAVE_HEADER_SAVE, pageTitle);
retrofit2.Response<PageLead> leadRsp = leadCall.execute();
totalSize += responseSize(leadRsp);
retrofit2.Response<PageRemaining> sectionsRsp = sectionsCall.execute();
totalSize += responseSize(sectionsRsp);
Set<String> imageUrls = new HashSet<>(pageImageUrlParser.parse(leadRsp.body()));
imageUrls.addAll(pageImageUrlParser.parse(sectionsRsp.body()));
if (!TextUtils.isEmpty(leadRsp.body().getThumbUrl())) {
page.thumbUrl(UriUtil.resolveProtocolRelativeUrl(pageTitle.getWikiSite(), leadRsp.body().getThumbUrl()));
persistPageThumbnail(pageTitle, page.thumbUrl());
imageUrls.add(page.thumbUrl());
}
page.description(leadRsp.body().getDescription());
if (Prefs.isImageDownloadEnabled()) {
totalSize += reqSaveImages(pageTitle.getWikiSite(), imageUrls);
}
String title = pageTitle.getPrefixedText();
L.i("Saved page " + title + " (" + totalSize + ")");
return totalSize;
}
use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class SearchResults method filter.
/**
* Filter the list of results to make sure the original page title isn't one of them
* and the suggestions have thumbnails if required.
*
* @param searchResults original results from server
* @return filtered results
*/
@NonNull
public static SearchResults filter(SearchResults searchResults, String title, boolean requireThumbnail) {
final boolean verbose = ReleaseUtil.isDevRelease();
List<SearchResult> filteredResults = new ArrayList<>();
List<SearchResult> results = searchResults.getResults();
for (int i = 0; i < results.size() && filteredResults.size() < Constants.MAX_SUGGESTION_RESULTS; i++) {
final SearchResult res = results.get(i);
final PageTitle pageTitle = res.getPageTitle();
if (verbose) {
L.v(pageTitle.getPrefixedText());
}
if (!title.equalsIgnoreCase(pageTitle.getPrefixedText()) && (!requireThumbnail || pageTitle.getThumbUrl() != null) && !(pageTitle.isMainPage() || pageTitle.isDisambiguationPage())) {
filteredResults.add(res);
}
}
return new SearchResults(filteredResults, null, null);
}
Aggregations