|
|
@ -1,8 +1,11 @@ |
|
|
|
package com.kanglai.push.ui.activity; |
|
|
|
package com.kanglai.push.ui.activity; |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context; |
|
|
|
import android.content.Context; |
|
|
|
|
|
|
|
import android.icu.text.SimpleDateFormat; |
|
|
|
|
|
|
|
import android.icu.util.Calendar; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.text.InputFilter; |
|
|
|
import android.text.InputFilter; |
|
|
|
|
|
|
|
import android.text.TextUtils; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
import android.view.inputmethod.InputMethodManager; |
|
|
|
import android.view.inputmethod.InputMethodManager; |
|
|
|
import android.widget.EditText; |
|
|
|
import android.widget.EditText; |
|
|
@ -15,6 +18,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; |
|
|
|
import androidx.recyclerview.widget.RecyclerView; |
|
|
|
import androidx.recyclerview.widget.RecyclerView; |
|
|
|
|
|
|
|
|
|
|
|
import com.blankj.utilcode.util.CacheDiskUtils; |
|
|
|
import com.blankj.utilcode.util.CacheDiskUtils; |
|
|
|
|
|
|
|
import com.blankj.utilcode.util.StringUtils; |
|
|
|
import com.dolphin.core.base.BaseActivity; |
|
|
|
import com.dolphin.core.base.BaseActivity; |
|
|
|
import com.dolphin.core.bus.RxBus; |
|
|
|
import com.dolphin.core.bus.RxBus; |
|
|
|
import com.dolphin.core.bus.RxSubscriptions; |
|
|
|
import com.dolphin.core.bus.RxSubscriptions; |
|
|
@ -36,6 +40,8 @@ import org.json.JSONObject; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Locale; |
|
|
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
|
|
|
import io.reactivex.disposables.Disposable; |
|
|
|
import io.reactivex.disposables.Disposable; |
|
|
|
|
|
|
|
|
|
|
@ -46,22 +52,17 @@ import io.reactivex.disposables.Disposable; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class InstantActivity extends BaseActivity<ActivityInstantBinding, InstantViewModel>{ |
|
|
|
public class InstantActivity extends BaseActivity<ActivityInstantBinding, InstantViewModel>{ |
|
|
|
|
|
|
|
|
|
|
|
private Disposable mSubscription; |
|
|
|
|
|
|
|
public SoloChatRoomAdapter mAdapter; |
|
|
|
public SoloChatRoomAdapter mAdapter; |
|
|
|
public RefreshLayout refreshLayout; |
|
|
|
public RefreshLayout refreshLayout; |
|
|
|
public RecyclerView mRecyclerView; |
|
|
|
public RecyclerView mRecyclerView; |
|
|
|
public TextView btn_send; |
|
|
|
|
|
|
|
public EditText input_box; |
|
|
|
public EditText input_box; |
|
|
|
public ImageView more_line; |
|
|
|
public ImageView more_line; |
|
|
|
public ImageView more_fill; |
|
|
|
public ImageView more_fill; |
|
|
|
public GridLayout bottom_grid; |
|
|
|
public GridLayout bottom_grid; |
|
|
|
public LinearLayout layout_footer; |
|
|
|
public LinearLayout layout_footer; |
|
|
|
public Boolean isShowBottom = false; // 底部功能模块显示开关,默认关闭
|
|
|
|
public Boolean isShowBottom = false; |
|
|
|
|
|
|
|
public LocalPushChatMsg localPushChatMsg; |
|
|
|
public List<PushChatMessage> list = new ArrayList<>(); // 聊天数据
|
|
|
|
private Disposable mSubscription; |
|
|
|
|
|
|
|
|
|
|
|
public LocalPushChatMsg msgData; // 聊天对象数据
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private User user = CacheDiskUtils.getInstance().getParcelable(CacheConstant.USER_INFO, User.CREATOR, new User()); |
|
|
|
private User user = CacheDiskUtils.getInstance().getParcelable(CacheConstant.USER_INFO, User.CREATOR, new User()); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -77,17 +78,6 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void onStart() { |
|
|
|
protected void onStart() { |
|
|
|
super.onStart(); |
|
|
|
super.onStart(); |
|
|
|
/* 实时监听友盟传输的聊天数据 */ |
|
|
|
|
|
|
|
/* mSubscription = RxBus.getInstance().toObservableSticky(ChatMsg.class) |
|
|
|
|
|
|
|
.compose(RxUtil.schedulersTransformer()) |
|
|
|
|
|
|
|
.compose(RxUtil.exceptionTransformer()) |
|
|
|
|
|
|
|
.subscribe(chat ->{ |
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(new Gson().toJson(chat)); |
|
|
|
|
|
|
|
// 收到友盟消息 查找最新的一条数据
|
|
|
|
|
|
|
|
if (jsonObject.getString("concernFanId").equals(mViewModel.adverseData.getId())) mViewModel.loadNewDate(); |
|
|
|
|
|
|
|
// LogUtils.d(jsonObject.getString("concernFanId"), mViewModel.adverseData.getId());
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
RxSubscriptions.add(mSubscription);*/ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -95,35 +85,36 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
super.mViewModel.mActivity = this; |
|
|
|
super.mViewModel.mActivity = this; |
|
|
|
// 其他基础控件
|
|
|
|
// 其他基础控件
|
|
|
|
input_box = (EditText)findViewById(R.id.instant_input_box); |
|
|
|
input_box = findViewById(R.id.instant_input_box); |
|
|
|
input_box.setFilters(new InputFilter[]{ViewFilterUtil.getNoSpecialCharactersFilter()}); // 去空格、换行符等特殊符号
|
|
|
|
input_box.setFilters(new InputFilter[]{ViewFilterUtil.getNoSpecialCharactersFilter()}); // 去空格、换行符等特殊符号
|
|
|
|
more_line = (ImageView)findViewById(R.id.iv_more_line); |
|
|
|
more_line = findViewById(R.id.iv_more_line); |
|
|
|
more_fill = (ImageView)findViewById(R.id.iv_more_fill); |
|
|
|
more_fill = findViewById(R.id.iv_more_fill); |
|
|
|
more_line.setOnClickListener(view -> changBottomType()); |
|
|
|
more_line.setOnClickListener(view -> changBottomType()); |
|
|
|
more_fill.setOnClickListener(view -> changBottomType()); |
|
|
|
more_fill.setOnClickListener(view -> changBottomType()); |
|
|
|
bottom_grid = (GridLayout) findViewById(R.id.instant_grid); // 隐藏的九宫格
|
|
|
|
bottom_grid = findViewById(R.id.instant_grid); |
|
|
|
layout_footer = (LinearLayout) findViewById(R.id.layout_footer); // 底部消息输入框、更多、发送按钮
|
|
|
|
layout_footer = findViewById(R.id.layout_footer); |
|
|
|
|
|
|
|
|
|
|
|
msgData = getIntent().getParcelableExtra("GOING_TO_INSTANT"); // 接收跳转过来的值
|
|
|
|
localPushChatMsg= getIntent().getParcelableExtra("GOING_TO_INSTANT"); |
|
|
|
if (msgData instanceof LocalPushChatMsg) { |
|
|
|
if (localPushChatMsg instanceof LocalPushChatMsg) { |
|
|
|
mViewModel.adverseData = msgData; // 将对方基础数据存起来
|
|
|
|
mViewModel.adverseData = localPushChatMsg; |
|
|
|
mViewModel.init(); // 加载一方聊天记录
|
|
|
|
mViewModel.init(); |
|
|
|
judgeViewType(msgData); |
|
|
|
judgeViewType(localPushChatMsg); |
|
|
|
} |
|
|
|
} |
|
|
|
// 一对一聊天室适配器初始化
|
|
|
|
mSubscription = RxBus.getInstance().toObservable(com.dolphin.umeng.entity.PushChatMessage.class) |
|
|
|
// final SoloChatRoomAdapter soloChatRoomAdapter = new SoloChatRoomAdapter(CollectionUtils.newArrayList(), msgData);
|
|
|
|
.compose(RxUtil.schedulersTransformer()) |
|
|
|
// mAdapter = soloChatRoomAdapter;
|
|
|
|
.compose(RxUtil.exceptionTransformer()) |
|
|
|
// RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this); // 初始化垂直适配器
|
|
|
|
.subscribe(msg -> { |
|
|
|
// mRecyclerView = findViewById(R.id.instant_recycler);
|
|
|
|
com.dolphin.umeng.entity.PushChatMessage pushChatMessage = (com.dolphin.umeng.entity.PushChatMessage) msg; |
|
|
|
// mRecyclerView.setLayoutManager(mLayoutManager);
|
|
|
|
PushChatMessage chatMessage = new PushChatMessage(); |
|
|
|
// mRecyclerView.setAdapter(mAdapter);
|
|
|
|
chatMessage.setUserId(pushChatMessage.getFanUserId()); |
|
|
|
//
|
|
|
|
chatMessage.setText(pushChatMessage.getText()); |
|
|
|
// refreshLayout = findViewById(R.id.instant_smart_refresh); // 刷新布局初始化
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
// refreshLayout.setEnableRefresh(true); // 下拉刷新
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); |
|
|
|
// refreshLayout.setEnableLoadMore(false); // 上拉加载更多
|
|
|
|
String currentTime = sdf.format(calendar.getTime()); |
|
|
|
// refreshLayout.setEnableAutoLoadMore(true); // 开启使上拉加载具有弹性效果
|
|
|
|
chatMessage.setCreateTime(currentTime); |
|
|
|
// refreshLayout.setEnableScrollContentWhenLoaded(true); // 加载完成时滚动列表显示新的内容
|
|
|
|
mAdapter.append(chatMessage); |
|
|
|
// refreshLayout.setOnRefreshListener(v -> mViewModel.init());
|
|
|
|
}); |
|
|
|
|
|
|
|
RxSubscriptions.add(mSubscription); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -131,31 +122,30 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan |
|
|
|
* @param requestList |
|
|
|
* @param requestList |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void adapterInit(ArrayList<PushChatMessage> requestList) { |
|
|
|
public void adapterInit(ArrayList<PushChatMessage> requestList) { |
|
|
|
final SoloChatRoomAdapter soloChatRoomAdapter = new SoloChatRoomAdapter(requestList, msgData); |
|
|
|
final SoloChatRoomAdapter soloChatRoomAdapter = new SoloChatRoomAdapter(requestList, localPushChatMsg); |
|
|
|
mAdapter = soloChatRoomAdapter; |
|
|
|
mAdapter = soloChatRoomAdapter; |
|
|
|
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this); // 初始化垂直适配器
|
|
|
|
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this); // 初始化垂直适配器
|
|
|
|
mRecyclerView = findViewById(R.id.instant_recycler); |
|
|
|
mRecyclerView = findViewById(R.id.instant_recycler); |
|
|
|
mRecyclerView.setLayoutManager(mLayoutManager); |
|
|
|
mRecyclerView.setLayoutManager(mLayoutManager); |
|
|
|
mRecyclerView.setAdapter(mAdapter); |
|
|
|
mRecyclerView.setAdapter(mAdapter); |
|
|
|
|
|
|
|
|
|
|
|
refreshLayout = findViewById(R.id.instant_smart_refresh); // 刷新布局初始化
|
|
|
|
refreshLayout = findViewById(R.id.instant_smart_refresh); |
|
|
|
refreshLayout.setEnableRefresh(true); // 下拉刷新
|
|
|
|
refreshLayout.setEnableRefresh(true); |
|
|
|
refreshLayout.setEnableLoadMore(false); // 上拉加载更多
|
|
|
|
refreshLayout.setEnableLoadMore(false); |
|
|
|
refreshLayout.setEnableAutoLoadMore(true); // 开启使上拉加载具有弹性效果
|
|
|
|
refreshLayout.setEnableAutoLoadMore(true); |
|
|
|
refreshLayout.setEnableScrollContentWhenLoaded(true); // 加载完成时滚动列表显示新的内容
|
|
|
|
refreshLayout.setEnableScrollContentWhenLoaded(true); |
|
|
|
refreshLayout.setOnRefreshListener(v -> mViewModel.loadMore()); |
|
|
|
refreshLayout.setOnRefreshListener(v -> mViewModel.loadMore()); |
|
|
|
refreshLayout.setDisableContentWhenRefresh(true); // 在刷新时候禁止操作内容视图
|
|
|
|
refreshLayout.setDisableContentWhenRefresh(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 加载不同用户类型时的界面 |
|
|
|
* 加载不同用户类型时的界面 |
|
|
|
* |
|
|
|
|
|
|
|
* app端不能给 系统/企业用户/企业内部/系统 用户发消息 |
|
|
|
* app端不能给 系统/企业用户/企业内部/系统 用户发消息 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void judgeViewType(LocalPushChatMsg data) { |
|
|
|
private void judgeViewType(LocalPushChatMsg data) { |
|
|
|
mViewModel.setTitleText(data.getUserName()); // 标题
|
|
|
|
mViewModel.setTitleText(data.getUserName()); // 标题
|
|
|
|
if ("2".equals(data.getUserType()) || "5".equals(data.getUserType()) || "0".equals(data.getUserType())){ |
|
|
|
if ("2".equals(data.getUserType()) || "5".equals(data.getUserType()) || "0".equals(data.getUserType())){ |
|
|
|
layout_footer.setVisibility(View.GONE); |
|
|
|
layout_footer.setVisibility(View.INVISIBLE); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -180,14 +170,13 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan |
|
|
|
public void hideKeyboard() { |
|
|
|
public void hideKeyboard() { |
|
|
|
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); |
|
|
|
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); |
|
|
|
View currentFocusView = getCurrentFocus(); |
|
|
|
View currentFocusView = getCurrentFocus(); |
|
|
|
if (currentFocusView != null) imm.hideSoftInputFromWindow(currentFocusView.getWindowToken(), 0); |
|
|
|
imm.hideSoftInputFromWindow(Objects.requireNonNullElseGet(currentFocusView, () -> getWindow().getDecorView()).getWindowToken(), 0); |
|
|
|
else imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void onDestroy() { |
|
|
|
protected void onDestroy() { |
|
|
|
super.onDestroy(); |
|
|
|
super.onDestroy(); |
|
|
|
if (mAdapter != null) mAdapter.clear(); // 清空数据
|
|
|
|
RxSubscriptions.remove(mSubscription); |
|
|
|
RxSubscriptions.remove(mSubscription); // 解除RX监听防止内存泄露
|
|
|
|
if (mAdapter != null) mAdapter.clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|