|
@@ -0,0 +1,124 @@
|
|
|
+package com.cooleshow.chatmodule.ui;
|
|
|
+
|
|
|
+import android.os.Bundle;
|
|
|
+import android.view.View;
|
|
|
+
|
|
|
+import com.cooleshow.base.ui.fragment.BaseFragment;
|
|
|
+import com.cooleshow.base.ui.fragment.BaseMVPFragment;
|
|
|
+import com.cooleshow.chatmodule.R;
|
|
|
+import com.cooleshow.chatmodule.adapter.ContactListTabPagerAdapter;
|
|
|
+import com.cooleshow.chatmodule.databinding.TcFragmentContactListTabBinding;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import androidx.fragment.app.Fragment;
|
|
|
+import androidx.viewpager.widget.ViewPager;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 创建日期:2022/6/9 18:01
|
|
|
+ *
|
|
|
+ * @author Ryan
|
|
|
+ * 类说明:
|
|
|
+ */
|
|
|
+public class ContactListTabFragment extends BaseFragment<TcFragmentContactListTabBinding> implements View.OnClickListener {
|
|
|
+ private boolean isSelectContact = false;
|
|
|
+ public static final String IS_SELECT_CONTACT = "IS_SELECT_CONTACT";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected TcFragmentContactListTabBinding getLayoutView() {
|
|
|
+ return TcFragmentContactListTabBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private ViewPager viewPager;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView(View rootView) {
|
|
|
+ if (getArguments() != null) {
|
|
|
+ isSelectContact = getArguments().getBoolean(IS_SELECT_CONTACT, false);
|
|
|
+ }
|
|
|
+ viewPager = mViewBinding.viewpager;
|
|
|
+ mViewBinding.llRoom.setOnClickListener(this);
|
|
|
+ mViewBinding.llSingle.setOnClickListener(this);
|
|
|
+ viewPager.setCurrentItem(0);
|
|
|
+ viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPageSelected(int position) {
|
|
|
+ if (position == 0) {
|
|
|
+ selectSingle();
|
|
|
+ } else {
|
|
|
+ selectRoom();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPageScrollStateChanged(int state) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void selectSingle() {
|
|
|
+ mViewBinding.imContactRoom.setBackgroundResource(R.drawable.icon_contact_room_normal);
|
|
|
+ mViewBinding.imContactSingle.setBackgroundResource(R.drawable.icon_contact_single_select);
|
|
|
+ mViewBinding.tvContactRoom.setTextColor(getResources().getColor(com.cooleshow.base.R.color.color_666666));
|
|
|
+ mViewBinding.tvContactSingle.setTextColor(getResources().getColor(com.cooleshow.base.R.color.color_2dc7aa));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void selectRoom() {
|
|
|
+ mViewBinding.imContactRoom.setBackgroundResource(R.drawable.icon_contact_room_select);
|
|
|
+ mViewBinding.imContactSingle.setBackgroundResource(R.drawable.icon_contact_single_normal);
|
|
|
+ mViewBinding.tvContactRoom.setTextColor(getResources().getColor(com.cooleshow.base.R.color.color_2dc7aa));
|
|
|
+ mViewBinding.tvContactSingle.setTextColor(getResources().getColor(com.cooleshow.base.R.color.color_666666));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initData() {
|
|
|
+ initTabLayoutAndViewPager();
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Fragment> fragments = new ArrayList<>();
|
|
|
+ private List<String> titles = new ArrayList<String>(Arrays.asList("联系人", "群聊"));
|
|
|
+
|
|
|
+ private void initTabLayoutAndViewPager() {
|
|
|
+ fragments.clear();
|
|
|
+ ContactPersonListFragment contactPersonListFragment = new ContactPersonListFragment();
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putBoolean(IS_SELECT_CONTACT, isSelectContact);
|
|
|
+ contactPersonListFragment.setArguments(bundle);
|
|
|
+ fragments.add(contactPersonListFragment);
|
|
|
+ Bundle bundle2 = new Bundle();
|
|
|
+ bundle2.putBoolean(IS_SELECT_CONTACT, isSelectContact);
|
|
|
+ ContactRoomListFragment contactRoomListFragment = new ContactRoomListFragment();
|
|
|
+ contactRoomListFragment.setArguments(bundle2);
|
|
|
+ fragments.add(contactRoomListFragment);
|
|
|
+
|
|
|
+ viewPager.setAdapter(new ContactListTabPagerAdapter(getParentFragmentManager(), fragments, titles));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ int id = v.getId();
|
|
|
+ if (id == R.id.ll_single) {
|
|
|
+ viewPager.setCurrentItem(0);
|
|
|
+ } else if (id == R.id.ll_room) {
|
|
|
+ viewPager.setCurrentItem(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void refreshContactList() {
|
|
|
+ if (fragments.size() > 0) {
|
|
|
+ ContactPersonListFragment fragment = (ContactPersonListFragment) fragments.get(0);
|
|
|
+ if (fragment != null) {
|
|
|
+ fragment.initData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|