<commit_before>/**
 * Copyright 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.lloydtorres.stately.report;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.NetworkError;
import com.android.volley.NoConnectionError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.lloydtorres.stately.R;
import com.lloydtorres.stately.dto.UserLogin;
import com.lloydtorres.stately.helpers.DashHelper;
import com.lloydtorres.stately.helpers.SparkleHelper;
import com.r0adkll.slidr.Slidr;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * Created by Lloyd on 2016-07-28.
 * Activity to report user content to the NS moderators.
 */
public class ReportActivity extends AppCompatActivity {
    // Keys for intent data and saved preferences
    public static final String REPORT_ID = "reportId";
    public static final String REPORT_TYPE = "reportType";
    public static final String REPORT_USER = "reportUser";
    private static final String REPORT_CATEGORY = "reportCategory";
    private static final String REPORT_CONTENT = "reportContent";

    // Types of reports
    public static final int REPORT_TYPE_TASK = 0;
    public static final int REPORT_TYPE_RMB = 1;
    public static final int REPORT_TYPE_TELEGRAM = 2;

    // Target URL for reports
    public static final String REPORT_URL = "https://www.nationstates.net/page=help";

    // Headers to send when submitting report
    private static final int HEADER_GHR_INAPPROPRIATE = 1;
    private static final int HEADER_GHR_SPAMMER = 3;
    private static final int HEADER_GHR_MODREPLY = 8;
    private static final int HEADER_GHR_OTHER = 9;

    // If no category selected
    private static final int CATEGORY_NONE = -1;

    private View view;
    private SwipeRefreshLayout mSwipeRefreshLayout;
    private RelativeLayout targetHolder;
    private TextView reportTarget;
    private CardView reportCategoryHolder;
    private RadioGroup reportCategorySelect;
    private EditText reportContent;

    private int targetId;
    private String targetName;
    private int type;
    private int categoryHolder = CATEGORY_NONE;
    private String contentHolder;

