VerificationActivity.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package jiguang.chat.activity;
  2. import android.app.Dialog;
  3. import android.os.Bundle;
  4. import android.text.TextUtils;
  5. import android.view.KeyEvent;
  6. import android.view.View;
  7. import android.view.inputmethod.EditorInfo;
  8. import android.widget.EditText;
  9. import android.widget.TextView;
  10. import net.zoneland.x.bpm.mobile.v1.zoneXBPM.R;
  11. import cn.jpush.im.android.api.ContactManager;
  12. import cn.jpush.im.android.api.JMessageClient;
  13. import cn.jpush.im.android.api.model.UserInfo;
  14. import cn.jpush.im.api.BasicCallback;
  15. import jiguang.chat.database.FriendRecommendEntry;
  16. import jiguang.chat.database.UserEntry;
  17. import jiguang.chat.entity.FriendInvitation;
  18. import jiguang.chat.model.InfoModel;
  19. import jiguang.chat.utils.DialogCreator;
  20. import jiguang.chat.utils.ToastUtil;
  21. /**
  22. * Created by ${chenyn} on 2017/3/14.
  23. */
  24. public class VerificationActivity extends BaseActivity {
  25. private EditText mEt_reason;
  26. private UserInfo mMyInfo;
  27. private String mTargetAppKey;
  28. @Override
  29. protected void onCreate(Bundle savedInstanceState) {
  30. super.onCreate(savedInstanceState);
  31. setContentView(R.layout.activity_verification);
  32. initView();
  33. initData();
  34. }
  35. private void initData() {
  36. mEt_reason.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  37. @Override
  38. public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  39. if (actionId == EditorInfo.IME_ACTION_SEND) {
  40. sendAddReason();
  41. }
  42. return false;
  43. }
  44. });
  45. mJmui_commit_btn.setOnClickListener(new View.OnClickListener() {
  46. @Override
  47. public void onClick(View v) {
  48. sendAddReason();
  49. }
  50. });
  51. }
  52. private void sendAddReason() {
  53. final String userName;
  54. String displayName;
  55. String targetAvatar;
  56. Long targetUid;
  57. if (getIntent().getFlags() == 1) {
  58. //添加好友申请时对方信息
  59. userName = getIntent().getStringExtra("detail_add_friend");
  60. displayName = getIntent().getStringExtra("detail_add_nick_name");
  61. targetAvatar = getIntent().getStringExtra("detail_add_avatar_path");
  62. targetUid = getIntent().getLongExtra("detail_add_uid", 0);
  63. if (TextUtils.isEmpty(displayName)) {
  64. displayName = userName;
  65. }
  66. //搜索方式添加好友
  67. } else {
  68. targetAvatar = InfoModel.getInstance().getAvatarPath();
  69. displayName = InfoModel.getInstance().getNickName();
  70. targetUid = InfoModel.getInstance().getUid();
  71. if (TextUtils.isEmpty(displayName)) {
  72. displayName = InfoModel.getInstance().getUserName();
  73. }
  74. userName = InfoModel.getInstance().getUserName();
  75. }
  76. final String reason = mEt_reason.getText().toString();
  77. final String finalTargetAvatar = targetAvatar;
  78. final String finalDisplayName = displayName;
  79. final Long finalUid = targetUid;
  80. final Dialog dialog = DialogCreator.createLoadingDialog(this, this.getString(R.string.jmui_loading));
  81. dialog.show();
  82. ContactManager.sendInvitationRequest(userName, null, reason, new BasicCallback() {
  83. @Override
  84. public void gotResult(int responseCode, String responseMessage) {
  85. dialog.dismiss();
  86. if (responseCode == 0) {
  87. UserEntry userEntry = UserEntry.getUser(mMyInfo.getUserName(), mMyInfo.getAppKey());
  88. FriendRecommendEntry entry = FriendRecommendEntry.getEntry(userEntry,
  89. userName, mTargetAppKey);
  90. if (null == entry) {
  91. entry = new FriendRecommendEntry(finalUid, userName, "", finalDisplayName, mTargetAppKey,
  92. finalTargetAvatar, finalDisplayName, reason, FriendInvitation.INVITING.getValue(), userEntry, 100);
  93. } else {
  94. entry.state = FriendInvitation.INVITING.getValue();
  95. entry.reason = reason;
  96. }
  97. entry.save();
  98. ToastUtil.shortToast(VerificationActivity.this, "申请成功");
  99. finish();
  100. } else if (responseCode == 871317) {
  101. ToastUtil.shortToast(VerificationActivity.this, "不能添加自己为好友");
  102. } else {
  103. ToastUtil.shortToast(VerificationActivity.this, "申请失败");
  104. }
  105. }
  106. });
  107. }
  108. private void initView() {
  109. initTitle(true, true, "验证信息", "", true, "发送");
  110. mEt_reason = (EditText) findViewById(R.id.et_reason);
  111. mMyInfo = JMessageClient.getMyInfo();
  112. mTargetAppKey = mMyInfo.getAppKey();
  113. String name;
  114. //群组详细信息点击非好友头像,跳转到此添加界面
  115. if (getIntent().getFlags() == 1) {
  116. name = getIntent().getStringExtra("detail_add_friend_my_nickname");
  117. if (TextUtils.isEmpty(name)) {
  118. mEt_reason.setText("我是");
  119. } else {
  120. mEt_reason.setText("我是" + name);
  121. }
  122. //搜索用户发送添加申请
  123. } else {
  124. name = mMyInfo.getNickname();
  125. if (TextUtils.isEmpty(name)) {
  126. mEt_reason.setText("我是");
  127. } else {
  128. mEt_reason.setText("我是" + name);
  129. }
  130. }
  131. }
  132. }