Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

android / dayu

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • dayu
  • ..
  • fragment
  • HomeSaleFragment.java
Find file
Normal viewHistoryPermalink
HomeSaleFragment.java 6.99 KB
Newer Older
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
1 2 3 4 5 6
package com.bigfish.salecenter.ui.fragment;

import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
mReturn's avatar
Tab字体大小,下载通知适配
5d6b971b
 
mReturn committed 4 years ago
7
import android.support.v4.app.Fragment;
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
8 9 10 11 12 13 14 15 16 17 18 19
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.bigfish.salecenter.R;
import com.bigfish.salecenter.databinding.FragmentHomeSaleBinding;
import com.bigfish.salecenter.event.RefreshSaleTab;
import com.bigfish.salecenter.model.SaleTab;
import com.bigfish.salecenter.presenter.homesale.HomeSaleContract;
import com.bigfish.salecenter.presenter.homesale.HomeSalePresenter;
import com.dayu.base.ui.adapter.FragmentAdapter;
import com.dayu.base.ui.fragment.BaseFragment;
mReturn's avatar
Tab字体大小,下载通知适配
5d6b971b
 
mReturn committed 4 years ago
20
import com.dayu.event.SaleTabNumEvent;
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
import com.dayu.utils.TabLayoutUtils;
import com.umeng.analytics.MobclickAgent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mReturn
 * on 2020/2/12
 **/
public class HomeSaleFragment extends BaseFragment<HomeSalePresenter, FragmentHomeSaleBinding>
        implements HomeSaleContract.View {

    public List<Fragment> list_fragments;
    private FragmentAdapter adapter;
    private TextView mTabNumTv;
    private TextView mTabTextTv;
    private boolean isFirstAddTab = true;
    private String[] tabDesc;
    private String mUmTag = "HomeSaleFragment";

    public static HomeSaleFragment newInstance() {
        Bundle args = new Bundle();
        HomeSaleFragment fragment = new HomeSaleFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_home_sale;
    }

    @Override
    public void setPresenter() {
//        mBind.setPresenter(mPresenter);
    }

    @Override
    public void initView() {
        tabDesc = new String[]{mActivity.getString(R.string.sale_products), mActivity.getString(R.string.sale_collect),
                mActivity.getString(R.string.in_sale), mActivity.getString(R.string.sale_done)};
        EventBus.getDefault().register(this);
        initData();
    }

    private void initData() {
        list_fragments = new ArrayList<>();
        list_fragments.add(SaleProductFragment.newInstance(1));
        list_fragments.add(SaleProductFragment.newInstance(2));
        list_fragments.add(SaleOrderFragment.newInstance(1));
        list_fragments.add(SaleOrderFragment.newInstance(2));
        adapter = new FragmentAdapter(getFragmentManager(), list_fragments);
        mBind.vpSale.setAdapter(adapter);
        mBind.tbSale.setupWithViewPager(mBind.vpSale);
        mBind.tbSale.setTabMode(TabLayout.MODE_FIXED);
        mBind.vpSale.setOffscreenPageLimit(4);
        mBind.tbSale.post(() ->
mReturn's avatar
sale
da569c02
 
mReturn committed 5 years ago
83
                TabLayoutUtils.setIndicator(mBind.tbSale, 0, 0, R.color.cl_order_item_line_bg, mActivity));
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
84 85 86 87 88 89 90 91 92
        mBind.tbSale.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                int temp = tab.getPosition();
                if (tab.getCustomView() == null) {
                    return;
                }
                mTabNumTv = tab.getCustomView().findViewById(R.id.tabtext);
                mTabTextTv = tab.getCustomView().findViewById(R.id.tabicon);
mReturn's avatar
fix bug
8330d922
 
mReturn committed 5 years ago
93 94
                if (temp != 2)
                    mTabNumTv.setTextColor(getResources().getColor(R.color.bg_button));
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
95 96
                mTabTextTv.setTextColor(getResources().getColor(R.color.bg_button));
                mBind.vpSale.setCurrentItem(temp);
mReturn's avatar
fix bug
8330d922
 
mReturn committed 5 years ago
97
                MobclickAgent.onPageStart("SaleChildFragment" + temp);
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
98 99 100 101 102 103 104
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                if (mTabNumTv == null || mTabTextTv == null) {
                    return;
                }
mReturn's avatar
fix bug
8330d922
 
mReturn committed 5 years ago
105 106 107
                int temp = tab.getPosition();
                if (temp != 2)
                    mTabNumTv.setTextColor(getResources().getColor(R.color.cl_tab_init));
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
108 109 110 111 112 113 114 115 116 117 118 119 120
                mTabTextTv.setTextColor(getResources().getColor(R.color.cl_tab_init));
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
            }
        });

        mPresenter.chooseTab(0);
    }

    @Override
    public void setTabNum(SaleTab tab, int myTabIndex) {
mReturn's avatar
share
0578d451
 
mReturn committed 5 years ago
121 122
//        EventBus.getDefault().post(new SaleTabNumEvent(tab.products+tab.collect+tab.inSale+tab.saleDone));
        EventBus.getDefault().post(new SaleTabNumEvent(tab.inSale));
mReturn's avatar
Tab字体大小,下载通知适配
5d6b971b
 
mReturn committed 4 years ago
123
        int[] tabNum = new int[]{tab.products, tab.collect, tab.inSale, tab.saleDone};
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
124 125
        if (isFirstAddTab) {
            mBind.tbSale.removeAllTabs();
mReturn's avatar
fix bug
8330d922
 
mReturn committed 5 years ago
126 127 128 129
            mBind.tbSale.addTab(mBind.tbSale.newTab().setCustomView(CreatTab(0,tabNum[0], tabDesc[0])));
            mBind.tbSale.addTab(mBind.tbSale.newTab().setCustomView(CreatTab(1,tabNum[1], tabDesc[1])));
            mBind.tbSale.addTab(mBind.tbSale.newTab().setCustomView(CreatTab(2,tabNum[2], tabDesc[2])));
            mBind.tbSale.addTab(mBind.tbSale.newTab().setCustomView(CreatTab(3,tabNum[3], tabDesc[3])));
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
130 131 132 133 134 135
            isFirstAddTab = false;
        } else {
            for (int i = 0; i < mBind.tbSale.getTabCount(); i++) {
                TextView tv = mBind.tbSale.getTabAt(i).getCustomView().findViewById(R.id.tabtext);
                TextView tvIcon = mBind.tbSale.getTabAt(i).getCustomView().findViewById(R.id.tabicon);
                tvIcon.setText(tabDesc[i]);
mReturn's avatar
Tab字体大小,下载通知适配
5d6b971b
 
mReturn committed 4 years ago
136 137 138 139 140 141 142 143 144 145 146 147
                int count = tabNum[i];
                tv.setText(count+"");
                tv.setTextSize(28);
                if (count>999){
                    tv.setTextSize(24);
                }
                if (count>9999){
                    tv.setTextSize(20);
                }
                if (count>99999){
                    tv.setTextSize(16);
                }
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
148 149 150 151 152 153 154 155
            }
            if (myTabIndex != -1) {
                mBind.vpSale.setCurrentItem(myTabIndex);
                mBind.tbSale.getTabAt(myTabIndex).select();
            }
        }
    }

