<commit_before>package com.malalaoshi.android.dialog;

import android.animation.ValueAnimator;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.malalaoshi.android.MalaApplication;
import com.malalaoshi.android.R;
import com.malalaoshi.android.entity.Comment;
import com.malalaoshi.android.net.Constants;
import com.malalaoshi.android.net.NetworkListener;
import com.malalaoshi.android.net.NetworkSender;
import com.malalaoshi.android.util.ImageCache;
import com.malalaoshi.android.util.JsonUtil;
import com.malalaoshi.android.util.MiscUtil;
import com.malalaoshi.android.view.CircleNetworkImage;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by kang on 16/3/2.
 */
public class CommentDialog extends DialogFragment{

    private static String ARGS_DIALOG_TEACHER_NAME   = "teacher name";
    private static String ARGS_DIALOG_TEACHER_AVATAR = "teacher avatar";
    private static String ARGS_DIALOG_COURSE_NAME    = "course name";
    private static String ARGS_DIALOG_COMMENT_ID     = "course_id";
    private static String ARGS_DIALOG_TIMESLOT       = "timeslot";

    private String teacherName;
    private String teacherAvatarUrl;
    private String courseName;
    private Long timeslot;
    private String commentId;

    @Bind(R.id.iv_teacher_avater)
    CircleNetworkImage teacherAvater;

    @Bind(R.id.tv_teacher_name)
    TextView tvTeacherName;

    @Bind(R.id.tv_course)
    TextView tvCourse;

    @Bind(R.id.edit_review)
    protected EditText editComment;

    @Bind(R.id.ll_course)
    protected LinearLayout llCourse;

    @Bind(R.id.ratingbar)
    protected RatingBar ratingbar;

    @Bind(R.id.tv_submit)
    protected TextView tvSubmit;

    @Bind(R.id.ll_load_fail)
    protected LinearLayout llLoadFail;

    @Bind(R.id.ll_loading)
    protected LinearLayout llLoading;

    @Bind(R.id.ll_content)
    protected LinearLayout llContent;

    private boolean isOpenInputMethod = false;
    //图片缓存
    private ImageLoader mImageLoader;

    public static CommentDialog newInstance(String teacherName,String teacherAvatarUrl,String courseName, Long timeslot, String commentId) {
        CommentDialog f = new CommentDialog();
        Bundle args = new Bundle();
        args.putString(ARGS_DIALOG_TEACHER_NAME, teacherName);
        args.putString(ARGS_DIALOG_TEACHER_AVATAR, teacherAvatarUrl);
        args.putString(ARGS_DIALOG_COURSE_NAME, courseName);
        args.putString(ARGS_DIALOG_COMMENT_ID, commentId);
        args.putLong(ARGS_DIALOG_TIMESLOT, timeslot);
        f.setArguments(args);
        return f;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setCancelable(false);          // 设置点击屏幕Dialog不消失
        teacherName = getArguments().getString(ARGS_DIALOG_TEACHER_NAME,"");
        teacherAvatarUrl = getArguments().getString(ARGS_DIALOG_TEACHER_AVATAR,"");
        courseName = getArguments().getString(ARGS_DIALOG_COURSE_NAME,"");
        commentId = getArguments().getString(ARGS_DIALOG_COMMENT_ID,"");
        timeslot = getArguments().getLong(ARGS_DIALOG_COMMENT_ID, 0);
        init();
        setStyle(DialogFragment.STYLE_NO_TITLE, 0);
    }

