Android Open Source - EnklawaPlayer Episode About Dialog






From Project

Back to project page EnklawaPlayer.

License

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.

Java Source Code

package macbury.pod.dialogs;
//  w w w .  jav a  2 s . co m
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import org.sufficientlysecure.htmltextview.HtmlTextView;

import macbury.pod.R;
import macbury.pod.db.models.Episode;
import macbury.pod.db.models.EpisodeFile;
import macbury.pod.managers.App;

/**
 * Created by macbury on 17.09.14.
 */
public class EpisodeAboutDialog extends Dialog implements View.OnClickListener {
  private static final String TAG = "EpisodeAboutDialog";
  private final Episode episode;
  private final Activity activity;
  private TextView     titleTextView;
  private HtmlTextView descriptionTextView;
  private ImageButton  websiteButton;
  private Button goToProgramButton;
  private ImageButton playDownloadButton;
  private ImageButton streamButton;
  private ImageButton deleteFileButton;
  private ImageButton addToPlaylistButton;

  public EpisodeAboutDialog(Activity activity, Episode episode) {
    super(activity);
    this.activity = activity;
    this.episode = episode;
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.dialog_episode_details);

    streamButton        = (ImageButton)findViewById(R.id.button_stream);
    playDownloadButton  = (ImageButton)findViewById(R.id.button_download_play);
    deleteFileButton    = (ImageButton)findViewById(R.id.button_trash);
    goToProgramButton   = (Button)findViewById(R.id.button_go_to_program);
    websiteButton       = (ImageButton)findViewById(R.id.button_website);
    titleTextView       = (TextView)findViewById(R.id.episode_title);
    descriptionTextView = (HtmlTextView)findViewById(R.id.episode_description);
    addToPlaylistButton = (ImageButton)findViewById(R.id.button_add_to_playlist);

    titleTextView.setText(episode.name);
    if (episode.description.length() <= 5) {
      descriptionTextView.setHtmlFromString(getContext().getString(R.string.episode_no_description), false);
    } else {
      descriptionTextView.setHtmlFromString(episode.description, false);
    }

    addToPlaylistButton.setOnClickListener(this);
    streamButton.setOnClickListener(this);
    websiteButton.setOnClickListener(this);
    goToProgramButton.setOnClickListener(this);
    playDownloadButton.setOnClickListener(this);
    deleteFileButton.setOnClickListener(this);

    updateUI();
  }

  private void updateUI() {
    EpisodeFile epf = episode.getFile();
    streamButton.setVisibility(View.GONE);
    deleteFileButton.setVisibility(View.GONE);
    if (epf != null && epf.inDownloadQueue()) {
      playDownloadButton.setImageResource(R.drawable.navigation_cancel);
    } else if (epf != null && epf.isDownloadedAndExists()) {
      playDownloadButton.setImageResource(R.drawable.av_play);
      deleteFileButton.setVisibility(View.VISIBLE);
    } else {
      streamButton.setVisibility(View.VISIBLE);
      playDownloadButton.setImageResource(R.drawable.av_download);
    }

    if (App.current().db.queue.have(episode)) {
      addToPlaylistButton.setVisibility(View.GONE);
    } else {
      addToPlaylistButton.setVisibility(View.VISIBLE);
    }
  }

  @Override
  public void onClick(View v) {
    updateUI();
    App app = App.current();
    if (v == websiteButton) {
      activity.startActivity(app.intents.openURL(episode.link));
    } else if (v == goToProgramButton) {
      activity.startActivity(app.intents.activityForProgramEpisodes(episode.program));
    } else if (v == playDownloadButton) {
      downloadOrPlay();
    } else if (v == streamButton) {
      playEpisode();
    } else if (v == deleteFileButton) {
      app.db.episodeFiles.destroy(episode.getFile());
    } else if (v == addToPlaylistButton) {
      addToPlaylist();
    }

    dismiss();
  }

  private void addToPlaylist() {
    App app     = App.current();
    app.db.queue.createFromEpisode(episode);
    Toast.makeText(app, R.string.added_to_playlist, Toast.LENGTH_LONG).show();
  }

  private void playEpisode() {
    activity.startActivity(App.current().intents.openPlayerForEpisode(episode));
  }

  private void downloadOrPlay() {
    App app     = App.current();
    EpisodeFile epf = episode.getFile();

    if (epf != null && epf.inDownloadQueue()) {
      activity.startService(app.intents.cancelEpisodeDownloadService(episode));
    } else if (epf != null && epf.isDownloadedAndExists()) {
      playEpisode();
    } else {
      app.db.episodeFiles.createFromEpisode(episode);
      app.services.downloadPendingEpisodes();
    }
  }

  @Override
  protected void onStop() {
    super.onStop();
  }
}




Java Source Code List

