| | |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.View.OnClickListener; |
| | | import android.view.ViewGroup; |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.TextView; |
| | |
| | | private LinearLayout ll_ad_containner; |
| | | private RatioLayout rl_recommend_top; |
| | | private CirclePageIndicator indicator_recommend; |
| | | private boolean isLoad; |
| | | private View loading; |
| | | |
| | | private void initHomeAd() { |
| | | View view = LayoutInflater.from(getContext()).inflate(R.layout.recommend_top, null); |
| | |
| | | decoration.setSize(DimenUtils.dip2px(rv_recommend.getContext(), 0)); |
| | | rv_recommend.addItemDecoration(decoration); |
| | | |
| | | loading = LayoutInflater.from(getContext()).inflate(R.layout.item_loading, null); |
| | | loading.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); |
| | | loading.setVisibility(View.GONE); |
| | | |
| | | |
| | | rv_recommend.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 && mHomeTypes.size() < homeTypeCount) { |
| | | if (mHomeTypes != null && mHomeTypes.size() > 0 && !rl_recommend.isRefreshing()) {//列表中有数据才能加载更多 |
| | | homeTypePage++; |
| | | isLoad = true; |
| | | loading.setVisibility(View.VISIBLE); |
| | | getHomeType(homeTypePage); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onScrolled(RecyclerView recyclerView, int dx, final int dy) { |
| | | super.onScrolled(recyclerView, dx, dy); |
| | | } |
| | | }); |
| | | |
| | | |
| | | rl_recommend.setClickable(false); |
| | | |
| | | iv_right_ad = contentView.findViewById(R.id.iv_right_ad); |
| | |
| | | mHomeTypes = new ArrayList(); |
| | | mRecommendNewAdapter = new RecommendNewAdapter(getActivity(), mHomeTypes, ScreenUtils.getScreenWidth(getContext())); |
| | | rv_recommend.setAdapter(mRecommendNewAdapter); |
| | | |
| | | mRecommendNewAdapter.setFooterView(loading); |
| | | setAdContent(); |
| | | initHomeAd(); |
| | | //加载缓存数据 |
| | |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | getHomeType(); |
| | | homeTypePage = 1; |
| | | getHomeType(homeTypePage); |
| | | } |
| | | }); |
| | | } |
| | |
| | | * 获取影片整体信息 |
| | | */ |
| | | |
| | | private void getHomeType() { |
| | | private int homeTypePage; |
| | | private int homeTypeCount; |
| | | |
| | | private void getHomeType(int page) { |
| | | SharedPreferences preferences = context.getSharedPreferences( |
| | | "user", Context.MODE_PRIVATE); |
| | | String uid = preferences.getString("uid", ""); |
| | | BeibeiVideoAPI.getHomeType(context, uid, type.getId(), type.getDataKey(), |
| | | BeibeiVideoAPI.getHomeType(context, uid, type.getId(), type.getDataKey(), page, 4, |
| | | new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | |
| | | List<HomeType> homeTypes = new ArrayList<HomeType>(); |
| | | JSONArray array = jsonObject.getJSONObject("Data") |
| | | .getJSONArray("data"); |
| | | homeTypeCount = jsonObject.getJSONObject("Data").optInt("count"); |
| | | for (int i = 0; i < array.length(); i++) { |
| | | HomeType type = new HomeType(); |
| | | JSONObject obj = array.optJSONObject(i); |
| | |
| | | } |
| | | |
| | | //清除老数据 |
| | | mHomeTypes.clear(); |
| | | mRecommendNewAdapter.removeAllAd(); |
| | | if (page == 1) { |
| | | mHomeTypes.clear(); |
| | | mRecommendNewAdapter.removeAllAd(); |
| | | } |
| | | mHomeTypes.addAll(homeTypes); |
| | | //填充数据 |
| | | setAdContent(); |
| | | if (position == 0) { |
| | | if (position == 0 && page == 1) { |
| | | DiskLruCache.Editor editor = cache |
| | | .edit(getKey("getHomeType") + type.getId()); |
| | | editor.set(0, jsonObject.getJSONObject("Data") |
| | |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | isLoad = false; |
| | | rl_recommend.setRefreshing(false); |
| | | loading.setVisibility(View.GONE); |
| | | try { |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |