This commit is contained in:
2023-10-20 18:25:06 +08:00
parent 0935f76bac
commit d3ab50e844
56 changed files with 2645 additions and 135 deletions

View File

@@ -0,0 +1,206 @@
package com.shayu.onetoone.activity;
import android.app.Dialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.ImageView;
import android.widget.TextView;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.JSONObject;
import com.makeramen.roundedimageview.RoundedImageView;
import com.shayu.onetoone.R;
import com.shayu.onetoone.activity.message.ChatActivity;
import com.shayu.onetoone.bean.MatchingInfoBean;
import com.shayu.onetoone.bean.MatchingInfoUserBean;
import com.shayu.onetoone.bean.SendConsumeBean;
import com.shayu.onetoone.bean.UserBean;
import com.shayu.onetoone.dialog.TipsDialog;
import com.shayu.onetoone.listener.OnDialogClickListener;
import com.shayu.onetoone.listener.OnSendMessageListener;
import com.shayu.onetoone.manager.OTONetManager;
import com.shayu.onetoone.manager.RouteManager;
import com.shayu.onetoone.manager.SendMessageManager;
import com.shayu.onetoone.utils.ConversationUtils;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.http.base.HttpCallback;
import com.yunbao.common.utils.ToastUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
@Route(path = RouteManager.ACTIVITY_MATCHING)
public class MatchingActivity extends AbsOTOActivity {
private Task task;
private Handler handler;
private RoundedImageView user1, user2, user3, user4, user5;
private TextView num;
private ImageView back;
List<RoundedImageView> imageViewList = new ArrayList<>();
@Override
protected int getLayoutId() {
return R.layout.activity_matching;
}
@Override
protected void main(Bundle savedInstanceState) {
handler = new Handler(Looper.getMainLooper());
if (initView()) {
task = new Task();
new Timer().schedule(task, 10000, 10000);
}
initData();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (task != null) {
task.cancel();
task = null;
}
handler = null;
}
private boolean initView() {
user1 = findViewById(R.id.user1);
user2 = findViewById(R.id.user2);
user3 = findViewById(R.id.user3);
user4 = findViewById(R.id.user4);
user5 = findViewById(R.id.user5);
num = findViewById(R.id.num);
back = findViewById(R.id.back);
imageViewList.add(user1);
imageViewList.add(user2);
imageViewList.add(user3);
imageViewList.add(user4);
imageViewList.add(user5);
back.setOnClickListener(v -> {
new TipsDialog(mContext)
.setTitle("確定要退出靈魂速配嗎?")
.setApplyText("繼續匹配")
.setCancelText("徹底離開")
.setOnDialogClickListener(new OnDialogClickListener() {
@Override
public void onCancel(Dialog dialog) {
super.onCancel(dialog);
task.cancel();
task = null;
MatchingActivity.this.finish();
}
}).showDialog();
});
Bundle bundle = getIntent().getBundleExtra("bundle");
if (bundle != null) {
String data = bundle.getString("data");
bundle.putInt("type",ChatActivity.CALL_CHAT_TYPE_MATCH);
if (data != null) {
SendConsumeBean bean = JSONObject.parseObject(data, SendConsumeBean.class);
if (bean != null) {
ToastUtil.show("有结果直接进");
new Handler(Looper.getMainLooper()).postDelayed(() -> {
ConversationUtils.startConversation(mContext, bean.getMateUser().getUser().getId() + "", bundle);
MatchingActivity.this.finish();
}, 5000);
return false;
}
}
}
return true;
}
private void initData() {
OTONetManager.getInstance(mContext)
.getMatchingInfo(new HttpCallback<MatchingInfoBean>() {
@Override
public void onSuccess(MatchingInfoBean data) {
List<MatchingInfoUserBean> list = data.getList();
for (int i = 0; i < 5; i++) {
ImgLoader.display(mContext, list.get(i).getAvatar(), imageViewList.get(i));
}
num.setText(data.getPeople() + "");
}
@Override
public void onError(String error) {
}
});
}
private void call() {
handler.post(() -> ToastUtil.show("匹配"));
SendMessageManager.matching(new OnSendMessageListener() {
@Override
public void onSuccess(String token, SendConsumeBean bean) {
super.onSuccess(token, bean);
task.cancel();
new Handler(Looper.getMainLooper()).postDelayed(() -> {
Bundle bundle = new Bundle();
bundle.putInt("type",ChatActivity.CALL_CHAT_TYPE_MATCH);
bundle.putString("data", JSONObject.toJSONString(bean));
ConversationUtils.startConversation(mContext, bean.getMateUser().getUser().getId() + "", bundle);
MatchingActivity.this.finish();
}, 5000);
}
@Override
public void onError(int status, String msg, SendConsumeBean bean) {
super.onError(status, msg, bean);
if (bean.getCode() == 503) {
handler.post(() -> ToastUtil.show("没人,继续"));
}else if(status==OnSendMessageListener.STATUS_NOT_PRICE){
task.cancel();
handler.post(() -> ToastUtil.show("价格不足"));
MatchingActivity.this.finish();
}
}
});
}
private class Task extends TimerTask {
final int MAX = 5;
int index = MAX;
@Override
public void run() {
if (index != 0) {
call();
} else {
handler.post(() -> {
new TipsDialog(mContext)
.setTitle("当前等待时间较长,建议您 先去观看动态哦,稍后再来哦~")
.setApplyText("去看动态")
.setCancelText("繼續匹配")
.setOnDialogClickListener(new OnDialogClickListener() {
@Override
public void onCancel(Dialog dialog) {
super.onCancel(dialog);
index = MAX;
}
@Override
public void onApply(Dialog dialog) {
super.onApply(dialog);
task.cancel();
task = null;
MatchingActivity.this.finish();
}
}).showDialog();
});
}
index--;
}
@Override
public boolean cancel() {
handler.post(() -> ToastUtil.show("取消"));
return super.cancel();
}
}
}