Back to project page EnklawaPlayer.
The source code is released under:
GNU General Public License
If you think the Android project EnklawaPlayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package macbury.pod.fragments.main.episodes; /*from w ww .j a v a 2 s .co m*/ import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.Toast; import java.util.List; import macbury.pod.R; import macbury.pod.db.models.Episode; import macbury.pod.db.models.Program; import macbury.pod.dialogs.ProgramAboutDialog; import macbury.pod.fragments.main.AbstractEpisodesFragment; import macbury.pod.managers.App; /** * Created by macbury on 15.09.14. */ public class ProgramEpisodesFragment extends AbstractEpisodesFragment { private Program program; private ProgramAboutDialog dialog; public ProgramEpisodesFragment() { super(); } @Override public List<Episode> getEpisodes() { return app.db.episodes.allForProgram(program); } public void setProgram(Program program) { this.program = program; if (isAdded()) { updateEpisodes(); getActivity().invalidateOptionsMenu(); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.program, menu); MenuItem item = menu.findItem(R.id.action_favorite); if (program.isFavorite()) { item.setIcon(R.drawable.ic_action_rating_important); item.setTitle(R.string.action_mark_as_not_favorite); } else { item.setIcon(R.drawable.ic_action_rating_not_important); item.setTitle(R.string.action_mark_as_favorite); } } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_favorite: toggleFavorite(); break; case R.id.action_about: this.dialog = new ProgramAboutDialog(getActivity(), program); dialog.show(); break; } return super.onOptionsItemSelected(item); } @Override public void onPause() { super.onPause(); if (dialog != null) { dialog.hide(); dialog = null; } } private void toggleFavorite() { App app = App.current(); program.favorite = !program.favorite; app.db.programs.update(program); app.broadcasts.favoriteProgramChange(program); Toast.makeText(getActivity(), program.favorite ? R.string.action_marked_as_favorite : R.string.action_marked_as_not_favorite, Toast.LENGTH_SHORT).show(); getActivity().invalidateOptionsMenu(); } public Program getProgram() { return program; } }