From b2f779f58a2c47b41208bd871e80f4f61abd8df5 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Sat, 18 Feb 2023 11:03:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=BB=E6=92=AD=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/dialog/AbsDialogPopupWindow.java | 6 ++ .../adapter/LiveDataInfoRecyclerAdapter.java | 66 +++++++++++++++++ .../yunbao/live/bean/LiveDataInfoModel.java | 33 +++++++++ .../live/dialog/LiveDataInfoDialog.java | 65 ++++++++++++++++ .../yunbao/live/dialog/LiveTaskDialog.java | 11 ++- .../live/dialog/LiveTaskInfoDialog.java | 8 +- live/src/main/res/layout/dialog_live_data.xml | 74 +++++++++++++++++++ live/src/main/res/layout/item_live_data.xml | 44 +++++++++++ .../yunbao/main/activity/TestActivity.java | 9 ++- 9 files changed, 304 insertions(+), 12 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/adapter/LiveDataInfoRecyclerAdapter.java create mode 100644 live/src/main/java/com/yunbao/live/bean/LiveDataInfoModel.java create mode 100644 live/src/main/java/com/yunbao/live/dialog/LiveDataInfoDialog.java create mode 100644 live/src/main/res/layout/dialog_live_data.xml create mode 100644 live/src/main/res/layout/item_live_data.xml diff --git a/common/src/main/java/com/yunbao/common/dialog/AbsDialogPopupWindow.java b/common/src/main/java/com/yunbao/common/dialog/AbsDialogPopupWindow.java index c1da205e2..150ca86e7 100644 --- a/common/src/main/java/com/yunbao/common/dialog/AbsDialogPopupWindow.java +++ b/common/src/main/java/com/yunbao/common/dialog/AbsDialogPopupWindow.java @@ -17,6 +17,12 @@ public abstract class AbsDialogPopupWindow extends BottomPopupView { } public abstract void buildDialog(XPopup.Builder builder); + public abstract int bindLayoutId(); + + @Override + protected int getImplLayoutId() { + return bindLayoutId(); + } public void showDialog() { XPopup.Builder builder = new XPopup.Builder(mContext); diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveDataInfoRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveDataInfoRecyclerAdapter.java new file mode 100644 index 000000000..0e58c2e75 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/adapter/LiveDataInfoRecyclerAdapter.java @@ -0,0 +1,66 @@ +package com.yunbao.live.adapter; + +import android.content.Context; +import android.text.Html; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.live.R; +import com.yunbao.live.bean.LiveDataInfoModel; + +import java.util.List; + +public class LiveDataInfoRecyclerAdapter extends RecyclerView.Adapter { + private Context mContext; + private List list; + + public LiveDataInfoRecyclerAdapter(Context mContext) { + this.mContext = mContext; + } + + public void setList(List list) { + this.list = list; + notifyDataSetChanged(); + } + + @NonNull + @Override + public LiveDataHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new LiveDataHolder(LayoutInflater.from(mContext).inflate(R.layout.item_live_data, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull LiveDataHolder holder, int position) { + holder.setData(list.get(position)); + } + + @Override + public int getItemCount() { + return list.size(); + } + + public static class LiveDataHolder extends RecyclerView.ViewHolder { + private TextView title, data; + + public LiveDataHolder(@NonNull View itemView) { + super(itemView); + title = itemView.findViewById(R.id.item_title); + data = itemView.findViewById(R.id.item_data); + } + + public void setData(LiveDataInfoModel model) { + if (model.getColor() != null) { + data.setText(Html.fromHtml("" + model.getData() + "")); + } else { + data.setText(model.getData()); + } + title.setText(model.getTitle()); + } + + } +} diff --git a/live/src/main/java/com/yunbao/live/bean/LiveDataInfoModel.java b/live/src/main/java/com/yunbao/live/bean/LiveDataInfoModel.java new file mode 100644 index 000000000..80f3f283a --- /dev/null +++ b/live/src/main/java/com/yunbao/live/bean/LiveDataInfoModel.java @@ -0,0 +1,33 @@ +package com.yunbao.live.bean; + +import com.yunbao.common.bean.BaseModel; + +public class LiveDataInfoModel extends BaseModel { + private String color; + private String title; + private String data; + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } +} diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveDataInfoDialog.java b/live/src/main/java/com/yunbao/live/dialog/LiveDataInfoDialog.java new file mode 100644 index 000000000..87392a0fb --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/LiveDataInfoDialog.java @@ -0,0 +1,65 @@ +package com.yunbao.live.dialog; + +import android.content.Context; +import android.widget.ImageView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.lxj.xpopup.XPopup; +import com.yunbao.common.dialog.AbsDialogPopupWindow; +import com.yunbao.live.R; +import com.yunbao.live.adapter.LiveDataInfoRecyclerAdapter; +import com.yunbao.live.bean.LiveDataInfoModel; + + +import java.util.ArrayList; +import java.util.List; + +public class LiveDataInfoDialog extends AbsDialogPopupWindow { + private ImageView img; + private RecyclerView recyclerView; + private LiveDataInfoRecyclerAdapter adapter; + private List list; + + public LiveDataInfoDialog(@NonNull Context context) { + super(context); + } + + + @Override + public void buildDialog(XPopup.Builder builder) { + } + + @Override + public int bindLayoutId() { + return R.layout.dialog_live_data; + } + + @Override + protected void onCreate() { + super.onCreate(); + img = findViewById(R.id.live_data_img); + img.setImageResource(R.mipmap.icon_free_pk_waring); + recyclerView = findViewById(R.id.live_data_list); + adapter = new LiveDataInfoRecyclerAdapter(getContext()); + recyclerView.setAdapter(adapter); + initData(); + } + + private void initData() { + list = new ArrayList<>(); + for (int i = 0; i < 8; i++) { + LiveDataInfoModel model = new LiveDataInfoModel(); + if (i == 0) { + model.setColor("#00FFFF"); + } else if (i == 1) { + model.setColor("#FFF69F"); + } + model.setTitle("标题:" + i); + model.setData("数据:" + i); + list.add(model); + } + adapter.setList(list); + } +} 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 50d4465f2..f044839df 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveTaskDialog.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveTaskDialog.java @@ -1,6 +1,5 @@ package com.yunbao.live.dialog; -import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; @@ -23,7 +22,6 @@ 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.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.adapter.LiveTaskRecyclerAdapter; @@ -60,16 +58,17 @@ public class LiveTaskDialog extends AbsDialogPopupWindow { builder.enableDrag(false); } + @Override + public int bindLayoutId() { + return R.layout.dialog_live_task; + } + @Override protected void onCreate() { super.onCreate(); initView(); } - @Override - protected int getImplLayoutId() { - return R.layout.dialog_live_task; - } private void initView() { newStarTime = findViewById(R.id.task_new_star_time); diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveTaskInfoDialog.java b/live/src/main/java/com/yunbao/live/dialog/LiveTaskInfoDialog.java index 6a83d645b..1b6423f49 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveTaskInfoDialog.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveTaskInfoDialog.java @@ -15,13 +15,13 @@ public class LiveTaskInfoDialog extends AbsDialogPopupWindow { } @Override - protected int getImplLayoutId() { - return R.layout.dialog_live_task_info; + public void buildDialog(XPopup.Builder builder) { + } @Override - public void buildDialog(XPopup.Builder builder) { - + public int bindLayoutId() { + return R.layout.dialog_live_task_info; } @Override diff --git a/live/src/main/res/layout/dialog_live_data.xml b/live/src/main/res/layout/dialog_live_data.xml new file mode 100644 index 000000000..ba1c8b8a1 --- /dev/null +++ b/live/src/main/res/layout/dialog_live_data.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/item_live_data.xml b/live/src/main/res/layout/item_live_data.xml new file mode 100644 index 000000000..f46e318f4 --- /dev/null +++ b/live/src/main/res/layout/item_live_data.xml @@ -0,0 +1,44 @@ + + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/java/com/yunbao/main/activity/TestActivity.java b/main/src/main/java/com/yunbao/main/activity/TestActivity.java index dcc14551c..e62419001 100644 --- a/main/src/main/java/com/yunbao/main/activity/TestActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/TestActivity.java @@ -14,6 +14,7 @@ import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import com.yunbao.common.utils.ToastUtil; +import com.yunbao.live.dialog.LiveDataInfoDialog; import com.yunbao.live.dialog.LiveTaskDialog; @@ -30,7 +31,8 @@ public class TestActivity extends AppCompatActivity { listView = new ListView(this); setContentView(listView); String[] strs = new String[]{ - "弹出主播任务" + "弹出主播任务", + "直播數據" }; listView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, strs)); @@ -39,7 +41,10 @@ public class TestActivity extends AppCompatActivity { public void onItemClick(AdapterView parent, View view, int position, long id) { switch (position) { case 0: - new LiveTaskDialog(TestActivity.this).showDialog(); + new LiveTaskDialog(TestActivity.this).showDialog(); + break; + case 1: + new LiveDataInfoDialog(TestActivity.this).showDialog(); break; }