package xxxx;
import org.json.JSONArray;
import org.json.JSONObject;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import x.R;
import x.BitmapManage;
import x.StringUtil;
import x.C_BaseActivity;
public class C_My1Demand_Detail extends C_BaseActivity {
private TextView title,author,time,demandDesc,replyAccount;
private ImageView imgs[],shopIcon;
private ViewGroup viewGroup;
private Context context = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.correcting_my_demand_detail);
initViews();
loadData();
}
private void initViews() {
title = (TextView) findViewById(R.id.title);
author = (TextView) findViewById(R.id.author);
time = (TextView) findViewById(R.id.time);
demandDesc = (TextView) findViewById(R.id.demand_desc);
replyAccount = (TextView) findViewById(R.id.reply_account);
/*shopName = (TextView) findViewById(R.id.shop_name);
replyWord = (TextView) findViewById(R.id.reply_word);
replyTime = (TextView) findViewById(R.id.reply_time);*/
imgs = new ImageView[3];
imgs[0] = (ImageView) findViewById(R.id.img1);
imgs[1] = (ImageView) findViewById(R.id.img2);
imgs[2] = (ImageView) findViewById(R.id.img3);
viewGroup = (ViewGroup) findViewById(R.id.view_group);
}
private void loadData() {
String perData = getIntent().getExtras().get("per_data").toString();
if (!StringUtil.isEmpty(perData)) {
try {
String fdDemaTitle = new JSONObject(perData).getString("fdDemaTitle");
String fdBuyeName = "";
try {
fdBuyeName = new JSONObject(new JSONObject(perData).getString("propBuyer")).getString("fdBuyeName");
} catch (Exception e) {
}
String fdDemaCreateAt = new JSONObject(perData).getString("fdDemaCreateAt");
String fdDemaRemark = new JSONObject(perData).getString("fdDemaRemark");
JSONArray propImages = new JSONArray(new JSONObject(perData).getString("propImages"));
String [] fdDeimImages = new String[propImages.length()];
for (int i = 0 ;i < propImages.length(); i++ ) {
fdDeimImages [i] = new JSONObject(propImages.get(i).toString()).getString("fdDeimImage");
}
String propReplyCount = new JSONObject(perData).getString("propReplyCount");
JSONArray propReplys = new JSONArray(new JSONObject(perData).getString("propReplys"));
String fdDereContent[] = new String[propReplys.length()];
String fdDereCreateAt[] = new String[propReplys.length()];
String fdShopName[] = new String[propReplys.length()];
String fdShopLogo[] = new String[propReplys.length()];
for (int i = 0 ;i < propReplys.length(); i++ ) {
fdDereContent[i] = new JSONObject(propReplys.get(i).toString()).getString("fdDereContent");
fdDereCreateAt[i] = new JSONObject(propReplys.get(i).toString()).getString("fdDereCreateAt");
fdShopLogo[i] = new JSONObject(new JSONObject(propReplys.get(i).toString()).getString("propShop")).getString("fdShopLogo");
fdShopName[i] = new JSONObject(new JSONObject(propReplys.get(i).toString()).getString("propShop")).getString("fdShopName");
}
title.setText(fdDemaTitle);
author.setText(fdBuyeName);
time.setText(fdDemaCreateAt);
demandDesc.setText(fdDemaRemark);
replyAccount.setText(propReplyCount);
for (int i = 0 ;i < propReplys.length(); i++ ) {
TextView shopName,replyWord,replyTime;
ImageView shopIcon;
LayoutInflater inflater = LayoutInflater.from(context);
RelativeLayout reply = (RelativeLayout) inflater.inflate(R.layout.correcting_my_demand_detail_reply, null);
shopName = (TextView) reply.findViewById(R.id.shop_name);
replyWord = (TextView) reply.findViewById(R.id.reply_word);
replyTime = (TextView) reply.findViewById(R.id.reply_time);
shopIcon = (ImageView) reply.findViewById(R.id.shop_icon);
BitmapManage.getInstance(context).get(fdShopLogo[0], shopIcon);
shopName.setText(fdShopName[i]);
replyWord.setText(fdDereContent[i]);
replyTime.setText(fdDereCreateAt[i]);
viewGroup.addView(reply);
if ( ! (propReplys.length() == 1 || propReplys.length()-1 == i)) {
ImageView iv = new ImageView(context);
iv.setBackgroundColor(0xaaaaaa);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(viewGroup.getLayoutParams().width, 1);
lp.setMargins(0, 10, 0, 0);
iv.setBackgroundColor(Color.parseColor("#000000"));
iv.setLayoutParams(lp);
viewGroup.addView(iv);
}
viewGroup.setVisibility(View.VISIBLE);
}
for (int i=0 ; i < fdDeimImages.length ; i++) {
BitmapManage.getInstance(context).get(fdDeimImages[i], imgs[i]);
imgs[i].getLayoutParams();
imgs[i].setVisibility(View.VISIBLE);
}
} catch (Exception e) {
Toast.makeText(context, "数据加载异常!", Toast.LENGTH_SHORT).show();
return;
}
}
}
}