|
|
@@ -0,0 +1,160 @@
|
|
|
+package com.sheep.gamegroup.module.game.fragment;
|
|
|
+
|
|
|
+import android.content.Intent;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
|
+import com.chad.library.adapter.base.BaseViewHolder;
|
|
|
+import com.sheep.gamegroup.absBase.AbsGetDownloadListener;
|
|
|
+import com.sheep.gamegroup.absBase.IApiRefresh;
|
|
|
+import com.sheep.gamegroup.absBase.NetApiRefresh;
|
|
|
+import com.sheep.gamegroup.event.BigEvent;
|
|
|
+import com.sheep.gamegroup.helper.DownloadHelper;
|
|
|
+import com.sheep.gamegroup.model.api.ApiService;
|
|
|
+import com.sheep.gamegroup.model.api.IDownload;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.GameEntity;
|
|
|
+import com.sheep.gamegroup.module.game.adapter.AdpGameCenterTypeList;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.gamegroup.view.fragment.BaseListFragment6;
|
|
|
+
|
|
|
+import org.afinal.simplecache.ApiKey;
|
|
|
+import org.greenrobot.eventbus.Subscribe;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import io.reactivex.Observable;
|
|
|
+
|
|
|
+import static com.sheep.gamegroup.view.adapter.TryMakeMoneyAdp.PUBLIC_TAG_PREFIX_TEXTVIEW_LIST;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by realicing on 2019/1/21.
|
|
|
+ * realicing@sina.com
|
|
|
+ * 小绵羊3.4.10新增 -- 绵羊新游、免费道具、绵羊推荐 界面
|
|
|
+ */
|
|
|
+public class FgtGameCenterType extends BaseListFragment6<GameEntity> {
|
|
|
+
|
|
|
+
|
|
|
+ private int type;
|
|
|
+ public static FgtGameCenterType newInstance(int type) {
|
|
|
+ FgtGameCenterType fgt = new FgtGameCenterType();
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putInt("type", type);
|
|
|
+ fgt.setArguments(bundle);
|
|
|
+ return fgt;
|
|
|
+ }
|
|
|
+// homepage_item_banner
|
|
|
+ @Override
|
|
|
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
+ View rootView = super.onCreateView(inflater, container, savedInstanceState);
|
|
|
+ Bundle bundle = getArguments();
|
|
|
+ if (bundle != null) {
|
|
|
+ type = bundle.getInt("type", 0);
|
|
|
+ }
|
|
|
+ return rootView;
|
|
|
+ }
|
|
|
+
|
|
|
+ private NetApiRefresh<GameEntity> apiRefresh;
|
|
|
+ @Override
|
|
|
+ protected void addApiRefresh(List<IApiRefresh> apiRefreshList) {
|
|
|
+ apiRefresh = new NetApiRefresh<GameEntity>(this) {
|
|
|
+ @Override
|
|
|
+ public String getKey(int page, int per_page) {
|
|
|
+ return ApiKey.pageKeyUrl(ApiKey.getGameGroup, page, per_page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Observable<BaseMessage> getApi(ApiService apiService) {
|
|
|
+ return apiService.getGameGroupByTag(type, page, per_page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Class<GameEntity> getTClass() {
|
|
|
+ return GameEntity.class;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void loadList(List<GameEntity> addList) {
|
|
|
+ if(addList != null) {
|
|
|
+ for (GameEntity item : addList) {
|
|
|
+ IDownload download = item.getDownload();
|
|
|
+ if (download != null) {
|
|
|
+ gameEntityMap.put(download.getDownload_link(), item);
|
|
|
+ gameEntityMap.put(download.getPackage_names(), item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ super.loadList(addList);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ apiRefreshList.add(apiRefresh);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected BaseQuickAdapter<GameEntity, BaseViewHolder> getAdapter() {
|
|
|
+ return new AdpGameCenterTypeList(apiRefresh.getList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void clear() {
|
|
|
+ gameEntityMap.clear();
|
|
|
+ super.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //更新下载进度
|
|
|
+ private Map<String, GameEntity> gameEntityMap = new HashMap<>();
|
|
|
+
|
|
|
+ private AbsGetDownloadListener absGetDownloadListener = new AbsGetDownloadListener(true) {
|
|
|
+ @Override
|
|
|
+ public String getDownloadUrl(String packageName) {
|
|
|
+ GameEntity item = gameEntityMap.get(packageName);
|
|
|
+ return item != null && item.getDownload() != null ? item.getDownload().getDownload_link() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TextView getTextView2(String packageName) {
|
|
|
+ return recyclerView.findViewWithTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + getDownloadUrl(packageName));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TextView getTextView(String downloadUrl) {
|
|
|
+ return recyclerView.findViewWithTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + downloadUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DownloadHelper getDownloadHelper(String downloadUrl) {
|
|
|
+ GameEntity item = gameEntityMap.get(downloadUrl);
|
|
|
+ return item != null ? item.getDownloadHelper(downloadUrl) : null;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ @Subscribe
|
|
|
+ public void onEventMainThread(Intent intent) {
|
|
|
+ absGetDownloadListener.onEventMainThread(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Subscribe
|
|
|
+ public void onEventMainThread(BigEvent event) {
|
|
|
+ absGetDownloadListener.onEventMainThread(event);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initView() {
|
|
|
+ super.initView();
|
|
|
+ ViewUtil.register(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ ViewUtil.unregister(this);
|
|
|
+ }
|
|
|
+}
|