Android Open Source - ponyville-live-android Bottom Drawer 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;
//from   w w w.  ja v a2s.c o m
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.ponyvillelive.app.PvlApp;
import com.ponyvillelive.app.R;
import com.ponyvillelive.app.model.NowPlayingMeta;
import com.ponyvillelive.app.model.Station;
import com.ponyvillelive.app.net.API;
import com.squareup.picasso.Picasso;

import javax.inject.Inject;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;


/**
 * A simple {@link Fragment} subclass.
 * Use the {@link BottomDrawerFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class BottomDrawerFragment extends Fragment {

    @InjectView(R.id.icon)
    ImageView icon;
    @InjectView(R.id.text_title)
    TextView  title;
    @InjectView(R.id.text_artist)
    TextView  artist;
//    @InjectView(R.id.bottom_drawer_list)
//    ListView  trackList;

    @Inject
    Picasso picasso;
    @Inject
    API     api;

    private TrackListAdapter adapter;
    private DrawerListener   listener;
    private Subscription     songSubscription;

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @return A new instance of fragment BottomDrawerFragment.
     */
    public static BottomDrawerFragment newInstance() {
        BottomDrawerFragment fragment = new BottomDrawerFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    public BottomDrawerFragment() {
        // Required empty public constructor
    }

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

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

        adapter = new TrackListAdapter();
//        trackList.setAdapter(adapter);

        return v;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        if(!(activity instanceof DrawerListener)) {
            throw new RuntimeException("Activity must implement DrawerListener");
        }

        this.listener = (DrawerListener) activity;
        PvlApp.get(activity).inject(this);
    }

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

    @OnClick(R.id.btn_drawer_cancel)
    public void handleStopClicked() {
        listener.handleStationCleared();
    }

    /**
     * Binds the view to the current station, displaying it's data in
     * the peek area, as well as its track history in the list
     * @param station The {@link com.ponyvillelive.app.model.Station} to bind to
     */
    public void showStationInfo(Station station) {
        songSubscription = api
                .getNowPlayingForStation(station.id)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe((nowPlayingStationResponse) -> {
                    if(getView() == null) return;

                    if(getView().getVisibility() != View.VISIBLE) {
                        getView().setVisibility(View.VISIBLE);
                    }

                    NowPlayingMeta data = nowPlayingStationResponse.result;
                    title.setText(data.currentSong.title);
                    artist.setText(data.currentSong.artist);
                    picasso
                            .load("http:" + data.station.imageUrl)
                            .into(icon);
                    adapter.setSongs(data.songHistory);
                    songSubscription.unsubscribe();
                });
    }

    public interface DrawerListener {
        public void handleStationCleared();
    }
}




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