|
@@ -2,42 +2,17 @@ package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
-import android.os.Handler;
|
|
|
|
|
-import android.os.Message;
|
|
|
|
|
-import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
|
|
-import android.support.v7.widget.LinearLayoutManager;
|
|
|
|
|
-import android.support.v7.widget.RecyclerView;
|
|
|
|
|
|
|
+import android.support.design.widget.TabLayout;
|
|
|
|
|
+import android.support.v4.view.ViewPager;
|
|
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.kfzs.duanduan.event.BigEvent;
|
|
import com.kfzs.duanduan.event.BigEvent;
|
|
|
-import com.sheep.gamegroup.di.components.DaggerTryMakeMoneyComponent;
|
|
|
|
|
-import com.sheep.gamegroup.di.modules.TryMakeMoneyModule;
|
|
|
|
|
-import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
|
|
-import com.sheep.gamegroup.model.entity.RecyleObj;
|
|
|
|
|
-import com.sheep.gamegroup.model.entity.RecyleType;
|
|
|
|
|
-import com.sheep.gamegroup.model.entity.RequestParameEty;
|
|
|
|
|
-import com.sheep.gamegroup.model.entity.TaskAcceptedEty;
|
|
|
|
|
-import com.sheep.gamegroup.model.entity.TaskReleaseEty;
|
|
|
|
|
-import com.sheep.gamegroup.presenter.TryMakeMoneyContract;
|
|
|
|
|
-import com.sheep.gamegroup.presenter.TryMakeMoneyPresenter;
|
|
|
|
|
-import com.sheep.gamegroup.util.CommonUtil;
|
|
|
|
|
-import com.sheep.gamegroup.util.Jump2View;
|
|
|
|
|
-import com.sheep.gamegroup.view.adapter.TryMakeMoneyAdp;
|
|
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
-import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
|
|
import com.sheep.jiuyan.samllsheep.base.BaseActivity;
|
|
import com.sheep.jiuyan.samllsheep.base.BaseActivity;
|
|
|
-import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-
|
|
|
|
|
-import javax.inject.Inject;
|
|
|
|
|
-
|
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.BindView;
|
|
|
import butterknife.ButterKnife;
|
|
import butterknife.ButterKnife;
|
|
|
|
|
|
|
@@ -46,28 +21,12 @@ import butterknife.ButterKnife;
|
|
|
* Created by ljy on 2018/3/10.
|
|
* Created by ljy on 2018/3/10.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-public class TryMakeMoneyact extends BaseActivity implements TryMakeMoneyContract.View{
|
|
|
|
|
- @BindView(R.id.recyclerview)
|
|
|
|
|
- RecyclerView recyclerview;
|
|
|
|
|
- @BindView(R.id.refresh)
|
|
|
|
|
- SwipeRefreshLayout refresh;
|
|
|
|
|
-
|
|
|
|
|
- @Inject
|
|
|
|
|
- TryMakeMoneyPresenter presenter;
|
|
|
|
|
|
|
+public class TryMakeMoneyact extends BaseActivity {
|
|
|
|
|
+ @BindView(R.id.indicator)
|
|
|
|
|
+ TabLayout indicator;
|
|
|
|
|
+ @BindView(R.id.pager)
|
|
|
|
|
+ ViewPager pager;
|
|
|
private Activity activity;
|
|
private Activity activity;
|
|
|
- private TryMakeMoneyAdp tryMakeMoneyAdp;
|
|
|
|
|
- private int position = 0;
|
|
|
|
|
- private List<TaskReleaseEty> releaseEtyLists = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
- Handler mhandler = new Handler(){
|
|
|
|
|
- @Override
|
|
|
|
|
- public void handleMessage(Message msg) {
|
|
|
|
|
- super.handleMessage(msg);
|
|
|
|
|
-
|
|
|
|
|
- tryMakeMoneyAdp.add(RecyleObj.make(RecyleType.RELEASE_TASK, releaseEtyLists),position);
|
|
|
|
|
- tryMakeMoneyAdp.notifyDataSetChanged();
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
protected int getLayoutId() {
|
|
@@ -82,174 +41,19 @@ public class TryMakeMoneyact extends BaseActivity implements TryMakeMoneyContrac
|
|
|
.getInstance()
|
|
.getInstance()
|
|
|
.setTitle(activity, "试玩赚钱")
|
|
.setTitle(activity, "试玩赚钱")
|
|
|
.setTitleFinish(activity);
|
|
.setTitleFinish(activity);
|
|
|
- DaggerTryMakeMoneyComponent.builder()
|
|
|
|
|
- .netComponent(SheepApp.get(this).getNetComponent())
|
|
|
|
|
- .tryMakeMoneyModule(new TryMakeMoneyModule(this))
|
|
|
|
|
- .build()
|
|
|
|
|
- .inject(this);
|
|
|
|
|
- recyclerview.setLayoutManager(new LinearLayoutManager(activity));
|
|
|
|
|
- tryMakeMoneyAdp = new TryMakeMoneyAdp(this);
|
|
|
|
|
- for (int i = 0; i < 2; i++) {
|
|
|
|
|
- tryMakeMoneyAdp.add(RecyleObj.make(RecyleType.NONE, null));
|
|
|
|
|
- }
|
|
|
|
|
- recyclerview.setAdapter(tryMakeMoneyAdp);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void initListener() {
|
|
public void initListener() {
|
|
|
- refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onRefresh() {
|
|
|
|
|
- initData();
|
|
|
|
|
- refresh.setRefreshing(false);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
|
|
|
- super.onScrollStateChanged(recyclerView, newState);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
|
-
|
|
|
|
|
- int topRowVerticalPosition =
|
|
|
|
|
- (recyclerView == null || recyclerView.getChildCount() == 0) ? 0 : recyclerView.getChildAt(0).getTop();
|
|
|
|
|
-
|
|
|
|
|
- refresh.setEnabled(topRowVerticalPosition >= 0);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void initData() {
|
|
public void initData() {
|
|
|
- showProgress(false);
|
|
|
|
|
- position = 0;
|
|
|
|
|
- tryMakeMoneyAdp.clear();
|
|
|
|
|
- tryMakeMoneyAdp.addType(0);
|
|
|
|
|
- for (int i = 0; i < 2; i++) {
|
|
|
|
|
- tryMakeMoneyAdp.add(RecyleObj.make(RecyleType.NONE, null));
|
|
|
|
|
- }
|
|
|
|
|
- tryMakeMoneyAdp.setTaskAcceptedEty(null);
|
|
|
|
|
- RequestParameEty parameEty = new RequestParameEty();
|
|
|
|
|
- parameEty.setHashMap(CommonUtil.getInstance().setHashMap(1,100,1,
|
|
|
|
|
- 0,1,0));
|
|
|
|
|
- presenter.releaseTask(parameEty);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void updateData2View(Object o) {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void failData2View(Object o) {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void acceptedTaskUpdataView(Object o) {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void failAcceptedTask2View(Object o) {
|
|
|
|
|
- hideProgress();
|
|
|
|
|
- try {
|
|
|
|
|
- BaseMessage baseMessage = (BaseMessage) o;
|
|
|
|
|
- switch (baseMessage.getCode()){
|
|
|
|
|
- case 300://未查询到数据
|
|
|
|
|
- G.showToast(" 未查询到数据!");
|
|
|
|
|
- break;
|
|
|
|
|
- default:
|
|
|
|
|
- G.showToast(" 网络错误!");
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- G.showToast(" 网络错误!");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void giveUpTaskSuccesView(Object o) {
|
|
|
|
|
- G.showToast("取消任务成功");
|
|
|
|
|
- initData();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void giveUpTaskFailView(Object o) {
|
|
|
|
|
- G.showToast("访问失败");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void returnTaskTaskUpdataView(Object o) {
|
|
|
|
|
-
|
|
|
|
|
- hideProgress();
|
|
|
|
|
- try{
|
|
|
|
|
- BaseMessage baseMessage = (BaseMessage) o;
|
|
|
|
|
- TaskAcceptedEty taskAcceptedEty = JSONObject.parseObject(JSONObject.toJSONString(baseMessage.getData()), TaskAcceptedEty.class);
|
|
|
|
|
- tryMakeMoneyAdp.add(RecyleObj.make(RecyleType.RUN_TASK, taskAcceptedEty),position);
|
|
|
|
|
- tryMakeMoneyAdp.addPresenter(presenter);
|
|
|
|
|
- tryMakeMoneyAdp.setTaskAcceptedEty(taskAcceptedEty);
|
|
|
|
|
- position ++;
|
|
|
|
|
-// mhandler.sendEmptyMessage(0);
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- mhandler.sendEmptyMessage(0);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void failReturnTask2View(Object o) {
|
|
|
|
|
- hideProgress();
|
|
|
|
|
- try {
|
|
|
|
|
- BaseMessage baseMessage = (BaseMessage) o;
|
|
|
|
|
- switch (baseMessage.getCode()){
|
|
|
|
|
- case 300://未查询到正在运行的任务
|
|
|
|
|
-// G.showToast(" 未查询到正在运行的任务!");
|
|
|
|
|
- break;
|
|
|
|
|
- default:
|
|
|
|
|
- G.showToast(" 网络错误!");
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- G.showToast(" 网络错误!");
|
|
|
|
|
- }
|
|
|
|
|
- mhandler.sendEmptyMessage(0);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取已经发布任务
|
|
|
|
|
- * @param o
|
|
|
|
|
- */
|
|
|
|
|
- @Override
|
|
|
|
|
- public void releaseTaskTaskUpdataView(Object o) {
|
|
|
|
|
- releaseEtyLists.clear();
|
|
|
|
|
- try{
|
|
|
|
|
- BaseMessage baseMessage = (BaseMessage) o;
|
|
|
|
|
- List<TaskReleaseEty> releaseEtyList = JSONArray.parseArray(JSONArray.toJSONString(baseMessage.getData()), TaskReleaseEty.class);
|
|
|
|
|
- if(releaseEtyList != null){
|
|
|
|
|
- releaseEtyLists.addAll(releaseEtyList);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-// mhandler.sendEmptyMessage(0);
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- presenter.returnTask(null);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void failReleaseTask2View(Object o) {
|
|
|
|
|
-
|
|
|
|
|
- presenter.returnTask(null);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Subscribe
|
|
@Subscribe
|
|
|
- public void onEventMainThread(BigEvent event){
|
|
|
|
|
- switch (event.getEventTypes()){
|
|
|
|
|
|
|
+ public void onEventMainThread(BigEvent event) {
|
|
|
|
|
+ switch (event.getEventTypes()) {
|
|
|
case ONFRESH_TRYMAKEMANY_PAGE:
|
|
case ONFRESH_TRYMAKEMANY_PAGE:
|
|
|
initData();
|
|
initData();
|
|
|
break;
|
|
break;
|
|
@@ -262,46 +66,16 @@ public class TryMakeMoneyact extends BaseActivity implements TryMakeMoneyContrac
|
|
|
|
|
|
|
|
EventBus.getDefault().unregister(this);
|
|
EventBus.getDefault().unregister(this);
|
|
|
}
|
|
}
|
|
|
- /**
|
|
|
|
|
- * 滚动到顶部
|
|
|
|
|
- */
|
|
|
|
|
- private boolean move;
|
|
|
|
|
- private String string = "0";
|
|
|
|
|
- private void goTop(){
|
|
|
|
|
- final LinearLayoutManager manager = (LinearLayoutManager) recyclerview.getLayoutManager();
|
|
|
|
|
- int fir = manager.findFirstVisibleItemPosition();
|
|
|
|
|
- int end = manager.findLastVisibleItemPosition();
|
|
|
|
|
- final int p = Integer.parseInt(string);
|
|
|
|
|
- if (p <= fir) {
|
|
|
|
|
- recyclerview.scrollToPosition(p);
|
|
|
|
|
- } else if (p <= end) {
|
|
|
|
|
- int top = recyclerview.getChildAt(p - fir).getTop();
|
|
|
|
|
- recyclerview.scrollBy(0, top);
|
|
|
|
|
- } else {
|
|
|
|
|
- recyclerview.scrollToPosition(p); //先让当前view滚动到列表内
|
|
|
|
|
- move = true;
|
|
|
|
|
- }
|
|
|
|
|
- recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener()
|
|
|
|
|
- {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
|
- super.onScrolled(recyclerView, dx, dy);
|
|
|
|
|
- if (move) {
|
|
|
|
|
- move = false;
|
|
|
|
|
- int n = p - manager.findFirstVisibleItemPosition();
|
|
|
|
|
- if (n >= 0 && n < recyclerView.getChildCount()) {
|
|
|
|
|
- recyclerView.scrollBy(0, recyclerView.getChildAt(n).getTop()); //滚动到顶部
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void onStop() {
|
|
protected void onStop() {
|
|
|
super.onStop();
|
|
super.onStop();
|
|
|
- if(tryMakeMoneyAdp != null){
|
|
|
|
|
- tryMakeMoneyAdp.cancelAllTimers();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
|
|
+ // TODO: add setContentView(...) invocation
|
|
|
|
|
+ ButterKnife.bind(this);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|