296 lines
11 KiB
Java
296 lines
11 KiB
Java
|
|
package com.tianrun.sipcall.call;
|
||
|
|
|
||
|
|
import android.content.DialogInterface;
|
||
|
|
import android.graphics.Color;
|
||
|
|
import android.os.Bundle;
|
||
|
|
import android.os.Message;
|
||
|
|
import android.view.View;
|
||
|
|
import android.view.ViewGroup;
|
||
|
|
import android.widget.AdapterView;
|
||
|
|
import android.widget.Button;
|
||
|
|
import android.widget.CheckBox;
|
||
|
|
import android.widget.CompoundButton;
|
||
|
|
import android.widget.GridView;
|
||
|
|
import android.widget.ImageView;
|
||
|
|
import android.widget.TextView;
|
||
|
|
import android.widget.Toast;
|
||
|
|
|
||
|
|
import androidx.annotation.NonNull;
|
||
|
|
import androidx.annotation.Nullable;
|
||
|
|
|
||
|
|
import com.alibaba.fastjson.JSONObject;
|
||
|
|
import com.qmuiteam.qmui.skin.QMUISkinManager;
|
||
|
|
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
|
||
|
|
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;
|
||
|
|
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;
|
||
|
|
import com.tianrun.sipcall.R;
|
||
|
|
import com.tianrun.sipcall.SipEngine;
|
||
|
|
import com.tianrun.sipcall.db.DBUser;
|
||
|
|
import com.tianrun.sipcall.net.Net;
|
||
|
|
import com.tianrun.sipcall.net.NetPkg;
|
||
|
|
import com.tianrun.sipcall.ui.TrAdapter;
|
||
|
|
import com.tianrun.sipcall.ui.TrBaseActivity;
|
||
|
|
import com.tianrun.sipcall.ui.UIUtl;
|
||
|
|
import com.tianrun.sipcall.utils.HttpUtl;
|
||
|
|
|
||
|
|
import java.util.ArrayList;
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
public class CreateMeetingActivity extends TrBaseActivity {
|
||
|
|
TextView meetingTopic;
|
||
|
|
TextView meetingDesc;
|
||
|
|
TextView meetingUsers;
|
||
|
|
GridView gridUsers;
|
||
|
|
TrAdapter adapterUser;
|
||
|
|
|
||
|
|
List<DBUser> users = new ArrayList<>();
|
||
|
|
HashMap<String, DBUser> mapUsers = new HashMap<>();
|
||
|
|
|
||
|
|
@Override
|
||
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||
|
|
super.onCreate(savedInstanceState);
|
||
|
|
setContentView(R.layout.creatmeeting_view);
|
||
|
|
|
||
|
|
meetingTopic = findViewById(R.id.meeting_name);
|
||
|
|
meetingDesc = findViewById(R.id.meeting_desc);
|
||
|
|
meetingUsers = findViewById(R.id.textViewMembers);
|
||
|
|
gridUsers = findViewById(R.id.GridUser_select);
|
||
|
|
|
||
|
|
users.clear();
|
||
|
|
mapUsers.clear();
|
||
|
|
DBUser u = new DBUser("", "添加分机号", "");
|
||
|
|
u.isAddFlag = true;
|
||
|
|
users.add(u);
|
||
|
|
|
||
|
|
setList(null);
|
||
|
|
refreshSelectedUsers();
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
protected void onResume() {
|
||
|
|
super.onResume();
|
||
|
|
refreshSelectedUsers();
|
||
|
|
}
|
||
|
|
|
||
|
|
public class UserSelectViews {
|
||
|
|
public TextView textViewName;
|
||
|
|
public TextView textViewNum;
|
||
|
|
public ImageView imageViewStatus;
|
||
|
|
public Button buttonDel;
|
||
|
|
public CheckBox checkBox;
|
||
|
|
public ImageView getImageViewPhoneIcon;
|
||
|
|
public ImageView imageViewAddflag;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setList(List<DBUser> list) {
|
||
|
|
if (list != null) {
|
||
|
|
for (DBUser u : list) {
|
||
|
|
mapUsers.put(u.phone, u);
|
||
|
|
users.add(users.size() - 1, u);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (adapterUser == null) {
|
||
|
|
adapterUser = UIUtl.setList(this, gridUsers, R.layout.list_item_user_select, users, new TrAdapter.Callback() {
|
||
|
|
@Override
|
||
|
|
public void initCallback(Object data, int position, View prefabView, ViewGroup parent) {
|
||
|
|
UserSelectViews views;
|
||
|
|
if (prefabView.getTag() == null) {
|
||
|
|
views = new UserSelectViews();
|
||
|
|
views.textViewName = prefabView.findViewById(R.id.textViewName);
|
||
|
|
views.textViewNum = prefabView.findViewById(R.id.textViewNum);
|
||
|
|
views.imageViewStatus = prefabView.findViewById(R.id.imageViewStatus);
|
||
|
|
views.buttonDel = prefabView.findViewById(R.id.buttonDel);
|
||
|
|
views.checkBox = prefabView.findViewById(R.id.checkBox);
|
||
|
|
views.getImageViewPhoneIcon = prefabView.findViewById(R.id.imageView3PhoneIcon);
|
||
|
|
views.imageViewAddflag = prefabView.findViewById(R.id.imageViewAddFlag);
|
||
|
|
prefabView.setTag(views);
|
||
|
|
} else {
|
||
|
|
views = (UserSelectViews) (prefabView.getTag());
|
||
|
|
}
|
||
|
|
|
||
|
|
DBUser user = (DBUser) data;
|
||
|
|
|
||
|
|
if (user.isAddFlag) {
|
||
|
|
views.imageViewAddflag.setVisibility(View.VISIBLE);
|
||
|
|
views.buttonDel.setVisibility(View.INVISIBLE);
|
||
|
|
views.checkBox.setVisibility(View.INVISIBLE);
|
||
|
|
views.getImageViewPhoneIcon.setVisibility(View.INVISIBLE);
|
||
|
|
} else {
|
||
|
|
views.imageViewAddflag.setVisibility(View.INVISIBLE);
|
||
|
|
views.buttonDel.setVisibility(View.VISIBLE);
|
||
|
|
views.checkBox.setVisibility(View.INVISIBLE);
|
||
|
|
views.getImageViewPhoneIcon.setVisibility(View.VISIBLE);
|
||
|
|
}
|
||
|
|
views.textViewName.setText(user.name);
|
||
|
|
views.textViewNum.setText(user.phone);
|
||
|
|
if (user.isOffline()) {
|
||
|
|
views.imageViewStatus.setColorFilter(Color.GRAY);
|
||
|
|
} else if (user.isOnline()) {
|
||
|
|
views.imageViewStatus.setColorFilter(Color.GREEN);
|
||
|
|
} else if (user.isBusy()) {
|
||
|
|
views.imageViewStatus.setColorFilter(Color.RED);
|
||
|
|
} else {
|
||
|
|
views.imageViewStatus.setColorFilter(Color.GRAY);
|
||
|
|
}
|
||
|
|
views.checkBox.setChecked(true);
|
||
|
|
views.checkBox.setClickable(false);
|
||
|
|
// views.checkBox.setOnClickListener(new View.OnClickListener() {
|
||
|
|
// @Override
|
||
|
|
// public void onClick(View v) {
|
||
|
|
// UserSelect d = (UserSelect) data;
|
||
|
|
// d.isSelected = !d.isSelected;
|
||
|
|
// adapterUser.notifyDataSetChanged();
|
||
|
|
// refreshSelectedUsers();
|
||
|
|
// }
|
||
|
|
// });
|
||
|
|
views.buttonDel.setOnClickListener(new View.OnClickListener() {
|
||
|
|
@Override
|
||
|
|
public void onClick(View v) {
|
||
|
|
users.remove(data);
|
||
|
|
mapUsers.remove(user.phone);
|
||
|
|
adapterUser.notifyDataSetChanged();
|
||
|
|
refreshSelectedUsers();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void clickCallback(Object data, AdapterView<?> parent, View view, int position, long id) {
|
||
|
|
DBUser d = (DBUser) data;
|
||
|
|
if (d.isAddFlag) {
|
||
|
|
showUsersMultiChoiceDialog();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
adapterUser.notifyDataSetChanged();
|
||
|
|
refreshSelectedUsers();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void showUsersMultiChoiceDialog() {
|
||
|
|
List<String> list = new ArrayList<>();
|
||
|
|
List<String> listPhone = new ArrayList<>();
|
||
|
|
for (DBUser u : DBUser.allUser) {
|
||
|
|
if (mapUsers.get(u.phone) == null) {
|
||
|
|
listPhone.add(u.phone);
|
||
|
|
list.add(u.phone + " | " + u.name);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if(list.size() == 0) {
|
||
|
|
UIUtl.toastI("所有分机已经添加");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
final String[] items = new String[list.size()];
|
||
|
|
list.toArray(items);
|
||
|
|
final QMUIDialog.MultiCheckableDialogBuilder builder = new QMUIDialog.MultiCheckableDialogBuilder(this)
|
||
|
|
.setTitle("选择要加入的分机号")
|
||
|
|
// .setCheckedItems(new int[]{1, 3})
|
||
|
|
.setSkinManager(QMUISkinManager.defaultInstance(this))
|
||
|
|
.addItems(items, new DialogInterface.OnClickListener() {
|
||
|
|
@Override
|
||
|
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
|
|
||
|
|
}
|
||
|
|
});
|
||
|
|
builder.addAction("取消", new QMUIDialogAction.ActionListener() {
|
||
|
|
@Override
|
||
|
|
public void onClick(QMUIDialog dialog, int index) {
|
||
|
|
dialog.dismiss();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
builder.addAction("确定", new QMUIDialogAction.ActionListener() {
|
||
|
|
@Override
|
||
|
|
public void onClick(QMUIDialog dialog, int index) {
|
||
|
|
int[] selectIndexs = builder.getCheckedItemIndexes();
|
||
|
|
if (selectIndexs.length > 0) {
|
||
|
|
List<DBUser> list = new ArrayList<>();
|
||
|
|
for (int i = 0; i < selectIndexs.length; i++) {
|
||
|
|
String phNum = listPhone.get(selectIndexs[i]);
|
||
|
|
list.add(DBUser.getUser(phNum));
|
||
|
|
}
|
||
|
|
setList(list);
|
||
|
|
}
|
||
|
|
|
||
|
|
dialog.dismiss();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
int mCurrentDialogStyle = com.qmuiteam.qmui.R.style.QMUI_Dialog;
|
||
|
|
builder.create(mCurrentDialogStyle).show();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void refreshSelectedUsers() {
|
||
|
|
meetingUsers.setText("已选择:" + getSelectedUsers());
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getSelectedUsers() {
|
||
|
|
String str = "";
|
||
|
|
for (DBUser us : users) {
|
||
|
|
if (!us.isAddFlag) {
|
||
|
|
str = str + us.phone + ",";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return str;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void createMeetingVoice(View view) {
|
||
|
|
createMeeting(false);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public void createMeetingVideo(View view) {
|
||
|
|
createMeeting(true);
|
||
|
|
}
|
||
|
|
|
||
|
|
void createMeeting(boolean isVideo) {
|
||
|
|
String userStr = getSelectedUsers();
|
||
|
|
if (userStr == null || userStr == "") {
|
||
|
|
UIUtl.toastI("请添加要加入会议的分机号");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
QMUITipDialog dialog = UIUtl.toastLoading("");
|
||
|
|
Net.createMeeting(meetingTopic.getText().toString(), meetingDesc.getText().toString(), userStr, new HttpUtl.CallBack() {
|
||
|
|
@Override
|
||
|
|
public void onRequestComplete(int cmd, String result, Object orgs) {
|
||
|
|
JSONObject jo = JSONObject.parseObject(result);
|
||
|
|
if (jo != null) {
|
||
|
|
String code = "";
|
||
|
|
if(isVideo) {
|
||
|
|
code = jo.getString("video_code");
|
||
|
|
} else {
|
||
|
|
code = jo.getString("audio_code");
|
||
|
|
}
|
||
|
|
SipEngine.getInstance().CallNumber(code, isVideo);
|
||
|
|
}
|
||
|
|
dialog.dismiss();
|
||
|
|
finish();
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void onRequestError(int cmd, String result, Object orgs) {
|
||
|
|
dialog.dismiss();
|
||
|
|
}
|
||
|
|
}, isVideo);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void exit(View view) {
|
||
|
|
finish();
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public boolean handleMessage(@NonNull Message msg) {
|
||
|
|
switch (msg.what) {
|
||
|
|
case Net.CMD_createMeeting:
|
||
|
|
NetPkg pkg =(NetPkg)(msg.obj);
|
||
|
|
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
return super.handleMessage(msg);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|