[Android] Remove focus helpers

Geoffrey Métais git at videolan.org
Mon Apr 11 15:45:14 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Apr 11 15:41:50 2016 +0200| [98e019217c440bc2c52fda54b373a3ecce9dd588] | committer: Geoffrey Métais

Remove focus helpers

> https://code.videolan.org/videolan/vlc-android/commit/98e019217c440bc2c52fda54b373a3ecce9dd588
---

 .../src/org/videolan/vlc/gui/HistoryFragment.java   | 15 +--------------
 .../vlc/gui/audio/AudioBrowserFragment.java         | 21 ---------------------
 .../vlc/gui/browser/BaseBrowserFragment.java        | 10 ----------
 .../videolan/vlc/gui/network/MRLPanelFragment.java  |  8 --------
 .../videolan/vlc/gui/video/VideoGridFragment.java   | 15 +--------------
 5 files changed, 2 insertions(+), 67 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
index caa6ac5..4255490 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
@@ -59,15 +59,6 @@ public class HistoryFragment extends MediaBrowserFragment implements IRefreshabl
         mHistoryAdapter = new HistoryAdapter();
     }
 
-    private void focusHelper(boolean idIsEmpty) {
-        MainActivity main = (MainActivity)getActivity();
-        if (main == null)
-            return;
-        main.setMenuFocusDown(idIsEmpty, android.R.id.list);
-        main.setSearchAsFocusDown(idIsEmpty, getView(),
-                android.R.id.list);
-    }
-
     @Override
     @TargetApi(Build.VERSION_CODES.HONEYCOMB)
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
@@ -84,7 +75,6 @@ public class HistoryFragment extends MediaBrowserFragment implements IRefreshabl
         mRecyclerView.setNextFocusRightId(android.R.id.list);
         if (AndroidUtil.isHoneycombOrLater())
             mRecyclerView.setNextFocusForwardId(android.R.id.list);
-        focusHelper(mHistoryAdapter.getItemCount() == 0);
         mRecyclerView.requestFocus();
         registerForContextMenu(mRecyclerView);
 
@@ -151,14 +141,11 @@ public class HistoryFragment extends MediaBrowserFragment implements IRefreshabl
         public void handleMessage(Message msg) {
             switch (msg.what){
                 case UPDATE_LIST:
-                    focusHelper(mHistoryAdapter.isEmpty());
                     mHistoryAdapter.setList((ArrayList<MediaWrapper>) msg.obj);
                     updateEmptyView();
                     if( mHistoryAdapter != null ) {
                         mHistoryAdapter.notifyDataSetChanged();
-                        focusHelper(mHistoryAdapter.getItemCount() == 0);
-                    } else
-                        focusHelper(true);
+                    }
                     mSwipeRefreshLayout.setRefreshing(false);
                     getActivity().supportInvalidateOptionsMenu();
             }
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index c976522..b71c18f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -268,7 +268,6 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
             updateLists();
         else {
             updateEmptyView(mViewPager.getCurrentItem());
-            focusHelper(false, mLists.get(mViewPager.getCurrentItem()).getId());
         }
         mMediaLibrary.addUpdateHandler(mHandler);
         mMediaLibrary.setBrowser(this);
@@ -282,20 +281,6 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
         updatePlaylists();
     }
 
-    private void focusHelper(final boolean idIsEmpty, final int listId) {
-        final View parent = getView();
-        final MainActivity main = (MainActivity)getActivity();
-        if (main == null)
-            return;
-        main.runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                main.setMenuFocusDown(false, R.id.header);
-                main.setSearchAsFocusDown(idIsEmpty, parent, listId);
-            }
-        });
-    }
-
     // Focus support. Start.
     View.OnKeyListener keyListener = new View.OnKeyListener() {
         @Override
@@ -324,10 +309,6 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
                     ListView vList = (ListView) mLists.get(newPosition);
 
                     mViewPager.setCurrentItem(newPosition);
-
-                    ((MainActivity)getActivity()).setSearchAsFocusDown(
-                            vList.getCount() == 0, getView(),
-                            vList.getId());
                 }
             }
 
@@ -647,7 +628,6 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
                         for (View v : mLists)
                             ((ListView)v).setFastScrollEnabled(true);
                     }
