[Android] Main activity: try to make the behaviour of all the fragments standard

Adrien Maglo git at videolan.org
Tue Jan 28 16:54:12 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Tue Jan 28 16:46:31 2014 +0100| [ce271c7c37af525fce455b0124277fb987735042] | committer: Adrien Maglo

Main activity: try to make the behaviour of all the fragments standard

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=ce271c7c37af525fce455b0124277fb987735042
---

 .../src/org/videolan/vlc/gui/MainActivity.java     |   29 ++++++++++++--------
 .../src/org/videolan/vlc/gui/SidebarAdapter.java   |    3 ++
 .../vlc/gui/audio/AudioBrowserFragment.java        |    4 +--
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 1d7f117..f5d08e7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -30,7 +30,6 @@ import org.videolan.vlc.Util;
 import org.videolan.vlc.VLCCallbackTask;
 import org.videolan.vlc.WeakHandler;
 import org.videolan.vlc.gui.SidebarAdapter.SidebarEntry;
-import org.videolan.vlc.gui.audio.EqualizerFragment;
 import org.videolan.vlc.gui.video.VideoListAdapter;
 import org.videolan.vlc.interfaces.ISortable;
 import org.videolan.vlc.widget.AudioMiniPlayer;
@@ -377,7 +376,8 @@ public class MainActivity extends SherlockFragmentActivity {
         /* Save the tab status in pref */
         SharedPreferences.Editor editor = getSharedPreferences("MainActivity", MODE_PRIVATE).edit();
         /* Do not save the albums songs fragment as the current fragment. */
-        if (mCurrentFragment.equals("albumsSongs"))
+        if (mCurrentFragment.equals("albumsSongs")
+            || mCurrentFragment.equals("equalizer"))
             mCurrentFragment = "audio";
         editor.putString("fragment", mCurrentFragment);
         editor.commit();
@@ -424,8 +424,9 @@ public class MainActivity extends SherlockFragmentActivity {
         }
 
         // If it's the albums songs fragment, we leave it.
-        if (mCurrentFragment.equals("albumsSongs")) {
-            hideAudioAlbumsSongsFragment();
+        if (mCurrentFragment.equals("albumsSongs")
+            || mCurrentFragment.equals("equalizer")) {
+            popFragmentBackStack();
             return;
         }
 
@@ -479,20 +480,23 @@ public class MainActivity extends SherlockFragmentActivity {
     }
 
     /**
-     * Show the new albums songs fragment.
+     * Show a new fragment.
      */
-    public Fragment showAudioAlbumsSongsFragment() {
+    public Fragment showNewFragment(String fragmentTag) {
+        // Slide down the mini player if needed.
+        slideDownMiniPlayer();
+
         mPreviousFragment = mCurrentFragment;
-        mCurrentFragment = "albumsSongs";
+        mCurrentFragment = fragmentTag;
         Fragment frag = getFragment(mCurrentFragment);
-        ShowFragment(this, "albumsSongs", frag);
+        ShowFragment(this, mCurrentFragment, frag);
         return frag;
     }
 
     /**
      * Hide the albums songs fragment.
      */
-    public void hideAudioAlbumsSongsFragment() {
+    public void popFragmentBackStack() {
         FragmentManager fragmentManager = getSupportFragmentManager();
         fragmentManager.popBackStack();
         mCurrentFragment = mPreviousFragment;
@@ -567,7 +571,7 @@ public class MainActivity extends SherlockFragmentActivity {
                 startActivityForResult(intent, ACTIVITY_RESULT_PREFERENCES);
                 break;
             case R.id.ml_menu_equalizer:
-                ShowFragment("equalizer", EqualizerFragment.class);
+                showNewFragment("equalizer");
                 break;
             // Refresh
             case R.id.ml_menu_refresh:
@@ -595,8 +599,9 @@ public class MainActivity extends SherlockFragmentActivity {
                 break;
             case android.R.id.home:
                 // If it's the albums songs view, a "backpressed" action shows .
-                if (mCurrentFragment.equals("albumsSongs")) {
-                    hideAudioAlbumsSongsFragment();
+                if (mCurrentFragment.equals("albumsSongs")
+                    || mCurrentFragment.equals("equalizer")) {
+                    popFragmentBackStack();
                     break;
                 }
                 /* Toggle the sidebar */
diff --git a/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java b/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
index 1ac8a95..395bfeb 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.Util;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.audio.AudioAlbumsSongsFragment;
 import org.videolan.vlc.gui.audio.AudioBrowserFragment;
+import org.videolan.vlc.gui.audio.EqualizerFragment;
 import org.videolan.vlc.gui.video.VideoGridFragment;
 
 import android.graphics.drawable.Drawable;
@@ -132,6 +133,8 @@ public class SidebarAdapter extends BaseAdapter {
             f = new HistoryFragment();
         } else if(id.equals("albumsSongs")) {
             f = new AudioAlbumsSongsFragment();
+        } else if(id.equals("equalizer")) {
+            f = new EqualizerFragment();
         }
         else
         { /* TODO */
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 d07c5ac..3928ce8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -179,7 +179,7 @@ public class AudioBrowserFragment extends SherlockFragment {
         public void onItemClick(AdapterView<?> av, View v, int p, long id) {
             ArrayList<Media> mediaList = mArtistsAdapter.getMedia(p);
             MainActivity activity = (MainActivity)getActivity();
-            AudioAlbumsSongsFragment frag = (AudioAlbumsSongsFragment)activity.showAudioAlbumsSongsFragment();
+            AudioAlbumsSongsFragment frag = (AudioAlbumsSongsFragment)activity.showNewFragment("albumsSongs");
             frag.setMediaList(mediaList, mediaList.get(0).getArtist());
         }
     };
@@ -197,7 +197,7 @@ public class AudioBrowserFragment extends SherlockFragment {
         public void onItemClick(AdapterView<?> av, View v, int p, long id) {
             ArrayList<Media> mediaList = mGenresAdapter.getMedia(p);
             MainActivity activity = (MainActivity)getActivity();
-            AudioAlbumsSongsFragment frag = (AudioAlbumsSongsFragment)activity.showAudioAlbumsSongsFragment();
+            AudioAlbumsSongsFragment frag = (AudioAlbumsSongsFragment)activity.showNewFragment("albumsSongs");
             frag.setMediaList(mediaList, mediaList.get(0).getGenre());
         }
     };



More information about the Android mailing list