<commit_before>package com.dentacoin.dentacare.fragments;

import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.anthonycr.grant.PermissionsManager;
import com.anthonycr.grant.PermissionsResultAction;
import com.dentacoin.dentacare.R;
import com.dentacoin.dentacare.model.DCError;
import com.dentacoin.dentacare.model.DCUser;
import com.dentacoin.dentacare.network.DCApiManager;
import com.dentacoin.dentacare.network.DCResponseListener;
import com.dentacoin.dentacare.network.DCSession;
import com.dentacoin.dentacare.utils.DCConstants;
import com.dentacoin.dentacare.utils.DCUtils;
import com.dentacoin.dentacare.utils.IDatePickerListener;
import com.dentacoin.dentacare.widgets.DCButton;
import com.dentacoin.dentacare.widgets.DCEditText;
import com.dentacoin.dentacare.widgets.DCTextInputEditText;
import com.dentacoin.dentacare.widgets.DCTextInputLayout;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.places.AutocompleteFilter;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlaceAutocomplete;
import com.mukesh.countrypicker.Country;
import com.theartofdev.edmodo.cropper.CropImage;
import com.theartofdev.edmodo.cropper.CropImageView;

import java.io.File;
import java.util.Date;
import java.util.List;

import de.mateware.snacky.Snacky;
import pl.aprilapps.easyphotopicker.DefaultCallback;
import pl.aprilapps.easyphotopicker.EasyImage;

import static android.app.Activity.RESULT_OK;

/**
 * Created by <NAME> on 9/5/17.
 */

public class DCProfileEditFragment extends DCFragment implements View.OnClickListener, View.OnFocusChangeListener {

    public static final String TAG = DCProfileEditFragment.class.getSimpleName();

    private SimpleDraweeView sdvProfileAvatar;
    private DCTextInputLayout tilProfileFirstname;
    private DCTextInputEditText tietProfileFirstname;
    private DCTextInputLayout tilProfileLastname;
    private DCTextInputEditText tietProfileLastname;
    private DCTextInputLayout tilProfileEmail;
    private DCTextInputEditText tietProfileEmail;
    private DCTextInputLayout tilProfilePassword;
    private DCTextInputEditText tietProfilePassword;
    private DCEditText etProfileBirthday;
    private DCEditText etProfileLocation;
    private DCTextInputLayout tilProfileZipcode;
    private DCTextInputEditText tietProfileZipcode;
    private DCButton btnProfileMale;
    private DCButton btnProfileFemale;

    private DCButton btnProfileUpdate;
    private DCUser user;
    private Uri avatarUri;
    private ImageView ivProfileClose;

    private int PLACE_AUTOCOMPLETE_REQUEST_CODE = 1002;

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

        sdvProfileAvatar = (SimpleDraweeView) view.findViewById(R.id.sdv_profile_avatar);
        sdvProfileAvatar.setOnClickListener(this);

        tilProfileFirstname = (DCTextInputLayout) view.findViewById(R.id.til_profile_firstname);
        tietProfileFirstname = (DCTextInputEditText) view.findViewById(R.id.tiet_profile_firstname);
        tietProfileFirstname.setOnFocusChangeListener(this);

        tilProfileLastname = (DCTextInputLayout) view.findViewById(R.id.til_profile_lastname);
        tietProfileLastname = (DCTextInputEditText) view.findViewById(R.id.tiet_profile_lastname);
        tietProfileLastname.setOnFocusChangeListener(this);

        tilProfileEmail = (DCTextInputLayout) view.findViewById(R.id.til_profile_email);
        tietProfileEmail = (DCTextInputEditText) view.findViewById(R.id.tiet_profile_email);

        tilProfilePassword = (DCTextInputLayout) view.findViewById(R.id.til_profile_password);
        tietProfilePassword = (DCTextInputEditText) view.findViewById(R.id.tiet_profile_password);
        tietProfilePassword.setOnFocusChangeListener(this);

        etProfileBirthday = (DCEditText) view.findViewById(R.id.et_profile_birthday);
        etProfileBirthday.setOnClickListener(this);

        etProfileLocation = (DCEditText) view.findViewById(R.id.et_profile_location);
        etProfileLocation.setOnClickListener(this);

        tilProfileZipcode = (DCTextInputLayout) view.findViewById(R.id.til_profile_zipcode);
        tietProfileZipcode = (DCTextInputEditText) view.findViewById(R.id.tiet_profile_zipcode);

