Search in sources :

Example 36 with PageTitle

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;
}
Also used : PageTitle(org.wikipedia.page.PageTitle) ArrayList(java.util.ArrayList) NonNull(android.support.annotation.NonNull)

Example 37 with PageTitle

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();
}
Also used : DescriptionEditFunnel(org.wikipedia.analytics.DescriptionEditFunnel) PageTitle(org.wikipedia.page.PageTitle)

Example 38 with PageTitle

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);
}
Also used : Locale(java.util.Locale) AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) PageTitle(org.wikipedia.page.PageTitle) EditSummaryTag(org.wikipedia.edit.summaries.EditSummaryTag) Resources(android.content.res.Resources) ProgressDialog(android.app.ProgressDialog) DisplayMetrics(android.util.DisplayMetrics)

Example 39 with PageTitle

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;
}
Also used : PageTitle(org.wikipedia.page.PageTitle)

Example 40 with PageTitle

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;
}
Also used : PageTitle(org.wikipedia.page.PageTitle)

Aggregations

PageTitle (org.wikipedia.page.PageTitle)60 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)15 WikiSite (org.wikipedia.dataclient.WikiSite)11 HistoryEntry (org.wikipedia.history.HistoryEntry)11 NonNull (android.support.annotation.NonNull)6 OnClick (butterknife.OnClick)5 ReadingListPage (org.wikipedia.readinglist.database.ReadingListPage)5 IOException (java.io.IOException)4 Date (java.util.Date)4 WikipediaApp (org.wikipedia.WikipediaApp)3 PageBackStackItem (org.wikipedia.page.PageBackStackItem)3 Tab (org.wikipedia.page.tabs.Tab)3 ProgressDialog (android.app.ProgressDialog)2 Intent (android.content.Intent)2 AssetManager (android.content.res.AssetManager)2 Configuration (android.content.res.Configuration)2 Resources (android.content.res.Resources)2 Bundle (android.os.Bundle)2 DisplayMetrics (android.util.DisplayMetrics)2