Commit 028132f43d218831dcfa384a2fbfaa70dd866c44
1 parent
1863fd36a1
Exists in
master
MessageDialog
Showing
5 changed files
with
215 additions
and
2 deletions
 
Show diff stats
app/src/main/java/com/hjx/parent/StuHomeworkActivity.java
| ... | ... | @@ -8,13 +8,13 @@ import android.widget.PopupWindow; | 
| 8 | 8 | import androidx.lifecycle.MutableLiveData; | 
| 9 | 9 | |
| 10 | 10 | import com.google.gson.Gson; | 
| 11 | -import com.hjx.parent.adapter.HomeworkAdapter; | |
| 12 | 11 | import com.hjx.parent.adapter.HomeworkListAdapter; | 
| 13 | 12 | import com.hjx.parent.databinding.ActivityStudentHomeworkBinding; | 
| 14 | 13 | import com.hjx.parent.databinding.PopupFilterFeedbackBinding; | 
| 15 | 14 | import com.hjx.parent.databinding.PopupFilterGradeBinding; | 
| 16 | 15 | import com.hjx.parent.databinding.PopupFilterSubjectBinding; | 
| 17 | 16 | import com.hjx.parent.databinding.PopupFilterTermBinding; | 
| 17 | +import com.hjx.parent.dialog.MsgConfirmDialog; | |
| 18 | 18 | import com.hjx.parent.rx.BaseRxActivity; | 
| 19 | 19 | import com.prws.common.bean.Student; | 
| 20 | 20 | import com.prws.common.net.NetWorks; | 
| ... | ... | @@ -32,6 +32,7 @@ public class StuHomeworkActivity extends BaseRxActivity<ActivityStudentHomeworkB | 
| 32 | 32 | private final HomeworkListAdapter homeworkAdapter = new HomeworkListAdapter(); | 
| 33 | 33 | |
| 34 | 34 | PopupWindow subjectFilter, gradeFilter, termFilter, feedbackFilter; | 
| 35 | + MsgConfirmDialog deleteDialog; | |
| 35 | 36 | State state = new State(); | 
| 36 | 37 | |
| 37 | 38 | private void handlerIntent() { | 
| ... | ... | @@ -59,6 +60,19 @@ public class StuHomeworkActivity extends BaseRxActivity<ActivityStudentHomeworkB | 
| 59 | 60 | binding.ftGrade.setOnClickListener(v -> showGradeFilter()); | 
| 60 | 61 | binding.ftTerm.setOnClickListener(v -> showTermFilter()); | 
| 61 | 62 | binding.ftFeedback.setOnClickListener(v -> showFeedbackFilter()); | 
| 63 | + homeworkAdapter.deleteCall = data -> { | |
| 64 | + if (deleteDialog == null) { | |
| 65 | + deleteDialog = new MsgConfirmDialog.Builder(this) | |
| 66 | + .setMessage("确认要删除吗?一旦删除不可恢复") | |
| 67 | + .setPositive("暂不删除") | |
| 68 | + .setNegative("确定删除") | |
| 69 | + .build(); | |
| 70 | + } | |
| 71 | + deleteDialog.show(() -> { | |
| 72 | + // TODO Delete | |
| 73 | + return true; | |
| 74 | + }, null); | |
| 75 | + }; | |
| 62 | 76 | } | 
| 63 | 77 | |
| 64 | 78 | |
| ... | ... | @@ -95,7 +109,9 @@ public class StuHomeworkActivity extends BaseRxActivity<ActivityStudentHomeworkB | 
| 95 | 109 | .toList() | 
| 96 | 110 | .subscribe((data, th) -> { | 
| 97 | 111 | if (th != null) th.printStackTrace(); | 
| 98 | - Collections.sort(data); | |
| 112 | + if (data != null) { | |
| 113 | + Collections.sort(data); | |
| 114 | + } | |
| 99 | 115 | homeworkAdapter.setNewData(data); | 
| 100 | 116 | }); | 
| 101 | 117 | } | ... | ... | 
app/src/main/java/com/hjx/parent/adapter/HomeworkListAdapter.java
| ... | ... | @@ -8,10 +8,14 @@ import androidx.annotation.NonNull; | 
| 8 | 8 | import com.chad.library.adapter.base.BaseQuickAdapter; | 
| 9 | 9 | import com.chad.library.adapter.base.BaseViewHolder; | 
| 10 | 10 | import com.hjx.parent.R; | 
| 11 | +import com.hjx.parent.function.Function0; | |
| 12 | +import com.hjx.parent.function.Function1; | |
| 11 | 13 | import com.prws.common.bean.homework.HomeworkList; | 
| 12 | 14 | |
| 13 | 15 | public class HomeworkListAdapter extends BaseQuickAdapter<HomeworkList, BaseViewHolder> { | 
| 14 | 16 | |
| 17 | + public Function1<HomeworkList> deleteCall; | |
| 18 | + | |
| 15 | 19 | public HomeworkListAdapter() { | 
| 16 | 20 | super(R.layout.item_homework_list); | 
| 17 | 21 | } | 
| ... | ... | @@ -51,5 +55,15 @@ public class HomeworkListAdapter extends BaseQuickAdapter<HomeworkList, BaseView | 
| 51 | 55 | tvDate.setVisibility(View.GONE); | 
| 52 | 56 | } | 
| 53 | 57 | tvDate.setText(homework.getFormatTime()); | 
| 58 | + | |
| 59 | + View btnDelete = helper.getView(R.id.btnDelete); | |
| 60 | + btnDelete.setOnClickListener(v -> { | |
| 61 | + if (deleteCall != null) deleteCall.invoke(homework); | |
| 62 | + }); | |
| 63 | + | |
| 64 | + View btnDetail = helper.getView(R.id.btnDetail); | |
| 65 | + btnDetail.setOnClickListener(v -> { | |
| 66 | + // TODO | |
| 67 | + }); | |
| 54 | 68 | } | 
| 55 | 69 | } | ... | ... | 
app/src/main/java/com/hjx/parent/dialog/MsgConfirmDialog.java
| ... | ... | @@ -0,0 +1,104 @@ | 
| 1 | +package com.hjx.parent.dialog; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | + | |
| 5 | +import androidx.annotation.NonNull; | |
| 6 | + | |
| 7 | +import com.hjx.parent.databinding.DialogMessageConfirmBinding; | |
| 8 | +import com.hjx.parent.function.Function10; | |
| 9 | + | |
| 10 | +public class MsgConfirmDialog extends BaseDialog<DialogMessageConfirmBinding>{ | |
| 11 | + private CharSequence title, message, positive, negative; | |
| 12 | + private Function10<Boolean> positiveClick, negativeClick; | |
| 13 | + | |
| 14 | + private MsgConfirmDialog(Builder builder) { | |
| 15 | + super(builder.context); | |
| 16 | + title = builder.title; | |
| 17 | + message = builder.message; | |
| 18 | + positive = builder.positive; | |
| 19 | + negative = builder.negative; | |
| 20 | + positiveClick = builder.positiveClick; | |
| 21 | + negativeClick = builder.negativeClick; | |
| 22 | + } | |
| 23 | + | |
| 24 | + @Override | |
| 25 | + public void initView() { | |
| 26 | + binding.tvTitle.setText(title); | |
| 27 | + binding.tvMessage.setText(message); | |
| 28 | + binding.btnPositive.setText(positive); | |
| 29 | + binding.btnNegative.setText(negative); | |
| 30 | + binding.btnPositive.setOnClickListener(v -> { | |
| 31 | + if (positiveClick != null) { | |
| 32 | + if (positiveClick.invoke()) dismiss(); | |
| 33 | + } else { | |
| 34 | + dismiss(); | |
| 35 | + } | |
| 36 | + }); | |
| 37 | + binding.btnNegative.setOnClickListener(v -> { | |
| 38 | + if (negativeClick != null) { | |
| 39 | + if (negativeClick.invoke()) dismiss(); | |
| 40 | + } else { | |
| 41 | + dismiss(); | |
| 42 | + } | |
| 43 | + }); | |
| 44 | + } | |
| 45 | + | |
| 46 | + public void show(Function10<Boolean> positiveClick, Function10<Boolean> negativeClick) { | |
| 47 | + this.positiveClick = positiveClick; | |
| 48 | + this.negativeClick = negativeClick; | |
| 49 | + super.show(); | |
| 50 | + } | |
| 51 | + | |
| 52 | + @NonNull | |
| 53 | + @Override | |
| 54 | + public DialogMessageConfirmBinding getBinding() { | |
| 55 | + return DialogMessageConfirmBinding.inflate(getLayoutInflater()); | |
| 56 | + } | |
| 57 | + | |
| 58 | + public static class Builder { | |
| 59 | + public Builder(Context context) { | |
| 60 | + this.context = context; | |
| 61 | + } | |
| 62 | + private Context context; | |
| 63 | + private CharSequence title = "温馨提示"; | |
| 64 | + private CharSequence message = ""; | |
| 65 | + private CharSequence positive = "确定"; | |
| 66 | + private CharSequence negative = "取消"; | |
| 67 | + private Function10<Boolean> positiveClick = () -> true; | |
| 68 | + private Function10<Boolean> negativeClick = () -> true; | |
| 69 | + | |
| 70 | + public Builder setTitle(CharSequence title) { | |
| 71 | + this.title = title; | |
| 72 | + return this; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public Builder setMessage(CharSequence message) { | |
| 76 | + this.message = message; | |
| 77 | + return this; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public Builder setPositive(CharSequence positive) { | |
| 81 | + this.positive = positive; | |
| 82 | + return this; | |
| 83 | + } | |
| 84 | + | |
| 85 | + public Builder setNegative(CharSequence negative) { | |
| 86 | + this.negative = negative; | |
| 87 | + return this; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public Builder setPositiveClick(Function10<Boolean> positiveClick) { | |
| 91 | + this.positiveClick = positiveClick; | |
| 92 | + return this; | |
| 93 | + } | |
| 94 | + | |
| 95 | + public Builder setNegativeClick(Function10<Boolean> negativeClick) { | |
| 96 | + this.negativeClick = negativeClick; | |
| 97 | + return this; | |
| 98 | + } | |
| 99 | + | |
| 100 | + public MsgConfirmDialog build() { | |
| 101 | + return new MsgConfirmDialog(this); | |
| 102 | + } | |
| 103 | + } | |
| 104 | +} | ... | ... | 
app/src/main/res/layout/dialog_message_confirm.xml
| ... | ... | @@ -0,0 +1,77 @@ | 
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<FrameLayout | |
| 3 | + xmlns:android="http://schemas.android.com/apk/res/android" | |
| 4 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 5 | + xmlns:tools="http://schemas.android.com/tools" | |
| 6 | + android:layout_width="match_parent" | |
| 7 | + android:layout_height="match_parent"> | |
| 8 | + | |
| 9 | + <LinearLayout | |
| 10 | + android:orientation="vertical" | |
| 11 | + android:background="@drawable/shape_radius_10" | |
| 12 | + android:backgroundTint="@color/white" | |
| 13 | + android:layout_gravity="center" | |
| 14 | + android:layout_width="280dp" | |
| 15 | + android:layout_height="wrap_content"> | |
| 16 | + | |
| 17 | + <TextView | |
| 18 | + android:id="@+id/tvTitle" | |
| 19 | + tools:text="温馨提示" | |
| 20 | + android:textSize="18sp" | |
| 21 | + android:textColor="#333" | |
| 22 | + android:textStyle="bold" | |
| 23 | + android:layout_gravity="center_horizontal" | |
| 24 | + android:layout_marginTop="20dp" | |
| 25 | + android:layout_width="wrap_content" | |
| 26 | + android:layout_height="wrap_content"/> | |
| 27 | + | |
| 28 | + <TextView | |
| 29 | + android:id="@+id/tvMessage" | |
| 30 | + tools:text="确认要删除吗?一旦删除不可恢复" | |
| 31 | + android:textSize="14sp" | |
| 32 | + android:textColor="#333" | |
| 33 | + android:gravity="center" | |
| 34 | + android:layout_marginHorizontal="15dp" | |
| 35 | + android:layout_marginTop="16dp" | |
| 36 | + android:layout_width="match_parent" | |
| 37 | + android:layout_height="wrap_content"/> | |
| 38 | + <View | |
| 39 | + android:background="#EEE" | |
| 40 | + android:layout_marginHorizontal="10dp" | |
| 41 | + android:layout_marginTop="26dp" | |
| 42 | + android:layout_width="match_parent" | |
| 43 | + android:layout_height="1dp"/> | |
| 44 | + <LinearLayout | |
| 45 | + android:orientation="horizontal" | |
| 46 | + android:weightSum="2" | |
| 47 | + android:layout_width="match_parent" | |
| 48 | + android:layout_height="44dp"> | |
| 49 | + <TextView | |
| 50 | + android:id="@+id/btnNegative" | |
| 51 | + tools:text="取消" | |
| 52 | + android:textSize="17sp" | |
| 53 | + android:textColor="#999" | |
| 54 | + android:textStyle="bold" | |
| 55 | + android:gravity="center" | |
| 56 | + android:layout_weight="1" | |
| 57 | + android:layout_width="0dp" | |
| 58 | + android:layout_height="match_parent"/> | |
| 59 | + <View | |
| 60 | + android:background="#EEE" | |
| 61 | + android:layout_marginVertical="3dp" | |
| 62 | + android:layout_width="1dp" | |
| 63 | + android:layout_height="match_parent"/> | |
| 64 | + <TextView | |
| 65 | + android:id="@+id/btnPositive" | |
| 66 | + tools:text="确定" | |
| 67 | + android:textSize="17sp" | |
| 68 | + android:textColor="#1C90F3" | |
| 69 | + android:textStyle="bold" | |
| 70 | + android:gravity="center" | |
| 71 | + android:layout_weight="1" | |
| 72 | + android:layout_width="0dp" | |
| 73 | + android:layout_height="match_parent"/> | |
| 74 | + </LinearLayout> | |
| 75 | + </LinearLayout> | |
| 76 | + | |
| 77 | +</FrameLayout> | |
| 0 | 78 | \ No newline at end of file | ... | ... | 
app/src/main/res/layout/item_homework_list.xml
| ... | ... | @@ -67,6 +67,7 @@ | 
| 67 | 67 | android:layout_height="wrap_content" /> | 
| 68 | 68 | <Space style="@style/empty_space"/> | 
| 69 | 69 | <androidx.appcompat.widget.AppCompatTextView | 
| 70 | + android:id="@+id/btnDelete" | |
| 70 | 71 | android:text="删除" | 
| 71 | 72 | android:textSize="10sp" | 
| 72 | 73 | android:textColor="#666" | 
| ... | ... | @@ -82,6 +83,7 @@ | 
| 82 | 83 | android:layout_width="1dp" | 
| 83 | 84 | android:layout_height="10dp"/> | 
| 84 | 85 | <androidx.appcompat.widget.AppCompatTextView | 
| 86 | + android:id="@+id/btnDetail" | |
| 85 | 87 | android:text="详情" | 
| 86 | 88 | android:textSize="10sp" | 
| 87 | 89 | android:textColor="#666" | ... | ... |