use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class PageActivity method handleIntent.
private void handleIntent(@NonNull Intent intent) {
if (Intent.ACTION_VIEW.equals(intent.getAction()) && intent.getData() != null) {
WikiSite wiki = new WikiSite(intent.getData());
PageTitle title = wiki.titleForUri(intent.getData());
HistoryEntry historyEntry = new HistoryEntry(title, intent.hasExtra(Constants.INTENT_EXTRA_VIEW_FROM_NOTIFICATION) ? HistoryEntry.SOURCE_NOTIFICATION_SYSTEM : HistoryEntry.SOURCE_EXTERNAL_LINK);
if (intent.hasExtra(Intent.EXTRA_REFERRER)) {
// Populate the referrer with the externally-referring URL, e.g. an external Browser URL.
// This can be a Uri or a String, so let's extract it safely as an Object.
historyEntry.setReferrer(intent.getExtras().get(Intent.EXTRA_REFERRER).toString());
}
if (title.isSpecial()) {
visitInExternalBrowser(this, intent.getData());
finish();
return;
}
loadPageInForegroundTab(title, historyEntry);
} else if (ACTION_LOAD_IN_NEW_TAB.equals(intent.getAction()) || ACTION_LOAD_IN_CURRENT_TAB.equals(intent.getAction())) {
PageTitle title = intent.getParcelableExtra(EXTRA_PAGETITLE);
HistoryEntry historyEntry = intent.getParcelableExtra(EXTRA_HISTORYENTRY);
if (ACTION_LOAD_IN_NEW_TAB.equals(intent.getAction())) {
loadPageInForegroundTab(title, historyEntry);
} else if (ACTION_LOAD_IN_CURRENT_TAB.equals(intent.getAction())) {
loadPage(title, historyEntry, TabPosition.CURRENT_TAB);
}
if (intent.hasExtra(Constants.INTENT_EXTRA_REVERT_QNUMBER)) {
showDescriptionEditRevertDialog(intent.getStringExtra(Constants.INTENT_EXTRA_REVERT_QNUMBER));
}
} else if (ACTION_LOAD_FROM_EXISTING_TAB.equals(intent.getAction())) {
PageTitle title = intent.getParcelableExtra(EXTRA_PAGETITLE);
HistoryEntry historyEntry = intent.getParcelableExtra(EXTRA_HISTORYENTRY);
loadPage(title, historyEntry, TabPosition.EXISTING_TAB);
} else if (ACTION_RESUME_READING.equals(intent.getAction()) || intent.hasExtra(Constants.INTENT_APP_SHORTCUT_CONTINUE_READING)) {
// do nothing, since this will be handled indirectly by PageFragment.
} else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
PageTitle title = new PageTitle(query, app.getWikiSite());
HistoryEntry historyEntry = new HistoryEntry(title, HistoryEntry.SOURCE_SEARCH);
loadPageInForegroundTab(title, historyEntry);
} else if (intent.hasExtra(Constants.INTENT_FEATURED_ARTICLE_FROM_WIDGET)) {
new IntentFunnel(app).logFeaturedArticleWidgetTap();
PageTitle title = intent.getParcelableExtra(EXTRA_PAGETITLE);
HistoryEntry historyEntry = new HistoryEntry(title, HistoryEntry.SOURCE_WIDGET);
loadPageInForegroundTab(title, historyEntry);
} else {
loadMainPageInCurrentTab();
}
}
use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class PageFragment method setupMessageHandlers.
private void setupMessageHandlers() {
linkHandler = new LinkHandler(requireActivity()) {
@Override
public void onPageLinkClicked(@NonNull String anchor, @NonNull String linkText) {
dismissBottomSheet();
JSONObject payload = new JSONObject();
try {
payload.put("anchor", anchor);
payload.put("text", linkText);
} catch (JSONException e) {
throw new RuntimeException(e);
}
bridge.sendMessage("handleReference", payload);
}
@Override
public void onInternalLinkClicked(@NonNull PageTitle title) {
handleInternalLink(title);
}
@Override
public WikiSite getWikiSite() {
return model.getTitle().getWikiSite();
}
};
bridge.addListener("linkClicked", linkHandler);
bridge.addListener("referenceClicked", new ReferenceHandler() {
@Override
protected void onReferenceClicked(int selectedIndex, @NonNull List<Reference> adjacentReferences) {
if (!isAdded()) {
Log.d("PageFragment", "Detached from activity, so stopping reference click.");
return;
}
showBottomSheet(new ReferenceDialog(requireActivity(), selectedIndex, adjacentReferences, linkHandler));
}
});
bridge.addListener("imageClicked", (String messageType, JSONObject messagePayload) -> {
try {
String href = decodeURL(messagePayload.getString("href"));
if (href.startsWith("/wiki/")) {
String filename = UriUtil.removeInternalLinkPrefix(href);
String fileUrl = null;
// Set the lead image url manually if the filename equals to the lead image file name.
if (getPage() != null && !TextUtils.isEmpty(getPage().getPageProperties().getLeadImageName())) {
String leadImageName = addUnderscores(getPage().getPageProperties().getLeadImageName());
String leadImageUrl = getPage().getPageProperties().getLeadImageUrl();
if (filename.contains(leadImageName) && leadImageUrl != null) {
fileUrl = UriUtil.resolveProtocolRelativeUrl(leadImageUrl);
}
}
WikiSite wiki = model.getTitle().getWikiSite();
requireActivity().startActivityForResult(GalleryActivity.newIntent(requireActivity(), model.getTitleOriginal(), filename, fileUrl, wiki, GalleryFunnel.SOURCE_NON_LEAD_IMAGE), Constants.ACTIVITY_REQUEST_GALLERY);
} else {
linkHandler.onUrlClick(href, messagePayload.optString("title"), "");
}
} catch (JSONException e) {
L.logRemoteErrorIfProd(e);
}
});
bridge.addListener("mediaClicked", (String messageType, JSONObject messagePayload) -> {
try {
String href = decodeURL(messagePayload.getString("href"));
String filename = StringUtil.removeUnderscores(UriUtil.removeInternalLinkPrefix(href));
WikiSite wiki = model.getTitle().getWikiSite();
requireActivity().startActivityForResult(GalleryActivity.newIntent(requireActivity(), model.getTitleOriginal(), filename, wiki, GalleryFunnel.SOURCE_NON_LEAD_IMAGE), Constants.ACTIVITY_REQUEST_GALLERY);
} catch (JSONException e) {
L.logRemoteErrorIfProd(e);
}
});
bridge.addListener("pronunciationClicked", (String messageType, JSONObject messagePayload) -> {
if (avPlayer == null) {
avPlayer = new DefaultAvPlayer(new MediaPlayerImplementation());
avPlayer.init();
}
if (avCallback == null) {
avCallback = new AvCallback();
}
if (!avPlayer.isPlaying()) {
updateProgressBar(true, true, 0);
avPlayer.play(getPage().getTitlePronunciationUrl(), avCallback, avCallback);
} else {
updateProgressBar(false, true, 0);
avPlayer.stop();
}
});
}
use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class NotificationActivity method deleteItems.
private void deleteItems(List<NotificationListItemContainer> items, boolean markUnread) {
Map<WikiSite, List<Notification>> notificationsPerWiki = new HashMap<>();
Long selectionKey = items.size() > 1 ? new Random().nextLong() : null;
for (NotificationListItemContainer item : items) {
WikiSite wiki = dbNameMap.containsKey(item.notification.wiki()) ? dbNameMap.get(item.notification.wiki()) : WikipediaApp.getInstance().getWikiSite();
if (!notificationsPerWiki.containsKey(wiki)) {
notificationsPerWiki.put(wiki, new ArrayList<>());
}
notificationsPerWiki.get(wiki).add(item.notification);
if (markUnread && !displayArchived) {
notificationList.add(item.notification);
} else {
notificationList.remove(item.notification);
new NotificationFunnel(WikipediaApp.getInstance(), item.notification).logMarkRead(selectionKey);
}
}
for (WikiSite wiki : notificationsPerWiki.keySet()) {
if (markUnread) {
NotificationPollBroadcastReceiver.markRead(wiki, notificationsPerWiki.get(wiki), true);
} else {
NotificationPollBroadcastReceiver.markRead(wiki, notificationsPerWiki.get(wiki), false);
showDeleteItemsUndoSnackbar(items);
}
}
postprocessAndDisplay();
}
use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class NotificationPollBroadcastReceiver method markRead.
public static void markRead(@NonNull WikiSite wiki, @NonNull List<Notification> notifications, boolean unread) {
final String idListStr = TextUtils.join("|", notifications);
CsrfTokenClient editTokenClient = new CsrfTokenClient(wiki, WikipediaApp.getInstance().getWikiSite());
editTokenClient.request(new CsrfTokenClient.DefaultCallback() {
@SuppressLint("CheckResult")
@Override
public void success(@NonNull String token) {
ServiceFactory.get(wiki).markRead(token, unread ? null : idListStr, unread ? idListStr : null).subscribeOn(Schedulers.io()).subscribe(response -> {
}, L::e);
}
});
}
use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class NotificationPollBroadcastReceiver method markItemsAsRead.
private void markItemsAsRead(List<Notification> items) {
Map<WikiSite, List<Notification>> notificationsPerWiki = new HashMap<>();
for (Notification item : items) {
WikiSite wiki = dbNameWikiSiteMap.containsKey(item.wiki()) ? dbNameWikiSiteMap.get(item.wiki()) : WikipediaApp.getInstance().getWikiSite();
if (!notificationsPerWiki.containsKey(wiki)) {
notificationsPerWiki.put(wiki, new ArrayList<>());
}
notificationsPerWiki.get(wiki).add(item);
}
for (WikiSite wiki : notificationsPerWiki.keySet()) {
markRead(wiki, notificationsPerWiki.get(wiki), false);
}
}
Aggregations