|
|
@@ -1,258 +0,0 @@
|
|
|
-package com.xzjmyk.pm.activity.util;
|
|
|
-
|
|
|
-import android.content.ComponentName;
|
|
|
-import android.content.Context;
|
|
|
-import android.content.ServiceConnection;
|
|
|
-import android.os.IBinder;
|
|
|
-import android.text.TextUtils;
|
|
|
-import android.util.Log;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.android.volley.Response;
|
|
|
-import com.android.volley.VolleyError;
|
|
|
-import com.xzjmyk.pm.activity.MyApplication;
|
|
|
-import com.xzjmyk.pm.activity.bean.Area;
|
|
|
-import com.xzjmyk.pm.activity.bean.message.MucRoom;
|
|
|
-import com.xzjmyk.pm.activity.volley.ObjectResult;
|
|
|
-import com.xzjmyk.pm.activity.volley.Result;
|
|
|
-import com.xzjmyk.pm.activity.volley.StringJsonObjectRequest;
|
|
|
-import com.xzjmyk.pm.activity.xmpp.CoreService;
|
|
|
-
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * 自动创建群工具类
|
|
|
- * Created by gongpm on 2016/7/26.
|
|
|
- */
|
|
|
-public class AutoCreateRoomUtil {
|
|
|
- private static AutoCreateRoomUtil instence = null;
|
|
|
-
|
|
|
- public AutoCreateRoomUtil() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public static AutoCreateRoomUtil getInstence() {
|
|
|
- if (instence == null) {
|
|
|
- synchronized (AutoCreateRoomUtil.class) {
|
|
|
- instence = new AutoCreateRoomUtil();
|
|
|
- }
|
|
|
- }
|
|
|
- return instence;
|
|
|
- }
|
|
|
-
|
|
|
- private ServiceConnection mServiceConnection = new ServiceConnection() {
|
|
|
- @Override
|
|
|
- public void onServiceDisconnected(ComponentName name) {
|
|
|
- mXmppService = null;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onServiceConnected(ComponentName name, IBinder service) {
|
|
|
- mXmppService = ((CoreService.CoreServiceBinder) service).getService();
|
|
|
- create();
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- private CoreService mXmppService;
|
|
|
-
|
|
|
-
|
|
|
- private void createGroupChat(String nickName, String roomName, String roomSubject, String roomDesc,
|
|
|
- List<String> inviteUsers, final int or_id) {
|
|
|
-// AppConfig mConfig = MyApplication.getInstance().getConfig();
|
|
|
-// String roomJid;
|
|
|
-//
|
|
|
-// //创建群组
|
|
|
-// try {
|
|
|
-// roomJid = mXmppService.createMucRoom(nickName, roomName, roomSubject, roomDesc);
|
|
|
-// } catch (NullPointerException e) {
|
|
|
-// roomJid = mXmppService.createMucRoom(nickName, roomName, "", roomDesc);
|
|
|
-// }
|
|
|
-// if (TextUtils.isEmpty(roomJid)) {
|
|
|
-// ToastUtil.showToast(context, R.string.create_room_failed);
|
|
|
-// return;
|
|
|
-// }
|
|
|
-//
|
|
|
-// Map<String, String> params = new HashMap<String, String>();
|
|
|
-// params.put("access_token", MyApplication.getInstance().mAccessToken);
|
|
|
-// params.put("jid", roomJid);
|
|
|
-// params.put("name", roomName);
|
|
|
-// params.put("category", "1");
|
|
|
-// params.put("desc", roomDesc);
|
|
|
-// params.put("countryId", String.valueOf(Area.getDefaultCountyId()));// 国家Id
|
|
|
-// Area area = Area.getDefaultProvince();
|
|
|
-// if (area != null) {
|
|
|
-// params.put("provinceId", String.valueOf(area.getId()));// 省份Id
|
|
|
-// }
|
|
|
-// area = Area.getDefaultCity();
|
|
|
-// if (area != null) {
|
|
|
-// params.put("cityId", String.valueOf(area.getId()));// 城市Id
|
|
|
-// area = Area.getDefaultDistrict(area.getId());
|
|
|
-// if (area != null) {
|
|
|
-// params.put("areaId", String.valueOf(area.getId()));// 城市Id
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// double latitude = MyApplication.getInstance().getBdLocationHelper().getLatitude();
|
|
|
-// double longitude = MyApplication.getInstance().getBdLocationHelper().getLongitude();
|
|
|
-// if (latitude != 0)
|
|
|
-// params.put("latitude", String.valueOf(latitude));
|
|
|
-// if (longitude != 0)
|
|
|
-// params.put("longitude", String.valueOf(longitude));
|
|
|
-// params.put("text", JSON.toJSONString(inviteUsers));
|
|
|
-// StringJsonObjectRequest<MucRoom> request = new StringJsonObjectRequest<MucRoom>(mConfig.ROOM_ADD,
|
|
|
-// new Response.ErrorListener() {
|
|
|
-// @Override
|
|
|
-// public void onErrorResponse(VolleyError arg0) {
|
|
|
-//
|
|
|
-// }
|
|
|
-// }, new StringJsonObjectRequest.Listener<MucRoom>() {
|
|
|
-// @Override
|
|
|
-// public void onResponse(ObjectResult<MucRoom> result) {
|
|
|
-// boolean parserResult = Result.defaultParser(context, result, true);
|
|
|
-// if (parserResult && result.getData() != null) {
|
|
|
-// Log.i("gongpengming", "创建群组成功");
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }, MucRoom.class, params);
|
|
|
-// String HASHCODE = Integer.toHexString(this.hashCode()) + "@";
|
|
|
-// MyApplication.getInstance().getFastVolley().addDefaultRequest(HASHCODE, request);
|
|
|
- }
|
|
|
-
|
|
|
- private String roomName;
|
|
|
- private String roomDesc;
|
|
|
- private List<String> inviteUsers;
|
|
|
- private Context context;
|
|
|
-
|
|
|
-
|
|
|
- public void create() {
|
|
|
- String nickName = MyApplication.getInstance().mLoginUser.getNickName();
|
|
|
- Log.i("gongpengming", "mXmppService==" + (mXmppService == null));
|
|
|
- String roomJid;
|
|
|
- try {
|
|
|
- roomJid = mXmppService.createMucRoom(nickName, roomName, "", roomDesc);
|
|
|
- } catch (NullPointerException e) {
|
|
|
- roomJid = mXmppService.createMucRoom(nickName, roomName, "", roomDesc);
|
|
|
- }
|
|
|
- if (TextUtils.isEmpty(roomJid)) {
|
|
|
- Log.i("gongpengming", "roomJid==null");
|
|
|
- return;
|
|
|
- }
|
|
|
- Map<String, String> params = new HashMap<String, String>();
|
|
|
- params.put("access_token", MyApplication.getInstance().mAccessToken);
|
|
|
- params.put("jid", roomJid);
|
|
|
- params.put("name", roomName);
|
|
|
- params.put("desc", roomDesc);
|
|
|
- params.put("countryId", String.valueOf(Area.getDefaultCountyId()));// 国家Id
|
|
|
-
|
|
|
- Area area = Area.getDefaultProvince();
|
|
|
- if (area != null) {
|
|
|
- params.put("provinceId", String.valueOf(area.getId()));// 省份Id
|
|
|
- }
|
|
|
- area = Area.getDefaultCity();
|
|
|
- if (area != null) {
|
|
|
- params.put("cityId", String.valueOf(area.getId()));// 城市Id
|
|
|
- area = Area.getDefaultDistrict(area.getId());
|
|
|
- if (area != null) {
|
|
|
- params.put("areaId", String.valueOf(area.getId()));// 城市Id
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- double latitude = MyApplication.getInstance().getBdLocationHelper().getLatitude();
|
|
|
- double longitude = MyApplication.getInstance().getBdLocationHelper().getLongitude();
|
|
|
- if (latitude != 0)
|
|
|
- params.put("latitude", String.valueOf(latitude));
|
|
|
- if (longitude != 0)
|
|
|
- params.put("longitude", String.valueOf(longitude));
|
|
|
- //TODO 开启线程处理合成群头像操作
|
|
|
- params.put("text", JSON.toJSONString(inviteUsers));
|
|
|
- StringJsonObjectRequest<MucRoom> request = new StringJsonObjectRequest<MucRoom>(MyApplication.getInstance().getConfig().ROOM_ADD,
|
|
|
- new Response.ErrorListener() {
|
|
|
- @Override
|
|
|
- public void onErrorResponse(VolleyError arg0) {
|
|
|
- Log.i("gongpengming", "网络错误");
|
|
|
- }
|
|
|
- }, new StringJsonObjectRequest.Listener<MucRoom>() {
|
|
|
- @Override
|
|
|
- public void onResponse(ObjectResult<MucRoom> result) {
|
|
|
- boolean parserResult = Result.defaultParser(context, result, true);
|
|
|
- if (parserResult && result.getData() != null) {
|
|
|
- Log.i("gongpengming", "创建成功" + result.toString());
|
|
|
- }
|
|
|
- }
|
|
|
- }, MucRoom.class, params);
|
|
|
- MyApplication.getInstance().getFastVolley().addDefaultRequest("", request);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param roomName 群名字
|
|
|
- * @param inviteUsers 群成员
|
|
|
- * @param roomDesc 群说明
|
|
|
- */
|
|
|
- public void createGroupChat(final Context context, final String roomName, final String roomDesc, List<String> inviteUsers) {
|
|
|
- String nickName = MyApplication.getInstance().mLoginUser.getNickName();
|
|
|
- boolean mBind = context.bindService(CoreService.getIntent(), mServiceConnection, Context.BIND_AUTO_CREATE);
|
|
|
- this.context = context;
|
|
|
- this.roomName = roomName;
|
|
|
- this.roomDesc = roomDesc;
|
|
|
- this.inviteUsers = inviteUsers;
|
|
|
-
|
|
|
-// Log.i("gongpengming", "mBind==" + mBind);
|
|
|
-// Log.i("gongpengming", "mXmppService==" + (mXmppService == null));
|
|
|
-// String roomJid;
|
|
|
-// try {
|
|
|
-// roomJid = mXmppService.createMucRoom(nickName, roomName, "", roomDesc);
|
|
|
-// } catch (NullPointerException e) {
|
|
|
-// roomJid = mXmppService.createMucRoom(nickName, roomName, "", roomDesc);
|
|
|
-// }
|
|
|
-// if (TextUtils.isEmpty(roomJid)) {
|
|
|
-// Log.i("gongpengming", "roomJid==null");
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// Map<String, String> params = new HashMap<String, String>();
|
|
|
-// params.put("access_token", MyApplication.getInstance().mAccessToken);
|
|
|
-// params.put("jid", roomJid);
|
|
|
-// params.put("name", roomName);
|
|
|
-// params.put("desc", roomDesc);
|
|
|
-// params.put("countryId", String.valueOf(Area.getDefaultCountyId()));// 国家Id
|
|
|
-//
|
|
|
-// Area area = Area.getDefaultProvince();
|
|
|
-// if (area != null) {
|
|
|
-// params.put("provinceId", String.valueOf(area.getId()));// 省份Id
|
|
|
-// }
|
|
|
-// area = Area.getDefaultCity();
|
|
|
-// if (area != null) {
|
|
|
-// params.put("cityId", String.valueOf(area.getId()));// 城市Id
|
|
|
-// area = Area.getDefaultDistrict(area.getId());
|
|
|
-// if (area != null) {
|
|
|
-// params.put("areaId", String.valueOf(area.getId()));// 城市Id
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// double latitude = MyApplication.getInstance().getBdLocationHelper().getLatitude();
|
|
|
-// double longitude = MyApplication.getInstance().getBdLocationHelper().getLongitude();
|
|
|
-// if (latitude != 0)
|
|
|
-// params.put("latitude", String.valueOf(latitude));
|
|
|
-// if (longitude != 0)
|
|
|
-// params.put("longitude", String.valueOf(longitude));
|
|
|
-// //TODO 开启线程处理合成群头像操作
|
|
|
-// params.put("text", JSON.toJSONString(inviteUsers));
|
|
|
-// StringJsonObjectRequest<MucRoom> request = new StringJsonObjectRequest<MucRoom>(MyApplication.getInstance().getConfig().ROOM_ADD,
|
|
|
-// new Response.ErrorListener() {
|
|
|
-// @Override
|
|
|
-// public void onErrorResponse(VolleyError arg0) {
|
|
|
-// Log.i("gongpengming", "网络错误");
|
|
|
-// }
|
|
|
-// }, new StringJsonObjectRequest.Listener<MucRoom>() {
|
|
|
-// @Override
|
|
|
-// public void onResponse(ObjectResult<MucRoom> result) {
|
|
|
-// boolean parserResult = Result.defaultParser(context, result, true);
|
|
|
-// if (parserResult && result.getData() != null) {
|
|
|
-// Log.i("gongpengming", "创建成功" + result.toString());
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }, MucRoom.class, params);
|
|
|
-// MyApplication.getInstance().getFastVolley().addDefaultRequest("", request);
|
|
|
- }
|
|
|
-}
|