admin
2021-03-09 6aed6290ad05fe2aa125bb8e804e2e8c2f13a613
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
package com.weikou.beibeivideo.ui.category;
 
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
 
import com.bumptech.glide.Glide;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.lcjian.library.RetainViewFragment;
import com.lcjian.library.util.RefreshLayout;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.umeng.analytics.MobclickAgent;
import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
import com.weikou.beibeivideo.BeibeiVideoAPI;
import com.weikou.beibeivideo.entity.VideoInfo;
import com.weikou.beibeivideo.entity.video.VideoContent;
import com.weikou.beibeivideo.ui.video.VideoCloumn1Adapter;
import com.weikou.beibeivideo.util.DimenUtils;
import com.weikou.beibeivideo.util.GlideCircleTransform;
import com.weikou.beibeivideo.util.ui.DividerItemDecoration;
import com.weikou.beibeivideo.R;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
import java.util.ArrayList;
import java.util.List;
 
public class StarDetailFragment extends RetainViewFragment {
    private View star_Detail_min_Top;
    SwipeRefreshLayout rl_detail;
    private RecyclerView rv_Star_Detail;
    private ImageView star_detail_portrait;
    private TextView star_detail_name, star_detail_job, star_detail_country,
            star_detail_works;
    private List<VideoContent> mVideoInfos;
    private VideoCloumn1Adapter mAdapter;
    private boolean isLoad;
 
    private int mCurrentPage = 1;
 
    private String star_id;
 
    @Override
    public int getContentResource() {
        return R.layout.star_detail_fragment;
    }
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        star_id = bundle.getString("star_id");
        rl_detail = contentView.findViewById(R.id.rl_detail);
        rv_Star_Detail = contentView
                .findViewById(R.id.rv_star_detail);
 
        rv_Star_Detail.setLayoutManager(new LinearLayoutManager(getContext()));
        DividerItemDecoration decoration = new DividerItemDecoration();
        decoration.setSize(DimenUtils.dip2px(rv_Star_Detail.getContext(), 6));
        rv_Star_Detail.addItemDecoration(decoration);
 
        star_Detail_min_Top = LayoutInflater.from(rv_Star_Detail.getContext()).inflate(
                R.layout.star_detail_min_top, null);
 
        star_detail_portrait = (ImageView) contentView
                .findViewById(R.id.star_detail_portrait);
        star_detail_name = (TextView) contentView
                .findViewById(R.id.star_detail_name);
        star_detail_job = (TextView) contentView
                .findViewById(R.id.star_detail_job);
        star_detail_country = (TextView) contentView
                .findViewById(R.id.star_detail_country);
        star_detail_works = (TextView) contentView
                .findViewById(R.id.star_detail_works);
 
        mVideoInfos = new ArrayList<>();
        mAdapter = new VideoCloumn1Adapter(getActivity(), mVideoInfos,"star");
        mAdapter.setHeaderView(star_Detail_min_Top);
        rv_Star_Detail.setAdapter(mAdapter);
        ProgressBar pb = new ProgressBar(rv_Star_Detail.getContext());
        rl_detail.setRefreshing(true);
        rl_detail.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mCurrentPage = 1;
                getHotStarDetail();
            }
        });
 
 
        rv_Star_Detail.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
                int first = manager.findFirstVisibleItemPosition();
                int last = manager.findLastVisibleItemPosition();
                int total = manager.getItemCount();
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    if ((!isLoad) && last == total - 1 && mVideoInfos.size() < 1000) {
                        isLoad = true;
                        mCurrentPage++;
                        getHotStarsVideo();
                    }
                }
            }
 
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, final int dy) {
                super.onScrolled(recyclerView, dx, dy);
            }
        });
 
 
        rv_Star_Detail.postDelayed(new Runnable() {
 
            @Override
            public void run() {
                getHotStarDetail();
            }
        }, 200);
 
    }
 
    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("明星详情页");
    }
 
    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("明星详情页");
    }
 
    private void getHotStarDetail() {
        SharedPreferences preferences = star_detail_country.getContext().getSharedPreferences(
                "user", Context.MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
 
        BeibeiVideoAPI.getHotStarDetail(star_detail_country.getContext(), uid, star_id,
                new BasicTextHttpResponseHandler() {
 
                    @Override
                    public void onSuccessPerfect(int statusCode,
                                                 Header[] headers, JSONObject jsonObject)
                            throws Exception {
                        if (jsonObject.getBoolean("IsPost")) {
                            star_detail_name.setText(jsonObject.getJSONObject(
                                    "Data").optString("Name"));
                            star_detail_job.setText("职业:"
                                    + jsonObject.getJSONObject("Data")
                                    .optString("Job"));
                            star_detail_country.setText("国籍:"
                                    + jsonObject.getJSONObject("Data")
                                    .optString("Country"));
                            star_detail_works.setText("代表作:"
                                    + jsonObject.getJSONObject("Data")
                                    .optString("Works"));
 
                            try {
                                Glide.with(getActivity().getApplicationContext())
                                        .load(jsonObject.getJSONObject("Data")
                                                .optString("Portrait"))
                                        .placeholder(R.drawable.img_head_portrait)
                                        .error(R.drawable.img_head_portrait)
                                        .transform(
                                                new GlideCircleTransform(
                                                        star_Detail_min_Top.getContext()))
                                        .into(star_detail_portrait);
                            } catch (IllegalArgumentException e) {
                                e.printStackTrace();
                            }
                        }
                    }
 
                    @Override
                    public void onFinish() {
                        getHotStarsVideo();
                    }
                });
    }
 
    private void getHotStarsVideo() {
        SharedPreferences preferences = rv_Star_Detail.getContext().getSharedPreferences(
                "user", Context.MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
 
        BeibeiVideoAPI.getHotStarsVideo(rv_Star_Detail.getContext(), uid, star_id,
                String.valueOf(mCurrentPage),
                new BasicTextHttpResponseHandler() {
 
                    @Override
                    public void onSuccessPerfect(int statusCode,
                                                 Header[] headers, JSONObject jsonObject)
                            throws Exception {
                        if (jsonObject.getBoolean("IsPost")) {
                            System.out.println("hhhhh===="
                                    + jsonObject.getJSONObject("Data")
                                    .toString());
                            Gson gson = new GsonBuilder().setFieldNamingPolicy(
                                    FieldNamingPolicy.UPPER_CAMEL_CASE)
                                    .create();
                            List<VideoInfo> videoInfos = gson.fromJson(
                                    jsonObject.getJSONObject("Data")
                                            .getJSONArray("data").toString(),
                                    new TypeToken<List<VideoInfo>>() {
                                    }.getType());
                            if (mCurrentPage == 1) {
                                mVideoInfos.clear();
                            }
 
                            if ((videoInfos == null || videoInfos.size() == 0)
                                    && mCurrentPage > 1) {
                                Toast.makeText(rv_Star_Detail.getContext(), "没有更多了",
                                        Toast.LENGTH_SHORT).show();
                                mCurrentPage--;
                            } else {
                                List<VideoContent> videoContentList = new ArrayList<>();
                                for (VideoInfo video : videoInfos) {
                                    videoContentList.add(VideoContent.createVideoContent(video));
                                }
                                mVideoInfos.addAll(videoContentList);
                            }
                            mAdapter.notifyDataSetChanged();
                        }
                    }
 
                    @Override
                    public void onFinish() {
                        isLoad = false;
                        rl_detail.setRefreshing(false);
                    }
                });
    }
 
}