直播任务对接接口

This commit is contained in:
zlzw 2023-02-20 17:16:37 +08:00
parent 1d66a9b7fb
commit cca8f43f61
10 changed files with 357 additions and 90 deletions

View File

@ -1,17 +1,23 @@
package com.yunbao.common.bean;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.List;
public class LiveTaskModel extends BaseModel {
public static final int TASK_TYPE_TIP=0;
public static final int TASK_TYPE_ITEM=1;
public static final int TASK_TYPE_TIP = 0;
public static final int TASK_TYPE_ITEM = 1;
int type;
String title;
int hot;
int xp;
int taskTarget;
int task;
boolean complete;
@SerializedName("new")
NewUser user;
@SerializedName("list")
List<List<Task>> list;
public LiveTaskModel() {
}
public int getType() {
return type;
@ -21,51 +27,205 @@ public class LiveTaskModel extends BaseModel {
this.type = type;
}
public String getTitle() {
return title;
public NewUser getUser() {
return user;
}
public void setTitle(String title) {
this.title = title;
public void setUser(NewUser user) {
this.user = user;
}
public int getHot() {
public List<List<Task>> getList() {
return list;
}
public void setList(List<List<Task>> list) {
this.list = list;
}
@Override
public String toString() {
return "LiveTaskModel{" +
"type=" + type +
", user=" + user +
", list=" + list +
'}';
}
public static class NewUser {
@SerializedName("isNew")
private int isNew;
@SerializedName("endTime")
private String endTime;
public NewUser() {
}
public boolean isNew() {
return isNew == 1;
}
public void setNew(int aNew) {
isNew = aNew;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
@Override
public String toString() {
return "NewUser{" +
"isNew=" + isNew +
", endTime='" + endTime + '\'' +
'}';
}
}
public static class Task implements Serializable {
@SerializedName("id")
private int id;
@SerializedName("type")
private int type;
@SerializedName("task_type")
private int taskType;
@SerializedName("task_name")
private String taskName;
@SerializedName("task_num")
private int taskNum;
@SerializedName("hot")
private long hot;
@SerializedName("exp")
private long exp;
@SerializedName("new_hot")
private long newUserHot;
@SerializedName("new_exp")
private long newUserExp;
@SerializedName("sort")
private int sort;
@SerializedName("status")
private int status;
private int nowValue;
public Task() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getTaskType() {
return taskType;
}
public void setTaskType(int taskType) {
this.taskType = taskType;
}
public String getTaskName() {
return taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName;
}
public int getTaskNum() {
return taskNum;
}
public void setTaskNum(int taskNum) {
this.taskNum = taskNum;
}
public long getHot() {
return hot;
}
public void setHot(int hot) {
public void setHot(long hot) {
this.hot = hot;
}
public int getXp() {
return xp;
public long getExp() {
return exp;
}
public void setXp(int xp) {
this.xp = xp;
public void setExp(long exp) {
this.exp = exp;
}
public int getTaskTarget() {
return taskTarget;
public long getNewUserHot() {
return newUserHot;
}
public void setTaskTarget(int taskTarget) {
this.taskTarget = taskTarget;
public void setNewUserHot(long newUserHot) {
this.newUserHot = newUserHot;
}
public int getTask() {
return task;
public long getNewUserExp() {
return newUserExp;
}
public void setTask(int task) {
this.task = task;
public void setNewUserExp(long newUserExp) {
this.newUserExp = newUserExp;
}
public boolean isComplete() {
return complete;
public int getSort() {
return sort;
}
public void setComplete(boolean complete) {
this.complete = complete;
public void setSort(int sort) {
this.sort = sort;
}
public boolean getStatus() {
return status==1;
}
public void setStatus(int status) {
this.status = status;
}
public int getNowValue() {
return nowValue;
}
public void setNowValue(int nowValue) {
this.nowValue = nowValue;
}
@Override
public String toString() {
return "Task{" +
"id=" + id +
", type=" + type +
", taskType=" + taskType +
", taskName='" + taskName + '\'' +
", taskNum=" + taskNum +
", hot=" + hot +
", exp=" + exp +
", newUserHot=" + newUserHot +
", newUserExp=" + newUserExp +
", sort=" + sort +
", status=" + status +
'}';
}
}
}

View File

@ -17,6 +17,7 @@ import com.yunbao.common.bean.LiveAiRobotBean;
import com.yunbao.common.bean.LiveInfoModel;
import com.yunbao.common.bean.LiveRoomActivityBanner;
import com.yunbao.common.bean.LiveStetUpStatusModel;
import com.yunbao.common.bean.LiveTaskModel;
import com.yunbao.common.bean.MsgSwitchDetailModel;
import com.yunbao.common.bean.NewPeopleInfo;
import com.yunbao.common.bean.NobleRankHideUserListModel;
@ -548,4 +549,13 @@ public interface PDLiveApi {
Observable<ResponseModel<List<ListInfoMessageModel>>> getListInfo(
@Query("type") String type,
@Query("p") int p);
/**
* 获取主播任务列表
*/
@GET("/api/public/?service=Live.getLiveTaskStatus")
Observable<ResponseModel<LiveTaskModel>> getLiveTaskList(
@Query("type") int type,
@Query("liveuid") String liveUid
);
}

View File

@ -19,6 +19,7 @@ import com.yunbao.common.bean.LiveAiRobotBean;
import com.yunbao.common.bean.LiveInfoModel;
import com.yunbao.common.bean.LiveRoomActivityBanner;
import com.yunbao.common.bean.LiveStetUpStatusModel;
import com.yunbao.common.bean.LiveTaskModel;
import com.yunbao.common.bean.NobleRankHideUserListModel;
import com.yunbao.common.bean.NobleTrumpetModel;
import com.yunbao.common.bean.PkRankBean;
@ -1088,6 +1089,22 @@ public class LiveNetManager {
}).isDisposed();
}
/**
* 获取直播任务
* @param type 1 直播任务 2粉丝任务
*/
public void getLiveTask(int type, String liveUid, HttpCallback<LiveTaskModel> callback) {
API.get().pdLiveApi(mContext)
.getLiveTaskList(type, liveUid)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(listResponseModel -> {
callback.onSuccess(listResponseModel.getData().getInfo());
}, throwable -> {
callback.onError(throwable.getMessage());
}).isDisposed();
}
/**
* 直播间取消网络请求
*/

View File

@ -673,6 +673,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
}
bundle.putBoolean(Constants.HAS_GAME, hasGame);
bundle.putInt("leave", leave);
bundle.putString("liveUid", mLiveUid);
bundle.putBoolean("isPk", isDRPK == 1 || PKing || mLivePushViewHolder.isPking());
bundle.putLong("liveTime", mLiveAnchorViewHolder.getmAnchorLiveTime());
bundle.putBoolean(Constants.OPEN_FLASH, mLivePushViewHolder != null && mLivePushViewHolder.isFlashOpen());
@ -938,9 +939,11 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
if (code == 0) {
JSONObject obj = JSON.parseObject(info[0]);
JSONObject datas = obj.getJSONObject("data");
try {
SocketRyChatUtil.closeLive(datas.getString("votes"), datas.getString("length"), datas.getString("nums"), mLiveUid, mSocketRyClient);
} catch (Exception e) {
e.printStackTrace();
}
if (mLiveEndViewHolder == null) {
mLiveEndViewHolder = new LiveEndViewHolder(mContext, mRoot, mLiveBean.getUid());

View File

@ -18,18 +18,19 @@ import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.live.R;
import java.util.ArrayList;
import java.util.List;
public class LiveTaskRecyclerAdapter extends RecyclerView.Adapter<LiveTaskRecyclerAdapter.TaskHolder> {
private Context mContext;
private List<LiveTaskModel> tasks;
private List<LiveTaskModel.Task> tasks = new ArrayList<>();
public LiveTaskRecyclerAdapter(Context mContext) {
this.mContext = mContext;
}
public void setTasks(List<LiveTaskModel> tasks) {
public void setTasks(List<LiveTaskModel.Task> tasks) {
this.tasks = tasks;
notifyDataSetChanged();
}
@ -91,15 +92,26 @@ public class LiveTaskRecyclerAdapter extends RecyclerView.Adapter<LiveTaskRecycl
}
}
public void setDate(LiveTaskModel task) {
title.setText(task.getTitle());
public void setDate(LiveTaskModel.Task task) {
title.setText(task.getTaskName());
if (task.getType() == LiveTaskModel.TASK_TYPE_TIP) {
return;
}
complete.setText(task.isComplete() ? R.string.live_task_item_complete_true : R.string.live_task_item_complete_false);
complete.setBackgroundResource(task.isComplete() ? R.drawable.background_6cbe53 : R.drawable.background_595959);
hot.setText(Html.fromHtml("<font color='#B3B3B3'>"+ WordUtil.getString(R.string.live_task_item_hot) +"</font>&nbsp&nbsp<font color='#F09FC2'>" + task.getHot() + "</font>"));
xp.setText(Html.fromHtml("<font color='#B3B3B3'>"+WordUtil.getString(R.string.live_task_item_xp)+"</font>&nbsp&nbsp<font color='#FFF69F'>" + task.getXp() + "</font>"));
if (task.getStatus() || task.getNowValue() >= task.getTaskNum()) {
task.setNowValue(task.getTaskNum());
}
title.setText(String.format("%s (%s/%s)",
task.getTaskName(),
task.getNowValue(),
task.getTaskNum())
);
if (task.getNowValue() == task.getTaskNum()) {
task.setStatus(1);
}
complete.setText(task.getStatus() ? R.string.live_task_item_complete_true : R.string.live_task_item_complete_false);
complete.setBackgroundResource(task.getStatus() ? R.drawable.background_6cbe53 : R.drawable.background_595959);
hot.setText(Html.fromHtml("<font color='#B3B3B3'>" + WordUtil.getString(R.string.live_task_item_hot) + "</font>&nbsp&nbsp<font color='#F09FC2'>" + task.getHot() + "</font>"));
xp.setText(Html.fromHtml("<font color='#B3B3B3'>" + WordUtil.getString(R.string.live_task_item_xp) + "</font>&nbsp&nbsp<font color='#FFF69F'>" + task.getExp() + "</font>"));
}
}
}

View File

@ -46,6 +46,8 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements
private boolean isPk;
private TextView mLiveTimeTextView;//主播的直播时长
private String liveUid;
// boolean isRy = false;
@Override
protected int getLayoutId() {
@ -86,6 +88,7 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements
isPk = bundle.getBoolean("isPk", false);
// isRy = bundle.getBoolean("isRy", false);
mAnchorLiveTime = bundle.getLong("liveTime");
liveUid = bundle.getString("liveUid");
}
mWishView = findViewById(R.id.live_tool_wish);
mPrankView = findViewById(R.id.live_tool_prank);
@ -182,13 +185,18 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements
dismiss();
} else if (id == R.id.anchor_task) {
//主播任务
new LiveTaskDialog(mContext).showDialog();
taskDialog = new LiveTaskDialog(mContext);
taskDialog.setLiveUid(liveUid);
taskDialog.updateLiveTimer(mAnchorLiveTime);
taskDialog.showDialog();
}
}
private final int WHAT_ANCHOR_LIVE_TIME = 3;//直播间主播计时
private LiveRoomHandler mLiveRoomHandler;
private long mAnchorLiveTime;//主播直播时间
private LiveTaskDialog taskDialog;
/**
* 主播显示直播时间

View File

@ -2,6 +2,7 @@ package com.yunbao.live.dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -22,6 +23,9 @@ import com.google.android.material.tabs.TabLayoutMediator;
import com.lxj.xpopup.XPopup;
import com.yunbao.common.bean.LiveTaskModel;
import com.yunbao.common.dialog.AbsDialogPopupWindow;
import com.yunbao.common.http.base.HttpCallback;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.live.R;
import com.yunbao.live.adapter.LiveTaskRecyclerAdapter;
@ -46,11 +50,12 @@ public class LiveTaskDialog extends AbsDialogPopupWindow {
private Context mContext;
String liveUid;
int liveTimer;
public LiveTaskDialog(Context context) {
super(context);
this.mContext = context;
}
@Override
@ -69,6 +74,9 @@ public class LiveTaskDialog extends AbsDialogPopupWindow {
initView();
}
public void setLiveUid(String liveUid) {
this.liveUid = liveUid;
}
private void initView() {
newStarTime = findViewById(R.id.task_new_star_time);
@ -77,11 +85,8 @@ public class LiveTaskDialog extends AbsDialogPopupWindow {
tipImg = findViewById(R.id.live_task_tip);
tabLayout = findViewById(R.id.live_task_menu);
viewPager = findViewById(R.id.live_task_viewpager);
newStarTime.setText("新秀主播時效截止至 2023/1/01 12:00");
initImgView();
initTabLayout();
createTask();
}
@ -112,7 +117,9 @@ public class LiveTaskDialog extends AbsDialogPopupWindow {
public Fragment createFragment(int position) {
TaskFragment fragment = new TaskFragment();
Bundle bundle = new Bundle();
bundle.putInt("position", position);
bundle.putInt("position", position + 1);
bundle.putInt("liveTimer", liveTimer);
bundle.putString("liveUid", liveUid);
fragment.setArguments(bundle);
return fragment;
}
@ -133,12 +140,47 @@ public class LiveTaskDialog extends AbsDialogPopupWindow {
mediator.attach();
}
private void updateMainUi(LiveTaskModel.NewUser task) {
if (task.isNew()) {
newStarImg.setVisibility(VISIBLE);
newStarTime.setVisibility(VISIBLE);
newStarTime.setText(task.getEndTime());
}
}
private void createTask() {
LiveNetManager.get(getContext())
.getLiveTask(1, liveUid, new HttpCallback<LiveTaskModel>() {
@Override
public void onSuccess(LiveTaskModel data) {
Log.i("直播任务", "onSuccess: " + data);
updateMainUi(data.getUser());
initTabLayout();
}
@Override
public void onError(String error) {
Log.e("直播任务", "onError: " + error);
}
});
}
public void updateLiveTimer(long time) {
liveTimer = (int) ((time % (1000 * 60 * 60)) / (1000 * 60));
/*TaskFragment fragment = (TaskFragment) ((AppCompatActivity) mContext).getSupportFragmentManager().findFragmentByTag("f0");
if (fragment != null) {
fragment.adapter.updateTimer(liveTimer);
}*/
}
public static class TaskFragment extends Fragment {
private RecyclerView taskList;
private LiveTaskRecyclerAdapter adapter;
private List<LiveTaskModel> tasks;
private int position;
private int liveTimer;
private String liveUid;
@Nullable
@Override
@ -150,9 +192,11 @@ public class LiveTaskDialog extends AbsDialogPopupWindow {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
this.position = getArguments().getInt("position", -1);
this.liveTimer = getArguments().getInt("liveTimer", -1);
this.liveUid = getArguments().getString("liveUid", "0");
taskList = (RecyclerView) view;
initTaskList();
createTask();
createTask(position);
}
private void initTaskList() {
@ -161,39 +205,45 @@ public class LiveTaskDialog extends AbsDialogPopupWindow {
taskList.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false));
}
private void createTask() {
tasks = new ArrayList<>();
for (int i = 0; i < 4; i++) {
LiveTaskModel model = new LiveTaskModel();
if (i == 0) {
model.setType(LiveTaskModel.TASK_TYPE_TIP);
model.setTitle(WordUtil.getString(R.string.live_task_no1));
} else {
model.setType(LiveTaskModel.TASK_TYPE_ITEM);
model.setTitle("开播测试标题");
}
model.setTask(30);
model.setXp(3000);
model.setHot(5000);
tasks.add(model);
private void createTask(int type) {
LiveNetManager.get(getContext())
.getLiveTask(type, liveUid, new HttpCallback<LiveTaskModel>() {
boolean debug = true;
}
for (int i = 0; i < 4; i++) {
LiveTaskModel model = new LiveTaskModel();
if (i == 0) {
model.setType(LiveTaskModel.TASK_TYPE_TIP);
model.setTitle(WordUtil.getString(R.string.live_task_no2));
@Override
public void onSuccess(LiveTaskModel data) {
Log.i("直播任务", "onSuccess: " + data);
LiveTaskModel.Task task = new LiveTaskModel.Task();
LiveTaskModel.Task task2 = new LiveTaskModel.Task();
if (type == 1) {
task.setTaskName(WordUtil.getString(R.string.live_task_no1));
task2.setTaskName(WordUtil.getString(R.string.live_task_no2));
} else {
model.setType(LiveTaskModel.TASK_TYPE_ITEM);
model.setTitle("PK测试标题");
task.setTaskName(WordUtil.getString(R.string.live_task_fans_no1));
task2.setTaskName(WordUtil.getString(R.string.live_task_fans_no2));
}
task.setType(LiveTaskModel.TASK_TYPE_TIP);
task2.setType(LiveTaskModel.TASK_TYPE_TIP);
List<LiveTaskModel.Task> task1 = new ArrayList<>();
task1.add(task);
task1.addAll(data.getList().get(0));
if (type == 1) {
for (LiveTaskModel.Task tk : task1) {
tk.setNowValue(liveTimer);
}
task1.get(1).setTaskNum(3);
task1.get(1).setTaskName("*" + task1.get(1).getTaskName());
}
task1.add(task2);
task1.addAll(data.getList().get(1));
adapter.setTasks(task1);
}
model.setTask(30);
model.setXp(3000);
model.setHot(5000);
tasks.add(model);
@Override
public void onError(String error) {
Log.e("直播任务", "onError: " + error);
}
adapter.setTasks(tasks);
});
}
}

View File

@ -23,10 +23,11 @@
android:id="@+id/task_new_star_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="14dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="14dp"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -37,6 +38,7 @@
android:layout_marginTop="5dp"
android:paddingTop="5dp"
android:scaleType="centerCrop"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/task_new_star_time"
@ -78,6 +80,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/live_task_banner2"
tools:srcCompat="@mipmap/icon_guize" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/live_task_viewpager"
android:layout_width="0dp"
@ -85,7 +88,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/live_task_menu"/>
app:layout_constraintTop_toBottomOf="@+id/live_task_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -20,6 +20,8 @@
<string name="live_mic_max">The number of voices has reached 3, and no more can be added.</string>
<string name="live_task_no1">當日連續開播時長(分鐘)</string>
<string name="live_task_no2">當日累計PK次數(不限模式)</string>
<string name="live_task_fans_no1">當日累積新增關註粉絲</string>
<string name="live_task_fans_no2">當日累積新增粉絲團成員</string>
<string name="live_task_tab1">直播互動</string>
<string name="live_task_tab2">粉絲增漲</string>
<string name="live_task_info_title">主播任務特別說明</string>

View File

@ -51,6 +51,8 @@
<string name="free_pk_num_null" translatable="false">PK次數已用完</string>
<string name="live_task_no1">當日連續開播時長(分鐘)</string>
<string name="live_task_no2">當日累計PK次數(不限模式)</string>
<string name="live_task_fans_no1">當日累積新增關註粉絲</string>
<string name="live_task_fans_no2">當日累積新增粉絲團成員</string>
<string name="live_task_tab1">直播互動</string>
<string name="live_task_tab2">粉絲增漲</string>
<string name="live_task_info_title">主播任務特別說明</string>