    private void init() {
        mImageLoader = new ImageLoader(MalaApplication.getHttpRequestQueue(), ImageCache.getInstance(MalaApplication.getInstance()));
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_comment, container, false);
        ButterKnife.bind(this, view);
        initViews();
        tvSubmit.setEnabled(false);
        initDatas();
        return view;
    }

    private void initViews() {
        //查看课程评价
        if (commentId!=null&&!commentId.isEmpty()){
            //查看课程评价
            updateLoadingUI();
            //控件不可编辑
            editComment.setEnabled(false);
            ratingbar.setIsIndicator(true);
        }else{
            //评价课程
            llContent.setVisibility(View.VISIBLE);
            llLoading.setVisibility(View.GONE);
            llLoadFail.setVisibility(View.GONE);
            editComment.setEnabled(true);
            ratingbar.setIsIndicator(false);

            editComment.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {<commit_msg>AN-56 Click the back button to close the commentDialog<commit_after>package com.malalaoshi.android.dialog;

import android.animation.ValueAnimator;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.malalaoshi.android.MalaApplication;
import com.malalaoshi.android.R;
import com.malalaoshi.android.entity.Comment;
import com.malalaoshi.android.net.Constants;
import com.malalaoshi.android.net.NetworkListener;
import com.malalaoshi.android.net.NetworkSender;
import com.malalaoshi.android.util.ImageCache;
import com.malalaoshi.android.util.JsonUtil;
import com.malalaoshi.android.util.MiscUtil;
import com.malalaoshi.android.view.CircleNetworkImage;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by kang on 16/3/2.
 */
public class CommentDialog extends DialogFragment{

    private static String ARGS_DIALOG_TEACHER_NAME   = "teacher name";
    private static String ARGS_DIALOG_TEACHER_AVATAR = "teacher avatar";
    private static String ARGS_DIALOG_COURSE_NAME    = "course name";
    private static String ARGS_DIALOG_COMMENT_ID     = "course_id";
    private static String ARGS_DIALOG_TIMESLOT       = "timeslot";

    private String teacherName;
    private String teacherAvatarUrl;
    private String courseName;
    private Long timeslot;
    private String commentId;

    @Bind(R.id.iv_teacher_avater)
    CircleNetworkImage teacherAvater;

    @Bind(R.id.tv_teacher_name)
    TextView tvTeacherName;

    @Bind(R.id.tv_course)
    TextView tvCourse;

    @Bind(R.id.edit_review)
    protected EditText editComment;

    @Bind(R.id.ll_course)
    protected LinearLayout llCourse;

    @Bind(R.id.ratingbar)
    protected RatingBar ratingbar;

    @Bind(R.id.tv_submit)
    protected TextView tvSubmit;

    @Bind(R.id.ll_load_fail)
    protected LinearLayout llLoadFail;

    @Bind(R.id.ll_loading)
    protected LinearLayout llLoading;

    @Bind(R.id.ll_content)
    protected LinearLayout llContent;

    private boolean isOpenInputMethod = false;
    //图片缓存
    private ImageLoader mImageLoader;

    public static CommentDialog newInstance(String teacherName,String teacherAvatarUrl,String courseName, Long timeslot, String commentId) {
        CommentDialog f = new CommentDialog();
        Bundle args = new Bundle();
        args.putString(ARGS_DIALOG_TEACHER_NAME, teacherName);
        args.putString(ARGS_DIALOG_TEACHER_AVATAR, teacherAvatarUrl);
        args.putString(ARGS_DIALOG_COURSE_NAME, courseName);
        args.putString(ARGS_DIALOG_COMMENT_ID, commentId);
        args.putLong(ARGS_DIALOG_TIMESLOT, timeslot);
        f.setArguments(args);
        return f;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setCancelable(false);          // 设置点击屏幕Dialog不消失
        teacherName = getArguments().getString(ARGS_DIALOG_TEACHER_NAME,"");
        teacherAvatarUrl = getArguments().getString(ARGS_DIALOG_TEACHER_AVATAR,"");
        courseName = getArguments().getString(ARGS_DIALOG_COURSE_NAME,"");
        commentId = getArguments().getString(ARGS_DIALOG_COMMENT_ID,"");
        timeslot = getArguments().getLong(ARGS_DIALOG_COMMENT_ID, 0L);
        init();
        setStyle(DialogFragment.STYLE_NO_TITLE, 0);
    }

    private void init() {
        mImageLoader = new ImageLoader(MalaApplication.getHttpRequestQueue(), ImageCache.getInstance(MalaApplication.getInstance()));
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        this.getDialog().setOnKeyListener(new DialogInterface.OnKeyListener()
        {
            @Override
            public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent arg2) {
                // TODO Auto-generated method stub 返回键关闭dialog
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    dismiss();
                    return true;
                }
                return false;
            }
        });
        View view = inflater.inflate(R.layout.dialog_comment, container, false);
        ButterKnife.bind(this, view);
        initViews();
        tvSubmit.setEnabled(false);
        initDatas();
        return view;
    }


    private void initViews() {
        //查看课程评价
        if (commentId!=null&&!commentId.isEmpty()){
            //查看课程评价
            updateLoadingUI();
            //控件不可编辑
            editComment.setEnabled(false);
            ratingbar.setIsIndicator(true);
        }else{
            //评价课程
            llContent.setVisibility(View.VISIBLE);
            llLoading.setVisibility(View.GONE);
            llLoadFail.setVisibility(View.GONE);
            editComment.setEnabled(true);
            ratingbar.setIsIndicator(false);

            editComment.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
{'fraction_non_alphanumeric': 0.08962721424164978, 'fraction_numerical': 0.0015863223759584031, 'mean_word_length': 3.2984848484848484, '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': '5938626', 'n_tokens_mistral': 3437, 'n_tokens_neox': 3366, 'n_words': 636}