聊天类型选择增加长期持有
This commit is contained in:
parent
114a6472fb
commit
f463557bc4
@ -81,7 +81,9 @@ public class MainConversationListAdapter extends ConversationListAdapter {
|
|||||||
if (this.mFilter == mFilter)
|
if (this.mFilter == mFilter)
|
||||||
return;
|
return;
|
||||||
this.mFilter = mFilter;
|
this.mFilter = mFilter;
|
||||||
super.setDataCollection(UiConversationCodeUtil.FilterData(mFilter, allDataList));
|
if (allDataList !=null && !allDataList.isEmpty()){
|
||||||
|
super.setDataCollection(UiConversationCodeUtil.FilterData(mFilter, allDataList));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
// <string name="all_chats">All Chats</string>
|
||||||
|
// <string name="online_only">Show Online </string>
|
||||||
|
// <string name="offline_only">Show Offline </string>
|
||||||
|
// <string name="read_only">Show Read </string>
|
||||||
|
// <string name="unread_only">Show Unread </string>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ import android.view.ViewGroup;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
import com.yunbao.common.R;
|
import com.yunbao.common.R;
|
||||||
import com.yunbao.common.adapter.MainConversationListAdapter;
|
import com.yunbao.common.adapter.MainConversationListAdapter;
|
||||||
@ -33,10 +34,12 @@ public class MainMessageChatFragment extends ConversationListFragment {
|
|||||||
|
|
||||||
private static final String TAG = "融云列表";
|
private static final String TAG = "融云列表";
|
||||||
int listHashCode = 0;
|
int listHashCode = 0;
|
||||||
|
// ChatViewModel chatViewModel;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
Log.i(TAG, "onCreateView: 创建融云");
|
Log.i(TAG, "onCreateView: 创建融云");
|
||||||
|
// chatViewModel = (ChatViewModel)(new ViewModelProvider(requireActivity())).get(ChatViewModel.class);
|
||||||
return inflater.inflate(R.layout.rc_conversationlist_fragment, container, false);
|
return inflater.inflate(R.layout.rc_conversationlist_fragment, container, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +172,9 @@ public class MainMessageChatFragment extends ConversationListFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConversationListAdapter onResolveAdapter() {
|
protected ConversationListAdapter onResolveAdapter() {
|
||||||
this.mAdapter = new MainConversationListAdapter(getContext());
|
MainConversationListAdapter adapter= new MainConversationListAdapter(getContext());
|
||||||
|
// adapter.setFilter(chatViewModel.getChatFilter());
|
||||||
|
this.mAdapter =adapter;
|
||||||
return this.mAdapter;
|
return this.mAdapter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import com.yunbao.common.R;
|
import com.yunbao.common.R;
|
||||||
@ -49,7 +50,7 @@ public class MainMessageChatListFragment extends AbsMainMessageChatListFragment
|
|||||||
public MainMessageChatListFragment(Context mContext) {
|
public MainMessageChatListFragment(Context mContext) {
|
||||||
this.mContext =mContext;
|
this.mContext =mContext;
|
||||||
}
|
}
|
||||||
|
ChatViewModel chatViewModel;
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
@ -62,8 +63,10 @@ public class MainMessageChatListFragment extends AbsMainMessageChatListFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
chatViewModel = (new ViewModelProvider(requireActivity())).get(ChatViewModel.class);
|
||||||
conversationListFragment = new MainMessageChatFragment();
|
conversationListFragment = new MainMessageChatFragment();
|
||||||
setAdapter(conversationListFragment.getAdapter());
|
setAdapter(conversationListFragment.getAdapter());
|
||||||
|
mAdapter.setFilter(chatViewModel.getChatFilter());
|
||||||
FragmentManager manager = getChildFragmentManager();
|
FragmentManager manager = getChildFragmentManager();
|
||||||
FragmentTransaction transaction = manager.beginTransaction();
|
FragmentTransaction transaction = manager.beginTransaction();
|
||||||
transaction.replace(R.id.container, conversationListFragment);
|
transaction.replace(R.id.container, conversationListFragment);
|
||||||
@ -171,6 +174,7 @@ public class MainMessageChatListFragment extends AbsMainMessageChatListFragment
|
|||||||
|
|
||||||
public void setFilter(int mFilter) {
|
public void setFilter(int mFilter) {
|
||||||
mAdapter.setFilter(mFilter);
|
mAdapter.setFilter(mFilter);
|
||||||
|
chatViewModel.setChatFilter(mFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ public class UiConversationCodeUtil {
|
|||||||
|
|
||||||
public static int getListHasCode(List<BaseUiConversation> list) {
|
public static int getListHasCode(List<BaseUiConversation> list) {
|
||||||
int hashCodeValue = 1;
|
int hashCodeValue = 1;
|
||||||
|
if (list == null || list.isEmpty())
|
||||||
|
return 1;
|
||||||
for (BaseUiConversation conversation : list) {
|
for (BaseUiConversation conversation : list) {
|
||||||
if (conversation != null) {
|
if (conversation != null) {
|
||||||
hashCodeValue = 31 * hashCodeValue + getBaseUiConversationHashCode(conversation);
|
hashCodeValue = 31 * hashCodeValue + getBaseUiConversationHashCode(conversation);
|
||||||
@ -71,7 +73,8 @@ public class UiConversationCodeUtil {
|
|||||||
|
|
||||||
public static List<BaseUiConversation> FilterData(int filterType, List<BaseUiConversation> data) {
|
public static List<BaseUiConversation> FilterData(int filterType, List<BaseUiConversation> data) {
|
||||||
List<BaseUiConversation> showData = new ArrayList<>();
|
List<BaseUiConversation> showData = new ArrayList<>();
|
||||||
;
|
if (data == null || data.isEmpty())
|
||||||
|
return showData;
|
||||||
Log.i("MainConversationListAdapter", "FilterData: 源" + data.size());
|
Log.i("MainConversationListAdapter", "FilterData: 源" + data.size());
|
||||||
switch (filterType) {
|
switch (filterType) {
|
||||||
case FILTER_ALL:
|
case FILTER_ALL:
|
||||||
|
@ -35,6 +35,7 @@ import androidx.constraintlayout.widget.ConstraintLayout;
|
|||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||||
import androidx.viewpager2.widget.ViewPager2;
|
import androidx.viewpager2.widget.ViewPager2;
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ import com.opensource.svgaplayer.SVGAImageView;
|
|||||||
import com.opensource.svgaplayer.SVGAParser;
|
import com.opensource.svgaplayer.SVGAParser;
|
||||||
import com.opensource.svgaplayer.SVGAVideoEntity;
|
import com.opensource.svgaplayer.SVGAVideoEntity;
|
||||||
import com.yunbao.common.CommonAppConfig;
|
import com.yunbao.common.CommonAppConfig;
|
||||||
|
import com.yunbao.common.fragment.ChatViewModel;
|
||||||
import com.yunbao.common.fragment.MainMessageRecommendFragment;
|
import com.yunbao.common.fragment.MainMessageRecommendFragment;
|
||||||
import com.yunbao.common.utils.DebugUtils;
|
import com.yunbao.common.utils.DebugUtils;
|
||||||
import com.yunbao.common.utils.DialogUitl;
|
import com.yunbao.common.utils.DialogUitl;
|
||||||
@ -148,6 +150,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder {
|
|||||||
private LinearLayout tabLayouts;
|
private LinearLayout tabLayouts;
|
||||||
|
|
||||||
private int userType = 0; // (0)普通用户 (1)主播A (2)主播B
|
private int userType = 0; // (0)普通用户 (1)主播A (2)主播B
|
||||||
|
ChatViewModel chatViewModel;
|
||||||
|
|
||||||
public MainMessageViewHolder setHomeZdyPop(String homeZdyPop) {
|
public MainMessageViewHolder setHomeZdyPop(String homeZdyPop) {
|
||||||
this.homeZdyPop = homeZdyPop;
|
this.homeZdyPop = homeZdyPop;
|
||||||
@ -161,6 +164,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder {
|
|||||||
public MainMessageViewHolder(MainActivity context, ViewGroup parentView) {
|
public MainMessageViewHolder(MainActivity context, ViewGroup parentView) {
|
||||||
super(context, parentView);
|
super(context, parentView);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
chatViewModel= (new ViewModelProvider(mContext)).get(ChatViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -483,7 +487,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder {
|
|||||||
tabLine.add(tab_line3);
|
tabLine.add(tab_line3);
|
||||||
if (userType == 0) { //普通用户
|
if (userType == 0) { //普通用户
|
||||||
relativeLayouts.get(0).setVisibility(View.VISIBLE);
|
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();
|
ViewGroup.LayoutParams params = tabLayouts.getLayoutParams();
|
||||||
params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||||
tabExpend.get(0).setVisibility(View.VISIBLE);
|
tabExpend.get(0).setVisibility(View.VISIBLE);
|
||||||
@ -506,12 +510,12 @@ public class MainMessageViewHolder extends AbsMainViewHolder {
|
|||||||
relativeLayouts.get(0).setVisibility(View.VISIBLE);
|
relativeLayouts.get(0).setVisibility(View.VISIBLE);
|
||||||
tabTexts.get(0).setText(WordUtil.getNewString(R.string.message_chat_msg_recommend));
|
tabTexts.get(0).setText(WordUtil.getNewString(R.string.message_chat_msg_recommend));
|
||||||
relativeLayouts.get(1).setVisibility(View.VISIBLE);
|
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);
|
tabExpend.get(1).setVisibility(View.VISIBLE);
|
||||||
} else { //主播B
|
} else { //主播B
|
||||||
tabExpend.get(0).setVisibility(View.VISIBLE);
|
tabExpend.get(0).setVisibility(View.VISIBLE);
|
||||||
relativeLayouts.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);
|
relativeLayouts.get(1).setVisibility(View.VISIBLE);
|
||||||
tabTexts.get(1).setText(WordUtil.getNewString(R.string.message_chat_msg_system));
|
tabTexts.get(1).setText(WordUtil.getNewString(R.string.message_chat_msg_system));
|
||||||
relativeLayouts.get(2).setVisibility(View.VISIBLE);
|
relativeLayouts.get(2).setVisibility(View.VISIBLE);
|
||||||
|
@ -377,16 +377,17 @@
|
|||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/expendImg1"
|
android:id="@+id/expendImg1"
|
||||||
android:layout_marginStart="5dp"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="5dp"
|
android:padding="5dp"
|
||||||
android:visibility="gone"
|
|
||||||
tools:visibility="visible"
|
|
||||||
android:src="@mipmap/ic_expend_down"
|
android:src="@mipmap/ic_expend_down"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
android:visibility="gone"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.1"
|
||||||
app:layout_constraintStart_toEndOf="@+id/tab_top1"
|
app:layout_constraintStart_toEndOf="@+id/tab_top1"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
@ -440,18 +441,20 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/tab2" />
|
app:layout_constraintTop_toBottomOf="@+id/tab2" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/expendImg2"
|
android:id="@+id/expendImg2"
|
||||||
android:layout_marginStart="5dp"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="5dp"
|
android:padding="5dp"
|
||||||
android:visibility="gone"
|
|
||||||
tools:visibility="visible"
|
|
||||||
android:src="@mipmap/ic_expend_down"
|
android:src="@mipmap/ic_expend_down"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
android:visibility="gone"
|
||||||
|
app:layout_constraintHorizontal_bias="0.1"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toEndOf="@+id/tab_top2"
|
app:layout_constraintStart_toEndOf="@+id/tab_top2"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:visibility="visible" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
@ -507,17 +510,18 @@
|
|||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/expendImg3"
|
android:id="@+id/expendImg3"
|
||||||
android:layout_marginStart="5dp"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="5dp"
|
|
||||||
android:visibility="gone"
|
|
||||||
tools:visibility="visible"
|
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
|
android:padding="5dp"
|
||||||
|
app:layout_constraintHorizontal_bias="0.1"
|
||||||
android:src="@mipmap/ic_expend_down"
|
android:src="@mipmap/ic_expend_down"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
android:visibility="gone"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toEndOf="@+id/tab_top3"
|
app:layout_constraintStart_toEndOf="@+id/tab_top3"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:visibility="visible" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user