OSDN Git Service

Eleven: Add loading dialogs to all fragments
[android-x86/packages-apps-Eleven.git] / src / com / cyngn / eleven / ui / fragments / profile / TopTracksFragment.java
1 /*
2  * Copyright (C) 2012 Andrew Neal Licensed under the Apache License, Version 2.0
3  * (the "License"); you may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6  * or agreed to in writing, software distributed under the License is
7  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8  * KIND, either express or implied. See the License for the specific language
9  * governing permissions and limitations under the License.
10  */
11
12 package com.cyngn.eleven.ui.fragments.profile;
13
14 import android.app.Activity;
15 import android.os.Bundle;
16 import android.support.v4.content.Loader;
17 import android.view.View;
18 import android.view.ViewGroup;
19 import android.widget.TextView;
20
21 import com.cyngn.eleven.Config;
22 import com.cyngn.eleven.R;
23 import com.cyngn.eleven.adapters.SongAdapter;
24 import com.cyngn.eleven.loaders.TopTracksLoader;
25 import com.cyngn.eleven.model.Song;
26 import com.cyngn.eleven.sectionadapter.SectionAdapter;
27 import com.cyngn.eleven.sectionadapter.SectionCreator;
28 import com.cyngn.eleven.sectionadapter.SectionListContainer;
29 import com.cyngn.eleven.ui.activities.BaseActivity;
30 import com.cyngn.eleven.ui.fragments.ISetupActionBar;
31 import com.cyngn.eleven.utils.MusicUtils;
32 import com.cyngn.eleven.widgets.NoResultsContainer;
33
34 /**
35  * This class is used to display all of the songs the user put on their device
36  * within the last four weeks.
37  *
38  * @author Andrew Neal (andrewdneal@gmail.com)
39  */
40 public class TopTracksFragment extends BasicSongFragment implements ISetupActionBar {
41
42     /**
43      * LoaderCallbacks identifier
44      */
45     private static final int LOADER = 0;
46
47     /**
48      * {@inheritDoc}
49      */
50     @Override
51     public Loader<SectionListContainer<Song>> onCreateLoader(final int id, final Bundle args) {
52         // show the loading progress bar
53         mLoadingEmptyContainer.showLoading();
54
55         TopTracksLoader loader = new TopTracksLoader(getActivity(),
56                 TopTracksLoader.QueryType.TopTracks);
57         return new SectionCreator<Song>(getActivity(), loader, null);
58     }
59
60     @Override
61     protected SectionAdapter<Song, SongAdapter> createAdapter() {
62         return new SectionAdapter(getActivity(),
63                 new TopTracksAdapter(
64                         getActivity(),
65                         R.layout.list_item_top_tracks
66                 )
67         );
68     }
69
70     @Override
71     public int getLoaderId() {
72         return LOADER;
73     }
74
75     @Override
76     public void playAll(int position) {
77         MusicUtils.playSmartPlaylist(getActivity(), position,
78                 Config.SmartPlaylistType.TopTracks);
79     }
80
81     @Override
82     public void setupActionBar() {
83         ((BaseActivity)getActivity()).setupActionBar(R.string.playlist_top_tracks);
84     }
85
86     public class TopTracksAdapter extends SongAdapter {
87         public TopTracksAdapter (final Activity context, final int layoutId) {
88             super(context, layoutId);
89         }
90
91         @Override
92         public View getView(int position, View convertView, ViewGroup parent) {
93             View view = super.getView(position, convertView, parent);
94             TextView positionText = (TextView) view.findViewById(R.id.position_number);
95             positionText.setText(String.valueOf(position + 1));
96             return view;
97         }
98     }
99
100     @Override
101     public void setupNoResultsContainer(NoResultsContainer empty) {
102         super.setupNoResultsContainer(empty);
103
104         empty.setMainText(R.string.empty_top_tracks_main);
105         empty.setSecondaryText(R.string.empty_top_tracks_secondary);
106     }
107 }