OSDN Git Service

663a9ee465f74a7ae390705836dbf1b40181d1c9
[android-x86/packages-apps-Eleven.git] / src / com / cyngn / eleven / ui / fragments / RecentFragment.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;
13
14 import android.os.Bundle;
15 import android.support.v4.content.Loader;
16
17 import com.cyngn.eleven.Config;
18 import com.cyngn.eleven.R;
19 import com.cyngn.eleven.loaders.TopTracksLoader;
20 import com.cyngn.eleven.menu.FragmentMenuItems;
21 import com.cyngn.eleven.model.Song;
22 import com.cyngn.eleven.sectionadapter.SectionCreator;
23 import com.cyngn.eleven.sectionadapter.SectionListContainer;
24 import com.cyngn.eleven.ui.activities.BaseActivity;
25 import com.cyngn.eleven.ui.fragments.profile.BasicSongFragment;
26 import com.cyngn.eleven.utils.MusicUtils;
27 import com.cyngn.eleven.widgets.NoResultsContainer;
28
29 import java.util.TreeSet;
30
31 /**
32  * This class is used to display all of the recently listened to songs by the
33  * user.
34  *
35  * @author Andrew Neal (andrewdneal@gmail.com)
36  */
37 public class RecentFragment extends BasicSongFragment implements ISetupActionBar {
38
39     /**
40      * LoaderCallbacks identifier
41      */
42     private static final int LOADER = 0;
43
44     @Override
45     protected void updateMenuIds(TreeSet<Integer> set) {
46         set.add(FragmentMenuItems.REMOVE_FROM_RECENT);
47     }
48
49     /**
50      * {@inheritDoc}
51      */
52     @Override
53     public Loader<SectionListContainer<Song>> onCreateLoader(final int id, final Bundle args) {
54         TopTracksLoader loader = new TopTracksLoader(getActivity(),
55                 TopTracksLoader.QueryType.RecentSongs);
56         return new SectionCreator<Song>(getActivity(), loader, null);
57     }
58
59     /**
60      * {@inheritDoc}
61      */
62     @Override
63     public void onMetaChanged() {
64         // refresh the list since a track playing means it should be recently played
65         getLoaderManager().restartLoader(LOADER, null, this);
66     }
67
68     @Override
69     public int getLoaderId() {
70         return LOADER;
71     }
72
73     @Override
74     public void playAll(int position) {
75         MusicUtils.playSmartPlaylist(getActivity(), position,
76                 Config.SmartPlaylistType.RecentlyPlayed);
77     }
78
79     @Override
80     public void setupNoResultsContainer(NoResultsContainer empty) {
81         super.setupNoResultsContainer(empty);
82
83         empty.setMainText(R.string.empty_recent_main);
84         empty.setSecondaryText(R.string.empty_recent);
85     }
86
87     @Override
88     public void setupActionBar() {
89         ((BaseActivity)getActivity()).setupActionBar(R.string.playlist_recently_played);
90     }
91 }
92