package com.weikou.beibeivideo.ui.category;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
import android.os.Bundle;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.RecyclerView;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.widget.ImageView;
|
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.glide.GlideCircleTransform;
|
import com.umeng.analytics.MobclickAgent;
|
import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
|
import com.weikou.beibeivideo.BeibeiVideoAPI;
|
import com.weikou.beibeivideo.R;
|
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.ui.DividerItemDecoration;
|
|
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);
|
}
|
});
|
}
|
|
}
|