[Android] Fix back toolbar button in Playlist activity

Geoffrey Métais git at videolan.org
Thu Jul 20 13:29:17 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jul 20 13:27:51 2017 +0200| [342dfb040227e87c6d4aafea0b1a7df2fbbb6fc1] | committer: Geoffrey Métais

Fix back toolbar button in Playlist activity

> https://code.videolan.org/videolan/vlc-android/commit/342dfb040227e87c6d4aafea0b1a7df2fbbb6fc1
---

 .../vlc/gui/AudioPlayerContainerActivity.java      | 25 ++++++++++++++++++++++
 .../src/org/videolan/vlc/gui/ContentActivity.java  | 13 -----------
 .../src/org/videolan/vlc/gui/MainActivity.java     |  2 +-
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
index 6a7eec4d5..33926fa05 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
@@ -44,6 +44,7 @@ import android.support.v7.preference.PreferenceManager;
 import android.support.v7.widget.Toolbar;
 import android.support.v7.widget.ViewStubCompat;
 import android.text.TextUtils;
+import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.FrameLayout;
@@ -56,6 +57,8 @@ import org.videolan.vlc.PlaybackService;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.audio.AudioPlayer;
+import org.videolan.vlc.gui.audio.EqualizerFragment;
+import org.videolan.vlc.gui.browser.StorageBrowserFragment;
 import org.videolan.vlc.interfaces.IRefreshable;
 import org.videolan.vlc.media.MediaUtils;
 import org.videolan.vlc.util.Permissions;
@@ -193,6 +196,28 @@ public class AudioPlayerContainerActivity extends BaseActivity implements Playba
         super.onBackPressed();
     }
 
+    protected Fragment getCurrentFragment() {
+        return getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+
+        // Handle item selection
+        switch (item.getItemId()) {
+            case android.R.id.home:
+                // Current fragment loaded
+                Fragment current = getCurrentFragment();
+                if (current instanceof StorageBrowserFragment)
+                    ((StorageBrowserFragment) current).goBack();
+                else
+                    finish();
+                return true;
+            default:
+                return super.onOptionsItemSelected(item);
+        }
+    }
+
     public void updateLib() {
         if (mPreventRescan) {
             mPreventRescan = false;
diff --git a/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java b/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java
index 1a4af371d..d362f5fb7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java
@@ -35,7 +35,6 @@ import android.view.View;
 
 import org.videolan.vlc.R;
 import org.videolan.vlc.gui.audio.EqualizerFragment;
-import org.videolan.vlc.gui.browser.StorageBrowserFragment;
 import org.videolan.vlc.interfaces.Filterable;
 
 public class ContentActivity extends AudioPlayerContainerActivity implements SearchView.OnQueryTextListener, MenuItemCompat.OnActionExpandListener {
@@ -69,14 +68,6 @@ public class ContentActivity extends AudioPlayerContainerActivity implements Sea
             case R.id.ml_menu_search:
                 startActivity(new Intent(Intent.ACTION_SEARCH, null, this, SearchActivity.class));
                 return true;
-            case android.R.id.home:
-                // Current fragment loaded
-                Fragment current = getCurrentFragment();
-                if (current instanceof StorageBrowserFragment)
-                    ((StorageBrowserFragment) current).goBack();
-                else
-                    finish();
-                return true;
             default:
                 return super.onOptionsItemSelected(item);
         }
@@ -123,10 +114,6 @@ public class ContentActivity extends AudioPlayerContainerActivity implements Sea
             ((Filterable) current).setSearchVisibility(visible);
     }
 
-    private Fragment getCurrentFragment() {
-        return getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
-    }
-
     public void onClick(View v) {
         if (v.getId() == R.id.searchButton)
             openSearchActivity();
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index d2d46f256..52e9ce3fa 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -709,7 +709,7 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
         }
     }
 
-    private Fragment getCurrentFragment() {
+    protected Fragment getCurrentFragment() {
         return mCurrentFragment instanceof BaseBrowserFragment
                 ? getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder)
                 : mCurrentFragment;



More information about the Android mailing list