<commit_before>package lt.vilnius.tvarkau.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.telephony.PhoneNumberFormattingTextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.auth.api.signin.GoogleSignInAccount;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import lt.vilnius.tvarkau.R;
import lt.vilnius.tvarkau.entity.Profile;
import lt.vilnius.tvarkau.utils.SharedPrefsManager;

import static android.app.Activity.RESULT_OK;


public class MyProfileFragment extends Fragment {

    private SharedPrefsManager prefsManager;

    @BindView(R.id.profile_name)
    EditText mProfileName;

    @BindView(R.id.profile_email)
    EditText mProfileEmail;

    @BindView(R.id.profile_telephone)
    EditText mProfileTelephone;

    private Unbinder unbinder;

    public MyProfileFragment() {
    }

    public static MyProfileFragment getInstance() {
        return new MyProfileFragment();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.my_profile, container, false);

        unbinder = ButterKnife.bind(this, view);

        return view;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setHasOptionsMenu(true);
        prefsManager = SharedPrefsManager.getInstance(getContext());
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        setUpUserProfile();
        mProfileTelephone.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.my_profile_menu, menu);

        super.onCreateOptionsMenu(menu, inflater);
    }

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

    public void saveUserProfile() {
        String name = mProfileName.getText().toString();
        String email = mProfileEmail.getText().toString();
        String phone = mProfileTelephone.getText().toString();

        Profile profile = new Profile(name, email, phone);

        prefsManager.saveUserDetails(profile);

        getActivity().setResult(RESULT_OK);

        Toast.makeText(getContext(), "Beta versijoje registracija dar neveikia", Toast.LENGTH_SHORT).show();

        getActivity().finish();
    }

    private void setUpUserProfile() {
        if (!prefsManager.isUserAnonymous()) {
            Profile profile = Profile.returnProfile(getContext());

            mProfileName.setText(profile.getName());
            mProfileEmail.setText(profile.getEmail());
            mProfileTelephone.setText(profile.getMobilePhone());
        }
    }

    public boolean isEditedByUser() {
        if (mProfileName == null || mProfileEmail == null || mProfileTelephone == null) {
            return true;
        }

        String name = mProfileName.getText().toString();
        String email = mProfileEmail.getText().toString();
        String telephone = mProfileTelephone.getText().toString();

        if (!prefsManager.isUserAnonymous()) {
            Profile oldProfile = prefsManager.getUserProfile();

            Profile newProfile = new Profile(name, email, telephone);
<commit_msg>Fix not closing keyboard on My Profile submit<commit_after>package lt.vilnius.tvarkau.fragments;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.telephony.PhoneNumberFormattingTextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.auth.api.signin.GoogleSignInAccount;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import lt.vilnius.tvarkau.R;
import lt.vilnius.tvarkau.entity.Profile;
import lt.vilnius.tvarkau.utils.SharedPrefsManager;

import static android.app.Activity.RESULT_OK;


public class MyProfileFragment extends Fragment {

    private SharedPrefsManager prefsManager;

    @BindView(R.id.profile_name)
    EditText mProfileName;

    @BindView(R.id.profile_email)
    EditText mProfileEmail;

    @BindView(R.id.profile_telephone)
    EditText mProfileTelephone;

    private Unbinder unbinder;

    public MyProfileFragment() {
    }

    public static MyProfileFragment getInstance() {
        return new MyProfileFragment();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.my_profile, container, false);

        unbinder = ButterKnife.bind(this, view);

        return view;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setHasOptionsMenu(true);
        prefsManager = SharedPrefsManager.getInstance(getContext());
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        setUpUserProfile();
        mProfileTelephone.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.my_profile_menu, menu);

        super.onCreateOptionsMenu(menu, inflater);
    }

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

    public void saveUserProfile() {
        String name = mProfileName.getText().toString();
        String email = mProfileEmail.getText().toString();
        String phone = mProfileTelephone.getText().toString();

        Profile profile = new Profile(name, email, phone);

        prefsManager.saveUserDetails(profile);

        getActivity().setResult(RESULT_OK);

        Toast.makeText(getContext(), "Beta versijoje registracija dar neveikia", Toast.LENGTH_SHORT).show();

        getActivity().finish();

        View view = getActivity().getCurrentFocus();
        if (view != null) {
            InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

    private void setUpUserProfile() {
        if (!prefsManager.isUserAnonymous()) {
            Profile profile = Profile.returnProfile(getContext());

            mProfileName.setText(profile.getName());
            mProfileEmail.setText(profile.getEmail());
            mProfileTelephone.setText(profile.getMobilePhone());
        }
    }

    public boolean isEditedByUser() {
        if (mProfileName == null || mProfileEmail == null || mProfileTelephone == null) {
            return true;
        }

        String name = mProfileName.getText().toString();
        String email = mProfileEmail.getText().toString();
        String telephone = mProfileTelephone.getText().toString();

        if (!prefsManager.isUserAnonymous()) {
            Profile oldProfile = prefsManager.getUserProfile();

            Profile newProfile = new Profile(name, email, telephone);

{'fraction_non_alphanumeric': 0.09589360709286048, 'fraction_numerical': 0.00034997666822211853, 'mean_word_length': 3.2045120156939677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1089434', 'n_tokens_mistral': 2379, 'n_tokens_neox': 2252, 'n_words': 454}