[Android] [PATCH 3/3] Auto show/hide network browsing

Geoffrey Métais geoffrey.metais at gmail.com
Tue Feb 10 17:12:23 CET 2015


According to device Wifi or Ethernet connection
---
 vlc-android/src/org/videolan/vlc/gui/MainActivity.java  |  4 ++++
 .../src/org/videolan/vlc/gui/SidebarAdapter.java        | 17 +++++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 804f558..5ef1e38 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -59,6 +59,7 @@ import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.Configuration;
 import android.graphics.Color;
+import android.net.ConnectivityManager;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
@@ -277,6 +278,7 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
         filter.addAction(ACTION_HIDE_PROGRESSBAR);
         filter.addAction(ACTION_SHOW_TEXTINFO);
         filter.addAction(ACTION_SHOW_PLAYER);
+        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
         registerReceiver(messageReceiver, filter);
 
         /* Reload the latest preferences */
@@ -814,6 +816,8 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
                 }
             } else if (action.equalsIgnoreCase(ACTION_SHOW_PLAYER)) {
                 showAudioPlayer();
+            } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
+                mSidebarAdapter.updateCategories();
             }
         }
     };
diff --git a/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java b/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
index 913fa31..a115435 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
@@ -29,6 +29,7 @@ import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.audio.AudioBrowserFragment;
 import org.videolan.vlc.gui.network.NetworkFragment;
 import org.videolan.vlc.gui.video.VideoGridFragment;
+import org.videolan.vlc.util.AndroidDevices;
 import org.videolan.vlc.util.Util;
 
 import android.content.Context;
@@ -80,19 +81,31 @@ public class SidebarAdapter extends BaseAdapter {
 
     static {
         entries = new ArrayList<SidebarEntry>();
+        sidebarFragments = new ArrayList<String>();
+        updateEntries();
+    }
+
+    private static void updateEntries(){
+        entries.clear();
         entries.add(new SidebarEntry(SidebarEntry.ID_VIDEO, R.string.video, R.attr.ic_menu_video, SidebarEntry.TYPE_FRAGMENT));
         entries.add(new SidebarEntry(SidebarEntry.ID_AUDIO, R.string.audio, R.attr.ic_menu_audio, SidebarEntry.TYPE_FRAGMENT));
-        entries.add(new SidebarEntry(SidebarEntry.ID_NETWORK, R.string.network_browsing, R.attr.ic_menu_openmrl, SidebarEntry.TYPE_FRAGMENT));
+        if (AndroidDevices.hasLANConnection())
+            entries.add(new SidebarEntry(SidebarEntry.ID_NETWORK, R.string.network_browsing, R.attr.ic_menu_openmrl, SidebarEntry.TYPE_FRAGMENT));
         entries.add(new SidebarEntry(SidebarEntry.ID_MRL, R.string.open_mrl, R.attr.ic_menu_openmrl, SidebarEntry.TYPE_FRAGMENT));
         entries.add(new SidebarEntry(SidebarEntry.ID_DIRECTORIES, R.string.directories, R.attr.ic_menu_folder, SidebarEntry.TYPE_FRAGMENT));
 //        entries.add(new SidebarEntry(SidebarEntry.ID_HISTORY, R.string.history, R.attr.ic_menu_history, SidebarEntry.TYPE_FRAGMENT));
-        sidebarFragments = new ArrayList<String>();
+        sidebarFragments.clear();
         for(SidebarEntry e : entries) {
             sidebarFragments.add(e.id);
         }
 //        entries.add(new SidebarEntry(SidebarEntry.ID_PREFERENCES, R.string.preferences, R.attr.ic_menu_preferences, SidebarEntry.TYPE_ACTION));
     }
 
+    public void updateCategories(){
+        updateEntries();
+        notifyDataSetChanged();
+    }
+
     public SidebarAdapter(Context context) {
         mContext = context;
         mInflater = LayoutInflater.from(context);
-- 
2.1.0



More information about the Android mailing list