use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class ParcelableTest method testPageImage.
@Test
public void testPageImage() throws Throwable {
WikiSite wiki = WikiSite.forLanguageCode("en");
PageTitle title = new PageTitle("Talk", "India", wiki);
PageImage pageImage = new PageImage(title, "Testing image");
TestParcelUtil.test(pageImage);
}
use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class EditPreviewFragment method displayPreview.
private void displayPreview(final String html) {
if (!isWebViewSetup) {
isWebViewSetup = true;
L10nUtil.setupDirectionality(parentActivity.getPageTitle().getWikiSite().languageCode(), Locale.getDefault().getLanguage(), bridge);
if (!WikipediaApp.getInstance().getCurrentTheme().isDefault()) {
ThemeBridgeAdapter.setTheme(bridge);
}
bridge.addListener("linkClicked", new LinkHandler(getActivity()) {
@Override
public void onPageLinkClicked(@NonNull String href) {
// TODO: also need to handle references, issues, disambig, ... in preview eventually
}
@Override
public void onInternalLinkClicked(@NonNull final PageTitle title) {
showLeavingEditDialogue(() -> startActivity(PageActivity.newIntentForNewTab(getContext(), new HistoryEntry(title, HistoryEntry.SOURCE_INTERNAL_LINK), title)));
}
@Override
public void onExternalLinkClicked(@NonNull final Uri uri) {
showLeavingEditDialogue(() -> handleExternalLink(getContext(), uri));
}
/**
* Shows the user a dialogue asking them if they really meant to leave the edit
* workflow, and warning them that their changes have not yet been saved.
* @param runnable The runnable that is run if the user chooses to leave.
*/
private void showLeavingEditDialogue(final Runnable runnable) {
// Ask the user if they really meant to leave the edit workflow
final AlertDialog leavingEditDialog = new AlertDialog.Builder(getActivity()).setMessage(R.string.dialog_message_leaving_edit).setPositiveButton(R.string.dialog_message_leaving_edit_leave, (dialog, which) -> {
// They meant to leave; close dialogue and run specified action
dialog.dismiss();
runnable.run();
}).setNegativeButton(R.string.dialog_message_leaving_edit_stay, null).create();
leavingEditDialog.show();
}
@Override
public WikiSite getWikiSite() {
return parentActivity.getPageTitle().getWikiSite();
}
});
bridge.addListener("imageClicked", (messageType, messagePayload) -> {
// TODO: do something when an image is clicked in Preview.
});
bridge.addListener("mediaClicked", (messageType, messagePayload) -> {
// TODO: do something when a video is clicked in Preview.
});
bridge.addListener("referenceClicked", (messageType, messagePayload) -> {
// TODO: do something when a reference is clicked in Preview.
});
}
ViewAnimations.fadeIn(previewContainer, () -> parentActivity.supportInvalidateOptionsMenu());
ViewAnimations.fadeOut(getActivity().findViewById(R.id.edit_section_container));
JSONObject payload = new JSONObject();
try {
payload.put("html", html);
payload.put("siteBaseUrl", parentActivity.getPageTitle().getWikiSite().url());
} catch (JSONException e) {
throw new RuntimeException(e);
}
bridge.sendMessage("displayPreviewHTML", payload);
}
use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class TabUnmarshallerTest method testUnmarshalNoHistoryEntryAuthority.
// T152980
@Test(expected = RuntimeException.class)
public void testUnmarshalNoHistoryEntryAuthority() {
PageTitle page = new PageTitle("text", WikiSite.forLanguageCode("test"));
PageTitle prevPage = new PageTitle("text", new WikiSite("", ""));
HistoryEntry history = new HistoryEntry(prevPage, new Date(0), HistoryEntry.SOURCE_SEARCH);
Tab tab = new Tab();
tab.getBackStack().add(new PageBackStackItem(page, history));
List<Tab> tabs = singletonList(tab);
TabUnmarshaller.unmarshal(GsonMarshaller.marshal(tabs));
}
use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class TabUnmarshallerTest method testUnmarshalNoPageTitleAuthority.
// T152980
@Test(expected = RuntimeException.class)
public void testUnmarshalNoPageTitleAuthority() {
PageTitle page = new PageTitle("text", new WikiSite("", ""));
HistoryEntry history = new HistoryEntry(page, new Date(0), HistoryEntry.SOURCE_SEARCH);
Tab tab = new Tab();
tab.getBackStack().add(new PageBackStackItem(page, history));
List<Tab> tabs = singletonList(tab);
TabUnmarshaller.unmarshal(GsonMarshaller.marshal(tabs));
}
use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.
the class WikipediaApp method getUserIdForLanguage.
private void getUserIdForLanguage(@NonNull final String code) {
if (!AccountUtil.isLoggedIn() || TextUtils.isEmpty(AccountUtil.getUserName())) {
return;
}
final WikiSite wikiSite = WikiSite.forLanguageCode(code);
userInfoClient.request(wikiSite, AccountUtil.getUserName(), new UserExtendedInfoClient.Callback() {
@Override
public void success(@NonNull Call<MwQueryResponse> call, int id, @NonNull UserExtendedInfoClient.ListUserResponse user) {
if (AccountUtil.isLoggedIn()) {
AccountUtil.putUserIdForLanguage(code, id);
L.v("Found user ID " + id + " for " + code);
}
}
@Override
public void failure(@NonNull Call<MwQueryResponse> call, @NonNull Throwable caught) {
L.e("Failed to get user ID for " + code, caught);
}
});
}
Aggregations