diff --git a/common/src/main/java/com/yunbao/common/bean/LiveTaskModel.java b/common/src/main/java/com/yunbao/common/bean/LiveTaskModel.java index b159fcad1..1ead7dd8c 100644 --- a/common/src/main/java/com/yunbao/common/bean/LiveTaskModel.java +++ b/common/src/main/java/com/yunbao/common/bean/LiveTaskModel.java @@ -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; + + 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() { - return hot; + public List> getList() { + return list; } - public void setHot(int hot) { - this.hot = hot; + public void setList(List> list) { + this.list = list; } - public int getXp() { - return xp; + @Override + public String toString() { + return "LiveTaskModel{" + + "type=" + type + + ", user=" + user + + ", list=" + list + + '}'; } - public void setXp(int xp) { - this.xp = xp; + 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 int getTaskTarget() { - return taskTarget; - } + 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; - public void setTaskTarget(int taskTarget) { - this.taskTarget = taskTarget; - } + private int nowValue; - public int getTask() { - return task; - } + public Task() { + } - public void setTask(int task) { - this.task = task; - } + public int getId() { + return id; + } - public boolean isComplete() { - return complete; - } + public void setId(int id) { + this.id = id; + } - public void setComplete(boolean complete) { - this.complete = complete; + 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(long hot) { + this.hot = hot; + } + + public long getExp() { + return exp; + } + + public void setExp(long exp) { + this.exp = exp; + } + + public long getNewUserHot() { + return newUserHot; + } + + public void setNewUserHot(long newUserHot) { + this.newUserHot = newUserHot; + } + + public long getNewUserExp() { + return newUserExp; + } + + public void setNewUserExp(long newUserExp) { + this.newUserExp = newUserExp; + } + + public int getSort() { + return sort; + } + + 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 + + '}'; + } } } 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 fc686a611..f90f9e761 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -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>> getListInfo( @Query("type") String type, @Query("p") int p); + + /** + * 获取主播任务列表 + */ + @GET("/api/public/?service=Live.getLiveTaskStatus") + Observable> getLiveTaskList( + @Query("type") int type, + @Query("liveuid") String liveUid + ); } 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 fcdcbb48f..1bb664ab2 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 @@ -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 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(); + } + /** * 直播间取消网络请求 */ diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 9ea7f5961..9b031e2c4 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -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"); - - SocketRyChatUtil.closeLive(datas.getString("votes"), datas.getString("length"), datas.getString("nums"), mLiveUid, mSocketRyClient); - + 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()); diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveTaskRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveTaskRecyclerAdapter.java index c9d1d4ac2..86b1408b8 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveTaskRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveTaskRecyclerAdapter.java @@ -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 { private Context mContext; - private List tasks; + private List tasks = new ArrayList<>(); public LiveTaskRecyclerAdapter(Context mContext) { this.mContext = mContext; } - public void setTasks(List tasks) { + public void setTasks(List tasks) { this.tasks = tasks; notifyDataSetChanged(); } @@ -91,15 +92,26 @@ public class LiveTaskRecyclerAdapter extends RecyclerView.Adapter"+ WordUtil.getString(R.string.live_task_item_hot) +"  " + task.getHot() + "")); - xp.setText(Html.fromHtml(""+WordUtil.getString(R.string.live_task_item_xp)+"  " + task.getXp() + "")); + 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("" + WordUtil.getString(R.string.live_task_item_hot) + "  " + task.getHot() + "")); + xp.setText(Html.fromHtml("" + WordUtil.getString(R.string.live_task_item_xp) + "  " + task.getExp() + "")); } } } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java index f28434947..bf647b326 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java @@ -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; /** * 主播显示直播时间 diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveTaskDialog.java b/live/src/main/java/com/yunbao/live/dialog/LiveTaskDialog.java index f044839df..34354c5b9 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveTaskDialog.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveTaskDialog.java @@ -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() { + @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 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() { + 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)); - } else { - model.setType(LiveTaskModel.TASK_TYPE_ITEM); - model.setTitle("PK测试标题"); - } - model.setTask(30); - model.setXp(3000); - model.setHot(5000); - tasks.add(model); + @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 { + 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 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); + } - } - adapter.setTasks(tasks); + @Override + public void onError(String error) { + Log.e("直播任务", "onError: " + error); + } + }); } } diff --git a/live/src/main/res/layout/dialog_live_task.xml b/live/src/main/res/layout/dialog_live_task.xml index 02e632c14..c32f64b03 100644 --- a/live/src/main/res/layout/dialog_live_task.xml +++ b/live/src/main/res/layout/dialog_live_task.xml @@ -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" /> + + app:layout_constraintTop_toBottomOf="@+id/live_task_menu" /> \ No newline at end of file diff --git a/live/src/main/res/values-en/strings.xml b/live/src/main/res/values-en/strings.xml index eb96a0f00..9c055f285 100644 --- a/live/src/main/res/values-en/strings.xml +++ b/live/src/main/res/values-en/strings.xml @@ -20,6 +20,8 @@ The number of voices has reached 3, and no more can be added. 當日連續開播時長(分鐘) 當日累計PK次數(不限模式) + 當日累積新增關註粉絲 + 當日累積新增粉絲團成員 直播互動 粉絲增漲 主播任務特別說明 diff --git a/live/src/main/res/values/strings.xml b/live/src/main/res/values/strings.xml index 981f1095a..8e5e42cf3 100644 --- a/live/src/main/res/values/strings.xml +++ b/live/src/main/res/values/strings.xml @@ -51,6 +51,8 @@ PK次數已用完 當日連續開播時長(分鐘) 當日累計PK次數(不限模式) + 當日累積新增關註粉絲 + 當日累積新增粉絲團成員 直播互動 粉絲增漲 主播任務特別說明