diff --git a/common/src/main/java/com/yunbao/common/adapter/MainConversationListAdapter.java b/common/src/main/java/com/yunbao/common/adapter/MainConversationListAdapter.java
index beabaff90..4835ceb5a 100644
--- a/common/src/main/java/com/yunbao/common/adapter/MainConversationListAdapter.java
+++ b/common/src/main/java/com/yunbao/common/adapter/MainConversationListAdapter.java
@@ -81,7 +81,9 @@ public class MainConversationListAdapter extends ConversationListAdapter {
if (this.mFilter == mFilter)
return;
this.mFilter = mFilter;
- super.setDataCollection(UiConversationCodeUtil.FilterData(mFilter, allDataList));
+ if (allDataList !=null && !allDataList.isEmpty()){
+ super.setDataCollection(UiConversationCodeUtil.FilterData(mFilter, allDataList));
+ }
}
diff --git a/common/src/main/java/com/yunbao/common/fragment/ChatViewModel.java b/common/src/main/java/com/yunbao/common/fragment/ChatViewModel.java
new file mode 100644
index 000000000..66f0d4189
--- /dev/null
+++ b/common/src/main/java/com/yunbao/common/fragment/ChatViewModel.java
@@ -0,0 +1,57 @@
+package com.yunbao.common.fragment;
+
+import android.app.Application;
+
+import androidx.annotation.NonNull;
+
+import androidx.lifecycle.ViewModel;
+
+import com.facebook.all.All;
+import com.yunbao.common.R;
+import com.yunbao.common.utils.UiConversationCodeUtil;
+
+public class ChatViewModel extends ViewModel {
+
+ private int mChatFilter = UiConversationCodeUtil.FILTER_ALL;
+
+ public int getChatFilter() {
+ return mChatFilter;
+ }
+
+ public void setChatFilter(int mChatFilter) {
+ this.mChatFilter = mChatFilter;
+ }
+
+// public static final int FILTER_OFFLINE = 0;
+// public static final int FILTER_ONLINE = 1;
+// public static final int FILTER_UNREAD = 2;
+// public static final int FILTER_READ = 4;
+// public static final int FILTER_ALL = 7;
+// All Chats
+// Show Online
+// Show Offline
+// Show Read
+// Show Unread
+
+ public int getTitleTextId() {
+ int id = R.string.all_chats;
+ switch (mChatFilter) {
+ case UiConversationCodeUtil.FILTER_ALL:
+ id = R.string.all_chats;
+ break;
+ case UiConversationCodeUtil.FILTER_ONLINE:
+ id = R.string.online_only;
+ break;
+ case UiConversationCodeUtil.FILTER_OFFLINE:
+ id = R.string.offline_only;
+ break;
+ case UiConversationCodeUtil.FILTER_READ:
+ id = R.string.read_only;
+ break;
+ case UiConversationCodeUtil.FILTER_UNREAD:
+ id = R.string.unread_only;
+ break;
+ }
+ return id;
+ }
+}
diff --git a/common/src/main/java/com/yunbao/common/fragment/MainMessageChatFragment.java b/common/src/main/java/com/yunbao/common/fragment/MainMessageChatFragment.java
index eeaaad722..fbd7bb028 100644
--- a/common/src/main/java/com/yunbao/common/fragment/MainMessageChatFragment.java
+++ b/common/src/main/java/com/yunbao/common/fragment/MainMessageChatFragment.java
@@ -9,6 +9,7 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
+import androidx.lifecycle.ViewModelProvider;
import com.yunbao.common.R;
import com.yunbao.common.adapter.MainConversationListAdapter;
@@ -33,10 +34,12 @@ public class MainMessageChatFragment extends ConversationListFragment {
private static final String TAG = "融云列表";
int listHashCode = 0;
+// ChatViewModel chatViewModel;
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Log.i(TAG, "onCreateView: 创建融云");
+// chatViewModel = (ChatViewModel)(new ViewModelProvider(requireActivity())).get(ChatViewModel.class);
return inflater.inflate(R.layout.rc_conversationlist_fragment, container, false);
}
@@ -169,7 +172,9 @@ public class MainMessageChatFragment extends ConversationListFragment {
@Override
protected ConversationListAdapter onResolveAdapter() {
- this.mAdapter = new MainConversationListAdapter(getContext());
+ MainConversationListAdapter adapter= new MainConversationListAdapter(getContext());
+// adapter.setFilter(chatViewModel.getChatFilter());
+ this.mAdapter =adapter;
return this.mAdapter;
}
}
diff --git a/common/src/main/java/com/yunbao/common/fragment/MainMessageChatListFragment.java b/common/src/main/java/com/yunbao/common/fragment/MainMessageChatListFragment.java
index 966eca9b0..35f9a6f70 100644
--- a/common/src/main/java/com/yunbao/common/fragment/MainMessageChatListFragment.java
+++ b/common/src/main/java/com/yunbao/common/fragment/MainMessageChatListFragment.java
@@ -13,6 +13,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
+import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.yunbao.common.R;
@@ -49,7 +50,7 @@ public class MainMessageChatListFragment extends AbsMainMessageChatListFragment
public MainMessageChatListFragment(Context mContext) {
this.mContext =mContext;
}
-
+ ChatViewModel chatViewModel;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@@ -62,8 +63,10 @@ public class MainMessageChatListFragment extends AbsMainMessageChatListFragment
@Override
public void onResume() {
super.onResume();
+ chatViewModel = (new ViewModelProvider(requireActivity())).get(ChatViewModel.class);
conversationListFragment = new MainMessageChatFragment();
setAdapter(conversationListFragment.getAdapter());
+ mAdapter.setFilter(chatViewModel.getChatFilter());
FragmentManager manager = getChildFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.container, conversationListFragment);
@@ -171,6 +174,7 @@ public class MainMessageChatListFragment extends AbsMainMessageChatListFragment
public void setFilter(int mFilter) {
mAdapter.setFilter(mFilter);
+ chatViewModel.setChatFilter(mFilter);
}
diff --git a/common/src/main/java/com/yunbao/common/utils/UiConversationCodeUtil.java b/common/src/main/java/com/yunbao/common/utils/UiConversationCodeUtil.java
index cc2aac47d..bdd2ac8de 100644
--- a/common/src/main/java/com/yunbao/common/utils/UiConversationCodeUtil.java
+++ b/common/src/main/java/com/yunbao/common/utils/UiConversationCodeUtil.java
@@ -33,6 +33,8 @@ public class UiConversationCodeUtil {
public static int getListHasCode(List list) {
int hashCodeValue = 1;
+ if (list == null || list.isEmpty())
+ return 1;
for (BaseUiConversation conversation : list) {
if (conversation != null) {
hashCodeValue = 31 * hashCodeValue + getBaseUiConversationHashCode(conversation);
@@ -71,7 +73,8 @@ public class UiConversationCodeUtil {
public static List FilterData(int filterType, List data) {
List showData = new ArrayList<>();
- ;
+ if (data == null || data.isEmpty())
+ return showData;
Log.i("MainConversationListAdapter", "FilterData: 源" + data.size());
switch (filterType) {
case FILTER_ALL:
diff --git a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java
index 7575fd000..a227aa485 100644
--- a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java
+++ b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java
@@ -35,6 +35,7 @@ import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
+import androidx.lifecycle.ViewModelProvider;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
@@ -51,6 +52,7 @@ import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGAVideoEntity;
import com.yunbao.common.CommonAppConfig;
+import com.yunbao.common.fragment.ChatViewModel;
import com.yunbao.common.fragment.MainMessageRecommendFragment;
import com.yunbao.common.utils.DebugUtils;
import com.yunbao.common.utils.DialogUitl;
@@ -148,6 +150,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder {
private LinearLayout tabLayouts;
private int userType = 0; // (0)普通用户 (1)主播A (2)主播B
+ ChatViewModel chatViewModel;
public MainMessageViewHolder setHomeZdyPop(String homeZdyPop) {
this.homeZdyPop = homeZdyPop;
@@ -161,6 +164,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder {
public MainMessageViewHolder(MainActivity context, ViewGroup parentView) {
super(context, parentView);
mContext = context;
+ chatViewModel= (new ViewModelProvider(mContext)).get(ChatViewModel.class);
}
@Override
@@ -483,7 +487,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder {
tabLine.add(tab_line3);
if (userType == 0) { //普通用户
relativeLayouts.get(0).setVisibility(View.VISIBLE);
- tabTexts.get(0).setText(WordUtil.getNewString(R.string.message_chat_msg_all_an_a));
+ tabTexts.get(0).setText(WordUtil.getNewString(chatViewModel.getTitleTextId()));
ViewGroup.LayoutParams params = tabLayouts.getLayoutParams();
params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
tabExpend.get(0).setVisibility(View.VISIBLE);
@@ -506,12 +510,12 @@ public class MainMessageViewHolder extends AbsMainViewHolder {
relativeLayouts.get(0).setVisibility(View.VISIBLE);
tabTexts.get(0).setText(WordUtil.getNewString(R.string.message_chat_msg_recommend));
relativeLayouts.get(1).setVisibility(View.VISIBLE);
- tabTexts.get(1).setText(WordUtil.getNewString(R.string.message_chat_msg_all_an_a));
+ tabTexts.get(1).setText(WordUtil.getNewString(chatViewModel.getTitleTextId()));
tabExpend.get(1).setVisibility(View.VISIBLE);
} else { //主播B
tabExpend.get(0).setVisibility(View.VISIBLE);
relativeLayouts.get(0).setVisibility(View.VISIBLE);
- tabTexts.get(0).setText(WordUtil.getNewString(R.string.message_chat_msg_all));
+ tabTexts.get(0).setText(WordUtil.getNewString(chatViewModel.getTitleTextId()));
relativeLayouts.get(1).setVisibility(View.VISIBLE);
tabTexts.get(1).setText(WordUtil.getNewString(R.string.message_chat_msg_system));
relativeLayouts.get(2).setVisibility(View.VISIBLE);
diff --git a/main/src/main/res/layout/view_main_message.xml b/main/src/main/res/layout/view_main_message.xml
index 4ea0338f7..8c1a02219 100644
--- a/main/src/main/res/layout/view_main_message.xml
+++ b/main/src/main/res/layout/view_main_message.xml
@@ -377,16 +377,17 @@
+ app:layout_constraintTop_toTopOf="parent"
+ tools:visibility="visible" />
@@ -440,18 +441,20 @@
app:layout_constraintTop_toBottomOf="@+id/tab2" />
+
+ app:layout_constraintTop_toTopOf="parent"
+ tools:visibility="visible" />
+ app:layout_constraintTop_toTopOf="parent"
+ tools:visibility="visible" />