Search in sources :

Example 1 with CaptchaHandler

use of org.wikipedia.captcha.CaptchaHandler 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)

Example 2 with CaptchaHandler

use of org.wikipedia.captcha.CaptchaHandler in project apps-android-wikipedia by wikimedia.

the class CreateAccountActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_account);
    ButterKnife.bind(this);
    if (ReadingListSyncAdapter.isDisabledByRemoteConfig()) {
        onboardingContainer.setVisibility(View.GONE);
    }
    progressDialog = new ProgressDialog(this);
    progressDialog.setIndeterminate(true);
    progressDialog.setCancelable(false);
    progressDialog.setMessage(getString(R.string.dialog_create_account_checking_progress));
    errorView.setBackClickListener((v) -> onBackPressed());
    errorView.setRetryClickListener((v) -> errorView.setVisibility(View.GONE));
    wiki = WikipediaApp.getInstance().getWikiSite();
    createAccountInfoClient = new CreateAccountInfoClient();
    createAccountClient = new CreateAccountClient();
    captchaHandler = new CaptchaHandler(this, WikipediaApp.getInstance().getWikiSite(), progressDialog, primaryContainer, getString(R.string.create_account_activity_title), getString(R.string.create_account_button));
    // Don't allow user to submit registration unless they've put in a username and password
    new NonEmptyValidator((isValid) -> createAccountButton.setEnabled(isValid), usernameInput, passwordInput);
    // Don't allow user to continue when they're shown a captcha until they fill it in
    new NonEmptyValidator((isValid) -> createAccountButtonCaptcha.setEnabled(isValid), captchaText);
    // Add listener so that when the user taps enter, it submits the captcha
    captchaText.setOnKeyListener((v, keyCode, event) -> {
        if ((event.getAction() == KeyEvent.ACTION_UP) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
            validateThenCreateAccount();
            return true;
        }
        return false;
    });
    usernameInput.getEditText().addTextChangedListener(userNameTextWatcher);
    if (savedInstanceState != null && savedInstanceState.containsKey("result")) {
        createAccountResult = savedInstanceState.getParcelable("result");
    }
    funnel = new CreateAccountFunnel(WikipediaApp.getInstance(), getIntent().getStringExtra(LOGIN_REQUEST_SOURCE));
    // Only send the editing start log event if the activity is created for the first time
    if (savedInstanceState == null) {
        funnel.logStart(getIntent().getStringExtra(LOGIN_SESSION_TOKEN));
    }
    // Set default result to failed, so we can override if it did not
    setResult(RESULT_ACCOUNT_NOT_CREATED);
}
Also used : CreateAccountFunnel(org.wikipedia.analytics.CreateAccountFunnel) CaptchaHandler(org.wikipedia.captcha.CaptchaHandler) NonEmptyValidator(org.wikipedia.views.NonEmptyValidator) ProgressDialog(android.app.ProgressDialog)

Aggregations

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