Android Open Source - haavi Episode List Activity

From Project

Back to project page haavi.


The source code is released under:

MIT License

If you think the Android project haavi 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 com.ilkkalaukkanen.haavi;
//from   ww  w  .j a  v  a 2s . c om
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.ilkkalaukkanen.haavi.model.Podcast;
import org.joda.time.format.DateTimeFormat;
import roboguice.activity.RoboFragmentActivity;
import rx.schedulers.Schedulers;

import java.util.ArrayList;
import java.util.List;

 * An activity representing a list of Episodes. This activity has different presentations for handset and tablet-size
 * devices. On handsets, the activity presents a list of items, which when touched, lead to a {@link
 * EpisodeDetailActivity} representing item details. On tablets, the activity presents the list of items and item
 * details side-by-side using two vertical panes.
 * <p/>
 * The activity makes heavy use of fragments. The list of items is a {@link EpisodeListFragment} and the item details
 * (if present) is a {@link EpisodeDetailFragment}.
 * <p/>
 * This activity also implements the required {@link EpisodeListFragment.Callbacks} interface to listen for item
 * selections.
public class EpisodeListActivity extends RoboFragmentActivity
        implements EpisodeListFragment.Callbacks {

     * Whether or not the activity is in two-pane mode, i.e. running on a tablet device.
    private boolean mTwoPane;

    FeedDownloader feedDownloader;
    private EpisodeListFragment   episodeListFragment;
    private ArrayAdapter<Podcast> podcastArrayAdapter;
    private ArrayList<Podcast>    podcastList;

    protected void onCreate(Bundle savedInstanceState) {

        episodeListFragment = (EpisodeListFragment) getSupportFragmentManager().findFragmentById(;

        if (findViewById( != null) {
            // The detail container view will be present only in the
            // large-screen layouts (res/values-large and
            // res/values-sw600dp). If this view is present, then the
            // activity should be in two-pane mode.
            mTwoPane = true;

            // In two-pane mode, list items should be given the
            // 'activated' state when touched.
        podcastList = new ArrayList<Podcast>();
        podcastArrayAdapter = new PodcastArrayAdapter(podcastList);


        // TODO: If exposing deep links into your app, handle intents here.

     * Callback method from {@link EpisodeListFragment.Callbacks} indicating that the item with the given ID was
     * selected.
     * @param position
    public void onItemSelected(int position) {
        Podcast item = podcastList.get(position);

        if (mTwoPane) {
            // In two-pane mode, show the detail view in this activity by
            // adding or replacing the detail fragment using a
            // fragment transaction.
            Bundle arguments = new Bundle();
            arguments.putString(EpisodeDetailFragment.ARG_ITEM_TITLE, item.getTitle());
            arguments.putString(EpisodeDetailFragment.ARG_ITEM_DESCRIPTION, item.getDescription());
            arguments.putString(EpisodeDetailFragment.ARG_ITEM_URL, item.getUrl());
            EpisodeDetailFragment fragment = new EpisodeDetailFragment();
                                .replace(, fragment)

        } else {
            // In single-pane mode, simply start the detail activity
            // for the selected item ID.
            Intent detailIntent = new Intent(this, EpisodeDetailActivity.class);
            detailIntent.putExtra(EpisodeDetailActivity.EXTRA_ITEM_TITLE, item.getTitle());
            detailIntent.putExtra(EpisodeDetailActivity.EXTRA_ITEM_DESCRIPTION, item.getDescription());
            detailIntent.putExtra(EpisodeDetailActivity.EXTRA_ITEM_URL, item.getUrl());

    private class PodcastArrayAdapter extends ArrayAdapter<Podcast> {
        public PodcastArrayAdapter(final List<Podcast> podcastList) {
            super(EpisodeListActivity.this, R.layout.episode_list_item, podcastList);

        public View getView(final int position, final View convertView, final ViewGroup parent) {
            View view = null;
            if (convertView != null) {
                if (convertView.findViewById( != null) {
                    view = convertView;
            if (view == null) {
                view = getLayoutInflater().inflate(R.layout.episode_list_item, null);
            assert view != null;
            TextView titleView = (TextView) view.findViewById(;
            TextView pubDateView = (TextView) view.findViewById(;
            TextView durationView = (TextView) view.findViewById(;

            Podcast podcast = getItem(position);
            durationView.setText(getString(R.string.sizeMb, podcast.getSizeInBytes() / (1024 * 1024)));
            return view;

Java Source Code List