package com.cjboya.edu.adapter;
import java.util.ArrayList;
import java.util.List;
import com.cjboya.edu.R;
import com.cjboya.edu.dialog.DialogDoubleButton;
import com.cjboya.edu.interfaces.IDataCallBack;
import com.cjboya.edu.model.ResData;
import com.cjboya.edu.model.StudentQuestionDetailsDoneInfo;
import com.cjboya.edu.model.StudentQuestionDetailsTeacherInfo;
import com.cjboya.edu.task.QuestionAnswerDeleteTask;
import com.cjboya.edu.util.DBUtil;
import com.cjboya.edu.util.StoreUtils;
import com.cjboya.edu.view.MyListView;
import com.facebook.drawee.view.SimpleDraweeView;
import android.annotation.SuppressLint;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;
import cn.trinea.android.common.util.ToastUtils;
public class StudentQuestionDetailDoneAdapter extends BaseAdapter {
private List<StudentQuestionDetailsDoneInfo> mDataList=new ArrayList<StudentQuestionDetailsDoneInfo>();
private List<StudentQuestionDetailsTeacherInfo> tData=new ArrayList<StudentQuestionDetailsTeacherInfo>();
protected DBUtil dbUtil;
protected StoreUtils mStoreUtils;
private Context context;
private StudentQuestionDetailsDoneInfo data;
private HolderView holder = null;
private OnClickListener onClickListener;
public void setOnClickListener(OnClickListener onClickListener) {
this.onClickListener = onClickListener;
}
public StudentQuestionDetailDoneAdapter(Context mcontext,List<StudentQuestionDetailsDoneInfo> list) {
this.context=mcontext;
this.mDataList=list;
}
@Override
public int getCount() {
return mDataList.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@SuppressLint({ "ViewHolder", "InflateParams" })
@Override
public View getView(int position, View view, ViewGroup parent) {
data=mDataList.get(position);
if (view == null) {
holder = new HolderView();
view=LayoutInflater.from(context).inflate(R.layout.list_item_student_question_details_done, null);
holder.hvIcon = (SimpleDraweeView) view.findViewById(R.id.header_view_qd);
holder.tvName = (TextView) view.findViewById(R.id.tv_reply_name);
// holder.tvdelete = (TextView) view.findViewById(R.id.tv_reply_delete_qd);
holder.tvContent = (TextView) view.findViewById(R.id.rb_evaluation);
holder.tvDate = (TextView) view.findViewById(R.id.tv_reply_date);
holder.listview=(MyListView) view.findViewById(R.id.tv_reply_content_layout);
// holder.rbRating = (RatingBar) view.findViewById(R.id.rb_evaluation_qd);
view.setTag(holder);
} else {
holder = (HolderView) view.getTag();
}
holder.hvIcon.setImageURI(Uri.parse(data.getPhoto()));
holder.tvName.setText(data.getLoginName());
holder.tvContent.setText(data.getQuestionName());
if (data.getCreateTime().length()>=16) {
String strTime=data.getCreateTime().substring(0, 16);
holder.tvDate.setText(strTime);
}else {
holder.tvDate.setText(data.getCreateTime());
}
// holder.rbRating.setRating(Float.parseFloat(data.getRankPoint()));
// if (datas.get(position).isDelete()) {
// holder.tvdelete.setVisibility(View.VISIBLE);
// }else{
// holder.tvdelete.setVisibility(View.INVISIBLE);
// }
// holder.tvdelete.setOnClickListener(onClickListener);
// holder.tvdelete.setTag(data.getId());
// holder.hvIcon.setOnClickListener(onClickListener);
// holder.hvIcon.setTag(data.getUserId());
dbUtil = DBUtil.getInstance(context);
mStoreUtils = StoreUtils.getInstance(context);
// tData.clear();
// tData.addAll();
teacher mAdapter =new teacher(dbUtil.getQuestionTeacher(mDataList.get(position).getId()));
holder.listview.setAdapter(mAdapter);
mAdapter.setOnClickListener(onClickListener);
holder.listview.setTag(mDataList.get(position));
// for (int i = 0; i < tData.size(); i++) {
//
// View v=new View(context);
// v=LayoutInflater.from(context).inflate(R.layout.student_question_teacher_answer, null);
// TextView answer=(TextView) v.findViewById(R.id.center_question_detail_teacher_answer);
// TextView delete=(TextView) v.findViewById(R.id.center_question_detail_teacher_answer_delete);
// answer.setText(tData.get(i).getAnwserValue());
// if (tData.get(i).getTeacherId().endsWith(mStoreUtils.getUserInfo().getId())) {
// delete.setVisibility(View.VISIBLE);
// }else {
// delete.setVisibility(View.GONE);
// }
// holder.mLlayout.addView(v);
// }
return view;
}
class HolderView {
SimpleDraweeView hvIcon;
TextView tvName;
TextView tvContent;
TextView tvDate;
TextView tvdelete;
RatingBar rbRating;
MyListView listview;
}
class teacher extends BaseAdapter{
private List<StudentQuestionDetailsTeacherInfo> listteacher;
private OnClickListener onClickListener;
public void setOnClickListener(OnClickListener onClickListener) {
this.onClickListener = onClickListener;
}
public teacher(List<StudentQuestionDetailsTeacherInfo> listr)
{
listteacher=listr;
}
@Override
public int getCount() {
return listteacher.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@SuppressLint({ "ViewHolder", "InflateParams" })
@Override
public View getView(final int position, View view, ViewGroup parent) {
view=LayoutInflater.from(context).inflate(R.layout.student_question_teacher_answer, null);
TextView answer=(TextView) view.findViewById(R.id.center_question_detail_teacher_answer);
TextView delete=(TextView) view.findViewById(R.id.center_question_detail_teacher_answer_delete);
TextView name=(TextView) view.findViewById(R.id.center_question_detail_teacher_answer_teacher_name);
answer.setText(listteacher.get(position).getAnwserValue());
if (listteacher.get(position).getTeacherId().equals(mStoreUtils.getUserInfo().getId())) {
delete.setVisibility(View.VISIBLE);
delete.setOnClickListener(onClickListener);
delete.setTag(listteacher.get(position).getId());
}else {
delete.setVisibility(View.GONE);
name.setText(listteacher.get(position).getTeacherName());
}
return view;
}
}
}