Răsfoiți Sursa

1.修改Android Apex Mobile KPI Title在视图切换时错误。

Pen Li 8 ani în urmă
părinte
comite
d2692e2e9e

+ 75 - 34
Apex Mobile/app/src/main/java/com/usai/apex/mainframe/HomeFragment.java

@@ -7,6 +7,7 @@ import android.support.annotation.Nullable;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -19,7 +20,7 @@ import com.usai.apex.SegmentView;
 /**
  * A simple {@link Fragment} subclass.
  */
-public class HomeFragment extends Fragment {
+public class HomeFragment extends Fragment implements KPIFragment.KPIPagerScrollListener{
 
     private SegmentView mSegmentView;
 
@@ -90,7 +91,7 @@ public class HomeFragment extends Fragment {
 
                         mode = 0;
                         ((RootActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
-                        ((Activity)getActivity()).setTitle(null);
+//                        ((Activity)getActivity()).setTitle(null);
 //                        getChildFragmentManager().beginTransaction().show(recentFragment).hide(kpiFragment).commit();
 
 //                        getChildFragmentManager().beginTransaction().show(getChildFragmentManager().getFragments().get(1)).hide(getChildFragmentManager().getFragments().get(0)).commit();
@@ -102,7 +103,7 @@ public class HomeFragment extends Fragment {
 
                         mode = 1;
                         ((RootActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true);
-                        ((Activity)getActivity()).setTitle(null);
+//                        ((Activity)getActivity()).setTitle(null);
 
 
 //                        getChildFragmentManager().beginTransaction().show(getChildFragmentManager().getFragments().get(0)).hide(getChildFragmentManager().getFragments().get(1)).commit();
@@ -146,9 +147,12 @@ public class HomeFragment extends Fragment {
                 fragment = kpiFragment;
             else
                 kpiFragment = (KPIFragment) fragment;
+
+            kpiFragment.setKPIScrollListener(this);
         }
         activeFragment = fragment;
 
+        Log.d("Home Switch Mode", "UserHint: " + getUserVisibleHint() + " isHidden: " + isHidden());
         if (activeFragment instanceof KPIFragment) {
             kpiFragment.showTitle(getActivity(),true);
         } else {
@@ -177,38 +181,65 @@ public class HomeFragment extends Fragment {
 //
 //    }
 
-    @Override
-    public void setUserVisibleHint(boolean isVisibleToUser) {
-        super.setUserVisibleHint(isVisibleToUser);
-        // 初始化的时候为null
-        if (getActivity() == null) {
-            return;
-        }
-        // 切换到History,再切回来
-        if (isVisibleToUser && activeFragment != null && activeFragment instanceof KPIFragment) {
-            ((KPIFragment) activeFragment).showTitle(getActivity(),true);
-        } else {
-            ((RootActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
-            ((Activity)getActivity()).setTitle(null);
-        }
-
-    }
-
-    @Override
-    public void onHiddenChanged(boolean hidden) {
-        super.onHiddenChanged(hidden);
-        if (getActivity() == null) {
-            return;
-        }
-        // 切换到History,再切回来
-        if (!hidden && activeFragment != null && activeFragment instanceof KPIFragment) {
-            ((KPIFragment) activeFragment).showTitle(getActivity(),true);
-        } else {
-            ((RootActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
-            ((Activity)getActivity()).setTitle(null);
-        }
-    }
+//    @Override
+//    public void setUserVisibleHint(boolean isVisibleToUser) {
+//        super.setUserVisibleHint(isVisibleToUser);
+//        // 初始化的时候为null
+//        if (getActivity() == null) {
+//            return;
+//        }
+//        // 切换到History,再切回来
+//        if (isVisibleToUser && activeFragment != null && activeFragment instanceof KPIFragment) {
+////            ((KPIFragment) activeFragment).showTitle(getActivity(),true);
+//            ((RootActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true);
+//        } else {
+//            ((RootActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
+////            ((Activity)getActivity()).setTitle(null);
+//        }
+////        Log.d("Home Switch Mode", " set UserHint: " +isVisibleToUser + " "+ getUserVisibleHint() + " isHidden: " + isHidden());
+//    }
+//
+//    @Override
+//    public void onHiddenChanged(boolean hidden) {
+//        super.onHiddenChanged(hidden);
+//        if (getActivity() == null) {
+//            return;
+//        }
+//        // 切换到History,再切回来
+//        if (!hidden && activeFragment != null && activeFragment instanceof KPIFragment) {
+//            ((KPIFragment) activeFragment).showTitle(getActivity(),true);
+//        } else {
+//            ((RootActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
+//            ((Activity)getActivity()).setTitle(null);
+//        }
+//    }
 
+//    @Override
+//    public void onResume() {
+//        super.onResume();
+//
+//        if (getActivity() == null) {
+//            return;
+//        }
+//        // 切换到History,再切回来
+//        if (getUserVisibleHint() && activeFragment != null && activeFragment instanceof KPIFragment) {
+//            ((RootActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true);
+//        } else {
+//            ((RootActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
+//        }
+//    }
+//
+//    @Override
+//    public void onStop() {
+//        super.onStop();
+//
+//        if (getActivity() == null) {
+//            return;
+//        }
+//
+//        ((RootActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
+//
+//    }
 
     @Override
     public void onSaveInstanceState(Bundle outState) {
@@ -227,4 +258,14 @@ public class HomeFragment extends Fragment {
                 mSegmentView.setSelect(mode);
             }
     }
+
+    @Override
+    public void KPIPagerDidScrollToPage(int position) {
+        Log.d("Home Switch Mode", " Scroll UserHint: "  + getUserVisibleHint() + " isHidden: " + isHidden());
+        if (activeFragment instanceof KPIFragment) {
+            kpiFragment.showTitle(getActivity(),true);
+        } else {
+            kpiFragment.showTitle(getActivity(),false);
+        }
+    }
 }

+ 18 - 3
Apex Mobile/app/src/main/java/com/usai/apex/mainframe/KPIFragment.java

@@ -78,6 +78,19 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
         }
     }
 
+    public interface KPIPagerScrollListener {
+        /*
+         * 解决Home.KPI --> My --> History显示KPI Title
+         * isHidden()、getUserHint()取得的值不正确
+         * */
+        void KPIPagerDidScrollToPage(int position);
+    }
+    private KPIPagerScrollListener mScrollListener;
+
+    public void setKPIScrollListener(KPIPagerScrollListener mScrollListener) {
+        this.mScrollListener = mScrollListener;
+    }
+
     Context mContext;
     KPIViewPager mKPIPager;
     KPIPagerAdapter mAdapter;
@@ -154,7 +167,9 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
                 } else  {
                     currentKPI = position;
                 }
-                showTitle(mContext,!isHidden());
+                if (mScrollListener != null) {
+                    mScrollListener.KPIPagerDidScrollToPage(currentKPI);
+                }
 
             }
 
@@ -206,14 +221,14 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
             return;
         }
         if (show) {
-            bar.setDisplayShowTitleEnabled(true);
+//            bar.setDisplayShowTitleEnabled(true);
             if (totalKPI > 0) {
                 ((Activity)ctx).setTitle(currentKPI + "/" + totalKPI);
             } else {
                 ((Activity)ctx).setTitle(null);
             }
         } else {
-            bar.setDisplayShowTitleEnabled(false);
+//            bar.setDisplayShowTitleEnabled(false);
             ((Activity)ctx).setTitle(null);
         }
     }

+ 2 - 2
Apex Mobile/app/src/main/java/com/usai/apex/mainframe/RootActivity.java

@@ -176,7 +176,7 @@ public class RootActivity extends AppCompatActivity {
                     public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                         actionbutton.getItem(0).setVisible(false);
                         getSupportActionBar().setHomeAsUpIndicator(R.drawable.apexlogo);
-//                        getSupportActionBar().setDisplayShowTitleEnabled(false);
+                        getSupportActionBar().setDisplayShowTitleEnabled(false);
                         switch (item.getItemId()) {
                             case R.id.item_login:
 
@@ -196,7 +196,7 @@ public class RootActivity extends AppCompatActivity {
                                 if (ApexTrackingApplication.get_instance().getPersonMode()) {
                                     getSupportActionBar().setHomeAsUpIndicator(R.drawable.apexlogo_p);
                                 }
-//                                getSupportActionBar().setDisplayShowTitleEnabled(false);
+                                getSupportActionBar().setDisplayShowTitleEnabled(true);
                                 viewPager.setCurrentItem(0);
                                 return true;