admin
2021-07-15 49982f5a1a305c0cc7da04735e1c604b802d2a22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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;
    }
    
}