|
|
@@ -0,0 +1,171 @@
|
|
|
+package com.sheep.gamegroup.module.game.fragment;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Intent;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
+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.entity.Applications;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.module.game.model.MyGame;
|
|
|
+import com.sheep.gamegroup.util.GlideImageLoader;
|
|
|
+import com.sheep.gamegroup.util.Jump2View;
|
|
|
+import com.sheep.gamegroup.util.ListUtil;
|
|
|
+import com.sheep.gamegroup.util.TimeUtil;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.gamegroup.view.fragment.BaseListFragment6;
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
+
|
|
|
+import org.afinal.simplecache.ApiKey;
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
+import org.greenrobot.eventbus.Subscribe;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import io.reactivex.Observable;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by realicing on 2019/1/11.
|
|
|
+ * realicing@sina.com
|
|
|
+ * <p>
|
|
|
+ * 小绵羊3.4.9新增--我的游戏列表
|
|
|
+ */
|
|
|
+public class FgtMyGameList extends BaseListFragment6<MyGame> {
|
|
|
+ @Override
|
|
|
+ public int getLayoutId() {
|
|
|
+ return R.layout.common_srl_rv;
|
|
|
+ }
|
|
|
+
|
|
|
+ private NetApiRefresh<MyGame> apiRefresh;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void addApiRefresh(List<IApiRefresh> apiRefreshList) {
|
|
|
+ apiRefresh = new NetApiRefresh<MyGame>(this) {
|
|
|
+ @Override
|
|
|
+ public String getKey(int page, int per_page) {
|
|
|
+ return ApiKey.pageKeyUrl(ApiKey.getMyGmeList, page, per_page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Observable<BaseMessage> getApi(ApiService apiService) {
|
|
|
+ return apiService.getMyGameList(page, per_page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Class<MyGame> getTClass() {
|
|
|
+ return MyGame.class;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ apiRefreshList.add(apiRefresh);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected BaseQuickAdapter<MyGame, BaseViewHolder> getAdapter() {
|
|
|
+ BaseQuickAdapter<MyGame, BaseViewHolder> baseQuickAdapter = new BaseQuickAdapter<MyGame, BaseViewHolder>(R.layout.item_my_game, apiRefresh.getList()) {
|
|
|
+ @Override
|
|
|
+ protected void convert(BaseViewHolder helper, MyGame item) {
|
|
|
+ int position = helper.getAdapterPosition() - getHeaderLayoutCount();
|
|
|
+ Applications applications = item.getApplication();
|
|
|
+ ImageView find_information_game_icon = helper.getView(R.id.find_information_game_icon);
|
|
|
+ TextView find_information_game_name = helper.getView(R.id.find_information_game_name);
|
|
|
+ TextView find_information_game_surplus = helper.getView(R.id.find_information_game_surplus);
|
|
|
+ TextView find_information_game_time = helper.getView(R.id.find_information_game_time);
|
|
|
+ TextView find_information_game_task_center = helper.getView(R.id.find_information_game_task_center);
|
|
|
+ GlideImageLoader.setGameImage(find_information_game_icon, applications.getIcon());
|
|
|
+ ViewUtil.setText(find_information_game_name, applications.getName());
|
|
|
+ final boolean isNeedReservation = !applications.isCanDownload();//这里认为只有两种状态:可下载与预约下载
|
|
|
+ ViewUtil.setText(find_information_game_surplus);
|
|
|
+ if (isNeedReservation)
|
|
|
+ ViewUtil.setText(find_information_game_time, String.format(Locale.CHINA, "开放时间:%s", TimeUtil.TimeStamp2Date(applications.getDownload_at(), "yyyy-MM-dd\u0020HH:mm")));
|
|
|
+ else
|
|
|
+ ViewUtil.setText(find_information_game_time, String.format(Locale.CHINA, "厂商:%s\u0020包体大小:%sM", applications.getManufacturer(), applications.getPackage_size()));
|
|
|
+ find_information_game_task_center.setVisibility(View.VISIBLE);
|
|
|
+
|
|
|
+ updateView(getActivity(), applications, find_information_game_task_center);
|
|
|
+
|
|
|
+ ViewUtil.setVisibility(helper.getView(R.id.item_my_game_v), position > 0);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ baseQuickAdapter.setOnItemClickListener((adapter, view, position) -> {
|
|
|
+ MyGame item = ListUtil.getItem(apiRefresh.getList(), position);
|
|
|
+ if(item != null)
|
|
|
+ Jump2View.getInstance().goFindGame(getActivity(), item.getApplication());
|
|
|
+ });
|
|
|
+ return baseQuickAdapter;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Applications> applicationMap = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ private Map<String, TextView> downLoadTextViewMap = new HashMap<>();
|
|
|
+
|
|
|
+ //更新按钮状态与添加点击事件
|
|
|
+ private void updateView(Activity activity, Applications findApp, TextView textView) {
|
|
|
+ if (findApp.isCanDownload()) {//可下载
|
|
|
+ downLoadTextViewMap.put(findApp.getDownload_link(), textView);
|
|
|
+ downLoadTextViewMap.put(findApp.getPackage_name(), textView);
|
|
|
+ applicationMap.put(findApp.getDownload_link(), findApp);
|
|
|
+ applicationMap.put(findApp.getPackage_name(), findApp);
|
|
|
+ findApp.getFindAppHelper().updateDownloadTaskView(activity, findApp, textView);
|
|
|
+ } else {//预约下载
|
|
|
+ findApp.getFindAppHelper().updateReservationView(activity, findApp, textView);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private AbsGetDownloadListener absGetDownloadListener = new AbsGetDownloadListener(true) {
|
|
|
+ @Override
|
|
|
+ public String getDownloadUrl(String packageName) {
|
|
|
+ Applications item = applicationMap.get(packageName);
|
|
|
+ return item != null ? item.getDownload_url() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TextView getTextView2(String packageName) {
|
|
|
+ return downLoadTextViewMap.get(packageName);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TextView getTextView(String downloadUrl) {
|
|
|
+ return downLoadTextViewMap.get(downloadUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DownloadHelper getDownloadHelper(String downloadUrl) {
|
|
|
+ Applications item = applicationMap.get(downloadUrl);
|
|
|
+ return item != null ? item.getDownloadHelper() : 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();
|
|
|
+ EventBus.getDefault().register(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ EventBus.getDefault().unregister(this);
|
|
|
+ }
|
|
|
+}
|