|
@@ -0,0 +1,98 @@
|
|
|
+package com.common.im.ui;
|
|
|
+
|
|
|
+import android.graphics.Typeface;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.common.im.adapter.MessagePagerAdapter;
|
|
|
+import com.common.im.contract.MessageFragmentContract;
|
|
|
+import com.common.im.presenter.MessagePresenter;
|
|
|
+import com.common.im_ui.R;
|
|
|
+import com.common.im_ui.databinding.FragmentMessageLayoutBinding;
|
|
|
+import com.cooleshow.base.ui.fragment.BaseMVPFragment;
|
|
|
+import com.cooleshow.base.utils.Utils;
|
|
|
+import com.google.android.material.tabs.TabLayout;
|
|
|
+import com.google.android.material.tabs.TabLayoutMediator;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.fragment.app.Fragment;
|
|
|
+import androidx.viewpager2.adapter.FragmentStateAdapter;
|
|
|
+import io.rong.imkit.conversationlist.ConversationListFragment;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Author by pq, Date on 2022/5/6.
|
|
|
+ */
|
|
|
+public class MessageFragment extends BaseMVPFragment<FragmentMessageLayoutBinding, MessagePresenter> implements MessageFragmentContract.MessageFragmentView {
|
|
|
+ public static final String[] titles = new String[]{"聊天", "联系人"};
|
|
|
+ private ArrayList<Fragment> fragments = new ArrayList<>();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView(View rootView) {
|
|
|
+ Utils.setHeadView(mViewBinding.viewStatusBar, requireContext(), 0);
|
|
|
+ TabLayoutMediator tabLayoutMediator = new TabLayoutMediator(mViewBinding.tabLayout, mViewBinding.viewPager, new TabLayoutMediator.TabConfigurationStrategy() {
|
|
|
+ @Override
|
|
|
+ public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
|
|
|
+ createTab(tab, titles[position]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mViewBinding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
|
|
+ @Override
|
|
|
+ public void onTabSelected(TabLayout.Tab tab) {
|
|
|
+ if (tab != null && tab.getCustomView() != null) {
|
|
|
+ View customView = tab.getCustomView();
|
|
|
+ TextView tv_text = customView.findViewById(R.id.tv_text);
|
|
|
+ tv_text.setTextColor(getResources().getColor(com.cooleshow.base.R.color.color_333333));
|
|
|
+ tv_text.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTabUnselected(TabLayout.Tab tab) {
|
|
|
+ if (tab != null && tab.getCustomView() != null) {
|
|
|
+ View customView = tab.getCustomView();
|
|
|
+ TextView tv_text = customView.findViewById(R.id.tv_text);
|
|
|
+ tv_text.setTextColor(getResources().getColor(com.cooleshow.base.R.color.color_666666));
|
|
|
+ tv_text.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTabReselected(TabLayout.Tab tab) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ ConversationListFragment conversationListFragment = new ConversationListFragment();
|
|
|
+ ConversationListFragment conversationListFragment2 = new ConversationListFragment();
|
|
|
+ fragments.add(conversationListFragment);
|
|
|
+ fragments.add(conversationListFragment2);
|
|
|
+ MessagePagerAdapter messagePagerAdapter = new MessagePagerAdapter(this);
|
|
|
+ messagePagerAdapter.setData(fragments);
|
|
|
+ mViewBinding.viewPager.setAdapter(messagePagerAdapter);
|
|
|
+ tabLayoutMediator.attach();
|
|
|
+ }
|
|
|
+
|
|
|
+ private TabLayout.Tab createTab(TabLayout.Tab tab, String text) {
|
|
|
+ View view = LayoutInflater.from(getContext()).inflate(R.layout.view_message_tab_layout, null);
|
|
|
+ TextView tv_text = view.findViewById(R.id.tv_text);
|
|
|
+ tv_text.setText(text);
|
|
|
+ tab.setCustomView(view);
|
|
|
+ return tab;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initData() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected FragmentMessageLayoutBinding getLayoutView() {
|
|
|
+ return FragmentMessageLayoutBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected MessagePresenter createPresenter() {
|
|
|
+ return new MessagePresenter();
|
|
|
+ }
|
|
|
+}
|