From abce02c7a61820f5d580f87364d542e817be429c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 06 七月 2021 15:22:11 +0800
Subject: [PATCH] 1.1.1完善

---
 app/src/main/java/com/tejia/lijin/app/ui/sellwellcommodity/SellWellGoods.java |  202 +++++++++++++++++--------------------------------
 1 files changed, 71 insertions(+), 131 deletions(-)

diff --git a/app/src/main/java/com/tejia/lijin/app/ui/sellwellcommodity/SellWellGoods.java b/app/src/main/java/com/tejia/lijin/app/ui/sellwellcommodity/SellWellGoods.java
index 1a535d2..e99eb3a 100644
--- a/app/src/main/java/com/tejia/lijin/app/ui/sellwellcommodity/SellWellGoods.java
+++ b/app/src/main/java/com/tejia/lijin/app/ui/sellwellcommodity/SellWellGoods.java
@@ -2,54 +2,83 @@
 
 import androidx.fragment.app.Fragment;
 import androidx.fragment.app.FragmentManager;
-import android.graphics.Color;
+
 import android.os.Build;
 import android.os.Bundle;
-import androidx.fragment.app.FragmentTransaction;
+
 import androidx.viewpager.widget.ViewPager;
+
 import android.view.View;
 import android.view.Window;
 import android.view.WindowManager;
+import android.widget.FrameLayout;
 import android.widget.TextView;
 
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 import com.tejia.lijin.app.R;
 import com.tejia.lijin.app.ui.BaseFragmentActivity;
+import com.tejia.lijin.app.ui.gmtemplate.GmTemplateContentFragment;
+import com.tejia.lijin.app.ui.gmtemplate.GmTemplateFragment;
+import com.tejia.lijin.app.util.downutil.StringUtils;
+import com.viewpagerindicator.TabPageIndicatorTrendsMainType;
 
+import java.lang.reflect.Type;
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.List;
 
 /**
  * 鐑攢鍟嗗搧
  */
 public class SellWellGoods extends BaseFragmentActivity implements View.OnClickListener {
     private TextView sellsellgoods_bar_left;//杩斿洖
-    private TextView sellsellgoods_bar_realtime;//瀹炴椂
-    private View sellsellgoods_bar_realtimebottom;//瀹炴椂搴曢儴鏉�
-    private TextView sellsellgoods_bar_today;//浠婃棩
-    private View sellsellgoods_bar_todaybottom;//浠婃棩搴曢儴鏉�
-    private TextView sellsellgoods_bar_sellwell;//鐑攢
-    private View sellsellgoods_bar_sellwellbottom;//鐑攢搴曢儴鏉�
 
     private ViewPager sellsellgoods_bar_viewpager;//viewpage
     private SellWellGoods_TabAdapter adapter;
 
+    //瀵艰埅鏍�
+    private FrameLayout fl_indicator;
+    private TabPageIndicatorTrendsMainType tab_indicator;
+
     /**
      * Tab鏍囬
      */
-    private ArrayList<Map<String, String>> Title = new ArrayList<>();
-    /**
-     * Tab鏍囬
-     */
-    private ArrayList<Fragment> fragments = new ArrayList<>();
+    private List<NavInfo> titles = new ArrayList<>();
+
+    private void initTopMenu() {
+        //鑾峰彇鏁版嵁
+        String navs = getIntent().getStringExtra("navs");
+        if (!StringUtils.isNullOrEmpty(navs)) {
+            navs = navs.replace("\\" + "\"", "\"");
+            Type type = new TypeToken<List<NavInfo>>() {
+            }.getType();
+            List<NavInfo> navList = new Gson().fromJson(navs, type);
+            titles.clear();
+            titles.addAll(navList);
+        }
+
+        FragmentManager fm = getSupportFragmentManager();
+        adapter = new SellWellGoods_TabAdapter(fm, titles);
+        sellsellgoods_bar_viewpager.setAdapter(adapter);
+
+        if (tab_indicator == null) {
+            tab_indicator = new TabPageIndicatorTrendsMainType(fl_indicator.getContext());
+            tab_indicator.setScaleRate(1.25f);
+        }
+        tab_indicator.setViewPager(sellsellgoods_bar_viewpager);
+        if (fl_indicator.getChildCount() > 0)
+            fl_indicator.removeAllViews();
+        fl_indicator.addView(tab_indicator);
+
+
+    }
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.sellwellgoods);
         setTheme(R.style.AppTabTheme4);
-        inint();
-        OnClickListener();
+        initView();
         //璁剧疆鐘舵�佹爮
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
             Window window = getWindow();
@@ -61,52 +90,18 @@
             //璁剧疆鐘舵�佹爮鏂囧瓧棰滆壊鍙婂浘鏍囦负娣辫壊
             getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
         }
-        FragmentManager fm = getSupportFragmentManager();
-        adapter = new SellWellGoods_TabAdapter(fm, Title, fragments);
-        sellsellgoods_bar_viewpager.setAdapter(adapter);
-        sellsellgoods_bar_viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
-            @Override
-            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
-
-            }
-
-            @Override
-            public void onPageSelected(int position) {
-//                sellsellgoods_bar_viewpager.setCurrentItem(position);
-                Variety(position + 1);
-            }
-
-            @Override
-            public void onPageScrollStateChanged(int state) {
-
-            }
-        });
-        getsellClass();
+        initTopMenu();
     }
 
 
     /**
      * 娉ㄥ唽鎺т欢
      */