mReturn's avatar
Tab字体大小,下载通知适配
5d6b971b
 
mReturn committed 4 years ago
156
    private View CreatTab(int index,int number, String iconID) {
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
157 158 159
        View newtab = LayoutInflater.from(mActivity).inflate(R.layout.layout_sale_tab, null);
        TextView textView_number = newtab.findViewById(R.id.tabtext);
        AssetManager mgr = mActivity.getAssets();
mReturn's avatar
fix bug
8330d922
 
mReturn committed 5 years ago
160 161 162
        if (index == 2){
            textView_number.setTextColor(getResources().getColor(R.color.cl_tab_read));
        }
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
163 164
        Typeface tf = Typeface.createFromAsset(mgr, "fonts/DIN Alternate Bold.ttf");
        textView_number.setTypeface(tf);
mReturn's avatar
Tab字体大小,下载通知适配
5d6b971b
 
mReturn committed 4 years ago
165
        textView_number.setText(number+"");
mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
        TextView textView = newtab.findViewById(R.id.tabicon);
        textView.setText(iconID);
        return newtab;
    }

    @Override
    public void onDetach() {
        super.onDetach();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onRefreshTab(RefreshSaleTab event) {
        mPresenter.chooseTab(event.getTabNum());
    }
mReturn's avatar
销售&搜索&评论
f5d1dccc
 
mReturn committed 5 years ago
181

mReturn's avatar
sale
7a9d5238
 
mReturn committed 5 years ago
182
}