|
@@ -0,0 +1,112 @@
|
|
|
|
|
+package com.tongyu.luck.happywork.ui.widget.dialog;
|
|
|
|
|
+
|
|
|
|
|
+import android.app.Dialog;
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.content.Intent;
|
|
|
|
|
+import android.support.annotation.NonNull;
|
|
|
|
|
+import android.text.SpannableString;
|
|
|
|
|
+import android.text.Spanned;
|
|
|
|
|
+import android.text.method.LinkMovementMethod;
|
|
|
|
|
+import android.text.style.ClickableSpan;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.widget.Button;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
+
|
|
|
|
|
+import com.tongyu.luck.happywork.R;
|
|
|
|
|
+import com.tongyu.luck.happywork.ui.activity.PrivacyTipsActivity;
|
|
|
|
|
+import com.tongyu.luck.happywork.ui.activity.UserTipsActivity;
|
|
|
|
|
+import com.tongyu.luck.happywork.ui.base.BaseViewHolder;
|
|
|
|
|
+import com.tongyu.luck.happywork.ui.span.TipsClickSpan;
|
|
|
|
|
+
|
|
|
|
|
+import butterknife.BindView;
|
|
|
|
|
+import butterknife.OnClick;
|
|
|
|
|
+
|
|
|
|
|
+public class TipsDialog {
|
|
|
|
|
+ private Dialog mDialog;
|
|
|
|
|
+ private ViewHolder mViewHolder;
|
|
|
|
|
+ private OnClickSureListener onClickSureListener;
|
|
|
|
|
+
|
|
|
|
|
+ public TipsDialog(final Context mContext) {
|
|
|
|
|
+ mViewHolder = new ViewHolder(mContext);
|
|
|
|
|
+ mDialog = new Dialog(mContext, R.style.HappyJobDialog);
|
|
|
|
|
+ mDialog.setCanceledOnTouchOutside(false);
|
|
|
|
|
+ mDialog.setCancelable(false);
|
|
|
|
|
+ mDialog.setContentView(mViewHolder.getView());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void dismiss() {
|
|
|
|
|
+ if (mDialog != null && mDialog.isShowing())
|
|
|
|
|
+ mDialog.dismiss();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void show() {
|
|
|
|
|
+ if (mDialog != null && !mDialog.isShowing())
|
|
|
|
|
+ mDialog.show();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setOnClickSureListener(OnClickSureListener onClickSureListener) {
|
|
|
|
|
+ this.onClickSureListener = onClickSureListener;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ class ViewHolder extends BaseViewHolder {
|
|
|
|
|
+
|
|
|
|
|
+ @BindView(R.id.btn_agree)
|
|
|
|
|
+ Button btnAgree;
|
|
|
|
|
+ @BindView(R.id.tv_disagree)
|
|
|
|
|
+ TextView tvDisagree;
|
|
|
|
|
+ @BindView(R.id.tv_tips)
|
|
|
|
|
+ TextView tvTips;
|
|
|
|
|
+
|
|
|
|
|
+ public ViewHolder(Context mContext) {
|
|
|
|
|
+ super(mContext);
|
|
|
|
|
+
|
|
|
|
|
+ ClickableSpan clickableSpan = new ClickableSpan() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(@NonNull View widget) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ SpannableString spannableString = new SpannableString(mContext.getResources().getString(R.string.tips));
|
|
|
|
|
+ spannableString.setSpan(new TipsClickSpan() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View widget) {
|
|
|
|
|
+ ViewHolder.super.mContext.startActivity(new Intent(ViewHolder.super.mContext, UserTipsActivity.class));
|
|
|
|
|
+ }
|
|
|
|
|
+ }, spannableString.length() - 19, spannableString.length() - 13, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
|
|
|
+ spannableString.setSpan(new TipsClickSpan() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View widget) {
|
|
|
|
|
+ ViewHolder.super.mContext.startActivity(new Intent(ViewHolder.super.mContext, PrivacyTipsActivity.class));
|
|
|
|
|
+ }
|
|
|
|
|
+ }, spannableString.length() - 12, spannableString.length() - 6, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
|
|
|
+ tvTips.setMovementMethod(LinkMovementMethod.getInstance());//不设置点击会失效
|
|
|
|
|
+ tvTips.setHintTextColor(mContext.getResources().getColor(R.color.transparent));//不设置会有背景色
|
|
|
|
|
+ tvTips.setText(spannableString);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int bindViewLayoutId() {
|
|
|
|
|
+ return R.layout.dialog_tips;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @OnClick({R.id.tv_disagree, R.id.btn_agree})
|
|
|
|
|
+ public void onClick(View view) {
|
|
|
|
|
+ if (view.getId() == R.id.tv_disagree) {
|
|
|
|
|
+ if (onClickSureListener != null)
|
|
|
|
|
+ onClickSureListener.onClick(false);
|
|
|
|
|
+ dismiss();
|
|
|
|
|
+ } else if (view.getId() == R.id.btn_agree) {
|
|
|
|
|
+ if (onClickSureListener != null)
|
|
|
|
|
+ onClickSureListener.onClick(true);
|
|
|
|
|
+ dismiss();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public interface OnClickSureListener {
|
|
|
|
|
+ void onClick(boolean isSure);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|