[Android] Access menu via activity toolbar
Geoffrey Métais
git at videolan.org
Wed Apr 4 18:35:21 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar 15 11:25:30 2018 +0100| [45f0412563d9b6aab54a5001611eb9e6f5867633] | committer: Geoffrey Métais
Access menu via activity toolbar
> https://code.videolan.org/videolan/vlc-android/commit/45f0412563d9b6aab54a5001611eb9e6f5867633
---
.../videolan/vlc/gui/AudioPlayerContainerActivity.java | 5 +++++
.../src/org/videolan/vlc/gui/HistoryFragment.java | 2 +-
.../org/videolan/vlc/gui/audio/BaseAudioBrowser.java | 2 +-
.../videolan/vlc/gui/browser/BaseBrowserFragment.java | 2 +-
.../videolan/vlc/gui/browser/MediaBrowserFragment.java | 18 ++++++++++++++----
.../vlc/gui/browser/NetworkBrowserFragment.java | 2 +-
.../src/org/videolan/vlc/gui/helpers/UiTools.java | 4 +++-
.../org/videolan/vlc/gui/video/VideoGridFragment.java | 2 +-
8 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
index 93cdabdaa..b8bed2b73 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
@@ -40,6 +40,7 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.ViewStubCompat;
+import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
@@ -175,6 +176,10 @@ public class AudioPlayerContainerActivity extends BaseActivity {
return getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
}
+ public Menu getMenu() {
+ return mToolbar.getMenu();
+ }
+
@Override
public boolean onOptionsItemSelected(MenuItem item) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
index 0fd5492be..02bb787b3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
@@ -246,7 +246,7 @@ public class HistoryFragment extends MediaBrowserFragment<HistoryProvider> imple
@Override
public void onUpdateFinished(RecyclerView.Adapter adapter) {
invalidateActionMode();
- UiTools.updateSortTitles(this, mMenu);
+ UiTools.updateSortTitles(this);
}
@Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
index 51fd67b5e..3e890e5b8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
@@ -182,6 +182,6 @@ public abstract class BaseAudioBrowser extends MediaBrowserFragment<AudioModel>
@Override
public void onUpdateFinished(RecyclerView.Adapter adapter) {
- if (adapter == getCurrentAdapter()) onPrepareOptionsMenu(mMenu);
+ if (adapter == getCurrentAdapter()) onPrepareOptionsMenu(getMenu());
}
}
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 f43202965..e8f8ec4b6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -597,7 +597,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment<BrowserPr
}
if (!mRoot) {
updateFab();
- UiTools.updateSortTitles(this, mMenu);
+ UiTools.updateSortTitles(this);
}
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
index 4b96b0629..71e84f770 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
@@ -23,6 +23,7 @@
package org.videolan.vlc.gui.browser;
import android.annotation.TargetApi;
+import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
@@ -44,6 +45,7 @@ import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
+import org.videolan.vlc.gui.AudioPlayerContainerActivity;
import org.videolan.vlc.gui.ContentActivity;
import org.videolan.vlc.gui.InfoActivity;
import org.videolan.vlc.gui.audio.BaseAudioBrowser;
@@ -69,7 +71,6 @@ public abstract class MediaBrowserFragment<T extends BaseModel> extends Fragment
protected Medialibrary mMediaLibrary;
protected ActionMode mActionMode;
public FloatingActionButton mFabPlay;
- protected Menu mMenu;
protected T mProvider;
public T getProvider() {
@@ -231,8 +232,8 @@ public abstract class MediaBrowserFragment<T extends BaseModel> extends Fragment
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
- mMenu = menu;
}
+
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
@@ -242,7 +243,7 @@ public abstract class MediaBrowserFragment<T extends BaseModel> extends Fragment
menu.findItem(R.id.ml_menu_sortby_length).setVisible(getProvider().canSortByDuration());
menu.findItem(R.id.ml_menu_sortby_date).setVisible(getProvider().canSortByReleaseDate() || getProvider().canSortByLastModified());
menu.findItem(R.id.ml_menu_sortby_number).setVisible(false);
- UiTools.updateSortTitles(this, menu);
+ UiTools.updateSortTitles(this);
}
@Override
@@ -274,9 +275,18 @@ public abstract class MediaBrowserFragment<T extends BaseModel> extends Fragment
getProvider().sort(sort);
}
+ public Menu getMenu() {
+ final AudioPlayerContainerActivity activity = (AudioPlayerContainerActivity) getActivity();
+ if (activity == null) return null;
+ return activity.getMenu();
+
+ }
+
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void startActionMode() {
- mActionMode = ((AppCompatActivity)getActivity()).startSupportActionMode(this);
+ final AppCompatActivity activity = (AppCompatActivity) getActivity();
+ if (activity == null) return;
+ mActionMode = activity.startSupportActionMode(this);
setFabPlayVisibility(false);
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
index 662f57362..2ed195e9a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
@@ -141,7 +141,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Simpl
switch (item.getItemId()) {
case R.id.ml_menu_save:
toggleFavorite();
- onPrepareOptionsMenu(mMenu);
+ onPrepareOptionsMenu(getMenu());
return true;
default:
return super.onOptionsItemSelected(item);
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
index fe005dafc..fcf555df7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -316,7 +316,9 @@ public class UiTools {
return outBitmap;
}
- public static void updateSortTitles(MediaBrowserFragment sortable, Menu menu) {
+ public static void updateSortTitles(MediaBrowserFragment sortable) {
+ final Menu menu = sortable.getMenu();
+ if (menu == null) return;
final BaseModel model = sortable.getProvider();
final int sort = model.getSort();
final boolean desc = model.getDesc();
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 4cacc5fcb..68c3edfee 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -461,7 +461,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
mHandler.sendEmptyMessage(UNSET_REFRESHING);
updateEmptyView();
setFabPlayVisibility(true);
- UiTools.updateSortTitles(this, mMenu);
+ UiTools.updateSortTitles(this);
}
public void updateSeenMediaMarker() {
More information about the Android
mailing list