* AppDialogConfig添加构造参数,简化自定义扩展用法

pull/27/head
Jenly 4 years ago
parent d3a759374c
commit dbfbac55de
  1. 117
      app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
  2. 229
      app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java
  3. 255
      app-dialog/src/main/java/com/king/app/dialog/BaseDialogConfig.java
  4. 15
      app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java
  5. 3
      app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java
  6. BIN
      app/release/app-release.apk
  7. 1
      app/release/output.json
  8. 12
      app/src/main/java/com/king/appupdater/MainActivity.java

@ -3,13 +3,10 @@ package com.king.app.dialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.text.TextUtils;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import com.king.app.dialog.fragment.AppDialogFragment; import com.king.app.dialog.fragment.AppDialogFragment;
@ -34,53 +31,26 @@ public enum AppDialog {
//------------------------------------------- //-------------------------------------------
/** /**
* 通过{@link AppDialogConfig} 创建一个视图
* @param context * @param context
* @param config 弹框配置 {@link AppDialogConfig} * @param config 弹框配置 {@link AppDialogConfig}
* @return * @return
* @deprecated 即将废弃下一个版本可能会移除此方法
*/ */
@Deprecated
public View createAppDialogView(@NonNull Context context,@NonNull AppDialogConfig config){ public View createAppDialogView(@NonNull Context context,@NonNull AppDialogConfig config){
View view = config.getView(context); return config.buildAppDialogView();
TextView tvDialogTitle = view.findViewById(config.getTitleId());
setText(tvDialogTitle,config.getTitle());
tvDialogTitle.setVisibility(config.isHideTitle() ? View.GONE : View.VISIBLE);
TextView tvDialogContent = view.findViewById(config.getContentId());
setText(tvDialogContent,config.getContent());
Button btnDialogCancel = view.findViewById(config.getCancelId());
setText(btnDialogCancel,config.getCancel());
btnDialogCancel.setOnClickListener(config.getOnClickCancel() != null ? config.getOnClickCancel() : mOnClickDismissDialog);
btnDialogCancel.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
//不强制要求要有中间的线
View line = view.findViewById(config.getLineId());
if(line != null){
line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
} }
Button btnDialogOK = view.findViewById(config.getOkId());
setText(btnDialogOK,config.getOk());
btnDialogOK.setOnClickListener(config.getOnClickOk() != null ? config.getOnClickOk() : mOnClickDismissDialog);
return view;
}
//------------------------------------------- //-------------------------------------------
private View.OnClickListener mOnClickDismissDialog = new View.OnClickListener() { View.OnClickListener mOnClickDismissDialog = new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
dismissDialog(); dismissDialog();
} }
}; };
private void setText(TextView tv,CharSequence text){
if(!TextUtils.isEmpty(text)){
tv.setText(text);
}
}
//------------------------------------------- //-------------------------------------------
public void dismissDialogFragment(FragmentManager fragmentManager){ public void dismissDialogFragment(FragmentManager fragmentManager){
@ -147,23 +117,45 @@ public enum AppDialog {
/** /**
* 显示弹框 * 显示弹框
* @param config 弹框配置 {@link AppDialogConfig}
*/
public void showDialog(AppDialogConfig config){
showDialog(config,true);
}
/**
* 显示弹框 请使用{@link #showDialog(AppDialogConfig)}
* @param context * @param context
* @param config 弹框配置 {@link AppDialogConfig} * @param config 弹框配置 {@link AppDialogConfig}
* @deprecated 即将废弃下一个版本可能会移除此方法
*/ */
@Deprecated
public void showDialog(Context context,AppDialogConfig config){ public void showDialog(Context context,AppDialogConfig config){
showDialog(context,config,true); showDialog(config,true);
} }
/** /**
* 显示弹框 * 显示弹框请使用{@link #showDialog(AppDialogConfig, boolean)}
* @param context * @param context
* @param config 弹框配置 {@link AppDialogConfig} * @param config 弹框配置 {@link AppDialogConfig}
* @param isCancel 是否可取消默认为truefalse则拦截back键 * @param isCancel 是否可取消默认为truefalse则拦截back键
* @deprecated 即将废弃下一个版本可能会移除此方法
*/ */
@Deprecated
public void showDialog(Context context,AppDialogConfig config,boolean isCancel){ public void showDialog(Context context,AppDialogConfig config,boolean isCancel){
showDialog(context,createAppDialogView(context,config),R.style.app_dialog,DEFAULT_WIDTH_RATIO,isCancel); showDialog(config,isCancel);
} }
/**
* 显示弹框
* @param config 弹框配置 {@link AppDialogConfig}
* @param isCancel 是否可取消默认为truefalse则拦截back键
*/
public void showDialog(AppDialogConfig config,boolean isCancel){
showDialog(config.getContext(),config.buildAppDialogView(),config.getStyleId(),DEFAULT_WIDTH_RATIO,isCancel);
}
/** /**
* 显示弹框 * 显示弹框
* @param context * @param context
@ -208,24 +200,24 @@ public enum AppDialog {
* 显示弹框 * 显示弹框
* @param context * @param context
* @param contentView 弹框内容视图 * @param contentView 弹框内容视图
* @param resId Dialog样式 * @param styleId Dialog样式
* @param widthRatio 宽度比例根据屏幕宽度计算得来 * @param widthRatio 宽度比例根据屏幕宽度计算得来
*/ */
public void showDialog(Context context, View contentView, @StyleRes int resId, float widthRatio){ public void showDialog(Context context, View contentView, @StyleRes int styleId, float widthRatio){
showDialog(context,contentView,resId,widthRatio,true); showDialog(context,contentView,styleId,widthRatio,true);
} }
/** /**
* 显示弹框 * 显示弹框
* @param context * @param context
* @param contentView 弹框内容视图 * @param contentView 弹框内容视图
* @param resId Dialog样式 * @param styleId Dialog样式
* @param widthRatio 宽度比例根据屏幕宽度计算得来 * @param widthRatio 宽度比例根据屏幕宽度计算得来
* @param isCancel 是否可取消默认为truefalse则拦截back键 * @param isCancel 是否可取消默认为truefalse则拦截back键
*/ */
public void showDialog(Context context, View contentView, @StyleRes int resId, float widthRatio,final boolean isCancel){ public void showDialog(Context context, View contentView, @StyleRes int styleId, float widthRatio,final boolean isCancel){
dismissDialog(); dismissDialog();
mDialog = createDialog(context,contentView,resId,widthRatio,isCancel); mDialog = createDialog(context,contentView,styleId,widthRatio,isCancel);
mDialog.show(); mDialog.show();
} }
@ -244,21 +236,42 @@ public enum AppDialog {
/** /**
* 创建弹框 * 创建弹框
* @param config 弹框配置 {@link AppDialogConfig}
*/
public Dialog createDialog(AppDialogConfig config){
return createDialog(config,true);
}
/**
* 创建弹框请使用{@link #createDialog(AppDialogConfig)}
* @param context * @param context
* @param config 弹框配置 {@link AppDialogConfig} * @param config 弹框配置 {@link AppDialogConfig}
* @deprecated 即将废弃下一个版本可能会移除此方法
*/ */
@Deprecated
public Dialog createDialog(Context context,AppDialogConfig config){ public Dialog createDialog(Context context,AppDialogConfig config){
return createDialog(context,config,true); return createDialog(config,true);
} }
/** /**
* 创建弹框 * 创建弹框请使用{@link #createDialog(AppDialogConfig, boolean)}
* @param context * @param context
* @param config 弹框配置 {@link AppDialogConfig} * @param config 弹框配置 {@link AppDialogConfig}
* @param isCancel 是否可取消默认为truefalse则拦截back键 * @param isCancel 是否可取消默认为truefalse则拦截back键
* @deprecated 即将废弃下一个版本可能会移除此方法
*/ */
@Deprecated
public Dialog createDialog(Context context,AppDialogConfig config,boolean isCancel){ public Dialog createDialog(Context context,AppDialogConfig config,boolean isCancel){
return createDialog(context,createAppDialogView(context,config),R.style.app_dialog,DEFAULT_WIDTH_RATIO,isCancel); return createDialog(config,isCancel);
}
/**
* 创建弹框
* @param config 弹框配置 {@link AppDialogConfig}
* @param isCancel 是否可取消默认为truefalse则拦截back键
*/
public Dialog createDialog(AppDialogConfig config,boolean isCancel){
return createDialog(config.getContext(),config.buildAppDialogView(),config.getStyleId(),DEFAULT_WIDTH_RATIO,isCancel);
} }
/** /**
@ -305,23 +318,23 @@ public enum AppDialog {
* 创建弹框 * 创建弹框
* @param context * @param context
* @param contentView 弹框内容视图 * @param contentView 弹框内容视图
* @param resId Dialog样式 * @param styleId Dialog样式
* @param widthRatio 宽度比例根据屏幕宽度计算得来 * @param widthRatio 宽度比例根据屏幕宽度计算得来
*/ */
public Dialog createDialog(Context context, View contentView, @StyleRes int resId, float widthRatio){ public Dialog createDialog(Context context, View contentView, @StyleRes int styleId, float widthRatio){
return createDialog(context,contentView,resId,widthRatio,true); return createDialog(context,contentView,styleId,widthRatio,true);
} }
/** /**
* 创建弹框 * 创建弹框
* @param context * @param context
* @param contentView 弹框内容视图 * @param contentView 弹框内容视图
* @param resId Dialog样式 * @param styleId Dialog样式
* @param widthRatio 宽度比例根据屏幕宽度计算得来 * @param widthRatio 宽度比例根据屏幕宽度计算得来
* @param isCancel 是否可取消默认为truefalse则拦截back键 * @param isCancel 是否可取消默认为truefalse则拦截back键
*/ */
public Dialog createDialog(Context context, View contentView, @StyleRes int resId, float widthRatio,final boolean isCancel){ public Dialog createDialog(Context context, View contentView, @StyleRes int styleId, float widthRatio,final boolean isCancel){
Dialog dialog = new Dialog(context,resId); Dialog dialog = new Dialog(context,styleId);
dialog.setContentView(contentView); dialog.setContentView(contentView);
dialog.setCanceledOnTouchOutside(false); dialog.setCanceledOnTouchOutside(false);
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() { dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

@ -1,221 +1,118 @@
package com.king.app.dialog; package com.king.app.dialog;
import android.content.Context; import android.content.Context;
import android.util.SparseArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.IdRes; import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes; import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
/** /**
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a> * @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/ */
public class AppDialogConfig { public class AppDialogConfig extends BaseDialogConfig{
/**
* 布局ID
*/
private @LayoutRes int layoutId = R.layout.app_dialog;
/**
* 标题视图ID
*/
private @IdRes int titleId = R.id.tvDialogTitle;
/**
* 内容视图ID
*/
private @IdRes int contentId = R.id.tvDialogContent;
/**
* 取消视图ID左边按钮
*/
private @IdRes int cancelId = R.id.btnDialogCancel;
/**
* 确定视图ID右边按钮
*/
private @IdRes int okId = R.id.btnDialogOK;
/**
* 按钮中间分割线ID
*/
private @IdRes int lineId = R.id.line;
/**
* 标题文本
*/
private CharSequence title;
/**
* 内容文本
*/
private CharSequence content;
/**
* 取消按钮文本
*/
private CharSequence cancel;
/**
* 确定按钮文本
*/
private CharSequence ok;
/**
* 是否隐藏取消按钮如果隐藏取消则底部只显示一个按钮
*/
private boolean isHideCancel;
/**
* 是否隐藏标题
*/
private boolean isHideTitle;
private View.OnClickListener onClickCancel; private Context context;
private View.OnClickListener onClickOk; private SparseArray<View> views;
private View view; private View view;
public @LayoutRes int getLayoutId() { public AppDialogConfig(@NonNull Context context){
return layoutId; this(context,R.layout.app_dialog);
}
public AppDialogConfig setLayoutId(@LayoutRes int layoutId) {
this.layoutId = layoutId;
return this;
}
public int getTitleId() {
return titleId;
}
public AppDialogConfig setTitleId(@IdRes int titleId) {
this.titleId = titleId;
return this;
}
public @IdRes int getContentId() {
return contentId;
}
public AppDialogConfig setContentId(@IdRes int contentId) {
this.contentId = contentId;
return this;
} }
public @IdRes int getCancelId() { public AppDialogConfig(@NonNull Context context,@LayoutRes int layoutId){
return cancelId; super(layoutId);
this.context = context;
views = new SparseArray<>();
} }
public AppDialogConfig setCancelId(@IdRes int cancelId) { public Context getContext(){
this.cancelId = cancelId; return context;
return this;
} }
public @IdRes int getOkId() {
return okId;
}
public AppDialogConfig setOkId(@IdRes int okId) { /**
this.okId = okId; * use {@link #getDialogView()}
return this; * @param context
} * @return
* @deprecated 即将废弃下一个版本可能会移除此方法
public @IdRes int getLineId() { */
return lineId; @Deprecated
} public View getView(@NonNull Context context){
return getDialogView();
public AppDialogConfig setLineId(@IdRes int lineId) {
this.lineId = lineId;
return this;
}
public CharSequence getTitle() {
return title;
}
public AppDialogConfig setTitle(CharSequence title) {
this.title = title;
return this;
}
public AppDialogConfig setTitle(@NonNull Context context,@StringRes int resId) {
this.title = context.getString(resId);
return this;
}
public CharSequence getContent() {
return content;
}
public AppDialogConfig setContent(CharSequence content) {
this.content = content;
return this;
}
public CharSequence getCancel() {
return cancel;
} }
public AppDialogConfig setCancel(CharSequence cancel) { public View getDialogView(){
this.cancel = cancel; if(view == null){
return this; view = LayoutInflater.from(context).inflate(getLayoutId(),null);
} }
return view;
public AppDialogConfig setCancel(@NonNull Context context,@StringRes int resId) {
this.cancel = context.getString(resId);
return this;
} }
public CharSequence getOk() { private <T extends View> T findView(@IdRes int id){
return ok; return (T)getDialogView().findViewById(id);
} }
public AppDialogConfig setOk(CharSequence ok) { public <T extends View> T getView(@IdRes int id){
this.ok = ok; View v = views.get(id);
return this; if(v == null){
v = findView(id);
views.put(id,v);
} }
public AppDialogConfig setOk(@NonNull Context context,@StringRes int resId) { return (T)v;
this.ok = context.getString(resId);
return this;
} }
public boolean isHideCancel() {
return isHideCancel;
}
public AppDialogConfig setHideCancel(boolean hideCancel) { /**
isHideCancel = hideCancel; * 通过{@link AppDialogConfig} 创建一个视图
return this; * @return
*/
View buildAppDialogView(){
TextView tvDialogTitle = getView(titleId);
if(tvDialogTitle != null){
setText(tvDialogTitle,title);
tvDialogTitle.setVisibility(isHideTitle ? View.GONE : View.VISIBLE);
} }
public boolean isHideTitle(){ TextView tvDialogContent = getView(contentId);
return isHideTitle; if(tvDialogContent != null){
setText(tvDialogContent,content);
} }
public AppDialogConfig setHideTitle(boolean hideTitle){ Button btnDialogCancel = getView(cancelId);
isHideTitle = hideTitle; if(btnDialogCancel != null){
return this; setText(btnDialogCancel,cancel);
btnDialogCancel.setOnClickListener(onClickCancel != null ? onClickCancel : AppDialog.INSTANCE.mOnClickDismissDialog);
btnDialogCancel.setVisibility(isHideCancel ? View.GONE : View.VISIBLE);
} }
public View.OnClickListener getOnClickCancel() { View line = getView(lineId);
return onClickCancel; if(line != null){
line.setVisibility(isHideCancel ? View.GONE : View.VISIBLE);
} }
public AppDialogConfig setOnClickCancel(View.OnClickListener onClickCancel) { Button btnDialogOK = getView(okId);
this.onClickCancel = onClickCancel; if(btnDialogOK != null){
return this; setText(btnDialogOK,ok);
} btnDialogOK.setOnClickListener(onClickOk != null ? onClickOk : AppDialog.INSTANCE.mOnClickDismissDialog);
public View.OnClickListener getOnClickOk() {
return onClickOk;
} }
public AppDialogConfig setOnClickOk(View.OnClickListener onClickOk) { return view;
this.onClickOk = onClickOk;
return this;
} }
public View getView(@NonNull Context context){ private void setText(TextView tv, CharSequence text){
if(view == null){ if(text != null){
view = LayoutInflater.from(context).inflate(layoutId,null); tv.setText(text);
} }
return view;
} }
} }

@ -0,0 +1,255 @@
package com.king.app.dialog;
import android.content.Context;
import android.view.View;
import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.annotation.StyleRes;
/**
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/
public class BaseDialogConfig {
/**
* 布局ID
*/
@LayoutRes
int layoutId;
/**
* 标题视图ID
*/
@IdRes
int titleId = R.id.tvDialogTitle;
/**
* 内容视图ID
*/
@IdRes int contentId = R.id.tvDialogContent;
/**
* 取消视图ID左边按钮
*/
@IdRes int cancelId = R.id.btnDialogCancel;
/**
* 确定视图ID右边按钮
*/
@IdRes int okId = R.id.btnDialogOK;
/**
* 按钮中间分割线ID
*/
@IdRes int lineId = R.id.line;
/**
* 样式ID
*/
@StyleRes
int styleId = R.style.app_dialog;
/**
* 标题文本
*/
CharSequence title;
/**
* 内容文本
*/
CharSequence content;
/**
* 取消按钮文本
*/
CharSequence cancel;
/**
* 确定按钮文本
*/
CharSequence ok;
/**
* 是否隐藏取消按钮如果隐藏取消则底部只显示一个按钮
*/
boolean isHideCancel;
/**
* 是否隐藏标题
*/
boolean isHideTitle;
View.OnClickListener onClickCancel;
View.OnClickListener onClickOk;
public BaseDialogConfig(){
this(R.layout.app_dialog);
}
public BaseDialogConfig(@LayoutRes int layoutId){
this.layoutId = layoutId;
}
public @LayoutRes int getLayoutId() {
return layoutId;
}
/**
* @param layoutId
* @return
* @deprecated 即将废弃下一个版本可能会移除此方法
*/
@Deprecated
public BaseDialogConfig setLayoutId(@IdRes int layoutId) {
this.layoutId = layoutId;
return this;
}
public int getTitleId() {
return titleId;
}
public BaseDialogConfig setTitleId(@IdRes int titleId) {
this.titleId = titleId;
return this;
}
public int getStyleId() {
return styleId;
}
public BaseDialogConfig setStyleId(@IdRes int styleId) {
this.styleId = styleId;
return this;
}
public @IdRes int getContentId() {
return contentId;
}
public BaseDialogConfig setContentId(@IdRes int contentId) {
this.contentId = contentId;
return this;
}
public @IdRes int getCancelId() {
return cancelId;
}
public BaseDialogConfig setCancelId(@IdRes int cancelId) {
this.cancelId = cancelId;
return this;
}
public @IdRes int getOkId() {
return okId;
}
public BaseDialogConfig setOkId(@IdRes int okId) {
this.okId = okId;
return this;
}
public @IdRes int getLineId() {
return lineId;
}
public BaseDialogConfig setLineId(@IdRes int lineId) {
this.lineId = lineId;
return this;
}
public CharSequence getTitle() {
return title;
}
public BaseDialogConfig setTitle(CharSequence title) {
this.title = title;
return this;
}
public BaseDialogConfig setTitle(@NonNull Context context, @StringRes int resId) {
this.title = context.getString(resId);
return this;
}
public CharSequence getContent() {
return content;
}
public BaseDialogConfig setContent(CharSequence content) {
this.content = content;
return this;
}
public CharSequence getCancel() {
return cancel;
}
public BaseDialogConfig setCancel(CharSequence cancel) {
this.cancel = cancel;
return this;
}
public BaseDialogConfig setCancel(@NonNull Context context, @StringRes int resId) {
this.cancel = context.getString(resId);
return this;
}
public CharSequence getOk() {
return ok;
}
public BaseDialogConfig setOk(CharSequence ok) {
this.ok = ok;
return this;
}
public BaseDialogConfig setOk(@NonNull Context context, @StringRes int resId) {
this.ok = context.getString(resId);
return this;
}
public boolean isHideCancel() {
return isHideCancel;
}
public BaseDialogConfig setHideCancel(boolean hideCancel) {
isHideCancel = hideCancel;
return this;
}
public boolean isHideTitle(){
return isHideTitle;
}
public BaseDialogConfig setHideTitle(boolean hideTitle){
isHideTitle = hideTitle;
return this;
}
public View.OnClickListener getOnClickCancel() {
return onClickCancel;
}
/**
* 设置取消按钮点击监听不设置默认点击关闭弹框
* @param onClickCancel
* @return
*/
public BaseDialogConfig setOnClickCancel(View.OnClickListener onClickCancel) {
this.onClickCancel = onClickCancel;
return this;
}
public View.OnClickListener getOnClickOk() {
return onClickOk;
}
/**
* 设置确定按钮点击监听不设置默认点击关闭弹框
* @param onClickOk
* @return
*/
public BaseDialogConfig setOnClickOk(View.OnClickListener onClickOk) {
this.onClickOk = onClickOk;
return this;
}
}

@ -5,7 +5,7 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import com.king.app.dialog.AppDialogConfig; import com.king.app.dialog.BaseDialogConfig;
import com.king.app.dialog.R; import com.king.app.dialog.R;
/** /**
@ -13,9 +13,9 @@ import com.king.app.dialog.R;
*/ */
public class AppDialogFragment extends BaseDialogFragment { public class AppDialogFragment extends BaseDialogFragment {
private AppDialogConfig config; private BaseDialogConfig config;
public static AppDialogFragment newInstance(AppDialogConfig config) { public static AppDialogFragment newInstance(BaseDialogConfig config) {
Bundle args = new Bundle(); Bundle args = new Bundle();
AppDialogFragment fragment = new AppDialogFragment(); AppDialogFragment fragment = new AppDialogFragment();
@ -35,26 +35,33 @@ public class AppDialogFragment extends BaseDialogFragment {
public void init(View rootView){ public void init(View rootView){
if(config != null){ if(config != null){
TextView tvDialogTitle = rootView.findViewById(config.getTitleId()); TextView tvDialogTitle = rootView.findViewById(config.getTitleId());
if(tvDialogTitle != null){
setText(tvDialogTitle,config.getTitle()); setText(tvDialogTitle,config.getTitle());
tvDialogTitle.setVisibility(config.isHideTitle() ? View.GONE : View.VISIBLE); tvDialogTitle.setVisibility(config.isHideTitle() ? View.GONE : View.VISIBLE);
}
TextView tvDialogContent = rootView.findViewById(config.getContentId()); TextView tvDialogContent = rootView.findViewById(config.getContentId());
if(tvDialogContent != null){
setText(tvDialogContent,config.getContent()); setText(tvDialogContent,config.getContent());
}
Button btnDialogCancel = rootView.findViewById(config.getCancelId()); Button btnDialogCancel = rootView.findViewById(config.getCancelId());
if(btnDialogCancel != null){
setText(btnDialogCancel,config.getCancel()); setText(btnDialogCancel,config.getCancel());
btnDialogCancel.setOnClickListener(config.getOnClickCancel() != null ? config.getOnClickCancel() : getOnClickDismiss()); btnDialogCancel.setOnClickListener(config.getOnClickCancel() != null ? config.getOnClickCancel() : getOnClickDismiss());
btnDialogCancel.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); btnDialogCancel.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
}
//不强制要求要有中间的线
View line = rootView.findViewById(config.getLineId()); View line = rootView.findViewById(config.getLineId());
if(line != null){ if(line != null){
line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
} }
Button btnDialogOK = rootView.findViewById(config.getOkId()); Button btnDialogOK = rootView.findViewById(config.getOkId());
if(btnDialogOK != null){
setText(btnDialogOK,config.getOk()); setText(btnDialogOK,config.getOk());
btnDialogOK.setOnClickListener(config.getOnClickOk() != null ? config.getOnClickOk() : getOnClickDismiss()); btnDialogOK.setOnClickListener(config.getOnClickOk() != null ? config.getOnClickOk() : getOnClickDismiss());
}
} }
} }

@ -5,7 +5,6 @@ import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -59,7 +58,7 @@ public abstract class BaseDialogFragment extends DialogFragment {
} }
protected void setText(TextView tv, CharSequence text){ protected void setText(TextView tv, CharSequence text){
if(!TextUtils.isEmpty(text)){ if(text != null){
tv.setText(text); tv.setText(text);
} }
} }

Binary file not shown.

@ -1 +0,0 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":16,"versionName":"1.0.9-androidx","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

@ -33,7 +33,8 @@ public class MainActivity extends AppCompatActivity {
private final Object mLock = new Object(); private final Object mLock = new Object();
//下载出现Failed to connect to raw.githubusercontent.com时,可以换个下载链接测试,github的raw.githubusercontent.com目前不太稳定。 //下载出现Failed to connect to raw.githubusercontent.com时,可以换个下载链接测试,github的raw.githubusercontent.com目前不太稳定。
private String mUrl = "https://raw.githubusercontent.com/jenly1314/AppUpdater/master/app/release/app-release.apk"; // private String mUrl = "https://raw.githubusercontent.com/jenly1314/AppUpdater/master/app/release/app-release.apk";
private String mUrl = "https://gitlab.com/jenly1314/AppUpdater/-/raw/master/app/release/app-release.apk";
private ProgressBar progressBar; private ProgressBar progressBar;
@ -159,7 +160,7 @@ public class MainActivity extends AppCompatActivity {
* 简单弹框升级 * 简单弹框升级
*/ */
private void clickBtn4(){ private void clickBtn4(){
AppDialogConfig config = new AppDialogConfig(); AppDialogConfig config = new AppDialogConfig(getContext());
config.setTitle("简单弹框升级") config.setTitle("简单弹框升级")
.setOk("升级") .setOk("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
@ -178,9 +179,8 @@ public class MainActivity extends AppCompatActivity {
* 简单自定义弹框升级 * 简单自定义弹框升级
*/ */
private void clickBtn5(){ private void clickBtn5(){
AppDialogConfig config = new AppDialogConfig(); AppDialogConfig config = new AppDialogConfig(getContext(),R.layout.dialog);
config.setLayoutId(R.layout.dialog) config.setOk("升级")
.setOk("升级")
.setHideCancel(true) .setHideCancel(true)
.setTitle("简单自定义弹框升级") .setTitle("简单自定义弹框升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
@ -241,7 +241,7 @@ public class MainActivity extends AppCompatActivity {
* 简单DialogFragment升级 * 简单DialogFragment升级
*/ */
private void clickBtn7(){ private void clickBtn7(){
AppDialogConfig config = new AppDialogConfig(); AppDialogConfig config = new AppDialogConfig(getContext());
config.setTitle("简单DialogFragment升级") config.setTitle("简单DialogFragment升级")
.setOk("升级") .setOk("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")

Loading…
Cancel
Save