<commit_before>package amu.roboclub.ui.fragments;


import android.app.Dialog;
import android.content.DialogInterface;
import android.net.Uri;
import android.support.design.widget.BottomSheetDialogFragment;
import android.support.design.widget.FloatingActionButton;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import java.lang.ref.WeakReference;
import java.util.Map;

import amu.roboclub.R;
import amu.roboclub.models.Profile;
import amu.roboclub.models.ProfileInfo;
import amu.roboclub.utils.CircleTransform;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnLongClick;

public class ProfileEditorFragment extends BottomSheetDialogFragment {

    private static final String TAG = "ProfileEditorFragment";

    private Profile profile;
    private WeakReference<OnProfileChangeListener> onProfileChangeListenerWeakReference;

    @BindView(R.id.close) ImageView close;
    @BindView(R.id.save_fab) FloatingActionButton saveFab;
    @BindView(R.id.photo_fab) FloatingActionButton photoFab;
    @BindView(R.id.avatar) ImageView avatar;
    @BindView(R.id.name) EditText name;
    @BindView(R.id.photo) EditText photoLink;
    @BindView(R.id.batch) EditText batch;
    @BindView(R.id.about) EditText about;
    @BindView(R.id.cv_link) EditText cvLink;

    private View root;

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

        ButterKnife.bind(this, root);

        close.setOnClickListener(view -> dismiss());

        showProfile();
    }

    public void setProfile(Profile profile) {
        this.profile = profile;

        showProfile();
    }

    public void setOnProfileChangeListener(OnProfileChangeListener onProfileChangeListener) {
        onProfileChangeListenerWeakReference.clear();
        onProfileChangeListenerWeakReference = new WeakReference<>(onProfileChangeListener);
    }

    @OnLongClick(R.id.save_fab)
    public boolean saveDescription() {
        Toast.makeText(getContext(), R.string.save, Toast.LENGTH_SHORT).show();

        return false;
    }

    @OnLongClick(R.id.photo_fab)
    public boolean photoDescription() {
        Toast.makeText(getContext(), R.string.upload_photo, Toast.LENGTH_SHORT).show();

        return false;
    }

    private void showProfile() {
        if(root == null || profile == null) return;

        name.setText(profile.name);

        if(profile.thumbnail != null) {<commit_msg>fix: Fix NPE on OnProfileChangeListener<commit_after>package amu.roboclub.ui.fragments;


import android.app.Dialog;
import android.content.DialogInterface;
import android.net.Uri;
import android.support.design.widget.BottomSheetDialogFragment;
import android.support.design.widget.FloatingActionButton;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import java.lang.ref.WeakReference;
import java.util.Map;

import amu.roboclub.R;
import amu.roboclub.models.Profile;
import amu.roboclub.models.ProfileInfo;
import amu.roboclub.utils.CircleTransform;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnLongClick;

public class ProfileEditorFragment extends BottomSheetDialogFragment {

    private static final String TAG = "ProfileEditorFragment";

    private Profile profile;
    private WeakReference<OnProfileChangeListener> onProfileChangeListenerWeakReference;

    @BindView(R.id.close) ImageView close;
    @BindView(R.id.save_fab) FloatingActionButton saveFab;
    @BindView(R.id.photo_fab) FloatingActionButton photoFab;
    @BindView(R.id.avatar) ImageView avatar;
    @BindView(R.id.name) EditText name;
    @BindView(R.id.photo) EditText photoLink;
    @BindView(R.id.batch) EditText batch;
    @BindView(R.id.about) EditText about;
    @BindView(R.id.cv_link) EditText cvLink;

    private View root;

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

        ButterKnife.bind(this, root);

        close.setOnClickListener(view -> dismiss());

        showProfile();
    }

    public void setProfile(Profile profile) {
        this.profile = profile;

        showProfile();
    }

    public void setOnProfileChangeListener(OnProfileChangeListener onProfileChangeListener) {
        if(onProfileChangeListenerWeakReference != null) onProfileChangeListenerWeakReference.clear();
        onProfileChangeListenerWeakReference = new WeakReference<>(onProfileChangeListener);
    }

    @OnLongClick(R.id.save_fab)
    public boolean saveDescription() {
        Toast.makeText(getContext(), R.string.save, Toast.LENGTH_SHORT).show();

        return false;
    }

    @OnLongClick(R.id.photo_fab)
    public boolean photoDescription() {
        Toast.makeText(getContext(), R.string.upload_photo, Toast.LENGTH_SHORT).show();

        return false;
    }

    private void showProfile() {
        if(root == null || profile == null) return;

        name.setText(profile.name);

        if(profile.thumbnail != null) {
{'fraction_non_alphanumeric': 0.09969017678148351, 'fraction_numerical': 0.0, 'mean_word_length': 4.1773584905660375, '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': '1919549', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1590, 'n_words': 306}