|
@@ -0,0 +1,255 @@
|
|
|
|
|
+package com.sheep.gamegroup.view.activity;
|
|
|
|
|
+
|
|
|
|
|
+import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.widget.ImageView;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.FindApp;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.FindAppReservation;
|
|
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
|
|
+import com.sheep.gamegroup.util.Jump2View;
|
|
|
|
|
+import com.sheep.gamegroup.util.ListUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.LogUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.SysAppUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.TimeUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.ViewHolder;
|
|
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
|
|
+import com.sheep.gamegroup.view.adapter.AdbCommonRecycler;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Locale;
|
|
|
|
|
+
|
|
|
|
|
+import butterknife.BindView;
|
|
|
|
|
+import rx.android.schedulers.AndroidSchedulers;
|
|
|
|
|
+import rx.functions.Action1;
|
|
|
|
|
+import rx.schedulers.Schedulers;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Created by realicing on 2018/5/10.
|
|
|
|
|
+ * realicing@sina.com
|
|
|
|
|
+ */
|
|
|
|
|
+public class ActReservation extends BaseActivity {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected int getLayoutId() {
|
|
|
|
|
+ return R.layout.net_empty_fresh_list_not_wrap;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @BindView(R.id.refresh)
|
|
|
|
|
+ SwipeRefreshLayout refresh;
|
|
|
|
|
+ @BindView(R.id.empty_view)
|
|
|
|
|
+ View empty_view;
|
|
|
|
|
+ @BindView(R.id.check_net_ll)
|
|
|
|
|
+ View check_net_ll;
|
|
|
|
|
+ @BindView(R.id.view_list)
|
|
|
|
|
+ RecyclerView view_list;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void initView() {
|
|
|
|
|
+ TitleBarUtils.getInstance()
|
|
|
|
|
+ .setTitle(this, "游戏预约")
|
|
|
|
|
+ .setTitleFinish(this);
|
|
|
|
|
+
|
|
|
|
|
+ refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onRefresh() {
|
|
|
|
|
+ initData();
|
|
|
|
|
+ refresh.setRefreshing(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ view_list.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
|
|
|
|
|
+ view_list.setAdapter(new AdbCommonRecycler<FindAppReservation>(SheepApp.getInstance(), list) {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int getItemViewType(int position) {
|
|
|
|
|
+ return position;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int getViewIdByType(int type) {//type来源于 getItemViewType 返回的值
|
|
|
|
|
+ switch (type) {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ return R.layout.find_reservation_item_top;
|
|
|
|
|
+ default:
|
|
|
|
|
+ if(type + 1 == list.size())
|
|
|
|
|
+ return R.layout.find_reservation_item_bottom;
|
|
|
|
|
+ else
|
|
|
|
|
+ return R.layout.find_reservation_item_center;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void convert(ViewHolder holder, FindAppReservation item) {
|
|
|
|
|
+ if(item != null)
|
|
|
|
|
+ loadItem(holder.itemView, item);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void loadItem(View itemView, final FindAppReservation item) {
|
|
|
|
|
+ ImageView find_information_game_icon = (ImageView) itemView.findViewById(R.id.find_information_game_icon);
|
|
|
|
|
+ TextView find_information_game_name = (TextView) itemView.findViewById(R.id.find_information_game_name);
|
|
|
|
|
+ TextView find_information_game_time = (TextView) itemView.findViewById(R.id.find_information_game_time);
|
|
|
|
|
+ TextView find_information_game_bt1 = (TextView) itemView.findViewById(R.id.find_information_game_bt1);
|
|
|
|
|
+ final TextView find_information_game_bt2 = (TextView) itemView.findViewById(R.id.find_information_game_bt2);
|
|
|
|
|
+
|
|
|
|
|
+ if(item != null && item.getApplication() != null){
|
|
|
|
|
+ final FindApp findApp = item.getApplication();
|
|
|
|
|
+
|
|
|
|
|
+ ViewUtil.setImage(find_information_game_icon, findApp.getIcon());
|
|
|
|
|
+ ViewUtil.setText(find_information_game_name, findApp.getName());
|
|
|
|
|
+ ViewUtil.setText(find_information_game_time, String.format(Locale.CHINA, "开放时间:%s", TimeUtil.TimeStamp2Date(findApp.getDownload_at(), "yyyy-MM-dd\tHH:mm")));
|
|
|
|
|
+ if(findApp.isCanDonload()){//可以下载
|
|
|
|
|
+ find_information_game_bt1.setEnabled(true);
|
|
|
|
|
+ find_information_game_bt1.setText("立即下载");
|
|
|
|
|
+ find_information_game_bt1.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View view) {
|
|
|
|
|
+ G.showToast("点击立即下载");
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ find_information_game_bt2.setEnabled(false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ find_information_game_bt1.setEnabled(false);
|
|
|
|
|
+ find_information_game_bt1.setText("即将开始");
|
|
|
|
|
+
|
|
|
|
|
+ find_information_game_bt2.setEnabled(true);
|
|
|
|
|
+ find_information_game_bt2.setText(item.isCancel() ? "立即预约" : "取消预约");
|
|
|
|
|
+ find_information_game_bt2.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View view) {
|
|
|
|
|
+ find_information_game_bt2.setEnabled(false);
|
|
|
|
|
+ if(item.isCancel()){//已经取消预约则进行预约
|
|
|
|
|
+ commitAppDownloads(find_information_game_bt2, findApp.getId());
|
|
|
|
|
+ } else {//取消预约
|
|
|
|
|
+ deleteDownloads(find_information_game_bt2, item.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View view) {
|
|
|
|
|
+ Jump2View.getInstance().goFindGame(ActReservation.this, findApp);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+
|
|
|
|
|
+ ViewUtil.setText(find_information_game_name);
|
|
|
|
|
+ ViewUtil.setText(find_information_game_time);
|
|
|
|
|
+ find_information_game_bt1.setEnabled(false);
|
|
|
|
|
+ find_information_game_bt2.setEnabled(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //预约下载
|
|
|
|
|
+ private void commitAppDownloads(final TextView find_information_game_bt2, int id) {
|
|
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().getDownloads(id)
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+ LogUtil.println("baseMessage onNext "+JSON.toJSONString(baseMessage));
|
|
|
|
|
+ find_information_game_bt2.setEnabled(true);
|
|
|
|
|
+ find_information_game_bt2.setText("取消预约");
|
|
|
|
|
+ G.showToast("预约成功");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ LogUtil.println("baseMessage onError "+JSON.toJSONString(baseMessage));
|
|
|
|
|
+ G.showToast("预约失败");
|
|
|
|
|
+ find_information_game_bt2.setEnabled(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ //取消预约
|
|
|
|
|
+ private void deleteDownloads(final TextView find_information_game_bt2, int id) {
|
|
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().deleteDownloads(id)
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+ LogUtil.println("baseMessage onNext "+JSON.toJSONString(baseMessage));
|
|
|
|
|
+ find_information_game_bt2.setEnabled(true);
|
|
|
|
|
+ find_information_game_bt2.setText("立即预约");
|
|
|
|
|
+ G.showToast("取消预约成功");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ LogUtil.println("baseMessage onError "+JSON.toJSONString(baseMessage));
|
|
|
|
|
+ G.showToast("取消预约失败");
|
|
|
|
|
+ find_information_game_bt2.setEnabled(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void initListener() {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<FindAppReservation> list = ListUtil.emptyList();
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void initData() {
|
|
|
|
|
+ empty_view.setVisibility(View.INVISIBLE);
|
|
|
|
|
+ SysAppUtil.checkNet(new Action1<Integer>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void call(Integer result) {
|
|
|
|
|
+ if (result != 0) {//无网络
|
|
|
|
|
+ if (check_net_ll != null)
|
|
|
|
|
+ check_net_ll.setVisibility(View.VISIBLE);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (check_net_ll != null)
|
|
|
|
|
+ check_net_ll.setVisibility(View.GONE);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().getFindAppReservationList(1, 100)
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+ LogUtil.println("baseMessage onNext " + JSON.toJSONString(baseMessage));
|
|
|
|
|
+ List<FindAppReservation> newList = baseMessage.getDataList(FindAppReservation.class);
|
|
|
|
|
+ if (ListUtil.isEmpty(newList)) {
|
|
|
|
|
+ } else {
|
|
|
|
|
+ list.clear();
|
|
|
|
|
+ ListUtil.addAll(list, newList);
|
|
|
|
|
+ if(!list.isEmpty())
|
|
|
|
|
+ list.add(null);//底部圆角
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ LogUtil.println("baseMessage onError " + JSON.toJSONString(baseMessage));
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private void notifyDataSetChanged() {
|
|
|
|
|
+ if (list.isEmpty())
|
|
|
|
|
+ empty_view.setVisibility(View.VISIBLE);
|
|
|
|
|
+ refresh.setRefreshing(false);
|
|
|
|
|
+ view_list.getAdapter().notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|