macbury.pod.ApplicationTest.java
macbury.pod.activities.DonateActivity.java
macbury.pod.activities.ProgramEpisodesActivity.java
macbury.pod.activities.SettingsActivity.java
macbury.pod.activities.ext.AccentFragmentActivity.java
macbury.pod.activities.main.MainActivityActionBarToggle.java
macbury.pod.activities.main.MainActivity.java
macbury.pod.activities.main.NavigationController.java
macbury.pod.activities.main.NavigationListener.java
macbury.pod.activities.player.PlayerActivity.java
macbury.pod.activities.player.RadioActivity.java
macbury.pod.adapters.EpisodesAdapterListener.java
macbury.pod.adapters.EpisodesAdapter.java
macbury.pod.adapters.ProgramsAdapter.java
macbury.pod.api.APICategory.java
macbury.pod.api.APIEpisode.java
macbury.pod.api.APIProgram.java
macbury.pod.api.APIResponse.java
macbury.pod.api.APIThread.java
macbury.pod.db.DatabaseCRUDListener.java
macbury.pod.db.models.EnqueueEpisode.java
macbury.pod.db.models.EpisodeFile.java
macbury.pod.db.models.Episode.java
macbury.pod.db.models.ForumThread.java
macbury.pod.db.models.Program.java
macbury.pod.db.scopes.AbstractScope.java
macbury.pod.db.scopes.EnqueueEpisodeScope.java
macbury.pod.db.scopes.EpisodeFilesScope.java
macbury.pod.db.scopes.EpisodesScope.java
macbury.pod.db.scopes.ProgramsScope.java
macbury.pod.db.scopes.ThreadScope.java
macbury.pod.dialogs.EpisodeAboutDialog.java
macbury.pod.dialogs.ProgramAboutDialog.java
macbury.pod.extensions.Converter.java
macbury.pod.extensions.DateDeserializer.java
macbury.pod.extensions.SleepTimer.java
macbury.pod.fragments.SettingsFragment.java
macbury.pod.fragments.main.AbstractEpisodesFragment.java
macbury.pod.fragments.main.AllProgramsFragment.java
macbury.pod.fragments.main.EnklawaBaseAbstractListFragment.java
macbury.pod.fragments.main.episodes.DownloadedEpisodesFragment.java
macbury.pod.fragments.main.episodes.NewestEpisodesFragment.java
macbury.pod.fragments.main.episodes.PlaylistFragment.java
macbury.pod.fragments.main.episodes.ProgramEpisodesFragment.java
macbury.pod.fragments.player.ExternalPlayerFragment.java
macbury.pod.fragments.player.PlayerArtworkAndInfoFragment.java
macbury.pod.fragments.player.PlayerControllerFragment.java
macbury.pod.managers.AlarmsManager.java
macbury.pod.managers.App.java
macbury.pod.managers.BroadcastsManager.java
macbury.pod.managers.DatabaseManager.java
macbury.pod.managers.IntentManager.java
macbury.pod.managers.NotificationsManager.java
macbury.pod.managers.ServiceManager.java
macbury.pod.managers.SettingsManager.java
macbury.pod.managers.StorageManager.java
macbury.pod.managers.download.DownloadEpisode.java
macbury.pod.managers.download.DownloadManagerListener.java
macbury.pod.managers.download.DownloadManager.java
macbury.pod.managers.player.PlaybackStatus.java
macbury.pod.managers.player.PlayerManagerListener.java
macbury.pod.managers.player.PlayerManager.java
macbury.pod.managers.player.sources.AbstractMediaSource.java
macbury.pod.managers.player.sources.EpisodeMediaSource.java
macbury.pod.managers.player.sources.RadioMediaSource.java
macbury.pod.navigation_drawer.NavAdapter.java
macbury.pod.navigation_drawer.NavBaseItem.java
macbury.pod.navigation_drawer.NavDivider.java
macbury.pod.navigation_drawer.items.AllProgramsNavItem.java
macbury.pod.navigation_drawer.items.DownloadedEpisodesNavItem.java
macbury.pod.navigation_drawer.items.FavoriteProgramNavItem.java
macbury.pod.navigation_drawer.items.ForumNavItem.java
macbury.pod.navigation_drawer.items.NavItemFragment.java
macbury.pod.navigation_drawer.items.NewestEpisodesNavItem.java
macbury.pod.navigation_drawer.items.PlayQueueNavItem.java
macbury.pod.receivers.BootReceiver.java
macbury.pod.receivers.MediaButtonReceiver.java
macbury.pod.services.DownloadService.java
macbury.pod.services.PlayerService.java
macbury.pod.services.SyncPodService.java
macbury.pod.tutorial.MainActivityTutorial.java
macbury.pod.views.TappableFrameLayout.java