        btnProfileMale = (DCButton) view.findViewById(R.id.btn_profile_male);
        btnProfileFemale = (DCButton) view.findViewById(R.id.btn_profile_female);
        btnProfileMale.setOnClickListener(this);
        btnProfileFemale.setOnClickListener(this);

        btnProfileUpdate = (DCButton) view.findViewById(R.id.btn_profile_update);
        btnProfileUpdate.setOnClickListener(this);

        ivProfileClose = (ImageView) view.findViewById(R.id.iv_profile_close);
        ivProfileClose.setOnClickListener(this);
        ivProfileClose.setVisibility(View.GONE);

        loadUser();
        return view;
    }

    private void loadUser() {
        if (DCSession.getInstance().getUser() != null) {
            setUser(DCSession.getInstance().getUser());
        } else {
            DCApiManager.getInstance().getUser(new DCResponseListener<DCUser>() {
                @Override
                public void onFailure(DCError error) {
                    onError(error);
                }

                @Override
                public void onResponse(DCUser object) {
                    setUser(DCSession.getInstance().getUser());
                }
            });
        }
    }

    private void setUser(DCUser user) {
        if (user == null || !isAdded())
            return;

        this.user = user;
        sdvProfileAvatar.setImageURI(user.getAvatarUrl(getActivity()));

        //TODO: handle ivProfileClose click
//        if (avatarUri != null || user.getAvatar() != null) {
//            ivProfileClose.setVisibility(View.VISIBLE);
//        } else {
//            ivProfileClose.setVisibility(View.GONE);
//        }

        tietProfileFirstname.setText(user.getFirstname());
        tietProfileLastname.setText(user.getLastname());
        tietProfileEmail.setText(user.getEmail());
        if (user.getBirthday() != null) {
            etProfileBirthday.setText(DCConstants.DATE_FORMAT_BIRTHDAY.format(user.getBirthday()));
        }
        etProfileLocation.setText(user.getLocation());

        btnProfileMale.setSelected(false);<commit_msg>- adding option to remove the uploaded avatar<commit_after>package com.dentacoin.dentacare.fragments;

import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.anthonycr.grant.PermissionsManager;
import com.anthonycr.grant.PermissionsResultAction;
import com.dentacoin.dentacare.R;
import com.dentacoin.dentacare.model.DCError;
import com.dentacoin.dentacare.model.DCUser;
import com.dentacoin.dentacare.network.DCApiManager;
import com.dentacoin.dentacare.network.DCResponseListener;
import com.dentacoin.dentacare.network.DCSession;
import com.dentacoin.dentacare.utils.DCConstants;
import com.dentacoin.dentacare.utils.DCUtils;
import com.dentacoin.dentacare.utils.IDatePickerListener;
import com.dentacoin.dentacare.widgets.DCButton;
import com.dentacoin.dentacare.widgets.DCEditText;
import com.dentacoin.dentacare.widgets.DCTextInputEditText;
import com.dentacoin.dentacare.widgets.DCTextInputLayout;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.places.AutocompleteFilter;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlaceAutocomplete;
import com.mukesh.countrypicker.Country;
import com.theartofdev.edmodo.cropper.CropImage;
import com.theartofdev.edmodo.cropper.CropImageView;

import java.io.File;
import java.util.Date;
import java.util.List;

import de.mateware.snacky.Snacky;
import pl.aprilapps.easyphotopicker.DefaultCallback;
import pl.aprilapps.easyphotopicker.EasyImage;

import static android.app.Activity.RESULT_OK;

/**
 * Created by <NAME> on 9/5/17.
 */

public class DCProfileEditFragment extends DCFragment implements View.OnClickListener, View.OnFocusChangeListener {

    public static final String TAG = DCProfileEditFragment.class.getSimpleName();

    private SimpleDraweeView sdvProfileAvatar;
    private DCTextInputLayout tilProfileFirstname;
    private DCTextInputEditText tietProfileFirstname;
    private DCTextInputLayout tilProfileLastname;
    private DCTextInputEditText tietProfileLastname;
    private DCTextInputLayout tilProfileEmail;
    private DCTextInputEditText tietProfileEmail;
    private DCTextInputLayout tilProfilePassword;
    private DCTextInputEditText tietProfilePassword;
    private DCEditText etProfileBirthday;
    private DCEditText etProfileLocation;
    private DCTextInputLayout tilProfileZipcode;
    private DCTextInputEditText tietProfileZipcode;
    private DCButton btnProfileMale;
    private DCButton btnProfileFemale;

    private DCButton btnProfileUpdate;
    private DCUser user;
    private Uri avatarUri;
    private ImageView ivProfileClose;

    private int PLACE_AUTOCOMPLETE_REQUEST_CODE = 1002;

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

        sdvProfileAvatar = (SimpleDraweeView) view.findViewById(R.id.sdv_profile_avatar);
        sdvProfileAvatar.setOnClickListener(this);

        tilProfileFirstname = (DCTextInputLayout) view.findViewById(R.id.til_profile_firstname);
        tietProfileFirstname = (DCTextInputEditText) view.findViewById(R.id.tiet_profile_firstname);
        tietProfileFirstname.setOnFocusChangeListener(this);

        tilProfileLastname = (DCTextInputLayout) view.findViewById(R.id.til_profile_lastname);
        tietProfileLastname = (DCTextInputEditText) view.findViewById(R.id.tiet_profile_lastname);
        tietProfileLastname.setOnFocusChangeListener(this);

        tilProfileEmail = (DCTextInputLayout) view.findViewById(R.id.til_profile_email);
        tietProfileEmail = (DCTextInputEditText) view.findViewById(R.id.tiet_profile_email);

        tilProfilePassword = (DCTextInputLayout) view.findViewById(R.id.til_profile_password);
        tietProfilePassword = (DCTextInputEditText) view.findViewById(R.id.tiet_profile_password);
        tietProfilePassword.setOnFocusChangeListener(this);

        etProfileBirthday = (DCEditText) view.findViewById(R.id.et_profile_birthday);
        etProfileBirthday.setOnClickListener(this);

        etProfileLocation = (DCEditText) view.findViewById(R.id.et_profile_location);
        etProfileLocation.setOnClickListener(this);

        tilProfileZipcode = (DCTextInputLayout) view.findViewById(R.id.til_profile_zipcode);
        tietProfileZipcode = (DCTextInputEditText) view.findViewById(R.id.tiet_profile_zipcode);

        btnProfileMale = (DCButton) view.findViewById(R.id.btn_profile_male);
        btnProfileFemale = (DCButton) view.findViewById(R.id.btn_profile_female);
        btnProfileMale.setOnClickListener(this);
        btnProfileFemale.setOnClickListener(this);

        btnProfileUpdate = (DCButton) view.findViewById(R.id.btn_profile_update);
        btnProfileUpdate.setOnClickListener(this);

        ivProfileClose = (ImageView) view.findViewById(R.id.iv_profile_close);
        ivProfileClose.setOnClickListener(this);
        ivProfileClose.setVisibility(View.GONE);

        loadUser();
        return view;
    }

    private void loadUser() {
        if (DCSession.getInstance().getUser() != null) {
            setUser(DCSession.getInstance().getUser());
        } else {
            DCApiManager.getInstance().getUser(new DCResponseListener<DCUser>() {
                @Override
                public void onFailure(DCError error) {
                    onError(error);
                }

                @Override
                public void onResponse(DCUser object) {
                    setUser(DCSession.getInstance().getUser());
                }
            });
        }
    }

    private void setUser(DCUser user) {
        if (user == null || !isAdded())
            return;

        this.user = user;
        sdvProfileAvatar.setImageURI(user.getAvatarUrl(getActivity()));

        if (avatarUri != null || user.getAvatar() != null) {
            ivProfileClose.setVisibility(View.VISIBLE);
        } else {
            ivProfileClose.setVisibility(View.GONE);
        }

        tietProfileFirstname.setText(user.getFirstname());
        tietProfileLastname.setText(user.getLastname());
        tietProfileEmail.setText(user.getEmail());
        if (user.getBirthday() != null) {
            etProfileBirthday.setText(DCConstants.DATE_FORMAT_BIRTHDAY.format(user.getBirthday()));
        }
        etProfileLocation.setText(user.getLocation());

        btnProfileMale.setSelected(false);
{'fraction_non_alphanumeric': 0.09016509101171158, 'fraction_numerical': 0.0012699308593198814, 'mean_word_length': 4.160174736075719, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3875597', 'n_tokens_mistral': 4380, 'n_tokens_neox': 4102, 'n_words': 620}