Use fragments setHasOptionsMenu

Remove complications by allowing android to handle fragment's
options menu.

See https://developer.android.com/guide/components/fragments.html#ActionBar
This commit is contained in:
Coffeemakr 2017-01-19 19:38:33 +01:00
parent 7efd111d9c
commit 8e451b2a83
5 changed files with 6 additions and 16 deletions

View File

@ -52,8 +52,6 @@ public class MainActivity extends AppCompatActivity {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu); inflater.inflate(R.menu.main_menu, menu);
mainFragment.onCreateOptionsMenu(menu, inflater);
return true; return true;
} }
@ -79,8 +77,7 @@ public class MainActivity extends AppCompatActivity {
return true; return true;
} }
default: default:
return mainFragment.onOptionsItemSelected(item) || return super.onOptionsItemSelected(item);
super.onOptionsItemSelected(item);
} }
} }
} }

View File

@ -162,19 +162,10 @@ public class VideoItemDetailActivity extends AppCompatActivity {
NavUtils.navigateUpTo(this, intent); NavUtils.navigateUpTo(this, intent);
return true; return true;
} else { } else {
return fragment.onOptionsItemSelected(item) || return super.onOptionsItemSelected(item);
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. * Retrieves all Strings which look remotely like URLs from a text.
* Used if NewPipe was called through share menu. * Used if NewPipe was called through share menu.

View File

@ -629,6 +629,7 @@ public class VideoItemDetailFragment extends Fragment {
onNotSpecifiedContentError(); onNotSpecifiedContentError();
} }
}); });
setHasOptionsMenu(true);
} }
@Override @Override

View File

@ -273,8 +273,7 @@ public class DownloadActivity extends AppCompatActivity implements AdapterView.O
return true; return true;
} }
default: default:
return mFragment.onOptionsItemSelected(item) || return super.onOptionsItemSelected(item);
super.onOptionsItemSelected(item);
} }
} }
} }

View File

@ -160,6 +160,8 @@ public class SearchInfoItemFragment extends Fragment {
} }
} }
setHasOptionsMenu(true);
SearchWorker sw = SearchWorker.getInstance(); SearchWorker sw = SearchWorker.getInstance();
sw.setSearchWorkerResultListener(new SearchWorker.SearchWorkerResultListener() { sw.setSearchWorkerResultListener(new SearchWorker.SearchWorkerResultListener() {
@Override @Override