Search in sources :

Example 1 with SyntaxHighlighter

use of org.wikipedia.edit.richtext.SyntaxHighlighter in project apps-android-wikipedia by wikimedia.

the class EditSectionActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_section);
    setStatusBarColor(ResourceUtil.getThemedAttributeId(this, R.attr.page_status_bar_color));
    if (!getIntent().getAction().equals(ACTION_EDIT_SECTION)) {
        throw new RuntimeException("Much wrong action. Such exception. Wow");
    }
    title = getIntent().getParcelableExtra(EXTRA_TITLE);
    sectionID = getIntent().getIntExtra(EXTRA_SECTION_ID, 0);
    sectionHeading = getIntent().getStringExtra(EXTRA_SECTION_HEADING);
    pageProps = getIntent().getParcelableExtra(EXTRA_PAGE_PROPS);
    textToHighlight = getIntent().getStringExtra(EXTRA_HIGHLIGHT_TEXT);
    progressDialog = new ProgressDialog(this);
    progressDialog.setIndeterminate(true);
    progressDialog.setCancelable(false);
    progressDialog.setMessage(getString(R.string.dialog_saving_in_progress));
    final ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.setTitle("");
    }
    sectionText = findViewById(R.id.edit_section_text);
    syntaxHighlighter = new SyntaxHighlighter(this, sectionText);
    sectionProgress = findViewById(R.id.edit_section_load_progress);
    sectionContainer = findViewById(R.id.edit_section_container);
    sectionContainer.setSmoothScrollingEnabled(false);
    errorView = findViewById(R.id.view_edit_section_error);
    abusefilterContainer = findViewById(R.id.edit_section_abusefilter_container);
    abuseFilterImage = findViewById(R.id.edit_section_abusefilter_image);
    abusefilterTitle = findViewById(R.id.edit_section_abusefilter_title);
    abusefilterText = findViewById(R.id.edit_section_abusefilter_text);
    captchaHandler = new CaptchaHandler(this, title.getWikiSite(), progressDialog, sectionContainer, "", null);
    editPreviewFragment = (EditPreviewFragment) getSupportFragmentManager().findFragmentById(R.id.edit_section_preview_fragment);
    editSummaryFragment = (EditSummaryFragment) getSupportFragmentManager().findFragmentById(R.id.edit_section_summary_fragment);
    updateEditLicenseText();
    editSummaryFragment.setTitle(title);
    funnel = WikipediaApp.getInstance().getFunnelManager().getEditFunnel(title);
    // Only send the editing start log event if the activity is created for the first time
    if (savedInstanceState == null) {
        funnel.logStart();
    }
    if (savedInstanceState != null && savedInstanceState.containsKey("sectionWikitext")) {
        sectionWikitext = savedInstanceState.getString("sectionWikitext");
    }
    captchaHandler.restoreState(savedInstanceState);
    if (savedInstanceState != null && savedInstanceState.containsKey("abusefilter")) {
        abusefilterEditResult = savedInstanceState.getParcelable("abusefilter");
        handleAbuseFilter();
    }
    errorView.setRetryClickListener((v) -> {
        errorView.setVisibility(View.GONE);
        fetchSectionText();
    });
    errorView.setBackClickListener((v) -> onBackPressed());
    setConditionalTextDirection(sectionText, title.getWikiSite().languageCode());
    fetchSectionText();
    if (savedInstanceState != null && savedInstanceState.containsKey("sectionTextModified")) {
        sectionTextModified = savedInstanceState.getBoolean("sectionTextModified");
    }
    sectionText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (sectionTextFirstLoad) {
                sectionTextFirstLoad = false;
                return;
            }
            if (!sectionTextModified) {
                sectionTextModified = true;
                // update the actionbar menu, which will enable the Next button.
                supportInvalidateOptionsMenu();
            }
        }
    });
    // set focus to the EditText, but keep the keyboard hidden until the user changes the cursor location:
    sectionText.requestFocus();
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
Also used : CaptchaHandler(org.wikipedia.captcha.CaptchaHandler) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) SyntaxHighlighter(org.wikipedia.edit.richtext.SyntaxHighlighter) ProgressDialog(android.app.ProgressDialog) ActionBar(android.support.v7.app.ActionBar)

Aggregations

ProgressDialog (android.app.ProgressDialog)1 ActionBar (android.support.v7.app.ActionBar)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 CaptchaHandler (org.wikipedia.captcha.CaptchaHandler)1 SyntaxHighlighter (org.wikipedia.edit.richtext.SyntaxHighlighter)1