-    private void inint() {
+    private void initView() {
         sellsellgoods_bar_left = findViewById(R.id.sellsellgoods_bar_left);
-        sellsellgoods_bar_realtime = findViewById(R.id.sellsellgoods_bar_realtime);
-        sellsellgoods_bar_realtimebottom = findViewById(R.id.sellsellgoods_bar_realtimebottom);
-        sellsellgoods_bar_today = findViewById(R.id.sellsellgoods_bar_today);
-        sellsellgoods_bar_todaybottom = findViewById(R.id.sellsellgoods_bar_todaybottom);
-        sellsellgoods_bar_sellwell = findViewById(R.id.sellsellgoods_bar_sellwell);
-        sellsellgoods_bar_sellwellbottom = findViewById(R.id.sellsellgoods_bar_sellwellbottom);
         sellsellgoods_bar_viewpager = findViewById(R.id.sellsellgoods_bar_viewpager);
-    }
-
-    /**
-     * 娉ㄥ唽鐩戝惉
-     */
-    private void OnClickListener() {
+        fl_indicator = findViewById(R.id.fl_indicator);
         sellsellgoods_bar_left.setOnClickListener(this);
-        sellsellgoods_bar_realtime.setOnClickListener(this);
-        sellsellgoods_bar_today.setOnClickListener(this);
-        sellsellgoods_bar_sellwell.setOnClickListener(this);
     }
 
 
@@ -121,87 +116,10 @@
             case R.id.sellsellgoods_bar_left://杩斿洖
                 finish();
                 break;
-            case R.id.sellsellgoods_bar_realtime://瀹炴椂
-                Variety(1);
-//                setIndexSelected(0);
-                sellsellgoods_bar_viewpager.setCurrentItem(0);
-                break;
-            case R.id.sellsellgoods_bar_today://浠婃棩
-                Variety(2);
-//                setIndexSelected(1);
-                sellsellgoods_bar_viewpager.setCurrentItem(1);
-                break;
-            case R.id.sellsellgoods_bar_sellwell://鐑攢
-                Variety(3);
-//                setIndexSelected(2);
-                sellsellgoods_bar_viewpager.setCurrentItem(2);
-                break;
 
             default:
                 break;
         }
-    }
-
-    /**
-     * 鏀瑰彉 titiel
-     */
-    private void Variety(int i) {
-        sellsellgoods_bar_realtime.setTextColor(i == 1 ? getResources().getColor(R.color.theme): Color.parseColor("#ff333333"));
-        sellsellgoods_bar_realtimebottom.setVisibility(i == 1 ? View.VISIBLE : View.GONE);
-        sellsellgoods_bar_today.setTextColor(i == 2? getResources().getColor(R.color.theme): Color.parseColor("#ff333333"));
-        sellsellgoods_bar_todaybottom.setVisibility(i == 2 ? View.VISIBLE : View.GONE);
-        sellsellgoods_bar_sellwell.setTextColor(i == 2? getResources().getColor(R.color.theme): Color.parseColor("#ff333333"));
-        sellsellgoods_bar_sellwellbottom.setVisibility(i == 3 ? View.VISIBLE : View.GONE);
-    }
-
-    /**
-     * 鑾峰彇鐑攢鍒嗙被
-     */
-    private void getsellClass() {
-        //瀹炴椂
-        RealTimeFragment time_fragment = new RealTimeFragment();
-        //浠婃棩
-        TodayFragment today_fragment = new TodayFragment();
-        //鐑攢
-        Sell_Fragment sell_fragment = new Sell_Fragment();
-        fragments.add(time_fragment);
-        fragments.add(today_fragment);
-        fragments.add(sell_fragment);
-        Map<String, String> map = new HashMap<>();
-        map.put("id", "3");
-        map.put("name", "浠婃棩");
-        Title.add(map);
-        Title.add(map);
-        Title.add(map);
-        adapter.notifyDataSetChanged();
-
-        //榛樿璁剧疆涓虹0涓�
-//        setIndexSelected(0);
-    }
-
-    private int mIndex = -1;
-
-    private void setIndexSelected(int index) {
-
-        if (mIndex == index) {
-            return;
-        }
-        FragmentManager fragmentManager = getSupportFragmentManager();
-        FragmentTransaction ft = fragmentManager.beginTransaction();
-
-
-        //闅愯棌
-        ft.hide(fragments.get(mIndex == -1 ? 0 : mIndex));
-        //鍒ゆ柇鏄惁娣诲姞
-        if (!fragments.get(index).isAdded()) {
-            ft.add(R.id.sellsellgoods_bar_viewpager, fragments.get(index)).show(fragments.get(index));
-        } else {
-            ft.show(fragments.get(index));
-        }
-
-        ft.commit();
-        //鍐嶆璧嬪��
-        mIndex = index;
     }
 
     @Override
@@ -210,4 +128,26 @@
         sellsellgoods_bar_viewpager = null;//viewpage
         adapter = null;
     }
+
+    public static class NavInfo {
+
+        private String key;
+        private String title;
+
+        public String getKey() {
+            return key;
+        }
+
+        public void setKey(String key) {
+            this.key = key;
+        }
+
+        public String getTitle() {
+            return title;
+        }
+
+        public void setTitle(String title) {
+            this.title = title;
+        }
+    }
 }

--
Gitblit v1.8.0