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

android
Jenly 4 years ago
parent 6d6848ed94
commit 165709991f
  1. 7
      README.md
  2. 117
      app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
  3. 229
      app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java
  4. 251
      app-dialog/src/main/java/com/king/app/dialog/BaseDialogConfig.java
  5. 17
      app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java
  6. 3
      app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java
  7. BIN
      app/release/app-release.apk
  8. 1
      app/release/output.json
  9. 13
      app/src/main/java/com/king/appupdater/MainActivity.java
  10. 4
      versions.gradle

@ -102,7 +102,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
``` ```
```Java ```Java
//简单弹框升级 //简单弹框升级
AppDialogConfig config = new AppDialogConfig(); AppDialogConfig config = new AppDialogConfig(context);
config.setTitle("简单弹框升级") config.setTitle("简单弹框升级")
.setOk("升级") .setOk("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
@ -120,7 +120,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
``` ```
```Java ```Java
//简单DialogFragment升级 //简单DialogFragment升级
AppDialogConfig config = new AppDialogConfig(); AppDialogConfig config = new AppDialogConfig(context);
config.setTitle("简单DialogFragment升级") config.setTitle("简单DialogFragment升级")
.setOk("升级") .setOk("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
@ -150,6 +150,9 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
## 版本记录 ## 版本记录
#### v1.0.10:2021-3-4
* AppDialogConfig添加构造参数,简化自定义扩展用法
#### v1.0.9:2020-12-11 #### v1.0.9:2020-12-11
* 优化默认Dialog样式的显示细节 * 优化默认Dialog样式的显示细节

@ -7,13 +7,10 @@ import android.support.annotation.NonNull;
import android.support.annotation.StyleRes; import android.support.annotation.StyleRes;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
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;
@ -33,53 +30,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){
@ -146,23 +116,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
@ -207,24 +199,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();
} }
@ -243,21 +235,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);
} }
/** /**
@ -304,23 +317,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() {

@ -4,217 +4,114 @@ import android.content.Context;
import android.support.annotation.IdRes; import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.StringRes; 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;
/** /**
* @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,251 @@
package com.king.app.dialog;
import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.annotation.StyleRes;
import android.view.View;
/**
* @author Jenly <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();
@ -33,28 +33,35 @@ 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());
}
} }
} }

@ -8,7 +8,6 @@ import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
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;
@ -58,7 +57,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":15,"versionName":"1.0.9","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

@ -3,7 +3,6 @@ package com.king.appupdater;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -33,7 +32,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 +159,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 +178,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 +240,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、")

@ -1,7 +1,7 @@
//App //App
def app_version = [:] def app_version = [:]
app_version.versionCode = 15 //androidx 16 app_version.versionCode = 17 //androidx 16
app_version.versionName = "1.0.9" app_version.versionName = "1.0.10"
ext.app_version = app_version ext.app_version = app_version
//build version //build version

Loading…
Cancel
Save