From 8e451b2a8368351b73a5ca95a2f69b2266f5ebca Mon Sep 17 00:00:00 2001 From: Coffeemakr Date: Thu, 19 Jan 2017 19:38:33 +0100 Subject: [PATCH] Use fragments setHasOptionsMenu Remove complications by allowing android to handle fragment's options menu. See https://developer.android.com/guide/components/fragments.html#ActionBar --- .../main/java/org/schabi/newpipe/MainActivity.java | 5 +---- .../newpipe/detail/VideoItemDetailActivity.java | 11 +---------- .../newpipe/detail/VideoItemDetailFragment.java | 1 + .../org/schabi/newpipe/download/DownloadActivity.java | 3 +-- .../search_fragment/SearchInfoItemFragment.java | 2 ++ 5 files changed, 6 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index bfeb74287..3dae561e7 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -52,8 +52,6 @@ public class MainActivity extends AppCompatActivity { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); - - mainFragment.onCreateOptionsMenu(menu, inflater); return true; } @@ -79,8 +77,7 @@ public class MainActivity extends AppCompatActivity { return true; } default: - return mainFragment.onOptionsItemSelected(item) || - super.onOptionsItemSelected(item); + return super.onOptionsItemSelected(item); } } } diff --git a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailActivity.java b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailActivity.java index 591017a92..2c4f9cf58 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailActivity.java +++ b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailActivity.java @@ -162,19 +162,10 @@ public class VideoItemDetailActivity extends AppCompatActivity { NavUtils.navigateUpTo(this, intent); return true; } else { - return fragment.onOptionsItemSelected(item) || - super.onOptionsItemSelected(item); + return super.onOptionsItemSelected(item); } } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - fragment.onCreateOptionsMenu(menu, getMenuInflater()); - return true; - } - - /** * Retrieves all Strings which look remotely like URLs from a text. * Used if NewPipe was called through share menu. diff --git a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java index 2c6e4b55a..9371397f8 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java @@ -629,6 +629,7 @@ public class VideoItemDetailFragment extends Fragment { onNotSpecifiedContentError(); } }); + setHasOptionsMenu(true); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java index a7e52c486..2ad4107ba 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java @@ -273,8 +273,7 @@ public class DownloadActivity extends AppCompatActivity implements AdapterView.O return true; } default: - return mFragment.onOptionsItemSelected(item) || - super.onOptionsItemSelected(item); + return super.onOptionsItemSelected(item); } } } diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java index 2afe149a8..09e7c0903 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java @@ -160,6 +160,8 @@ public class SearchInfoItemFragment extends Fragment { } } + setHasOptionsMenu(true); + SearchWorker sw = SearchWorker.getInstance(); sw.setSearchWorkerResultListener(new SearchWorker.SearchWorkerResultListener() { @Override