/dateLoveInternational/src/main/java/com/datelove/online/International/dialog/ReportDialog.java

https://bitbucket.org/juzhiwiscom/datelove · Java · 138 lines · 118 code · 16 blank · 4 comment · 12 complexity · 0bc5eb0033f7e1734d3b416e1a25924a MD5 · raw file

  1. package com.datelove.online.International.dialog;
  2. import android.text.TextUtils;
  3. import android.view.View;
  4. import android.widget.Button;
  5. import android.widget.EditText;
  6. import android.widget.RadioButton;
  7. import android.widget.RadioGroup;
  8. import android.widget.TextView;
  9. import com.alibaba.fastjson.JSON;
  10. import com.datelove.online.International.R;
  11. import com.datelove.online.International.bean.BaseModel;
  12. import com.datelove.online.International.constant.IUrlConstant;
  13. import com.datelove.online.International.xml.PlatformInfoXml;
  14. import com.library.app.BaseDialogFragment;
  15. import com.library.utils.ToastUtil;
  16. import com.zhy.http.okhttp.OkHttpUtils;
  17. import com.zhy.http.okhttp.callback.Callback;
  18. import okhttp3.Call;
  19. import okhttp3.Response;
  20. /**
  21. * 举报对话框
  22. * Created by zhangdroid on 2016/7/4.
  23. */
  24. public class ReportDialog extends BaseDialogFragment {
  25. private String mUserId;
  26. public static ReportDialog newInstance(String title, String uId) {
  27. ReportDialog reportDialog = new ReportDialog();
  28. reportDialog.mUserId = uId;
  29. reportDialog.setArguments(getDialogBundle(title, null, null, null, true));
  30. return reportDialog;
  31. }
  32. @Override
  33. protected int getLayoutResId() {
  34. return R.layout.dialog_report;
  35. }
  36. @Override
  37. protected void setDialogContentView(View view) {
  38. TextView tvTitle = (TextView) view.findViewById(R.id.dialog_report_title);
  39. View dividerView = view.findViewById(R.id.dialog_report_divider);// 标题栏下分割线
  40. final RadioGroup radioGroupReason = (RadioGroup) view.findViewById(R.id.dialog_reason_group);
  41. final EditText etMore = (EditText) view.findViewById(R.id.dialog_report_reason_more);// 补充说明
  42. Button btnPositive = (Button) view.findViewById(R.id.dialog_report_sure);
  43. Button btnNegative = (Button) view.findViewById(R.id.dialog_report_cancel);
  44. String title = getDialogTitle();
  45. if (!TextUtils.isEmpty((title))) {
  46. tvTitle.setText(title);
  47. tvTitle.setVisibility(View.VISIBLE);
  48. dividerView.setVisibility(View.VISIBLE);
  49. } else {
  50. tvTitle.setVisibility(View.GONE);
  51. dividerView.setVisibility(View.GONE);
  52. }
  53. String positive = getDialogPositive();
  54. if (!TextUtils.isEmpty((positive))) {
  55. btnPositive.setText(positive);
  56. }
  57. String negative = getDialogNegative();
  58. if (!TextUtils.isEmpty((negative))) {
  59. btnNegative.setText(negative);
  60. }
  61. btnPositive.setOnClickListener(new View.OnClickListener() {
  62. @Override
  63. public void onClick(View v) {
  64. RadioButton checkBtn = (RadioButton) radioGroupReason.findViewById(radioGroupReason.getCheckedRadioButtonId());
  65. if(checkBtn==null){
  66. ToastUtil.showShortToast(getActivity(), getActivity().getString(R.string.report_reason_empty));
  67. return;
  68. }
  69. String reason = checkBtn.getText().toString();
  70. if (TextUtils.isEmpty(reason)) {
  71. ToastUtil.showShortToast(getActivity(), getActivity().getString(R.string.report_reason_empty));
  72. return;
  73. }
  74. reportUser(reason, etMore.getText().toString().trim());
  75. }
  76. });
  77. btnNegative.setOnClickListener(new View.OnClickListener() {
  78. @Override
  79. public void onClick(View v) {
  80. dismiss();
  81. }
  82. });
  83. }
  84. private void reportUser(String reason, String contentMore) {
  85. if (TextUtils.isEmpty(mUserId)) {
  86. dismiss();
  87. return;
  88. }
  89. OkHttpUtils.post()
  90. .url(IUrlConstant.URL_REPORT)
  91. .addHeader("token", PlatformInfoXml.getToken())
  92. .addParams("platformInfo", PlatformInfoXml.getPlatformJsonString())
  93. .addParams("contentId", reason)// 举报原因
  94. .addParams("content", contentMore)// 补充说明
  95. .build()
  96. .execute(new Callback<BaseModel>() {
  97. @Override
  98. public BaseModel parseNetworkResponse(Response response, int id) throws Exception {
  99. String resultJson = response.body().string();
  100. if (!TextUtils.isEmpty(resultJson)) {
  101. return JSON.parseObject(resultJson, BaseModel.class);
  102. }
  103. return null;
  104. }
  105. @Override
  106. public void onError(Call call, Exception e, int id) {
  107. ToastUtil.showShortToast(getActivity(), getString(R.string.report_fail));
  108. dismiss();
  109. }
  110. @Override
  111. public void onResponse(BaseModel response, int id) {
  112. if (response != null) {
  113. String isSucceed = response.getIsSucceed();
  114. if (!TextUtils.isEmpty(isSucceed) && "1".equals(isSucceed)) {
  115. ToastUtil.showShortToast(getActivity(), getString(R.string.report_success));
  116. dismiss();
  117. }
  118. }
  119. }
  120. });
  121. }
  122. }