-                    focusHelper(false, R.id.artists_list);
                     mHandler.removeMessages(MSG_LOADING);
                     mSwipeRefreshLayout.setRefreshing(false);
                     mDisplaying = false;
@@ -809,7 +789,6 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
             updateEmptyView(mViewPager.getCurrentItem());
             mSwipeRefreshLayout.setRefreshing(false);
             mTabLayout.setVisibility(View.GONE);
-            focusHelper(true, R.id.artists_list);
         } else {
             mTabLayout.setVisibility(View.VISIBLE);
             mHandler.sendEmptyMessageDelayed(MSG_LOADING, 300);
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 0ca39b5..dd2a4aa 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -317,7 +317,6 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
         }
         mAdapter.notifyDataSetChanged();
         parseSubDirectories();
-        focusHelper();
         if (mFAB != null) {
             if (mAdapter.getMediaCount() > 0) {
                 mFAB.setVisibility(View.VISIBLE);
@@ -394,15 +393,6 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
         }
     }
 
-    protected void focusHelper() {
-        if (getActivity() == null || !(getActivity() instanceof MainActivity))
-            return;
-        boolean isEmpty = mAdapter.isEmpty();
-        MainActivity main = (MainActivity) getActivity();
-        main.setMenuFocusDown(isEmpty, R.id.network_list);
-        main.setSearchAsFocusDown(isEmpty, getView(), R.id.network_list);
-    }
-
     public void clear(){
         mAdapter.clear();
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.java b/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.java
index fc05dc5..bbe19cb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.java
@@ -36,7 +36,6 @@ import android.widget.ImageView;
 import android.widget.TextView;
 
 import org.videolan.vlc.R;
-import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.gui.helpers.UiTools;
 import org.videolan.vlc.interfaces.IHistory;
 import org.videolan.vlc.media.MediaDatabase;
@@ -83,7 +82,6 @@ public class MRLPanelFragment extends Fragment implements IHistory, View.OnKeyLi
     public void onStart(){
         super.onStart();
         getActivity().supportInvalidateOptionsMenu();
-        focusHelper(mAdapter.isEmpty());
     }
 
     private void updateHistory() {
@@ -127,12 +125,6 @@ public class MRLPanelFragment extends Fragment implements IHistory, View.OnKeyLi
         return false;
     }
 
-    private void focusHelper(boolean idIsEmpty) {
-        MainActivity main = (MainActivity)getActivity();
-        main.setMenuFocusDown(idIsEmpty, R.id.mrl_list);
-        main.setSearchAsFocusDown(idIsEmpty, mRootView, R.id.mrl_list);
-    }
-
     public boolean isEmpty(){
         return mAdapter.isEmpty();
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 23d1eca..9cf6b83 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -183,7 +183,6 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
             updateList();
         else {
             mViewNomedia.setVisibility(View.GONE);
-            focusHelper(false);
         }
         //Get & set times
         ArrayMap<String, Long> times = MediaDatabase.getInstance().getVideoTimes();
@@ -388,16 +387,6 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
         mVideoAdapter.update(item);
     }
 
-    private void focusHelper(boolean idIsEmpty) {
-        View parent = getView();
-        if (getActivity() == null || !(getActivity() instanceof MainActivity))
-            return;
-        MainActivity activity = (MainActivity)getActivity();
-        activity.setMenuFocusDown(idIsEmpty, android.R.id.list);
-        activity.setSearchAsFocusDown(idIsEmpty, parent,
-                android.R.id.list);
-    }
-
     public void updateList() {
         if (!mSwipeRefreshLayout.isRefreshing())
             mSwipeRefreshLayout.setRefreshing(true);
@@ -438,8 +427,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
                         display();
                 }
             });
-        } else
-            focusHelper(true);
+        }
         stopRefresh();
     }
 
@@ -520,7 +508,6 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
                     mViewNomedia.setVisibility(mVideoAdapter.getItemCount() > 0 ? View.GONE : View.VISIBLE);
                     mReadyToDisplay = true;
                     mGridView.requestFocus();
-                    focusHelper(false);
                 }
             });
     }



More information about the Android mailing list