Search in sources :

Example 1 with EditSummaryTag

use of org.wikipedia.edit.summaries.EditSummaryTag 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)

Aggregations

ProgressDialog (android.app.ProgressDialog)1 AssetManager (android.content.res.AssetManager)1 Configuration (android.content.res.Configuration)1 Resources (android.content.res.Resources)1 DisplayMetrics (android.util.DisplayMetrics)1 Locale (java.util.Locale)1 EditSummaryTag (org.wikipedia.edit.summaries.EditSummaryTag)1 PageTitle (org.wikipedia.page.PageTitle)1