<commit_before>package com.benjaminearley.mysubs;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Dialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialogFragment;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;

import com.benjaminearley.mysubs.adapter.BottomSheetAdapter;
import com.benjaminearley.mysubs.data.MySubsContract;
import com.benjaminearley.mysubs.model.Data__;
import com.benjaminearley.mysubs.model.Subreddit;
import com.benjaminearley.mysubs.net.WebService;
import com.benjaminearley.mysubs.sync.MySubsSyncAdapter;
import com.benjaminearley.mysubs.util.Utility;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SubredditBottomSheetDialogFragment extends BottomSheetDialogFragment implements LoaderManager.LoaderCallbacks<Cursor> {

    public static final int COLUMN_TITLE = 1;
    public static final int COLUMN_URL = 2;
    private static final int SUBREDDIT_LOADER = 0;
    private static final String[] SUBREDDIT_COLUMNS = {
            MySubsContract.SubredditEntry.TABLE_NAME + "." + MySubsContract.SubredditEntry._ID,
            MySubsContract.SubredditEntry.COLUMN_TITLE,
            MySubsContract.SubredditEntry.COLUMN_URL
    };
    ImageButton addButton;
    EditText subredditSearch;
    BottomSheetAdapter subredditAdapter;
    RecyclerView recyclerView;
    Cursor data;
    ProgressBar spinner;
    Integer deletePosition = null;

    private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() {

        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                dismiss();
            }

        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        }
    };

    @Override
    public void setupDialog(Dialog dialog, int style) {
        super.setupDialog(dialog, style);
        View contentView = View.inflate(getContext(), R.layout.fragment_bottom_sheet, null);
        dialog.setContentView(contentView);

        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
        CoordinatorLayout.Behavior behavior = params.getBehavior();

        if (behavior != null && behavior instanceof BottomSheetBehavior) {
            ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
        }

        recyclerView = (RecyclerView) contentView.findViewById(R.id.subreddit_list);
        subredditAdapter = new BottomSheetAdapter(new SimpleAdapterOnClickHandler() {
            @Override
            public void onClick(final String subreddit, final int position) {

                new AlertDialog.Builder(getContext())
                        .setMessage(
                                String.format(
                                        getActivity().getString(R.string.delete_subreddit_message),
                                        subreddit))

                        .setPositiveButton(getActivity().getString(R.string.delete_subreddit_positive_button_text),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Uri subredditUri = MySubsContract.SubredditEntry.buildSubreddit();
                                        deletePosition = position;
                                        getContext().getContentResolver().delete(subredditUri, getActivity().getString(R.string.db_title_query), new String[]{subreddit});
                                        MySubsSyncAdapter.syncImmediately(getContext());
                                    }
                                })
                        .setNegativeButton(getActivity().getString(R.string.delete_subreddit_negative_button_text), null)
                        .create()
                        .show();
            }
        });
        recyclerView.setAdapter(subredditAdapter);

        spinner = (ProgressBar) contentView.findViewById(R.id.spinner);
        subredditSearch = (EditText) contentView.findViewById(R.id.subreddit_search);
        addButton = (ImageButton) contentView.findViewById(R.id.addButton);
        addButton.setOnClickListener(new View.OnClickListener() {
            @Override<commit_msg>force correct field input on subreddit add field<commit_after>package com.benjaminearley.mysubs;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Dialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialogFragment;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;

import com.benjaminearley.mysubs.adapter.BottomSheetAdapter;
import com.benjaminearley.mysubs.data.MySubsContract;
import com.benjaminearley.mysubs.model.Data__;
import com.benjaminearley.mysubs.model.Subreddit;
import com.benjaminearley.mysubs.net.WebService;
import com.benjaminearley.mysubs.sync.MySubsSyncAdapter;
import com.benjaminearley.mysubs.util.Utility;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SubredditBottomSheetDialogFragment extends BottomSheetDialogFragment implements LoaderManager.LoaderCallbacks<Cursor> {

    public static final int COLUMN_TITLE = 1;
    public static final int COLUMN_URL = 2;
    private static final int SUBREDDIT_LOADER = 0;
    private static final String[] SUBREDDIT_COLUMNS = {
            MySubsContract.SubredditEntry.TABLE_NAME + "." + MySubsContract.SubredditEntry._ID,
            MySubsContract.SubredditEntry.COLUMN_TITLE,
            MySubsContract.SubredditEntry.COLUMN_URL
    };
    ImageButton addButton;
    EditText subredditSearch;
    BottomSheetAdapter subredditAdapter;
    RecyclerView recyclerView;
    Cursor data;
    ProgressBar spinner;
    Integer deletePosition = null;

    private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() {

        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                dismiss();
            }

        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        }
    };

    @Override
    public void setupDialog(Dialog dialog, int style) {
        super.setupDialog(dialog, style);
        View contentView = View.inflate(getContext(), R.layout.fragment_bottom_sheet, null);
        dialog.setContentView(contentView);

        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
        CoordinatorLayout.Behavior behavior = params.getBehavior();

        if (behavior != null && behavior instanceof BottomSheetBehavior) {
            ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
        }

        recyclerView = (RecyclerView) contentView.findViewById(R.id.subreddit_list);
        subredditAdapter = new BottomSheetAdapter(new SimpleAdapterOnClickHandler() {
            @Override
            public void onClick(final String subreddit, final int position) {

                new AlertDialog.Builder(getContext())
                        .setMessage(
                                String.format(
                                        getActivity().getString(R.string.delete_subreddit_message),
                                        subreddit))

                        .setPositiveButton(getActivity().getString(R.string.delete_subreddit_positive_button_text),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Uri subredditUri = MySubsContract.SubredditEntry.buildSubreddit();
                                        deletePosition = position;
                                        getContext().getContentResolver().delete(subredditUri, getActivity().getString(R.string.db_title_query), new String[]{subreddit});
                                        MySubsSyncAdapter.syncImmediately(getContext());
                                    }
                                })
                        .setNegativeButton(getActivity().getString(R.string.delete_subreddit_negative_button_text), null)
                        .create()
                        .show();
            }
        });
        recyclerView.setAdapter(subredditAdapter);

        spinner = (ProgressBar) contentView.findViewById(R.id.spinner);
        subredditSearch = (EditText) contentView.findViewById(R.id.subreddit_search);

        subredditSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

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

            }

            @Override
            public void afterTextChanged(Editable s) {
                String result = s.toString().replaceAll(" ", "").toLowerCase();
                if (!s.toString().equals(result)) {
                    subredditSearch.setText(result);
                    subredditSearch.setSelection(result.length());
                    // alert the user
                }
            }
        });

        addButton = (ImageButton) contentView.findViewById(R.id.addButton);
        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
{'fraction_non_alphanumeric': 0.08113898063018835, 'fraction_numerical': 0.00196375970722128, 'mean_word_length': 2.609536082474227, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5110637', 'n_tokens_mistral': 2828, 'n_tokens_neox': 2767, 'n_words': 506}