package com.mugua.mgvideo.ui.mine;
|
|
import java.util.List;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.view.ViewGroup;
|
import android.widget.BaseAdapter;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.yeshi.base.utils.http.BasicTextHttpResponseHandler;
|
import com.mugua.mgvideo.MGVideoAPI;
|
import com.mugua.mgvideo.R;
|
import com.mugua.mgvideo.entity.AccumulateUseRule;
|
|
public class AccumulateUseRuleAdapter extends BaseAdapter {
|
|
private List<AccumulateUseRule> mAccumulateUseRules;
|
|
public AccumulateUseRuleAdapter(List<AccumulateUseRule> accumulateUseRules) {
|
super();
|
this.mAccumulateUseRules = accumulateUseRules;
|
}
|
|
@Override
|
public int getCount() {
|
return mAccumulateUseRules == null ? 0: mAccumulateUseRules.size();
|
}
|
|
@Override
|
public Object getItem(int position) {
|
return mAccumulateUseRules.get(position);
|
}
|
|
@Override
|
public long getItemId(int position) {
|
return position;
|
}
|
|
@Override
|
public View getView(int position, View convertView, final ViewGroup parent) {
|
ViewHolder viewHolder;
|
if (convertView == null) {
|
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.accumulate_ad_item, parent, false);
|
viewHolder = new ViewHolder();
|
viewHolder.tv_accumulate_description = (TextView) convertView.findViewById(R.id.tv_accumulate_description);
|
viewHolder.tv_accumulate_point = (TextView) convertView.findViewById(R.id.tv_accumulate_point);
|
viewHolder.tv_accumulate_use = (TextView) convertView.findViewById(R.id.tv_accumulate_use);
|
convertView.setTag(viewHolder);
|
} else {
|
viewHolder = (ViewHolder) convertView.getTag();
|
}
|
final AccumulateUseRule accumulateUseRule = (AccumulateUseRule) getItem(position);
|
viewHolder.tv_accumulate_point.setText(parent.getResources().getString(R.string.minus_accumulate, accumulateUseRule.getScore()));
|
viewHolder.tv_accumulate_description.setText(accumulateUseRule.getAdType().getName());
|
if (accumulateUseRule.getType() == 1) {
|
viewHolder.tv_accumulate_use.setEnabled(true);
|
} else {
|
viewHolder.tv_accumulate_use.setEnabled(false);
|
}
|
viewHolder.tv_accumulate_use.setOnClickListener(new OnClickListener() {
|
|
@Override
|
public void onClick(View v) {
|
SharedPreferences preferences = v.getContext().getSharedPreferences("user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
MGVideoAPI.costScore(v.getContext(), uid, accumulateUseRule.getId(), new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers,
|
JSONObject jsonObject) throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
Toast.makeText(parent.getContext(), "使用成功", Toast.LENGTH_SHORT).show();
|
// if (parent.getContext() instanceof AccumulateActivity) {
|
// ((AccumulateActivity) parent.getContext()).refresh();
|
// }
|
} else {
|
Toast.makeText(parent.getContext(), jsonObject.getString("Error"), Toast.LENGTH_SHORT).show();
|
}
|
}
|
});
|
}
|
});
|
return convertView;
|
}
|
|
private static class ViewHolder {
|
TextView tv_accumulate_description;
|
TextView tv_accumulate_point;
|
TextView tv_accumulate_use;
|
}
|
|
}
|