Android Open Source - ponyville-live-android Station Fragment






From Project

Back to project page ponyville-live-android.

License

The source code is released under:

Apache License

If you think the Android project ponyville-live-android 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.ponyvillelive.app.ui;
/* w w  w. ja  v a  2s  .c o m*/
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;

import com.ponyvillelive.app.R;
import com.ponyvillelive.app.model.Station;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * A fragment representing a list of Items.
 * <p>
 * Large screen devices (such as tablets) are supported by replacing the ListView
 * with a GridView.
 * <p>
 */
public class StationFragment extends Fragment implements AbsListView.OnItemClickListener {

    private static final String ARG_TYPE = "type";

    @InjectView(android.R.id.list)
    RecyclerView listView;
//    @InjectView(android.R.id.empty)
//    ImageView    emptyView;

    private String                     stationType;
    private StationFragmentListener    listener;
    private StationAdapter             adapter;
    private RecyclerView.LayoutManager layoutManager;

    /**
     * Mandatory empty constructor for the fragment manager to instantiate the
     * fragment (e.g. upon screen orientation changes).
     */
    public StationFragment() {
    }

    /**
     * A basic {@link android.support.v4.app.Fragment} containing a {@link android.widget.AbsListView}
     * of {@link com.ponyvillelive.app.model.Station}s
     *
     * @param stationType {@link com.ponyvillelive.app.model.Station#STATION_TYPE_AUDIO}
     *                    or {@link com.ponyvillelive.app.model.Station#STATION_TYPE_VIDEO}
     * @return A new {@link com.ponyvillelive.app.ui.StationFragment} instance
     */
    public static StationFragment newInstance(String stationType) {
        StationFragment fragment = new StationFragment();
        Bundle args = new Bundle();
        args.putString(ARG_TYPE, stationType);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getArguments() != null) {
            this.stationType = getArguments().getString(ARG_TYPE, "audio");
        }
        adapter = new StationAdapter(getLayoutInflater(savedInstanceState), this.stationType);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_station, container, false);
        ButterKnife.inject(this, view);

        layoutManager = new LinearLayoutManager(getActivity());

        // Set the adapter
        listView.setAdapter(adapter);
        listView.setLayoutManager(layoutManager);

        return view;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if (!(activity instanceof StationFragmentListener)) {
            throw new RuntimeException("Activities must implement StationFragmentListener");
        } else {
            listener = (StationFragmentListener) activity;
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        listener = null;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (listener != null) {
            listener.handleStationSelected(adapter.getItem(position));
        }
    }

    /**
     * The interaction contract that all {@link android.app.Activity}s embedding a
     * {@link com.ponyvillelive.app.ui.StationFragment} must implement
     */
    public interface StationFragmentListener {
        /**
         * Handle a station being selected inside of the {@link com.ponyvillelive.app.ui.StationFragment}
         *
         * @param station The {@link com.ponyvillelive.app.model.Station} that was selected
         */
        public void handleStationSelected(Station station);
    }
}




Java Source Code List

com.ponyvillelive.app.DebugPvlModule.java
com.ponyvillelive.app.Modules.java
com.ponyvillelive.app.Modules.java
com.ponyvillelive.app.PvlApp.java
com.ponyvillelive.app.PvlModule.java
com.ponyvillelive.app.model.ArrayResponse.java
com.ponyvillelive.app.model.DebugData.java
com.ponyvillelive.app.model.Entity.java
com.ponyvillelive.app.model.MapResponse.java
com.ponyvillelive.app.model.NowPlayingMeta.java
com.ponyvillelive.app.model.ObjectResponse.java
com.ponyvillelive.app.model.Show.java
com.ponyvillelive.app.model.SongWrapper.java
com.ponyvillelive.app.model.Song.java
com.ponyvillelive.app.model.StationMeta.java
com.ponyvillelive.app.model.Station.java
com.ponyvillelive.app.net.API.java
com.ponyvillelive.app.net.DebugNetModule.java
com.ponyvillelive.app.net.MockAPI.java
com.ponyvillelive.app.net.NetModule.java
com.ponyvillelive.app.prefs.AnimationSpeed.java
com.ponyvillelive.app.prefs.ApiEndpoint.java
com.ponyvillelive.app.prefs.ApiEndpoints.java
com.ponyvillelive.app.prefs.BooleanPreference.java
com.ponyvillelive.app.prefs.Endpoint.java
com.ponyvillelive.app.prefs.Endpoints.java
com.ponyvillelive.app.prefs.IntPreference.java
com.ponyvillelive.app.prefs.IsMockMode.java
com.ponyvillelive.app.prefs.MockDownloader.java
com.ponyvillelive.app.prefs.NetworkProxy.java
com.ponyvillelive.app.prefs.ObjectPreference.java
com.ponyvillelive.app.prefs.PicassoDebugging.java
com.ponyvillelive.app.prefs.PixelGridEnabled.java
com.ponyvillelive.app.prefs.PixelRatioEnabled.java
com.ponyvillelive.app.prefs.ScalpelEnabled.java
com.ponyvillelive.app.prefs.ScalpelWireframeEnabled.java
com.ponyvillelive.app.prefs.SeenDebugDrawer.java
com.ponyvillelive.app.prefs.StringPreference.java
com.ponyvillelive.app.ui.ActionbarHideSlidePanelListener.java
com.ponyvillelive.app.ui.ActivityHierarchyServer.java
com.ponyvillelive.app.ui.AnimationSpeedAdapter.java
com.ponyvillelive.app.ui.AppContainer.java
com.ponyvillelive.app.ui.BindableAdapter.java
com.ponyvillelive.app.ui.BottomDrawerFragment.java
com.ponyvillelive.app.ui.DebugAppContainer.java
com.ponyvillelive.app.ui.DebugUiModule.java
com.ponyvillelive.app.ui.EnumAdapter.java
com.ponyvillelive.app.ui.HierarchyTreeChangeListener.java
com.ponyvillelive.app.ui.MainActivity.java
com.ponyvillelive.app.ui.NetworkDelayAdapter.java
com.ponyvillelive.app.ui.NetworkErrorAdapter.java
com.ponyvillelive.app.ui.NetworkVarianceAdapter.java
com.ponyvillelive.app.ui.ProxyAdapter.java
com.ponyvillelive.app.ui.ServerEndpointAdapter.java
com.ponyvillelive.app.ui.SocketActivityHierarchyServer.java
com.ponyvillelive.app.ui.StationAdapter.java
com.ponyvillelive.app.ui.StationFragment.java
com.ponyvillelive.app.ui.TrackListAdapter.java
com.ponyvillelive.app.ui.UiModule.java
com.ponyvillelive.app.util.Strings.java