<commit_before>package cgeo.geocaching.ui;

import cgeo.geocaching.R;
import cgeo.geocaching.activity.Keyboard;
import cgeo.geocaching.ui.dialog.Dialogs;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;

import org.apache.commons.lang3.StringUtils;

public class EditNoteDialog extends DialogFragment {

    public static final String ARGUMENT_INITIAL_NOTE = "initialNote";
    public static final String ARGUMENT_INITIAL_PREVENT = "initialPrevent";

    private EditText mEditText;
    private CheckBox mPreventCheckbox;

    public interface EditNoteDialogListener {
        void onFinishEditNoteDialog(String inputText, boolean preventWaypointsFromNote);
    }

    /**
     * Create a new dialog to edit a note.
     * <em>This fragment must be inserted into an activity implementing the EditNoteDialogListener interface.</em>
     *
     * @param initialNote the initial note to insert in the edit dialog
     */
    public static EditNoteDialog newInstance(final String initialNote, final boolean preventWaypointsFromNote) {
        final EditNoteDialog dialog = new EditNoteDialog();

        final Bundle arguments = new Bundle();
        arguments.putString(ARGUMENT_INITIAL_NOTE, initialNote);
        arguments.putBoolean(ARGUMENT_INITIAL_PREVENT, preventWaypointsFromNote);
        dialog.setArguments(arguments);

        return dialog;
    }


    @Override
    @androidx.annotation.NonNull
    public Dialog onCreateDialog(final Bundle savedInstanceState) {
        final FragmentActivity activity = getActivity();

        final View view = View.inflate(activity, R.layout.fragment_edit_note, null);
        mEditText = view.findViewById(R.id.note);
        String initialNote = getArguments().getString(ARGUMENT_INITIAL_NOTE);
        if (initialNote != null) {
            // add a new line when editing existing text, to avoid accidental overwriting of the last line
            if (StringUtils.isNotBlank(initialNote) && !initialNote.endsWith("\n")) {
                initialNote = initialNote + "\n";
            }
            mEditText.setText(initialNote);
            Dialogs.moveCursorToEnd(mEditText);
            getArguments().remove(ARGUMENT_INITIAL_NOTE);
        }
        mPreventCheckbox = view.findViewById(R.id.preventWaypointsFromNote);
        final boolean preventWaypointsFromNote = getArguments().getBoolean(ARGUMENT_INITIAL_PREVENT);
        mPreventCheckbox.setChecked(preventWaypointsFromNote);

        final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setView(view);
        final AlertDialog dialog = builder.create();

        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        final TextView title = view.findViewById(R.id.dialog_title_title);
        title.setText(R.string.cache_personal_note);
        title.setVisibility(View.VISIBLE);

        final ImageButton cancel = view.findViewById(R.id.dialog_title_cancel);
        cancel.setOnClickListener(view1 -> dialog.dismiss());
        cancel.setVisibility(View.VISIBLE);

        final ImageButton done = view.findViewById(R.id.dialog_title_done);
        done.setOnClickListener(view12 -> {
            // trim note to avoid unnecessary uploads for whitespace only changes
            final String personalNote = StringUtils.trim(mEditText.getText().toString());
            ((EditNoteDialogListener) getActivity()).onFinishEditNoteDialog(personalNote, mPreventCheckbox.isChecked());
            dialog.dismiss();
        });
        done.setVisibility(View.VISIBLE);

        new Keyboard(activity).showDelayed(mEditText);

        //prevent popup window to extend under the virtual keyboard or above the top of phone display (see #8793)
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        return dialog;
    }
}
<commit_msg>[Personal Note] Immediately activate keyboard on press of "edit"<commit_after>package cgeo.geocaching.ui;

import cgeo.geocaching.R;
import cgeo.geocaching.activity.Keyboard;
import cgeo.geocaching.ui.dialog.Dialogs;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;

import org.apache.commons.lang3.StringUtils;

public class EditNoteDialog extends DialogFragment {

    public static final String ARGUMENT_INITIAL_NOTE = "initialNote";
    public static final String ARGUMENT_INITIAL_PREVENT = "initialPrevent";

    private EditText mEditText;
    private CheckBox mPreventCheckbox;

    public interface EditNoteDialogListener {
        void onFinishEditNoteDialog(String inputText, boolean preventWaypointsFromNote);
    }

    /**
     * Create a new dialog to edit a note.
     * <em>This fragment must be inserted into an activity implementing the EditNoteDialogListener interface.</em>
     *
     * @param initialNote the initial note to insert in the edit dialog
     */
    public static EditNoteDialog newInstance(final String initialNote, final boolean preventWaypointsFromNote) {
        final EditNoteDialog dialog = new EditNoteDialog();

        final Bundle arguments = new Bundle();
        arguments.putString(ARGUMENT_INITIAL_NOTE, initialNote);
        arguments.putBoolean(ARGUMENT_INITIAL_PREVENT, preventWaypointsFromNote);
        dialog.setArguments(arguments);

        return dialog;
    }


    @Override
    @androidx.annotation.NonNull
    public Dialog onCreateDialog(final Bundle savedInstanceState) {
        final FragmentActivity activity = getActivity();

        final View view = View.inflate(activity, R.layout.fragment_edit_note, null);
        mEditText = view.findViewById(R.id.note);
        String initialNote = getArguments().getString(ARGUMENT_INITIAL_NOTE);
        if (initialNote != null) {
            // add a new line when editing existing text, to avoid accidental overwriting of the last line
            if (StringUtils.isNotBlank(initialNote) && !initialNote.endsWith("\n")) {
                initialNote = initialNote + "\n";
            }
            mEditText.setText(initialNote);
            Dialogs.moveCursorToEnd(mEditText);
            getArguments().remove(ARGUMENT_INITIAL_NOTE);
        }
        mPreventCheckbox = view.findViewById(R.id.preventWaypointsFromNote);
        final boolean preventWaypointsFromNote = getArguments().getBoolean(ARGUMENT_INITIAL_PREVENT);
        mPreventCheckbox.setChecked(preventWaypointsFromNote);

        final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setView(view);
        final AlertDialog dialog = builder.create();

        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        final TextView title = view.findViewById(R.id.dialog_title_title);
        title.setText(R.string.cache_personal_note);
        title.setVisibility(View.VISIBLE);

        final ImageButton cancel = view.findViewById(R.id.dialog_title_cancel);
        cancel.setOnClickListener(view1 -> dialog.dismiss());
        cancel.setVisibility(View.VISIBLE);

        final ImageButton done = view.findViewById(R.id.dialog_title_done);
        done.setOnClickListener(view12 -> {
            // trim note to avoid unnecessary uploads for whitespace only changes
            final String personalNote = StringUtils.trim(mEditText.getText().toString());
            ((EditNoteDialogListener) getActivity()).onFinishEditNoteDialog(personalNote, mPreventCheckbox.isChecked());
            dialog.dismiss();
        });
        done.setVisibility(View.VISIBLE);

        mEditText.requestFocus();
        new Keyboard(activity).showDelayed(mEditText);

        //prevent popup window to extend under the virtual keyboard or above the top of phone display (see #8793)
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        return dialog;
    }
}

{'fraction_non_alphanumeric': 0.08446705311723648, 'fraction_numerical': 0.0018928191174730864, 'mean_word_length': 3.567260940032415, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7312815', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2174, 'n_words': 509}