diff --git a/README.md b/README.md
index cb3a6cf..c363b4d 100644
--- a/README.md
+++ b/README.md
@@ -102,7 +102,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
```
```Java
//简单弹框升级
- AppDialogConfig config = new AppDialogConfig();
+ AppDialogConfig config = new AppDialogConfig(context);
config.setTitle("简单弹框升级")
.setOk("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
@@ -120,7 +120,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
```
```Java
//简单DialogFragment升级
- AppDialogConfig config = new AppDialogConfig();
+ AppDialogConfig config = new AppDialogConfig(context);
config.setTitle("简单DialogFragment升级")
.setOk("升级")
.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
* 优化默认Dialog样式的显示细节
diff --git a/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java b/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
index 7e78ba4..3c9bd63 100644
--- a/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
+++ b/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
@@ -7,13 +7,10 @@ import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
-import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
-import android.widget.Button;
-import android.widget.TextView;
import com.king.app.dialog.fragment.AppDialogFragment;
@@ -33,53 +30,26 @@ public enum AppDialog {
//-------------------------------------------
/**
- * 通过{@link AppDialogConfig} 创建一个视图
* @param context
* @param config 弹框配置 {@link AppDialogConfig}
* @return
+ * @deprecated 即将废弃,下一个版本可能会移除此方法。
*/
+ @Deprecated
public View createAppDialogView(@NonNull Context context,@NonNull AppDialogConfig config){
- View view = config.getView(context);
- 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;
+ return config.buildAppDialogView();
}
+
//-------------------------------------------
- private View.OnClickListener mOnClickDismissDialog = new View.OnClickListener() {
+ View.OnClickListener mOnClickDismissDialog = new View.OnClickListener() {
@Override
public void onClick(View v) {
dismissDialog();
}
};
- private void setText(TextView tv,CharSequence text){
- if(!TextUtils.isEmpty(text)){
- tv.setText(text);
- }
- }
-
//-------------------------------------------
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 config 弹框配置 {@link AppDialogConfig}
+ * @deprecated 即将废弃,下一个版本可能会移除此方法。
*/
+ @Deprecated
public void showDialog(Context context,AppDialogConfig config){
- showDialog(context,config,true);
+ showDialog(config,true);
}
/**
- * 显示弹框
+ * 显示弹框,请使用{@link #showDialog(AppDialogConfig, boolean)}
* @param context
* @param config 弹框配置 {@link AppDialogConfig}
* @param isCancel 是否可取消(默认为true,false则拦截back键)
+ * @deprecated 即将废弃,下一个版本可能会移除此方法。
*/
+ @Deprecated
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 是否可取消(默认为true,false则拦截back键)
+ */
+ public void showDialog(AppDialogConfig config,boolean isCancel){
+ showDialog(config.getContext(),config.buildAppDialogView(),config.getStyleId(),DEFAULT_WIDTH_RATIO,isCancel);
}
+
/**
* 显示弹框
* @param context
@@ -207,24 +199,24 @@ public enum AppDialog {
* 显示弹框
* @param context
* @param contentView 弹框内容视图
- * @param resId Dialog样式
+ * @param styleId Dialog样式
* @param widthRatio 宽度比例,根据屏幕宽度计算得来
*/
- public void showDialog(Context context, View contentView, @StyleRes int resId, float widthRatio){
- showDialog(context,contentView,resId,widthRatio,true);
+ public void showDialog(Context context, View contentView, @StyleRes int styleId, float widthRatio){
+ showDialog(context,contentView,styleId,widthRatio,true);
}
/**
* 显示弹框
* @param context
* @param contentView 弹框内容视图
- * @param resId Dialog样式
+ * @param styleId Dialog样式
* @param widthRatio 宽度比例,根据屏幕宽度计算得来
* @param isCancel 是否可取消(默认为true,false则拦截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();
- mDialog = createDialog(context,contentView,resId,widthRatio,isCancel);
+ mDialog = createDialog(context,contentView,styleId,widthRatio,isCancel);
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 config 弹框配置 {@link AppDialogConfig}
+ * @deprecated 即将废弃,下一个版本可能会移除此方法。
*/
+ @Deprecated
public Dialog createDialog(Context context,AppDialogConfig config){
- return createDialog(context,config,true);
+ return createDialog(config,true);
}
/**
- * 创建弹框
+ * 创建弹框,请使用{@link #createDialog(AppDialogConfig, boolean)}
* @param context
* @param config 弹框配置 {@link AppDialogConfig}
* @param isCancel 是否可取消(默认为true,false则拦截back键)
+ * @deprecated 即将废弃,下一个版本可能会移除此方法。
*/
+ @Deprecated
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 是否可取消(默认为true,false则拦截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 contentView 弹框内容视图
- * @param resId Dialog样式
+ * @param styleId Dialog样式
* @param widthRatio 宽度比例,根据屏幕宽度计算得来
*/
- public Dialog createDialog(Context context, View contentView, @StyleRes int resId, float widthRatio){
- return createDialog(context,contentView,resId,widthRatio,true);
+ public Dialog createDialog(Context context, View contentView, @StyleRes int styleId, float widthRatio){
+ return createDialog(context,contentView,styleId,widthRatio,true);
}
/**
* 创建弹框
* @param context
* @param contentView 弹框内容视图
- * @param resId Dialog样式
+ * @param styleId Dialog样式
* @param widthRatio 宽度比例,根据屏幕宽度计算得来
* @param isCancel 是否可取消(默认为true,false则拦截back键)
*/
- public Dialog createDialog(Context context, View contentView, @StyleRes int resId, float widthRatio,final boolean isCancel){
- Dialog dialog = new Dialog(context,resId);
+ public Dialog createDialog(Context context, View contentView, @StyleRes int styleId, float widthRatio,final boolean isCancel){
+ Dialog dialog = new Dialog(context,styleId);
dialog.setContentView(contentView);
dialog.setCanceledOnTouchOutside(false);
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
diff --git a/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java b/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java
index f754d7c..130eccc 100644
--- a/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java
+++ b/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java
@@ -4,217 +4,114 @@ 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.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
/**
* @author Jenly Jenly
*/
-public class AppDialogConfig {
- /**
- * 布局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;
+public class AppDialogConfig extends BaseDialogConfig{
- private View.OnClickListener onClickCancel;
+ private Context context;
- private View.OnClickListener onClickOk;
+ private SparseArray views;
private View view;
- public @LayoutRes int getLayoutId() {
- return layoutId;
- }
-
- 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() {
- return cancelId;
- }
-
- public AppDialogConfig setCancelId(@IdRes int cancelId) {
- this.cancelId = cancelId;
- return this;
- }
-
- public @IdRes int getOkId() {
- return okId;
+ public AppDialogConfig(@NonNull Context context){
+ this(context,R.layout.app_dialog);
}
- public AppDialogConfig setOkId(@IdRes int okId) {
- this.okId = okId;
- return this;
+ public AppDialogConfig(@NonNull Context context,@LayoutRes int layoutId){
+ super(layoutId);
+ this.context = context;
+ views = new SparseArray<>();
}
- public @IdRes int getLineId() {
- return lineId;
+ public Context getContext(){
+ return context;
}
- 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) {
- this.cancel = cancel;
- return this;
+ /**
+ * use {@link #getDialogView()}
+ * @param context
+ * @return
+ * @deprecated 即将废弃,下一个版本可能会移除此方法。
+ */
+ @Deprecated
+ public View getView(@NonNull Context context){
+ return getDialogView();
}
- public AppDialogConfig setCancel(@NonNull Context context,@StringRes int resId) {
- this.cancel = context.getString(resId);
- return this;
+ public View getDialogView(){
+ if(view == null){
+ view = LayoutInflater.from(context).inflate(getLayoutId(),null);
+ }
+ return view;
}
- public CharSequence getOk() {
- return ok;
+ private T findView(@IdRes int id){
+ return (T)getDialogView().findViewById(id);
}
- public AppDialogConfig setOk(CharSequence ok) {
- this.ok = ok;
- return this;
- }
+ public T getView(@IdRes int id){
+ View v = views.get(id);
+ if(v == null){
+ v = findView(id);
+ views.put(id,v);
+ }
- public AppDialogConfig setOk(@NonNull Context context,@StringRes int resId) {
- this.ok = context.getString(resId);
- return this;
+ return (T)v;
}
- public boolean isHideCancel() {
- return isHideCancel;
- }
- public AppDialogConfig setHideCancel(boolean hideCancel) {
- isHideCancel = hideCancel;
- return this;
- }
+ /**
+ * 通过{@link AppDialogConfig} 创建一个视图
+ * @return
+ */
+ View buildAppDialogView(){
+ TextView tvDialogTitle = getView(titleId);
+ if(tvDialogTitle != null){
+ setText(tvDialogTitle,title);
+ tvDialogTitle.setVisibility(isHideTitle ? View.GONE : View.VISIBLE);
+ }
- public boolean isHideTitle(){
- return isHideTitle;
- }
+ TextView tvDialogContent = getView(contentId);
+ if(tvDialogContent != null){
+ setText(tvDialogContent,content);
+ }
- public AppDialogConfig setHideTitle(boolean hideTitle){
- isHideTitle = hideTitle;
- return this;
- }
+ Button btnDialogCancel = getView(cancelId);
+ if(btnDialogCancel != null){
+ setText(btnDialogCancel,cancel);
+ btnDialogCancel.setOnClickListener(onClickCancel != null ? onClickCancel : AppDialog.INSTANCE.mOnClickDismissDialog);
+ btnDialogCancel.setVisibility(isHideCancel ? View.GONE : View.VISIBLE);
+ }
- public View.OnClickListener getOnClickCancel() {
- return onClickCancel;
- }
+ View line = getView(lineId);
+ if(line != null){
+ line.setVisibility(isHideCancel ? View.GONE : View.VISIBLE);
+ }
- public AppDialogConfig setOnClickCancel(View.OnClickListener onClickCancel) {
- this.onClickCancel = onClickCancel;
- return this;
- }
+ Button btnDialogOK = getView(okId);
+ if(btnDialogOK != null){
+ setText(btnDialogOK,ok);
+ btnDialogOK.setOnClickListener(onClickOk != null ? onClickOk : AppDialog.INSTANCE.mOnClickDismissDialog);
- public View.OnClickListener getOnClickOk() {
- return onClickOk;
- }
+ }
- public AppDialogConfig setOnClickOk(View.OnClickListener onClickOk) {
- this.onClickOk = onClickOk;
- return this;
+ return view;
}
- public View getView(@NonNull Context context){
- if(view == null){
- view = LayoutInflater.from(context).inflate(layoutId,null);
+ private void setText(TextView tv,CharSequence text){
+ if(text != null){
+ tv.setText(text);
}
- return view;
}
-
}
diff --git a/app-dialog/src/main/java/com/king/app/dialog/BaseDialogConfig.java b/app-dialog/src/main/java/com/king/app/dialog/BaseDialogConfig.java
new file mode 100644
index 0000000..646e485
--- /dev/null
+++ b/app-dialog/src/main/java/com/king/app/dialog/BaseDialogConfig.java
@@ -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 Jenly
+ */
+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;
+ }
+
+
+}
diff --git a/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java b/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java
index ebf2ded..b71353b 100644
--- a/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java
+++ b/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java
@@ -5,7 +5,7 @@ import android.view.View;
import android.widget.Button;
import android.widget.TextView;
-import com.king.app.dialog.AppDialogConfig;
+import com.king.app.dialog.BaseDialogConfig;
import com.king.app.dialog.R;
/**
@@ -13,9 +13,9 @@ import com.king.app.dialog.R;
*/
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();
AppDialogFragment fragment = new AppDialogFragment();
@@ -33,28 +33,35 @@ public class AppDialogFragment extends BaseDialogFragment {
}
public void init(View rootView){
- if(config!=null){
+ if(config != null){
TextView tvDialogTitle = rootView.findViewById(config.getTitleId());
- setText(tvDialogTitle,config.getTitle());
- tvDialogTitle.setVisibility(config.isHideTitle() ? View.GONE : View.VISIBLE);
+ if(tvDialogTitle != null){
+ setText(tvDialogTitle,config.getTitle());
+ tvDialogTitle.setVisibility(config.isHideTitle() ? View.GONE : View.VISIBLE);
+ }
TextView tvDialogContent = rootView.findViewById(config.getContentId());
- setText(tvDialogContent,config.getContent());
+ if(tvDialogContent != null){
+ setText(tvDialogContent,config.getContent());
+ }
Button btnDialogCancel = rootView.findViewById(config.getCancelId());
- setText(btnDialogCancel,config.getCancel());
- btnDialogCancel.setOnClickListener(config.getOnClickCancel() != null ? config.getOnClickCancel() : getOnClickDismiss());
- btnDialogCancel.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
+ if(btnDialogCancel != null){
+ setText(btnDialogCancel,config.getCancel());
+ btnDialogCancel.setOnClickListener(config.getOnClickCancel() != null ? config.getOnClickCancel() : getOnClickDismiss());
+ btnDialogCancel.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
+ }
- //不强制要求要有中间的线
View line = rootView.findViewById(config.getLineId());
if(line != null){
line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
}
Button btnDialogOK = rootView.findViewById(config.getOkId());
- setText(btnDialogOK,config.getOk());
- btnDialogOK.setOnClickListener(config.getOnClickOk() != null ? config.getOnClickOk() : getOnClickDismiss());
+ if(btnDialogOK != null){
+ setText(btnDialogOK,config.getOk());
+ btnDialogOK.setOnClickListener(config.getOnClickOk() != null ? config.getOnClickOk() : getOnClickDismiss());
+ }
}
}
diff --git a/app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java b/app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java
index 50863b6..488715c 100644
--- a/app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java
+++ b/app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java
@@ -8,7 +8,6 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
-import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -58,7 +57,7 @@ public abstract class BaseDialogFragment extends DialogFragment {
}
protected void setText(TextView tv, CharSequence text){
- if(!TextUtils.isEmpty(text)){
+ if(text != null){
tv.setText(text);
}
}
diff --git a/app/release/app-release.apk b/app/release/app-release.apk
deleted file mode 100644
index 57643d2..0000000
Binary files a/app/release/app-release.apk and /dev/null differ
diff --git a/app/release/output.json b/app/release/output.json
deleted file mode 100644
index 1e7126e..0000000
--- a/app/release/output.json
+++ /dev/null
@@ -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":{}}]
\ No newline at end of file
diff --git a/app/src/main/java/com/king/appupdater/MainActivity.java b/app/src/main/java/com/king/appupdater/MainActivity.java
index 80caae0..d8042d7 100644
--- a/app/src/main/java/com/king/appupdater/MainActivity.java
+++ b/app/src/main/java/com/king/appupdater/MainActivity.java
@@ -3,7 +3,6 @@ package com.king.appupdater;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
-import android.os.Environment;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
@@ -33,7 +32,8 @@ public class MainActivity extends AppCompatActivity {
private final Object mLock = new Object();
//下载出现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;
@@ -159,7 +159,7 @@ public class MainActivity extends AppCompatActivity {
* 简单弹框升级
*/
private void clickBtn4(){
- AppDialogConfig config = new AppDialogConfig();
+ AppDialogConfig config = new AppDialogConfig(getContext());
config.setTitle("简单弹框升级")
.setOk("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
@@ -178,9 +178,8 @@ public class MainActivity extends AppCompatActivity {
* 简单自定义弹框升级
*/
private void clickBtn5(){
- AppDialogConfig config = new AppDialogConfig();
- config.setLayoutId(R.layout.dialog)
- .setOk("升级")
+ AppDialogConfig config = new AppDialogConfig(getContext(),R.layout.dialog);
+ config.setOk("升级")
.setHideCancel(true)
.setTitle("简单自定义弹框升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
@@ -241,7 +240,7 @@ public class MainActivity extends AppCompatActivity {
* 简单DialogFragment升级
*/
private void clickBtn7(){
- AppDialogConfig config = new AppDialogConfig();
+ AppDialogConfig config = new AppDialogConfig(getContext());
config.setTitle("简单DialogFragment升级")
.setOk("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
diff --git a/versions.gradle b/versions.gradle
index 11e8033..1e9a5fc 100644
--- a/versions.gradle
+++ b/versions.gradle
@@ -1,7 +1,7 @@
//App
def app_version = [:]
-app_version.versionCode = 15 //androidx 16
-app_version.versionName = "1.0.9"
+app_version.versionCode = 17 //androidx 16
+app_version.versionName = "1.0.10"
ext.app_version = app_version
//build version