<commit_before>package lt.vilnius.tvarkau;

import android.content.Context;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
import com.google.android.gms.maps.model.LatLng;
import com.google.firebase.crash.FirebaseCrash;
import com.gun0912.tedpicker.Config;
import com.gun0912.tedpicker.ImagePickerActivity;
import com.viewpagerindicator.CirclePageIndicator;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnItemSelected;
import icepick.State;
import lt.vilnius.tvarkau.entity.Profile;
import lt.vilnius.tvarkau.entity.ReportType;
import lt.vilnius.tvarkau.utils.GlobalConsts;
import lt.vilnius.tvarkau.utils.PermissionUtils;
import lt.vilnius.tvarkau.views.adapters.ProblemImagesPagerAdapter;

import static android.Manifest.permission.CAMERA;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static lt.vilnius.tvarkau.ChooseReportTypeActivity.EXTRA_REPORT_TYPE;

public class NewProblemActivity extends BaseActivity {

    private static final int REQUEST_IMAGE_CAPTURE = 1;
    private static final int PERMISSION_REQUEST_CODE = 10;

    public static final int REQUEST_PLACE_PICKER = 11;
    public static final int REQUEST_PROFILE = 12;
    public static final int REQUEST_CHOOSE_REPORT_TYPE = 13;

    private static final String[] REQUIRED_PERMISSIONS = {WRITE_EXTERNAL_STORAGE, CAMERA, READ_EXTERNAL_STORAGE};


    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.report_problem_location)
    EditText mAddProblemLocation;
    @BindView(R.id.problem_images_view_pager)
    ViewPager mProblemImagesViewPager;
    @BindView(R.id.problem_images_view_pager_indicator)
    CirclePageIndicator mProblemImagesViewPagerIndicator;
    @BindView(R.id.report_problem_type)
    EditText mReportProblemType;
    @BindView(R.id.report_problem_privacy_mode)
    Spinner mReportProblemPrivacyMode;
    @BindView(R.id.report_problem_description)
    EditText mReportProblemDescription;
    @BindView(R.id.report_problem_take_photo)
    FloatingActionButton mReportProblemTakePhoto;
    @BindView(R.id.report_problem_location_wrapper)
    TextInputLayout reportProblemLocationWrapper;
    @BindView(R.id.report_problem_description_wrapper)
    TextInputLayout reportProblemDescriptionWrapper;
    @BindView(R.id.report_problem_type_wrapper)
    TextInputLayout reportProblemTypeWrapper;

    @State
    File lastPhotoFile;
    @State
    LatLng locationCords;
    @State
    ArrayList<Uri> problemImagesURIs;
    @State
    Profile profile;
    @State
    ReportType reportType;
    String address;

    private Snackbar snackbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_problem);

        ButterKnife.bind(this);

        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close);

        initProblemImagesPager();
        initPrivacyModeSpinner();
    }

    private void initPrivacyModeSpinner() {
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.report_privacy_mode, R.layout.item_report_type_spinner);
        adapter.setDropDownViewResource(R.layout.item_report_type_spinner_dropdown);
        mReportProblemPrivacyMode.setAdapter(adapter);
    }

    private void initProblemImagesPager() {
        mProblemImagesViewPager.setAdapter(ProblemImagesPagerAdapter.empty(this));
        mProblemImagesViewPager.setOffscreenPageLimit(3);
        mProblemImagesViewPagerIndicator.setViewPager(mProblemImagesViewPager);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                return true;
            case R.id.action_send:
                sendProblem();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.new_problem_toolbar_menu, menu);

        return true;
    }


    public void sendProblem() {
        Toast.makeText(this, "Should implement send behaviour", Toast.LENGTH_SHORT).show();

    private Boolean validateProblemInputs() {
        Boolean addressIsValid = false;
        Boolean descriptionIsValid = false;
        Boolean problemTypeIsValid = false;

        if (address != null) {
            addressIsValid = true;
            reportProblemDescriptionWrapper.setError(null);
        } else {
            reportProblemLocationWrapper.setError(getText(R.string.error_problem_location_is_empty));
        }

        if (mReportProblemDescription.getText() != null && mReportProblemDescription.getText().length() > 0) {
            descriptionIsValid = true;
        } else {
            reportProblemDescriptionWrapper.setError(getText(R.string.error_problem_description_is_empty));
        }
<commit_msg>Call new problem input validation method<commit_after>package lt.vilnius.tvarkau;

import android.content.Context;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
import com.google.android.gms.maps.model.LatLng;
import com.google.firebase.crash.FirebaseCrash;
import com.gun0912.tedpicker.Config;
import com.gun0912.tedpicker.ImagePickerActivity;
import com.viewpagerindicator.CirclePageIndicator;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnItemSelected;
import icepick.State;
import lt.vilnius.tvarkau.entity.Profile;
import lt.vilnius.tvarkau.entity.ReportType;
import lt.vilnius.tvarkau.utils.GlobalConsts;
import lt.vilnius.tvarkau.utils.PermissionUtils;
import lt.vilnius.tvarkau.views.adapters.ProblemImagesPagerAdapter;

import static android.Manifest.permission.CAMERA;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static lt.vilnius.tvarkau.ChooseReportTypeActivity.EXTRA_REPORT_TYPE;

public class NewProblemActivity extends BaseActivity {

    private static final int REQUEST_IMAGE_CAPTURE = 1;
    private static final int PERMISSION_REQUEST_CODE = 10;

    public static final int REQUEST_PLACE_PICKER = 11;
    public static final int REQUEST_PROFILE = 12;
    public static final int REQUEST_CHOOSE_REPORT_TYPE = 13;

    private static final String[] REQUIRED_PERMISSIONS = {WRITE_EXTERNAL_STORAGE, CAMERA, READ_EXTERNAL_STORAGE};


    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.report_problem_location)
    EditText mAddProblemLocation;
    @BindView(R.id.problem_images_view_pager)
    ViewPager mProblemImagesViewPager;
    @BindView(R.id.problem_images_view_pager_indicator)
    CirclePageIndicator mProblemImagesViewPagerIndicator;
    @BindView(R.id.report_problem_type)
    EditText mReportProblemType;
    @BindView(R.id.report_problem_privacy_mode)
    Spinner mReportProblemPrivacyMode;
    @BindView(R.id.report_problem_description)
    EditText mReportProblemDescription;
    @BindView(R.id.report_problem_take_photo)
    FloatingActionButton mReportProblemTakePhoto;
    @BindView(R.id.report_problem_location_wrapper)
    TextInputLayout reportProblemLocationWrapper;
    @BindView(R.id.report_problem_description_wrapper)
    TextInputLayout reportProblemDescriptionWrapper;
    @BindView(R.id.report_problem_type_wrapper)
    TextInputLayout reportProblemTypeWrapper;

    @State
    File lastPhotoFile;
    @State
    LatLng locationCords;
    @State
    ArrayList<Uri> problemImagesURIs;
    @State
    Profile profile;
    @State
    ReportType reportType;
    String address;

    private Snackbar snackbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_problem);

        ButterKnife.bind(this);

        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close);

        initProblemImagesPager();
        initPrivacyModeSpinner();
    }

    private void initPrivacyModeSpinner() {
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.report_privacy_mode, R.layout.item_report_type_spinner);
        adapter.setDropDownViewResource(R.layout.item_report_type_spinner_dropdown);
        mReportProblemPrivacyMode.setAdapter(adapter);
    }

    private void initProblemImagesPager() {
        mProblemImagesViewPager.setAdapter(ProblemImagesPagerAdapter.empty(this));
        mProblemImagesViewPager.setOffscreenPageLimit(3);
        mProblemImagesViewPagerIndicator.setViewPager(mProblemImagesViewPager);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                return true;
            case R.id.action_send:
                sendProblem();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.new_problem_toolbar_menu, menu);

        return true;
    }


    public void sendProblem() {
        if (validateProblemInputs()) {
            Toast.makeText(this, "All inputs are ok; API integration in process", Toast.LENGTH_SHORT).show();
        }
    }

    private Boolean validateProblemInputs() {
        Boolean addressIsValid = false;
        Boolean descriptionIsValid = false;
        Boolean problemTypeIsValid = false;

        if (address != null) {
            addressIsValid = true;
            reportProblemDescriptionWrapper.setError(null);
        } else {
            reportProblemLocationWrapper.setError(getText(R.string.error_problem_location_is_empty));
        }

        if (mReportProblemDescription.getText() != null && mReportProblemDescription.getText().length() > 0) {
            descriptionIsValid = true;
        } else {
            reportProblemDescriptionWrapper.setError(getText(R.string.error_problem_description_is_empty));
        }

{'fraction_non_alphanumeric': 0.08175519630484988, 'fraction_numerical': 0.003695150115473441, 'mean_word_length': 4.161303138657131, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1460866', 'n_tokens_mistral': 3951, 'n_tokens_neox': 3774, 'n_words': 617}