use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class MwQueryResult method langLinks.
@NonNull
public List<PageTitle> langLinks() {
List<PageTitle> result = new ArrayList<>();
if (pages == null || pages.isEmpty() || pages.get(0).langLinks() == null) {
return result;
}
// noinspection ConstantConditions
for (MwQueryPage.LangLink link : pages.get(0).langLinks()) {
PageTitle title = new PageTitle(link.title(), WikiSite.forLanguageCode(link.lang()));
result.add(title);
}
return result;
}
use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class DescriptionEditFragment method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pageTitle = GsonUnmarshaller.unmarshal(PageTitle.class, getArguments().getString(ARG_TITLE));
DescriptionEditFunnel.Type type = pageTitle.getDescription() == null ? DescriptionEditFunnel.Type.NEW : DescriptionEditFunnel.Type.EXISTING;
funnel = new DescriptionEditFunnel(WikipediaApp.getInstance(), pageTitle, type);
funnel.logStart();
}
use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class EditPreviewFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
parentActivity = (EditSectionActivity) getActivity();
PageTitle pageTitle = parentActivity.getPageTitle();
funnel = WikipediaApp.getInstance().getFunnelManager().getEditFunnel(pageTitle);
/*
Use a Resources object with a different Locale, so that the text of the canned summary
buttons is shown in the selected Wiki language, instead of the current UI language.
However, there's a caveat: creating a new Resources object actually modifies something
internally in the AssetManager, so we'll need to create another new Resources object
with the original Locale when we're done.
https://code.google.com/p/android/issues/detail?id=67672
*/
Resources oldResources = getResources();
AssetManager assets = oldResources.getAssets();
DisplayMetrics metrics = oldResources.getDisplayMetrics();
Locale oldLocale = ConfigurationCompat.getLocale(oldResources.getConfiguration());
Locale newLocale = new Locale(pageTitle.getWikiSite().languageCode());
Configuration config = new Configuration(oldResources.getConfiguration());
Resources tempResources = getResources();
if (!oldLocale.getLanguage().equals(newLocale.getLanguage()) && !newLocale.getLanguage().equals("test")) {
L10nUtil.setDesiredLocale(config, newLocale);
tempResources = new Resources(assets, metrics, config);
}
// build up summary tags...
int[] summaryTagStrings = { R.string.edit_summary_tag_typo, R.string.edit_summary_tag_grammar, R.string.edit_summary_tag_links };
summaryTags = new ArrayList<>();
for (int i : summaryTagStrings) {
final EditSummaryTag tag = new EditSummaryTag(getActivity());
tag.setText(tempResources.getString(i));
tag.setTag(i);
tag.setOnClickListener((view) -> {
funnel.logEditSummaryTap((Integer) view.getTag());
tag.setSelected(!tag.getSelected());
});
editSummaryTagsContainer.addView(tag);
summaryTags.add(tag);
}
otherTag = new EditSummaryTag(getActivity());
otherTag.setText(tempResources.getString(R.string.edit_summary_tag_other));
editSummaryTagsContainer.addView(otherTag);
otherTag.setOnClickListener((view) -> {
funnel.logEditSummaryTap(R.string.edit_summary_tag_other);
if (otherTag.getSelected()) {
otherTag.setSelected(false);
} else {
parentActivity.showCustomSummary();
}
});
/*
Reset AssetManager to its original state, by creating a new Resources object
with the original Locale (from above)
*/
if (!oldLocale.getLanguage().equals(newLocale.getLanguage())) {
config.setLocale(oldLocale);
new Resources(assets, metrics, config);
}
if (savedInstanceState != null) {
for (int i = 0; i < summaryTags.size(); i++) {
summaryTags.get(i).setSelected(savedInstanceState.getBoolean("summaryTag" + i, false));
}
if (savedInstanceState.containsKey("otherTag")) {
otherTag.setSelected(true);
otherTag.setText(savedInstanceState.getString("otherTag"));
}
previewHTML = savedInstanceState.getString("previewHTML");
boolean isActive = savedInstanceState.getBoolean("isActive");
previewContainer.setVisibility(isActive ? View.VISIBLE : View.GONE);
if (isActive) {
displayPreview(previewHTML);
}
}
progressDialog = new ProgressDialog(getActivity());
progressDialog.setIndeterminate(true);
progressDialog.setMessage(getString(R.string.edit_preview_fetching_dialog_message));
progressDialog.setCancelable(false);
}
use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class LangLinksActivityTest method getExpectedZhHantResults.
private List<PageTitle> getExpectedZhHantResults() {
List<PageTitle> result = getBaseLanguageEntries();
result.add(new PageTitle("洋基體育場 (1923年)", WikiSite.forLanguageCode("zh-hans")));
return result;
}
use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.
the class LangLinksActivityTest method getBaseLanguageEntriesWithZhVariants.
private List<PageTitle> getBaseLanguageEntriesWithZhVariants() {
List<PageTitle> result = getBaseLanguageEntries();
result.add(new PageTitle("洋基体育场 (1923年)", WikiSite.forLanguageCode("zh-hans")));
// TODO: change to correct variant, an API issue
result.add(new PageTitle("洋基体育场 (1923年)", WikiSite.forLanguageCode("zh-hant")));
return result;
}
Aggregations