diff --git a/common/src/main/java/com/yunbao/common/adapter/DrawerTaskAdapter.java b/common/src/main/java/com/yunbao/common/adapter/DrawerTaskAdapter.java index 60085cc5f..b5954d649 100644 --- a/common/src/main/java/com/yunbao/common/adapter/DrawerTaskAdapter.java +++ b/common/src/main/java/com/yunbao/common/adapter/DrawerTaskAdapter.java @@ -33,7 +33,16 @@ public class DrawerTaskAdapter extends RecyclerView.Adapter { @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { DrawerTaskChildViewHolder taskChildViewHolder = (DrawerTaskChildViewHolder) holder; - taskChildViewHolder.setData(child.get(position)); + taskChildViewHolder.setData(child.get(position), position); + taskChildViewHolder.setListener(new DrawerTaskChildViewHolder.DrawerTaskChildListener() { + @Override + public void giftSuccess(CustomSidebarChildModel model, int index) { + //将领取的任务移动至任务列表尾部 + child.remove(index); + child.add(child.size() - 1, model); + notifyDataSetChanged(); + } + }); } @Override diff --git a/common/src/main/java/com/yunbao/common/bean/CustomSidebarChildModel.java b/common/src/main/java/com/yunbao/common/bean/CustomSidebarChildModel.java index cd1d238ea..e4cb4fc15 100644 --- a/common/src/main/java/com/yunbao/common/bean/CustomSidebarChildModel.java +++ b/common/src/main/java/com/yunbao/common/bean/CustomSidebarChildModel.java @@ -30,6 +30,17 @@ public class CustomSidebarChildModel extends BaseModel { private String nowNum; @SerializedName("activity_id") private String activityId; + @SerializedName("flag") + private String flag; + + public String getFlag() { + return flag; + } + + public CustomSidebarChildModel setFlag(String flag) { + this.flag = flag; + return this; + } public String getActivityId() { return activityId; diff --git a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java index 5e71880e0..0b42fddcd 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -256,4 +256,10 @@ public interface PDLiveApi { */ @GET("/api/public/?service=Live.getCustomSidebarInfo") Observable>> getCustomSidebarInfo(); + + /** + * 任务领取接口 + */ + @GET("/api/public/?service=Task.sendTaskGift") + Observable> sendTaskGift(@Query("flag") String flag, @Query("type") String type); } diff --git a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java index bc4913516..4083c7650 100644 --- a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java @@ -15,10 +15,12 @@ import com.yunbao.common.bean.SetAttentsModel; import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.VipModel; import com.yunbao.common.http.API; +import com.yunbao.common.http.ResponseModel; import com.yunbao.common.http.base.HttpCallback; import java.util.List; +import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; @@ -271,4 +273,22 @@ public class LiveNetManager { throwable.printStackTrace(); }).isDisposed(); } + + /** + * 任务领取接口 + */ + public void sendTaskGift(String flag, HttpCallback callback) { + + API.get().pdLiveApi(mContext) + .sendTaskGift(flag, "2") + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(observableResponseModel -> { + if (observableResponseModel.getData().getCode() == 0) { + callback.onSuccess(""); + } else { + callback.onError(observableResponseModel.getData().getMsg()); + } + }, throwable -> callback.onError(throwable.getMessage())).isDisposed(); + } } diff --git a/common/src/main/java/com/yunbao/common/views/DrawerTaskChildViewHolder.java b/common/src/main/java/com/yunbao/common/views/DrawerTaskChildViewHolder.java index 24c8f6134..87e60bd2f 100644 --- a/common/src/main/java/com/yunbao/common/views/DrawerTaskChildViewHolder.java +++ b/common/src/main/java/com/yunbao/common/views/DrawerTaskChildViewHolder.java @@ -15,6 +15,8 @@ import com.yunbao.common.R; import com.yunbao.common.bean.CustomSidebarChildModel; import com.yunbao.common.event.CustomDrawerPopupEvent; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.views.weight.ViewClicksAntiShake; @@ -35,7 +37,7 @@ public class DrawerTaskChildViewHolder extends RecyclerView.ViewHolder { toReceiveLayout = itemView.findViewById(R.id.to_receive_layout); } - public void setData(CustomSidebarChildModel model) { + public void setData(CustomSidebarChildModel model, int index) { ImgLoader.display2(itemView.getContext(), model.getIcon(), icon); StringBuffer titleBuffer = new StringBuffer(); titleBuffer @@ -70,9 +72,33 @@ public class DrawerTaskChildViewHolder extends RecyclerView.ViewHolder { .setDisMiss(true)); if (TextUtils.equals(model.getStatus(), "2")) { - ToastUtil.show("敬请期待"); + LiveNetManager.get(itemView.getContext()) + .sendTaskGift(model.getFlag(), new HttpCallback() { + @Override + public void onSuccess(String data) { + if (listener != null) { + listener.giftSuccess(model, index); + } + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); } } }); } + + private DrawerTaskChildListener listener; + + public DrawerTaskChildViewHolder setListener(DrawerTaskChildListener listener) { + this.listener = listener; + return this; + } + + public interface DrawerTaskChildListener { + void giftSuccess(CustomSidebarChildModel model, int index); + } }