|
|
@@ -0,0 +1,199 @@
|
|
|
+package com.sheishuo.app.main.activity;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.support.design.widget.FloatingActionButton;
|
|
|
+import android.support.design.widget.Snackbar;
|
|
|
+import android.support.v7.app.AppCompatActivity;
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
+import android.support.v7.widget.Toolbar;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.Toast;
|
|
|
+
|
|
|
+import com.netease.nim.uikit.common.ui.dialog.DialogMaker;
|
|
|
+import com.netease.nimlib.sdk.NIMClient;
|
|
|
+import com.netease.nimlib.sdk.RequestCallback;
|
|
|
+import com.netease.nimlib.sdk.team.TeamService;
|
|
|
+import com.netease.nimlib.sdk.team.model.Team;
|
|
|
+import com.sheishuo.app.R;
|
|
|
+import com.sheishuo.app.cache.SocialInfoCache;
|
|
|
+import com.sheishuo.app.common.beans.RequestBean;
|
|
|
+import com.sheishuo.app.common.util.net.INet;
|
|
|
+import com.sheishuo.app.common.util.net.NetImpl;
|
|
|
+import com.sheishuo.app.common.util.net.ResponseCallback;
|
|
|
+import com.sheishuo.app.common.views.BaseToolbar;
|
|
|
+import com.sheishuo.app.core_module.friends.activity.ContactsListActivity;
|
|
|
+import com.sheishuo.app.impl.SheishuoUI;
|
|
|
+import com.sheishuo.app.impl.SheishuoUIKit;
|
|
|
+import com.sheishuo.app.main.adapter.RequestAdapter;
|
|
|
+import com.sheishuo.app.main.adapter.RequestItemClickListener;
|
|
|
+
|
|
|
+public class RequestActivity extends SheishuoUI {
|
|
|
+
|
|
|
+ private BaseToolbar toolbar;
|
|
|
+ private RecyclerView recyclerView;
|
|
|
+ private Context context = this;
|
|
|
+ private RequestAdapter requestAdapter;
|
|
|
+ private INet net = new NetImpl();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setContentView(R.layout.activity_request);
|
|
|
+
|
|
|
+ findViews();
|
|
|
+ init();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void findViews() {
|
|
|
+ toolbar = findView(R.id.toolbar);
|
|
|
+ recyclerView = findView(R.id.request_list_layout);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void init() {
|
|
|
+
|
|
|
+ toolbar.setTitle("新的朋友");
|
|
|
+ toolbar.setBackOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ requestAdapter = new RequestAdapter(this);
|
|
|
+ recyclerView.setAdapter(requestAdapter);
|
|
|
+ recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
|
|
+ requestAdapter.setOnItemClickListener(new RequestItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onAcceptClick(View view) {
|
|
|
+ final RequestBean.ListBean bean = (RequestBean.ListBean)view.getTag();
|
|
|
+ if(bean.getType().equals("0"))
|
|
|
+ {
|
|
|
+ net.addFriend(bean.getId(), new ResponseCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Object object) {
|
|
|
+ SocialInfoCache.setFollow(bean.getUser_id(), true);
|
|
|
+ makeToast("已关注该用户");
|
|
|
+ removeRequest(bean);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailed(String error) {
|
|
|
+ makeToast("加好友失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else if(bean.getType().equals("1"))
|
|
|
+ {
|
|
|
+ String groupId = bean.getExtra_id();
|
|
|
+ Team targetTeam = NIMClient.getService(TeamService.class).queryTeamBlock(groupId);
|
|
|
+ if(targetTeam == null)
|
|
|
+ {
|
|
|
+ NIMClient.getService(TeamService.class).queryTeam(groupId).setCallback(new RequestCallback<Team>() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Team team) {
|
|
|
+ joinTeam(team, bean);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailed(int i) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onException(Throwable throwable) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ joinTeam(targetTeam, bean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRejectClick(View view) {
|
|
|
+ DialogMaker.showProgressDialog(context, "", false);
|
|
|
+ final RequestBean.ListBean bean = (RequestBean.ListBean)view.getTag();
|
|
|
+ net.requestDelete(bean.getId(), new ResponseCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Object object) {
|
|
|
+ DialogMaker.dismissProgressDialog();
|
|
|
+ removeRequest(bean);
|
|
|
+ makeToast("已删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailed(String error) {
|
|
|
+ DialogMaker.dismissProgressDialog();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void joinTeam(Team team, final RequestBean.ListBean bean)
|
|
|
+ {
|
|
|
+ if (!team.isMyTeam())
|
|
|
+ {
|
|
|
+ NIMClient.getService(TeamService.class).applyJoinTeam(team.getId(), "申请入群").setCallback(new RequestCallback<Team>() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Team team) {
|
|
|
+ makeToast("已经加入群"+team.getName());
|
|
|
+ removeRequest(bean);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailed(int i) {
|
|
|
+ makeToast("加入群失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onException(Throwable throwable) {
|
|
|
+ makeToast("加入群出错");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DialogMaker.showProgressDialog(context, "", false);
|
|
|
+ net.requestDelete(bean.getId(), new ResponseCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Object object) {
|
|
|
+ DialogMaker.dismissProgressDialog();
|
|
|
+ removeRequest(bean);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailed(String error) {
|
|
|
+ DialogMaker.dismissProgressDialog();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ makeToast("已经在群里");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void removeRequest(RequestBean.ListBean bean)
|
|
|
+ {
|
|
|
+ ContactsListActivity.requestBean.getD().remove(bean);
|
|
|
+ getHandler().post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ requestAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void makeToast(final String value)
|
|
|
+ {
|
|
|
+ getHandler().post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ Toast.makeText(context, value, Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|