    private boolean isInProgress = false;
    private DialogInterface.OnClickListener dialogListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_report);
        Slidr.attach(this, SparkleHelper.slidrConfig);

        // Either get data from intent or restore state
        if (getIntent() != null)
        {
            if (getIntent().getData() != null) {
                targetId = Integer.valueOf(getIntent().getData().getHost());
                type = REPORT_TYPE_TASK;
            }
            else {
                targetId = getIntent().getIntExtra(REPORT_ID, 0);
                targetName = SparkleHelper.getNameFromId(getIntent().getStringExtra(REPORT_USER));
                type = getIntent().getIntExtra(REPORT_TYPE, REPORT_TYPE_TASK);
            }
        }
        if (savedInstanceState != null)
        {
            targetId = savedInstanceState.getInt(REPORT_ID);
            targetName = savedInstanceState.getString(REPORT_USER);
            type = savedInstanceState.getInt(REPORT_TYPE);
            categoryHolder = savedInstanceState.getInt(REPORT_CATEGORY, CATEGORY_NONE);
            contentHolder = savedInstanceState.getString(REPORT_CONTENT);
        }

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_report);
        setToolbar(toolbar);

        mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.report_refresher);
        mSwipeRefreshLayout.setColorSchemeResources(SparkleHelper.refreshColours);
        mSwipeRefreshLayout.setEnabled(false);

        dialogListener = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mSwipeRefreshLayout.post(new Runnable() {
                    @Override
                    public void run() {
                        mSwipeRefreshLayout.setRefreshing(true);
                        sendReport();
                    }
                });
            }
        };

        view = findViewById(R.id.report_main);
        targetHolder = (RelativeLayout) findViewById(R.id.report_target_holder);
        reportTarget = (TextView) findViewById(R.id.report_target);
        reportCategoryHolder = (CardView) findViewById(R.id.report_category_holder);
        reportCategorySelect = (RadioGroup) findViewById(R.id.report_category);
        reportContent = (EditText) findViewById(R.id.report_content);

        targetHolder.setVisibility(View.VISIBLE);
        reportCategoryHolder.setVisibility(View.VISIBLE);

        // If replying to mod mail, use this message instead
        if (type == REPORT_TYPE_TASK) {<commit_msg>Add NullActionCallback to report EditText<commit_after>/**
 * Copyright 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.lloydtorres.stately.report;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.NetworkError;
import com.android.volley.NoConnectionError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.lloydtorres.stately.R;
import com.lloydtorres.stately.dto.UserLogin;
import com.lloydtorres.stately.helpers.DashHelper;
import com.lloydtorres.stately.helpers.NullActionCallback;
import com.lloydtorres.stately.helpers.SparkleHelper;
import com.r0adkll.slidr.Slidr;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * Created by Lloyd on 2016-07-28.
 * Activity to report user content to the NS moderators.
 */
public class ReportActivity extends AppCompatActivity {
    // Keys for intent data and saved preferences
    public static final String REPORT_ID = "reportId";
    public static final String REPORT_TYPE = "reportType";
    public static final String REPORT_USER = "reportUser";
    private static final String REPORT_CATEGORY = "reportCategory";
    private static final String REPORT_CONTENT = "reportContent";

    // Types of reports
    public static final int REPORT_TYPE_TASK = 0;
    public static final int REPORT_TYPE_RMB = 1;
    public static final int REPORT_TYPE_TELEGRAM = 2;

    // Target URL for reports
    public static final String REPORT_URL = "https://www.nationstates.net/page=help";

    // Headers to send when submitting report
    private static final int HEADER_GHR_INAPPROPRIATE = 1;
    private static final int HEADER_GHR_SPAMMER = 3;
    private static final int HEADER_GHR_MODREPLY = 8;
    private static final int HEADER_GHR_OTHER = 9;

    // If no category selected
    private static final int CATEGORY_NONE = -1;

    private View view;
    private SwipeRefreshLayout mSwipeRefreshLayout;
    private RelativeLayout targetHolder;
    private TextView reportTarget;
    private CardView reportCategoryHolder;
    private RadioGroup reportCategorySelect;
    private EditText reportContent;

    private int targetId;
    private String targetName;
    private int type;
    private int categoryHolder = CATEGORY_NONE;
    private String contentHolder;

    private boolean isInProgress = false;
    private DialogInterface.OnClickListener dialogListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_report);
        Slidr.attach(this, SparkleHelper.slidrConfig);

        // Either get data from intent or restore state
        if (getIntent() != null)
        {
            if (getIntent().getData() != null) {
                targetId = Integer.valueOf(getIntent().getData().getHost());
                type = REPORT_TYPE_TASK;
            }
            else {
                targetId = getIntent().getIntExtra(REPORT_ID, 0);
                targetName = SparkleHelper.getNameFromId(getIntent().getStringExtra(REPORT_USER));
                type = getIntent().getIntExtra(REPORT_TYPE, REPORT_TYPE_TASK);
            }
        }
        if (savedInstanceState != null)
        {
            targetId = savedInstanceState.getInt(REPORT_ID);
            targetName = savedInstanceState.getString(REPORT_USER);
            type = savedInstanceState.getInt(REPORT_TYPE);
            categoryHolder = savedInstanceState.getInt(REPORT_CATEGORY, CATEGORY_NONE);
            contentHolder = savedInstanceState.getString(REPORT_CONTENT);
        }

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_report);
        setToolbar(toolbar);

        mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.report_refresher);
        mSwipeRefreshLayout.setColorSchemeResources(SparkleHelper.refreshColours);
        mSwipeRefreshLayout.setEnabled(false);

        dialogListener = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mSwipeRefreshLayout.post(new Runnable() {
                    @Override
                    public void run() {
                        mSwipeRefreshLayout.setRefreshing(true);
                        sendReport();
                    }
                });
            }
        };

        view = findViewById(R.id.report_main);
        targetHolder = (RelativeLayout) findViewById(R.id.report_target_holder);
        reportTarget = (TextView) findViewById(R.id.report_target);
        reportCategoryHolder = (CardView) findViewById(R.id.report_category_holder);
        reportCategorySelect = (RadioGroup) findViewById(R.id.report_category);
        reportContent = (EditText) findViewById(R.id.report_content);
        reportContent.setCustomSelectionActionModeCallback(new NullActionCallback());

        targetHolder.setVisibility(View.VISIBLE);
        reportCategoryHolder.setVisibility(View.VISIBLE);

        // If replying to mod mail, use this message instead
        if (type == REPORT_TYPE_TASK) {
{'fraction_non_alphanumeric': 0.0807925596441569, 'fraction_numerical': 0.005014152850788516, 'mean_word_length': 3.255333792154164, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, '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': '3837757', 'n_tokens_mistral': 3436, 'n_tokens_neox': 3308, 'n_words': 856}