Skip to content

Commit

Permalink
增加几个全局配置项,完善点击按钮回调后是否dismiss的判定逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Mar 24, 2018
1 parent 62bee51 commit fa6f5a7
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public void onGetChoose(boolean[] states) {
public void onItemClick(CharSequence text, int position) {
showToast(text + "--" + position);
}
}).show();
}).setDismissAfterResultCallback(false).show();

break;
case R.id.btn_md_bs:
Expand Down
34 changes: 22 additions & 12 deletions dialog/src/main/java/com/hss01248/dialog/Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@
*/
public class Tool {

public static void dismiss(ConfigBean bean){
public static void dismiss(ConfigBean bean,boolean isAfterResult){

if(!bean.dismissAfterButtonClick){
if(isAfterResult && !bean.dismissAfterResultCallback){
return;
}

//先隐藏keyboard
hideKeyBorad(bean);
if(bean.showAsActivity){
Expand All @@ -77,6 +78,11 @@ public static void dismiss(ConfigBean bean){
}
}

public static void dismiss(ConfigBean bean){
dismiss(bean,false);
}


public static Handler getMainHandler() {
if(mainHandler ==null){
mainHandler = new Handler(Looper.getMainLooper());
Expand Down Expand Up @@ -257,18 +263,22 @@ public void onClick(View v) {
return;
}
bean.listener.onGetInput(holder.getTxt1(),holder.getTxt2());
}
bean.listener.onGetChoose(bean.checkedItems);
List<Integer> selectedIndex = new ArrayList<Integer>();
List<CharSequence> selectedStrs = new ArrayList<CharSequence>();
for(int j=0;j<bean.checkedItems.length;j++){
if(bean.checkedItems[j]){
selectedIndex.add(j);
selectedStrs.add(bean.wordsMd[j]);
}else if(bean.type == DefaultConfig.TYPE_MD_SINGLE_CHOOSE){

}else if(bean.type == DefaultConfig.TYPE_MD_MULTI_CHOOSE){
bean.listener.onGetChoose(bean.checkedItems);
List<Integer> selectedIndex = new ArrayList<Integer>();
List<CharSequence> selectedStrs = new ArrayList<CharSequence>();
for(int j=0;j<bean.checkedItems.length;j++){
if(bean.checkedItems[j]){
selectedIndex.add(j);
selectedStrs.add(bean.wordsMd[j]);
}
}
bean.listener.onChoosen(selectedIndex,selectedStrs,bean.checkedItems);
}
bean.listener.onChoosen(selectedIndex,selectedStrs,bean.checkedItems);
dismiss(bean);
bean.listener.onFirst();
dismiss(bean,true);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected SuperLvHolder generateNewHolder(Context context, int itemViewType) {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
BottomSheetBean sheetBean = bean.lvDatas.get(position);
bean.itemListener.onItemClick(sheetBean.text,position);
Tool.dismiss(bean);
Tool.dismiss(bean,true);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
int actualPosition = pageNum * bean.gridColumns * 2 +position;
bean.itemListener.onItemClick(bean.lvDatas.get(actualPosition).text,actualPosition);
}
Tool.dismiss(bean);
Tool.dismiss(bean,true);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
bean.listener.onFirst();
bean.listener.onGetChoose(singleChosen,bean.wordsMd[singleChosen]);
}
Tool.dismiss(bean);
Tool.dismiss(bean,true);
}
})
.setNegativeButton(bean.text2, new DialogInterface.OnClickListener() {
Expand All @@ -310,7 +310,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
if (bean.itemListener != null){
bean.itemListener.onItemClick(bean.wordsMd[i],i);
}
Tool.dismiss(bean);
Tool.dismiss(bean,true);

}
});
Expand Down Expand Up @@ -346,7 +346,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
}
bean.listener.onChoosen(selectedIndex,selectedStrs,bean.checkedItems);
}
Tool.dismiss(bean);
Tool.dismiss(bean,true);
}
})
.setNegativeButton(bean.text2, new DialogInterface.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
bean.listener.onFirst();
bean.listener.onGetChoose(singleChosen,bean.wordsMd[singleChosen]);
}
Tool.dismiss(bean);
Tool.dismiss(bean,true);
}
})
.setNegativeButton(bean.text2, new DialogInterface.OnClickListener() {
Expand All @@ -311,7 +311,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
if (bean.itemListener != null){
bean.itemListener.onItemClick(bean.wordsMd[i],i);
}
Tool.dismiss(bean);
Tool.dismiss(bean,true);

}
});
Expand Down Expand Up @@ -347,7 +347,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
}
bean.listener.onChoosen(selectedIndex,selectedStrs,bean.checkedItems);
}
Tool.dismiss(bean);
Tool.dismiss(bean,true);
}
})
.setNegativeButton(bean.text2, new DialogInterface.OnClickListener() {
Expand Down
14 changes: 7 additions & 7 deletions dialog/src/main/java/com/hss01248/dialog/config/ConfigBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ public class ConfigBean extends MyDialogBuilder implements Styleable {
public boolean isTransparentBehind;
public MyDialogListener listener;
public MyItemDialogListener itemListener;
public boolean cancelable = true;//默认可以点击后退键来dismiss对话框
public boolean outsideTouchable = true;//默认外部半透明处点击消失
public boolean dismissAfterButtonClick = true;
public boolean cancelable = DefaultConfig.cancelable;//默认可以点击后退键来dismiss对话框
public boolean outsideTouchable = DefaultConfig.outsideTouchable;//默认外部半透明处点击消失
public boolean dismissAfterResultCallback = DefaultConfig.dismissAfterResultCallback;
public Dialog dialog;
public AlertDialog alertDialog;
public boolean dimBehind = true;
public boolean dimBehind = DefaultConfig.dimBehind;
public @DrawableRes
int bgRes;
public boolean useTheShadowBg = true;
public boolean useTheShadowBg = DefaultConfig.useTheShadowBg;
public int viewHeight;
//各类对话框特有的参数
public CharSequence[] wordsMd;
Expand Down Expand Up @@ -253,8 +253,8 @@ public ConfigBean setBottomSheetDialogMaxHeightPercent(float bottomSheetDialogMa
return this;
}

public ConfigBean setDismissAfterButtonClicked(boolean dismissAfterButtonClick) {
this.dismissAfterButtonClick = dismissAfterButtonClick;
public ConfigBean setDismissAfterResultCallback(boolean dismissAfterResultCallback) {
this.dismissAfterResultCallback = dismissAfterResultCallback;
return this;
}

Expand Down
17 changes: 17 additions & 0 deletions dialog/src/main/java/com/hss01248/dialog/config/DefaultConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ public class DefaultConfig {
public static @ColorRes int inputTxtColor = R.color.dialogutil_text_input_44;


public static boolean cancelable = true;//默认可以点击后退键来dismiss对话框
public static boolean outsideTouchable = false;//默认外部半透明处点击消失

/**
* 是否在点击按钮后自动消失
* 针对有的情况下点击按钮/item拿到回调后,需要dialog不消失
*/
public static boolean dismissAfterResultCallback = false;
/**
* 半透明遮罩
*/
public static boolean dimBehind = true;
/**
* 是否使用带阴影的背景(以防有的手机无法显示后面的半透明遮罩,而与下方界面黏连)
*/
public static boolean useTheShadowBg = true;

/* <dimen name="btn_txt_size">14sp</dimen>
<dimen name="title_txt_size">17sp</dimen>
<dimen name="msg_txt_size">14sp</dimen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public View getView(final int position, View convertView, ViewGroup parent) {
@Override
public void onClick(View v) {
//StyledDialog.dismiss(bean.dialog,bean.alertDialog);
Tool.dismiss(bean);
Tool.dismiss(bean,true);
bean.itemListener.onItemClick(bean.wordsIos.get(position),position);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void onClick(View view) {
}
bean.listener.onGetInput(et1.getText().toString().trim(),et2.getText().toString().trim());
}
Tool.dismiss(bean);
Tool.dismiss(bean,true);
bean.listener.onFirst();

}
Expand Down Expand Up @@ -174,7 +174,7 @@ public void onClick(View view) {
}
bean.listener.onGetInput(et1.getText().toString().trim(),et2.getText().toString().trim());
}
Tool.dismiss(bean);
Tool.dismiss(bean,true);
bean.listener.onFirst();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public View getView(final int position, View convertView, ViewGroup parent) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Tool.dismiss(bean);
bean.itemListener.onItemClick(bean.wordsIos.get(position),position);
Tool.dismiss(bean,true);

}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void onClick(View v) {
}
bean.listener.onGetInput(mdInputHolder.getTxt1(),mdInputHolder.getTxt2());
}
Tool.dismiss(bean);
Tool.dismiss(bean,true);
if(bean.listener!=null){
bean.listener.onFirst();
}
Expand Down

0 comments on commit fa6f5a7

Please sign in to comment.