|
@@ -1,5 +1,6 @@
|
|
|
package io.rong.imkit.conversation;
|
|
|
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
import android.text.TextUtils;
|
|
|
import android.view.KeyEvent;
|
|
@@ -9,18 +10,35 @@ import androidx.lifecycle.Observer;
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
|
|
|
|
|
import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
+import com.cooleshow.base.common.BaseApplication;
|
|
|
+import com.cooleshow.base.data.net.ApiException;
|
|
|
+import com.cooleshow.base.data.net.BaseResponse;
|
|
|
+import com.cooleshow.base.data.net.RetrofitFactory;
|
|
|
import com.cooleshow.base.router.RouterPath;
|
|
|
+import com.cooleshow.base.rx.BaseObserver;
|
|
|
+import com.cooleshow.base.utils.LogUtils;
|
|
|
+import com.cooleshow.base.widgets.dialog.CommonDialog;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
|
|
|
+import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.rxjava3.annotations.NonNull;
|
|
|
+import io.reactivex.rxjava3.core.Observable;
|
|
|
+import io.reactivex.rxjava3.disposables.Disposable;
|
|
|
+import io.reactivex.rxjava3.schedulers.Schedulers;
|
|
|
+import io.rong.imkit.IMCenter;
|
|
|
import io.rong.imkit.R;
|
|
|
+import io.rong.imkit.RongIM;
|
|
|
import io.rong.imkit.activity.RongBaseActivity;
|
|
|
+import io.rong.imkit.api.APIService;
|
|
|
+import io.rong.imkit.model.GroupInfoBean;
|
|
|
import io.rong.imkit.model.TypingInfo;
|
|
|
import io.rong.imkit.userinfo.RongUserInfoManager;
|
|
|
import io.rong.imkit.userinfo.db.model.User;
|
|
|
import io.rong.imkit.utils.RouteUtils;
|
|
|
import io.rong.imkit.widget.TitleBar;
|
|
|
+import io.rong.imlib.RongIMClient;
|
|
|
import io.rong.imlib.model.Conversation;
|
|
|
import io.rong.imlib.model.Group;
|
|
|
import io.rong.imlib.model.UserInfo;
|
|
@@ -174,6 +192,12 @@ public class RongConversationActivity extends RongBaseActivity {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ queryGroupInfo();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
if (KeyEvent.KEYCODE_BACK == event.getKeyCode()) {
|
|
|
if (mConversationFragment != null && !mConversationFragment.onBackPressed()) {
|
|
@@ -182,4 +206,96 @@ public class RongConversationActivity extends RongBaseActivity {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private void queryGroupInfo() {
|
|
|
+ if (BaseApplication.Companion.isTeacherClient()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(mTargetId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!mConversationType.equals(Conversation.ConversationType.GROUP)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LogUtils.i("pq", "queryGroupInfo");
|
|
|
+ RetrofitFactory.Companion.getInstance()
|
|
|
+ .create(APIService.class)
|
|
|
+ .queryStuGroupDetail(mTargetId)
|
|
|
+ .subscribeOn(Schedulers.newThread())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new io.reactivex.rxjava3.core.Observer<BaseResponse<GroupInfoBean>>() {
|
|
|
+ @Override
|
|
|
+ public void onSubscribe(@NonNull Disposable d) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(@NonNull BaseResponse<GroupInfoBean> rongIMGroupInfoBaseResponse) {
|
|
|
+ int responseCode = rongIMGroupInfoBaseResponse.getErrorCode();
|
|
|
+ if (responseCode == 200) {
|
|
|
+ if (rongIMGroupInfoBaseResponse.getData() != null) {
|
|
|
+ GroupInfoBean data = rongIMGroupInfoBaseResponse.getData();
|
|
|
+ RongIM.getInstance().refreshGroupInfoCache(new Group(data.getId(), data.getName(), Uri.parse(TextUtils.isEmpty(data.getImg()) ? "" : data.getImg())));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (responseCode == 204) {
|
|
|
+ //群不存在,提示
|
|
|
+ showGroupNotExitDialog();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(@NonNull Throwable e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onComplete() {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showGroupNotExitDialog() {
|
|
|
+ CommonDialog commonDialog = new CommonDialog(this);
|
|
|
+ commonDialog.show();
|
|
|
+ commonDialog.setCancelable(false);
|
|
|
+ commonDialog.setCanceledOnTouchOutside(false);
|
|
|
+ commonDialog.setTitle("提示");
|
|
|
+ commonDialog.setContent("当前群组已被解散,是否删除聊天记录?");
|
|
|
+ commonDialog.setOnConfirmClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (commonDialog != null) {
|
|
|
+ commonDialog.dismiss();
|
|
|
+ }
|
|
|
+ delLocalConversation(mTargetId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ commonDialog.setOnCancelClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (commonDialog != null) {
|
|
|
+ commonDialog.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public void delLocalConversation(String targetId) {
|
|
|
+ IMCenter.getInstance().removeConversation(Conversation.ConversationType.GROUP, targetId, new RongIMClient.ResultCallback<Boolean>() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Boolean aBoolean) {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(RongIMClient.ErrorCode e) {
|
|
|
+ LogUtils.i("pq", "errorMsg:" + e.msg + "\n" + "errorCode:" + e.code);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|