[Android] Albums songs fragment: leave the fragment on pressing the action bar home button

Adrien Maglo git at videolan.org
Mon Jan 27 18:13:27 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Mon Jan 27 18:13:19 2014 +0100| [9f068a9151c5b2ef8bd2a6101affd5d3c85cd21e] | committer: Adrien Maglo

Albums songs fragment: leave the fragment on pressing the action bar home button

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

 .../src/org/videolan/vlc/gui/MainActivity.java     |   33 ++++++++++++++++++++
 .../src/org/videolan/vlc/gui/SidebarAdapter.java   |    7 ++++-
 .../vlc/gui/audio/AudioAlbumsSongsFragment.java    |    2 +-
 .../vlc/gui/audio/AudioBrowserFragment.java        |   10 +++---
 4 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 8d666a5..c776de5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -108,6 +108,7 @@ public class MainActivity extends SherlockFragmentActivity {
     private TextView mInfoText;
     private View mAudioPlayerFilling;
     private String mCurrentFragment;
+    private String mPreviousFragment;
 
     private SharedPreferences mSettings;
 
@@ -421,6 +422,13 @@ public class MainActivity extends SherlockFragmentActivity {
                 return;
             }
         }
+
+        // If it's the albums songs fragment, we leave it.
+        if (mCurrentFragment.equals("albumsSongs")) {
+            hideAudioAlbumsSongsFragment();
+            return;
+        }
+
         super.onBackPressed();
     }
 
@@ -466,6 +474,26 @@ public class MainActivity extends SherlockFragmentActivity {
         ft.commit();
     }
 
+    /**
+     * Show the new albums songs fragment.
+     */
+    public Fragment showAudioAlbumsSongsFragment() {
+        mPreviousFragment = mCurrentFragment;
+        mCurrentFragment = "albumsSongs";
+        Fragment frag = getFragment(mCurrentFragment);
+        ShowFragment(this, "albumsSongs", frag);
+        return frag;
+    }
+
+    /**
+     * Hide the albums songs fragment.
+     */
+    public void hideAudioAlbumsSongsFragment() {
+        FragmentManager fragmentManager = getSupportFragmentManager();
+        fragmentManager.popBackStack();
+        mCurrentFragment = mPreviousFragment;
+    }
+
     /** Create menu from XML
      */
     @Override
@@ -562,6 +590,11 @@ public class MainActivity extends SherlockFragmentActivity {
                 onSearchRequested();
                 break;
             case android.R.id.home:
+                // If it's the albums songs view, a "backpressed" action shows .
+                if (mCurrentFragment.equals("albumsSongs")) {
+                    hideAudioAlbumsSongsFragment();
+                    break;
+                }
                 /* Toggle the sidebar */
                 if(mMenu.isMenuShowing())
                     mMenu.showContent();
diff --git a/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java b/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
index 71801bd..1ac8a95 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
@@ -27,6 +27,7 @@ import java.util.List;
 import org.videolan.vlc.R;
 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.video.VideoGridFragment;
 
@@ -129,7 +130,11 @@ public class SidebarAdapter extends BaseAdapter {
             f = new DirectoryViewFragment();
         } else if(id.equals("history")) {
             f = new HistoryFragment();
-        } else { /* TODO */
+        } else if(id.equals("albumsSongs")) {
+            f = new AudioAlbumsSongsFragment();
+        }
+        else
+        { /* TODO */
             f = new AboutLicenceFragment();
         }
         f.setRetainInstance(true);
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index c48ff4a..855da1c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -82,7 +82,7 @@ public class AudioAlbumsSongsFragment extends SherlockFragment {
     /* All subclasses of Fragment must include a public empty constructor. */
     public AudioAlbumsSongsFragment() { }
 
-    public AudioAlbumsSongsFragment(ArrayList<Media> mediaList, String title) {
+    public void setMediaList(ArrayList<Media> mediaList, String title) {
         this.mediaList = mediaList;
         mTitle = title;
     }
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 320078a..07d75c6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -177,8 +177,9 @@ public class AudioBrowserFragment extends SherlockFragment {
         @Override
         public void onItemClick(AdapterView<?> av, View v, int p, long id) {
             ArrayList<Media> mediaList = mArtistsAdapter.getMedia(p);
-            AudioAlbumsSongsFragment frag = new AudioAlbumsSongsFragment(mediaList, mediaList.get(0).getArtist());
-            MainActivity.ShowFragment(getActivity(), "albumsSongsFromArtist", frag);
+            MainActivity activity = (MainActivity)getActivity();
+            AudioAlbumsSongsFragment frag = (AudioAlbumsSongsFragment)activity.showAudioAlbumsSongsFragment();
+            frag.setMediaList(mediaList, mediaList.get(0).getArtist());
         }
     };
 
@@ -194,8 +195,9 @@ public class AudioBrowserFragment extends SherlockFragment {
         @Override
         public void onItemClick(AdapterView<?> av, View v, int p, long id) {
             ArrayList<Media> mediaList = mGenresAdapter.getMedia(p);
-            AudioAlbumsSongsFragment frag = new AudioAlbumsSongsFragment(mediaList, mediaList.get(0).getGenre());
-            MainActivity.ShowFragment(getActivity(), "albumsSongsFromArtist", frag);
+            MainActivity activity = (MainActivity)getActivity();
+            AudioAlbumsSongsFragment frag = (AudioAlbumsSongsFragment)activity.showAudioAlbumsSongsFragment();
+            frag.setMediaList(mediaList, mediaList.get(0).getGenre());
         }
     };
 



More information about the Android mailing list