Skip to content

Commit 64ae225

Browse files
committed
承运商条件展示时新增可按选择条件展示
1 parent 1c5a483 commit 64ae225

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

app/src/main/java/com/tick/conditiondialogdemo/MainActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class MainActivity extends AppCompatActivity implements VehicleConditionS
2525
private TextView mTextView;
2626
private VehicleCdSelector mVehicleCdSelector;
2727
private CarrierTypeCdSelector mTypeCdSelector;
28+
private String mSelectedType;
2829

2930
@Override
3031
protected void onCreate(Bundle savedInstanceState) {
@@ -41,7 +42,7 @@ protected void onCreate(Bundle savedInstanceState) {
4142
mVehicleButton = findViewById(R.id.btVehicel);
4243
mVehicleButton.setOnClickListener(v -> mVehicleCdSelector.show(v));
4344
mCarrierTypeButton = findViewById(R.id.btCarrierType);
44-
mCarrierTypeButton.setOnClickListener(v -> mTypeCdSelector.show(v));
45+
mCarrierTypeButton.setOnClickListener(v -> mTypeCdSelector.show(v, mSelectedType));
4546
}
4647

4748
public String getContent(VehicleCondition condition) {
@@ -108,6 +109,7 @@ public void onSure(List<CarrierType> carrierTypes) {
108109
result.append(",");
109110
}
110111
}
111-
mTextView.setText(result.toString());
112+
mSelectedType = result.toString();
113+
mTextView.setText(mSelectedType);
112114
}
113115
}

conditiondialog/src/main/java/com/tick/conditiondialog/ConditionDialogAdapter.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.widget.CheckBox;
99

1010
import java.util.ArrayList;
11+
import java.util.List;
1112

1213
/**
1314
* 条件选择框适配器
@@ -122,6 +123,42 @@ public final void onCheckItemClick(int position) {
122123
notifyDataSetChanged();
123124
}
124125

126+
/**
127+
* 标记已经选中的条件
128+
*
129+
* @param args 选中条件数组
130+
*/
131+
public final void setItemClicked(String[] args) {
132+
if (args == null || args.length == 0) {
133+
return;
134+
}
135+
if (TYPE_SINGLE == mType) {
136+
//单选模式
137+
clearCheck();
138+
String selected = args[0];
139+
for (T t : mConditions) {
140+
if (selected.equals(t.getValue())) {
141+
t.setCheck(true);
142+
mSelectChilds.add(t);
143+
break;
144+
}
145+
}
146+
} else {
147+
//多选模式
148+
clearCheck();
149+
for (String select : args) {
150+
for (T t : mConditions) {
151+
if (select.equals(t.getValue())) {
152+
t.setCheck(true);
153+
mSelectChilds.add(t);
154+
}
155+
}
156+
}
157+
}
158+
notifyDataSetChanged();
159+
}
160+
161+
125162
public ArrayList<T> getSelectChilds() {
126163
return mSelectChilds;
127164
}

conditiondialog/src/main/java/com/tick/conditiondialog/carrier/CarrierTypeCdSelector.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.support.v4.content.ContextCompat;
5+
import android.text.TextUtils;
56
import android.util.DisplayMetrics;
67
import android.view.Gravity;
78
import android.view.LayoutInflater;
@@ -87,6 +88,14 @@ public void show(View v) {
8788
mTop.animate().alpha(1f).setDuration(100).setStartDelay(600);
8889
}
8990

91+
public void show(View v, String types) {
92+
if (!TextUtils.isEmpty(types)) {
93+
String[] conditions = types.split(",");
94+
mTypeAdapter.setItemClicked(conditions);
95+
}
96+
show(v);
97+
}
98+
9099
public void hide() {
91100
mTop.setAlpha(0f);
92101
mTop.postDelayed(this::dismiss, 10);

0 commit comments

Comments
 (0)