| | |
| | | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | import de.greenrobot.event.EventBus; |
| | | |
| | | import android.util.Log; |
| | | import android.view.LayoutInflater; |
| | |
| | | import com.hanju.lib.library.util.common.StorageUtils; |
| | | import com.hanju.lib.library.util.common.StringUtils; |
| | | import com.hanju.lib.library.widget.RatioLayout; |
| | | import com.hanju.video.app.util.JsonUtil; |
| | | import com.lzj.gallery.library.views.BannerViewPager; |
| | | import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; |
| | | import com.umeng.analytics.MobclickAgent; |
| | |
| | | import com.hanju.video.app.util.ui.GlideUtil; |
| | | import com.hanju.update.appupdate.GoReview; |
| | | import com.hanju.update.appupdate.service.DownLoadFileService; |
| | | import com.video.youth.entity.YouthModeChange; |
| | | import com.video.youth.util.YouthUtil; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONArray; |
| | |
| | | |
| | | private Set<String> emptyHomeTypes = new HashSet<>(); |
| | | |
| | | private SwipeRefreshLayout.OnRefreshListener refreshListener = new SwipeRefreshLayout.OnRefreshListener() { |
| | | @Override |
| | | public void onRefresh() { |
| | | if (position == 0) { |
| | | getHotStars(); |
| | | } |
| | | page = 1; |
| | | //加载广告 |
| | | loadAd(); |
| | | getHomeAd(); |
| | | getRecommendSearchSpecial(); |
| | | Log.i("mResult", "onCreate---setOnRefreshListener---loadAD1"); |
| | | } |
| | | }; |
| | | |
| | | public static Fragment newInstance(HomeNav type, String position) { |
| | | if (Integer.parseInt(position) < 2) { |
| | | RecommendFragment fragment = new RecommendFragment(); |
| | |
| | | @Override |
| | | public void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | EventBus.getDefault().register(this); |
| | | context = getActivity().getApplicationContext(); |
| | | try { |
| | | cache = DiskLruCache.open( |
| | |
| | | int last = manager.findLastVisibleItemPosition(); |
| | | int total = manager.getItemCount(); |
| | | if (newState == RecyclerView.SCROLL_STATE_IDLE) { |
| | | if ((!isLoad) && last == total - 1 && mHomeTypes.size() > 0 && totalCount > mHomeTypes.size() + (emptyHomeTypes==null?0: emptyHomeTypes.size())) { |
| | | if ((!isLoad) && last == total - 1 && mHomeTypes.size() > 0 && totalCount > mHomeTypes.size() + (emptyHomeTypes == null ? 0 : emptyHomeTypes.size())) { |
| | | Log.i("RecommendFragment", "加载更多"); |
| | | page++; |
| | | isLoad = true; |
| | |
| | | mHomeAds = new ArrayList<>(); |
| | | mHomeSpecials = new ArrayList<>(); |
| | | |
| | | rl_recommend.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
| | | @Override |
| | | public void onRefresh() { |
| | | if (position == 0) { |
| | | getHotStars(); |
| | | } |
| | | page = 1; |
| | | //加载广告 |
| | | loadAd(); |
| | | getHomeAd(); |
| | | getRecommendSearchSpecial(); |
| | | Log.i("mResult", "onCreate---setOnRefreshListener---loadAD1"); |
| | | } |
| | | }); |
| | | rl_recommend.setOnRefreshListener(refreshListener); |
| | | |
| | | if (mHomeTypes == null) |
| | | mHomeTypes = new ArrayList(); |
| | |
| | | try { |
| | | snapshot = cache.get(getKey("getHomeType") + type.getId()); |
| | | if (snapshot != null) { |
| | | Gson gson = new GsonBuilder().setFieldNamingPolicy( |
| | | FieldNamingPolicy.UPPER_CAMEL_CASE).create(); |
| | | List<HomeType> homeTypes = gson.fromJson( |
| | | |
| | | List<HomeType> homeTypes = JsonUtil.videoGson.fromJson( |
| | | snapshot.getString(0), |
| | | new TypeToken<List<HomeType>>() { |
| | | }.getType()); |
| | |
| | | try { |
| | | snapshot = cache.get(getKey("getRecommendSearchSpecial") + type.getId()); |
| | | if (snapshot != null) { |
| | | Gson gson = new GsonBuilder().setFieldNamingPolicy( |
| | | FieldNamingPolicy.UPPER_CAMEL_CASE).create(); |
| | | List<HomeSpecial> homeSpecials = gson.fromJson( |
| | | |
| | | List<HomeSpecial> homeSpecials = JsonUtil.videoGson.fromJson( |
| | | snapshot.getString(0), |
| | | new TypeToken<List<HomeSpecial>>() { |
| | | }.getType()); |
| | |
| | | return new Md5FileNameGenerator().generate(method); |
| | | } |
| | | |
| | | |
| | | private static boolean needRefresh = false; |
| | | |
| | | public void onEventMainThread(YouthModeChange youth) { |
| | | needRefresh = true; |
| | | } |
| | | |
| | | @Override |
| | | public void onResume() { |
| | | super.onResume(); |
| | | mChangeHelper.registerReceiver(); |
| | | MobclickAgent.onPageStart("主页面—推荐"); |
| | | if (needRefresh) { |
| | | needRefresh = false; |
| | | if (refreshListener != null) { |
| | | rl_recommend.setRefreshing(true); |
| | | refreshListener.onRefresh(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onPause() { |
| | | super.onPause(); |
| | | mChangeHelper.unregisterReceiver(); |
| | | MobclickAgent.onPageEnd("主页面—推荐"); |
| | | } |
| | | |
| | | private String content; |
| | |
| | | Header[] headers, JSONObject jsonObject) |
| | | throws Exception { |
| | | if (jsonObject.getBoolean("IsPost")) { |
| | | Gson gson = new GsonBuilder() |
| | | .setPrettyPrinting() |
| | | .setFieldNamingPolicy( |
| | | FieldNamingPolicy.UPPER_CAMEL_CASE) |
| | | .create(); |
| | | List<HomeAd> homeAds = gson.fromJson(jsonObject |
| | | |
| | | List<HomeAd> homeAds = JsonUtil.videoGson.fromJson(jsonObject |
| | | .getJSONObject("Data").getJSONArray("data") |
| | | .toString(), new TypeToken<List<HomeAd>>() { |
| | | }.getType()); |
| | |
| | | Header[] headers, JSONObject jsonObject) |
| | | throws Exception { |
| | | if (jsonObject.getBoolean("IsPost")) { |
| | | Gson gson = new GsonBuilder().setVersion(1.0).setFieldNamingPolicy( |
| | | FieldNamingPolicy.UPPER_CAMEL_CASE) |
| | | .create(); |
| | | |
| | | JSONObject data = jsonObject.getJSONObject("Data"); |
| | | totalCount = data.optInt("count"); |
| | | List<HomeType> homeTypes = new ArrayList<>(); |
| | |
| | | List<HomeVideo> homeList = new ArrayList<HomeVideo>(); |
| | | if (homeArray != null && homeArray.length() > 0) { |
| | | for (int j = 0; j < homeArray.length(); j++) { |
| | | homeList.add(gson.fromJson(homeArray |
| | | homeList.add( JsonUtil.videoGson.fromJson(homeArray |
| | | .optJSONObject(j).toString(), |
| | | HomeVideo.class)); |
| | | } |
| | |
| | | if (itemArray != null && itemArray.length() > 0) { |
| | | for (int k = 0; k < itemArray.length(); k++) { |
| | | if (itemArray.optJSONObject(k) != null) { |
| | | itemList.add(gson.fromJson( |
| | | itemList.add(JsonUtil.videoGson.fromJson( |
| | | itemArray.optJSONObject(k) |
| | | .toString(), |
| | | HomeTypeItem.class)); |
| | |
| | | @Override |
| | | public void onDestroy() { |
| | | super.onDestroy(); |
| | | EventBus.getDefault().unregister(this); |
| | | } |
| | | |
| | | private List<HomeVideo> adList1 = new ArrayList<>(); |
| | |
| | | throws Exception { |
| | | if (jsonObject.getBoolean("IsPost")) { |
| | | hotStars.clear(); |
| | | Gson gson = new GsonBuilder().setFieldNamingPolicy( |
| | | FieldNamingPolicy.UPPER_CAMEL_CASE) |
| | | .create(); |
| | | List<HotStar> hotStarList = gson.fromJson( |
| | | |
| | | List<HotStar> hotStarList = JsonUtil.videoGson.fromJson( |
| | | jsonObject.getJSONObject("Data") |
| | | .getJSONArray("data").toString(), |
| | | new TypeToken<List<HotStar>>() { |